Class SourceBase

java.lang.Object
org.graphstream.stream.SourceBase
All Implemented Interfaces:
Source
Direct Known Subclasses:
BarnesHutLayout, ByteProxy, FileSourceBase, FileSourceParser, FileSourceXML, GraphListeners, GraphReplay, NetStreamDecoder, PipeBase, ThreadProxyPipe, ViewerPipe

public abstract class SourceBase
extends Object
implements Source
Base implementation of an input that provide basic sink handling.

This implementation can register a set of graph sinks (or separate sets of attributes or elements sinks) and provides protected methods to easily broadcast events to all the sinks (beginning with "send").

Each time you want to produce an event toward all registered sinks, you call one of the "send*" methods with correct parameters. The parameters of the "send*" methods maps to the usual GraphStream events.

This class is "reentrant". This means that if a send*() method is called during the execution of another or the same send*() method, the event is deferred until the first send*() method is finished. This avoid recursive loops if a sink modifies the input during event handling.

  • Method Details

    • attributeSinks

      public Iterable<AttributeSink> attributeSinks()
    • elementSinks

      public Iterable<ElementSink> elementSinks()
    • addSink

      public void addSink​(Sink sink)
      Description copied from interface: Source
      Add a sink for all graph events (attributes and graph elements) coming from this source. This is similar to registering a sink for attributes an another for elements.
      Specified by:
      addSink in interface Source
      Parameters:
      sink - The sink to register.
    • addAttributeSink

      public void addAttributeSink​(AttributeSink sink)
      Description copied from interface: Source
      Add a sink for attribute events only. Attribute events include attribute addition change and removal.
      Specified by:
      addAttributeSink in interface Source
      Parameters:
      sink - The sink to register.
    • addElementSink

      public void addElementSink​(ElementSink sink)
      Description copied from interface: Source
      Add a sink for elements events only. Elements events include, addition and removal of nodes and edges, as well as step events.
      Specified by:
      addElementSink in interface Source
      Parameters:
      sink - The sink to register.
    • clearSinks

      public void clearSinks()
      Description copied from interface: Source
      Remove all listener sinks.
      Specified by:
      clearSinks in interface Source
    • clearElementSinks

      public void clearElementSinks()
      Description copied from interface: Source
      Remove all listener element sinks.
      Specified by:
      clearElementSinks in interface Source
    • clearAttributeSinks

      public void clearAttributeSinks()
      Description copied from interface: Source
      Remove all listener attribute sinks.
      Specified by:
      clearAttributeSinks in interface Source
    • removeSink

      public void removeSink​(Sink sink)
      Description copied from interface: Source
      Remove a sink.
      Specified by:
      removeSink in interface Source
      Parameters:
      sink - The sink to remove, if it does not exist, this is ignored silently.
    • removeAttributeSink

      public void removeAttributeSink​(AttributeSink sink)
      Description copied from interface: Source
      Remove an attribute sink.
      Specified by:
      removeAttributeSink in interface Source
      Parameters:
      sink - The sink to remove, if it does not exist, this is ignored silently.
    • removeElementSink

      public void removeElementSink​(ElementSink sink)
      Description copied from interface: Source
      Remove an element sink.
      Specified by:
      removeElementSink in interface Source
      Parameters:
      sink - The sink to remove, if it does not exist, this is ignored silently.
    • sendGraphCleared

      public void sendGraphCleared​(String sourceId)
      Send a "graph cleared" event to all element sinks.
      Parameters:
      sourceId - The source identifier.
    • sendGraphCleared

      public void sendGraphCleared​(String sourceId, long timeId)
      Send a "graph cleared" event to all element sinks.
      Parameters:
      sourceId - The source identifier.
      timeId -
    • sendStepBegins

      public void sendStepBegins​(String sourceId, double step)
      Send a "step begins" event to all element sinks.
      Parameters:
      sourceId - The graph identifier.
      step - The step time stamp.
    • sendStepBegins

      public void sendStepBegins​(String sourceId, long timeId, double step)
      Send a "step begins" event to all element sinks.
      Parameters:
      sourceId - The graph identifier.
      timeId -
      step - The step time stamp.
    • sendNodeAdded

      public void sendNodeAdded​(String sourceId, String nodeId)
      Send a "node added" event to all element sinks.
      Parameters:
      sourceId - The source identifier.
      nodeId - The node identifier.
    • sendNodeAdded

      public void sendNodeAdded​(String sourceId, long timeId, String nodeId)
      Send a "node added" event to all element sinks.
      Parameters:
      sourceId - The source identifier.
      timeId -
      nodeId - The node identifier.
    • sendNodeRemoved

      public void sendNodeRemoved​(String sourceId, String nodeId)
      Send a "node removed" event to all element sinks.
      Parameters:
      sourceId - The graph identifier.
      nodeId - The node identifier.
    • sendNodeRemoved

      public void sendNodeRemoved​(String sourceId, long timeId, String nodeId)
      Send a "node removed" event to all element sinks.
      Parameters:
      sourceId - The graph identifier.
      timeId -
      nodeId - The node identifier.
    • sendEdgeAdded

      public void sendEdgeAdded​(String sourceId, String edgeId, String fromNodeId, String toNodeId, boolean directed)
      Send an "edge added" event to all element sinks.
      Parameters:
      sourceId - The source identifier.
      edgeId - The edge identifier.
      fromNodeId - The edge start node.
      toNodeId - The edge end node.
      directed - Is the edge directed?.
    • sendEdgeAdded

      public void sendEdgeAdded​(String sourceId, long timeId, String edgeId, String fromNodeId, String toNodeId, boolean directed)
      Send an "edge added" event to all element sinks.
      Parameters:
      sourceId - The source identifier.
      timeId -
      edgeId - The edge identifier.
      fromNodeId - The edge start node.
      toNodeId - The edge end node.
      directed - Is the edge directed?.
    • sendEdgeRemoved

      public void sendEdgeRemoved​(String sourceId, String edgeId)
      Send a "edge removed" event to all element sinks.
      Parameters:
      sourceId - The source identifier.
      edgeId - The edge identifier.
    • sendEdgeRemoved

      public void sendEdgeRemoved​(String sourceId, long timeId, String edgeId)
      Send a "edge removed" event to all element sinks.
      Parameters:
      sourceId - The source identifier.
      timeId -
      edgeId - The edge identifier.
    • sendEdgeAttributeAdded

      public void sendEdgeAttributeAdded​(String sourceId, String edgeId, String attribute, Object value)
      Send a "edge attribute added" event to all attribute sinks.
      Parameters:
      sourceId - The source identifier.
      edgeId - The edge identifier.
      attribute - The attribute name.
      value - The attribute value.
    • sendEdgeAttributeAdded

      public void sendEdgeAttributeAdded​(String sourceId, long timeId, String edgeId, String attribute, Object value)
      Send a "edge attribute added" event to all attribute sinks.
      Parameters:
      sourceId - The source identifier.
      timeId -
      edgeId - The edge identifier.
      attribute - The attribute name.
      value - The attribute value.
    • sendEdgeAttributeChanged

      public void sendEdgeAttributeChanged​(String sourceId, String edgeId, String attribute, Object oldValue, Object newValue)
      Send a "edge attribute changed" event to all attribute sinks.
      Parameters:
      sourceId - The source identifier.
      edgeId - The edge identifier.
      attribute - The attribute name.
      oldValue - The old attribute value.
      newValue - The new attribute value.
    • sendEdgeAttributeChanged

      public void sendEdgeAttributeChanged​(String sourceId, long timeId, String edgeId, String attribute, Object oldValue, Object newValue)
      Send a "edge attribute changed" event to all attribute sinks.
      Parameters:
      sourceId - The source identifier.
      timeId -
      edgeId - The edge identifier.
      attribute - The attribute name.
      oldValue - The old attribute value.
      newValue - The new attribute value.
    • sendEdgeAttributeRemoved

      public void sendEdgeAttributeRemoved​(String sourceId, String edgeId, String attribute)
      Send a "edge attribute removed" event to all attribute sinks.
      Parameters:
      sourceId - The source identifier.
      edgeId - The edge identifier.
      attribute - The attribute name.
    • sendEdgeAttributeRemoved

      public void sendEdgeAttributeRemoved​(String sourceId, long timeId, String edgeId, String attribute)
      Send a "edge attribute removed" event to all attribute sinks.
      Parameters:
      sourceId - The source identifier.
      timeId -
      edgeId - The edge identifier.
      attribute - The attribute name.
    • sendGraphAttributeAdded

      public void sendGraphAttributeAdded​(String sourceId, String attribute, Object value)
      Send a "graph attribute added" event to all attribute sinks.
      Parameters:
      sourceId - The source identifier.
      attribute - The attribute name.
      value - The attribute value.
    • sendGraphAttributeAdded

      public void sendGraphAttributeAdded​(String sourceId, long timeId, String attribute, Object value)
      Send a "graph attribute added" event to all attribute sinks.
      Parameters:
      sourceId - The source identifier.
      timeId -
      attribute - The attribute name.
      value - The attribute value.
    • sendGraphAttributeChanged

      public void sendGraphAttributeChanged​(String sourceId, String attribute, Object oldValue, Object newValue)
      Send a "graph attribute changed" event to all attribute sinks.
      Parameters:
      sourceId - The source identifier.
      attribute - The attribute name.
      oldValue - The attribute old value.
      newValue - The attribute new value.
    • sendGraphAttributeChanged

      public void sendGraphAttributeChanged​(String sourceId, long timeId, String attribute, Object oldValue, Object newValue)
      Send a "graph attribute changed" event to all attribute sinks.
      Parameters:
      sourceId - The source identifier.
      timeId -
      attribute - The attribute name.
      oldValue - The attribute old value.
      newValue - The attribute new value.
    • sendGraphAttributeRemoved

      public void sendGraphAttributeRemoved​(String sourceId, String attribute)
      Send a "graph attribute removed" event to all attribute sinks.
      Parameters:
      sourceId - The source identifier.
      attribute - The attribute name.
    • sendGraphAttributeRemoved

      public void sendGraphAttributeRemoved​(String sourceId, long timeId, String attribute)
      Send a "graph attribute removed" event to all attribute sinks.
      Parameters:
      sourceId - The source identifier.
      timeId -
      attribute - The attribute name.
    • sendNodeAttributeAdded

      public void sendNodeAttributeAdded​(String sourceId, String nodeId, String attribute, Object value)
      Send a "node attribute added" event to all attribute sinks.
      Parameters:
      sourceId - The source identifier.
      nodeId - The node identifier.
      attribute - The attribute name.
      value - The attribute value.
    • sendNodeAttributeAdded

      public void sendNodeAttributeAdded​(String sourceId, long timeId, String nodeId, String attribute, Object value)
      Send a "node attribute added" event to all attribute sinks.
      Parameters:
      sourceId - The source identifier.
      timeId -
      nodeId - The node identifier.
      attribute - The attribute name.
      value - The attribute value.
    • sendNodeAttributeChanged

      public void sendNodeAttributeChanged​(String sourceId, String nodeId, String attribute, Object oldValue, Object newValue)
      Send a "node attribute changed" event to all attribute sinks.
      Parameters:
      sourceId - The source identifier.
      nodeId - The node identifier.
      attribute - The attribute name.
      oldValue - The attribute old value.
      newValue - The attribute new value.
    • sendNodeAttributeChanged

      public void sendNodeAttributeChanged​(String sourceId, long timeId, String nodeId, String attribute, Object oldValue, Object newValue)
      Send a "node attribute changed" event to all attribute sinks.
      Parameters:
      sourceId - The source identifier.
      timeId -
      nodeId - The node identifier.
      attribute - The attribute name.
      oldValue - The attribute old value.
      newValue - The attribute new value.
    • sendNodeAttributeRemoved

      public void sendNodeAttributeRemoved​(String sourceId, String nodeId, String attribute)
      Send a "node attribute removed" event to all attribute sinks.
      Parameters:
      sourceId - The source identifier.
      nodeId - The node identifier.
      attribute - The attribute name.
    • sendNodeAttributeRemoved

      public void sendNodeAttributeRemoved​(String sourceId, long timeId, String nodeId, String attribute)
      Send a "node attribute removed" event to all attribute sinks.
      Parameters:
      sourceId - The source identifier.
      timeId -
      nodeId - The node identifier.
      attribute - The attribute name.
    • sendAttributeChangedEvent

      public void sendAttributeChangedEvent​(String sourceId, String eltId, SourceBase.ElementType eltType, String attribute, AbstractElement.AttributeChangeEvent event, Object oldValue, Object newValue)
      Send a add/change/remove attribute event on an element. This method is a generic way of notifying of an attribute change and is equivalent to individual send*Attribute*() methods.
      Parameters:
      sourceId - The source identifier.
      eltId - The changed element identifier.
      eltType - The changed element type.
      attribute - The changed attribute.
      event - The add/change/remove action.
      oldValue - The old attribute value (null if the attribute is removed or added).
      newValue - The new attribute value (null if removed).
    • sendAttributeChangedEvent

      public void sendAttributeChangedEvent​(String sourceId, long timeId, String eltId, SourceBase.ElementType eltType, String attribute, AbstractElement.AttributeChangeEvent event, Object oldValue, Object newValue)