Class ThreadProxyPipe

java.lang.Object
org.graphstream.stream.SourceBase
org.graphstream.stream.thread.ThreadProxyPipe
All Implemented Interfaces:
AttributeSink, ElementSink, Pipe, ProxyPipe, Sink, Source

public class ThreadProxyPipe
extends SourceBase
implements ProxyPipe
Filter that allows to pass graph events between two threads without explicit synchronization.

This filter allows to register it as an output for some source of events in a source thread (hereafter called the input thread) and to register listening outputs in a destination thread (hereafter called the sink thread).

                       |
   Source ---> ThreadProxyFilter ----> Sink
  Thread 1             |              Thread 2
                       |
 

In other words, this class allows to listen in a sink thread graph events that are produced in another source thread without any explicit synchronization on the source of events.

The only restriction is that the sink thread must regularly call the pump() method to dispatch events coming from the source to all sinks registered (see the explanation in ProxyPipe).

You can register any kind of input as source of event, but if the input is a graph, then you can choose to "replay" all the content of the graph so that at the other end of the filter, all outputs receive the complete content of the graph. This is the default behavior if this filter is constructed with a graph as input.

  • Constructor Details

  • Method Details

    • init

      public void init()
    • init

      public void init​(Source source)
      Init the proxy. If there are previous events, they will be cleared.
      Parameters:
      source - source of the events
    • init

      public void init​(Source source, boolean replay)
      Init the proxy. If there are previous events, they will be cleared.
      Parameters:
      source - source of the events
      replay - true if the source should be replayed. You need a Replayable source to enable replay, else nothing happens.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • unregisterFromSource

      public void unregisterFromSource()
      Ask the proxy to unregister from the event input source (stop receive events) as soon as possible (when the next event will occur in the graph).
    • pump

      public void pump()
      This method must be called regularly in the output thread to check if the input source sent events. If some event occurred, the listeners will be called.
      Specified by:
      pump in interface ProxyPipe
    • blockingPump

      public void blockingPump() throws InterruptedException
      Description copied from interface: ProxyPipe
      Same as ProxyPipe.pump() but try to block until new events were available. Note that this feature will not be available on all proxy pipe implementation and may throws an UnsupportedOperationException. It can throw an InterruptedException if the current thread is interrupted while proxy is waiting for events.
      Specified by:
      blockingPump in interface ProxyPipe
      Throws:
      InterruptedException
    • blockingPump

      public void blockingPump​(long timeout) throws InterruptedException
      Description copied from interface: ProxyPipe
      Same as ProxyPipe.blockingPump() but including a timeout delay.
      Specified by:
      blockingPump in interface ProxyPipe
      Throws:
      InterruptedException
    • hasPostRemaining

      public boolean hasPostRemaining()
    • edgeAttributeAdded

      public void edgeAttributeAdded​(String graphId, long timeId, String edgeId, String attribute, Object value)
      Description copied from interface: AttributeSink
      A edge attribute was added.
      Specified by:
      edgeAttributeAdded in interface AttributeSink
      Parameters:
      graphId - Identifier of the graph where the change occurred.
      edgeId - Identifier of the edge whose attribute changed.
      attribute - The attribute name.
      value - The attribute new value.
    • edgeAttributeChanged

      public void edgeAttributeChanged​(String graphId, long timeId, String edgeId, String attribute, Object oldValue, Object newValue)
      Description copied from interface: AttributeSink
      A edge attribute was changed.
      Specified by:
      edgeAttributeChanged in interface AttributeSink
      Parameters:
      graphId - Identifier of the graph where the change occurred.
      edgeId - Identifier of the edge whose attribute changed.
      attribute - The attribute name.
      oldValue - The attribute old value.
      newValue - The attribute new value.
    • edgeAttributeRemoved

      public void edgeAttributeRemoved​(String graphId, long timeId, String edgeId, String attribute)
      Description copied from interface: AttributeSink
      A edge attribute was removed.
      Specified by:
      edgeAttributeRemoved in interface AttributeSink
      Parameters:
      graphId - Identifier of the graph where the attribute was removed.
      edgeId - Identifier of the edge whose attribute was removed.
      attribute - The removed attribute name.
    • graphAttributeAdded

      public void graphAttributeAdded​(String graphId, long timeId, String attribute, Object value)
      Description copied from interface: AttributeSink
      A graph attribute was added.
      Specified by:
      graphAttributeAdded in interface AttributeSink
      Parameters:
      graphId - Identifier of the graph where the attribute changed.
      attribute - The attribute name.
      value - The attribute new value.
    • graphAttributeChanged

      public void graphAttributeChanged​(String graphId, long timeId, String attribute, Object oldValue, Object newValue)
      Description copied from interface: AttributeSink
      A graph attribute was changed.
      Specified by:
      graphAttributeChanged in interface AttributeSink
      Parameters:
      graphId - Identifier of the graph where the attribute changed.
      attribute - The attribute name.
      oldValue - The attribute old value.
      newValue - The attribute new value.
    • graphAttributeRemoved

      public void graphAttributeRemoved​(String graphId, long timeId, String attribute)
      Description copied from interface: AttributeSink
      A graph attribute was removed.
      Specified by:
      graphAttributeRemoved in interface AttributeSink
      Parameters:
      graphId - Identifier of the graph where the attribute was removed.
      attribute - The removed attribute name.
    • nodeAttributeAdded

      public void nodeAttributeAdded​(String graphId, long timeId, String nodeId, String attribute, Object value)
      Description copied from interface: AttributeSink
      A node attribute was added.
      Specified by:
      nodeAttributeAdded in interface AttributeSink
      Parameters:
      graphId - Identifier of the graph where the change occurred.
      nodeId - Identifier of the node whose attribute changed.
      attribute - The attribute name.
      value - The attribute new value.
    • nodeAttributeChanged

      public void nodeAttributeChanged​(String graphId, long timeId, String nodeId, String attribute, Object oldValue, Object newValue)
      Description copied from interface: AttributeSink
      A node attribute was changed.
      Specified by:
      nodeAttributeChanged in interface AttributeSink
      Parameters:
      graphId - Identifier of the graph where the change occurred.
      nodeId - Identifier of the node whose attribute changed.
      attribute - The attribute name.
      oldValue - The attribute old value.
      newValue - The attribute new value.
    • nodeAttributeRemoved

      public void nodeAttributeRemoved​(String graphId, long timeId, String nodeId, String attribute)
      Description copied from interface: AttributeSink
      A node attribute was removed.
      Specified by:
      nodeAttributeRemoved in interface AttributeSink
      Parameters:
      graphId - Identifier of the graph where the attribute was removed.
      nodeId - Identifier of the node whose attribute was removed.
      attribute - The removed attribute name.
    • edgeAdded

      public void edgeAdded​(String graphId, long timeId, String edgeId, String fromNodeId, String toNodeId, boolean directed)
      Description copied from interface: ElementSink
      An edge was inserted in graph.
      Specified by:
      edgeAdded in interface ElementSink
      Parameters:
      graphId - Identifier of the graph where the edge was added.
      edgeId - Identifier of the added edge.
      fromNodeId - Identifier of the first node of the edge.
      toNodeId - Identifier of the second node of the edge.
      directed - If true, the edge is directed.
    • edgeRemoved

      public void edgeRemoved​(String graphId, long timeId, String edgeId)
      Description copied from interface: ElementSink
      An edge of graph was removed.The nodes the edge connects may already have been removed from the graph.
      Specified by:
      edgeRemoved in interface ElementSink
      Parameters:
      graphId - The graph where the edge will be removed.
      edgeId - The edge that will be removed.
    • graphCleared

      public void graphCleared​(String graphId, long timeId)
      Description copied from interface: ElementSink
      The whole graph was cleared. All the nodes, edges and attributes of the graph are removed.
      Specified by:
      graphCleared in interface ElementSink
      Parameters:
      graphId - The graph cleared.
    • nodeAdded

      public void nodeAdded​(String graphId, long timeId, String nodeId)
      Description copied from interface: ElementSink
      A node was inserted in the given graph.
      Specified by:
      nodeAdded in interface ElementSink
      Parameters:
      graphId - Identifier of the graph where the node was added.
      nodeId - Identifier of the added node.
    • nodeRemoved

      public void nodeRemoved​(String graphId, long timeId, String nodeId)
      Description copied from interface: ElementSink
      A node was removed from the graph.
      Specified by:
      nodeRemoved in interface ElementSink
      Parameters:
      graphId - Identifier of the graph where the node will be removed.
      nodeId - Identifier of the removed node.
    • stepBegins

      public void stepBegins​(String graphId, long timeId, double step)
      Description copied from interface: ElementSink

      Since dynamic graphs are based on discrete event modifications, the notion of step is defined to simulate elapsed time between events. So a step is a event that occurs in the graph, it does not modify it but it gives a kind of timestamp that allow the tracking of the progress of the graph over the time.

      This kind of event is useful for dynamic algorithms that listen to the dynamic graph and need to measure the time in the graph's evolution.

      Specified by:
      stepBegins in interface ElementSink
      Parameters:
      graphId - Identifier of the graph where the step starts.
      timeId - A numerical value that may give a timestamp to track the evolution of the graph over the time.