public interface GraphListener extends EventListener, Serializable
There are eight interface methods, representing combinations of (before/after) (add/remove) (edge/vertex). Note that a single graph modification method call may result in multiple listener method invocations. For example, when an edge is added and an incident vertex is not already part of the graph, the vertex will be added implicitly; this results in a listener sequence like (beforeVertexAdded, afterVertexAdded, beforeEdgeAdded, afterEdgeAdded). Similarly, when a vertex is removed, all incident edges are removed as well. Listeners can detect compound events because extra event fields are set for these cases with information about the related object.
Listeners may throw exceptions from before-methods, but not after-methods. An exception thrown from a before-method causes the intended operation to fail without modifying the graph. The reason that after-methods may not throw exceptions is that by this time, the graph has already been modified, so throwing an exception would be misleading, and might also interfere with other listeners. So to be safe, a before-method should do all necessary validation on the event, and throw an exception if validation fails, but should NOT update any of the listener's own state, since the operation is not guaranteed to complete. Likewise, an after-method should update any listener state to reflect the modification which took place.
Note that in the case of compound modifications described previously, the overall operation is guaranteed to be atomic, because all before-listeners involved are invoked before any modification takes place. For example, suppose a call is made to remove a vertex which has one incident edge. First the before-listeners for both vertex and edge removal are invoked, and only then is the edge removed, and then the vertex. So if any before-listener throws an exception, the operation is aborted with no work done. Because of this ordering rule, before-listeners have to be coded carefully; when beforeEdgeAdded is called, the incident vertices might not yet have been added to the graph; likewise, when beforeVertexRemoved is called, the incident edges might not yet have been removed.
GraphListener is declared as Serializable, and when a graph is serialized, any attached GraphListeners are serialized as well. If serialization of an attached listener fails, this will cause graph serialization to fail as well, so care should be taken when developing listeners to mark fields as transient where necessary.
The source for all events originating from graph modifications is the graph itself.
To write a listener which is only interested in specific events, see salvo.jesus.graph.listener.NullGraphListener.
| Modifier and Type | Method and Description |
|---|---|
void |
afterEdgeAdded(GraphAddEdgeEvent event)
Called when an edge is being added to a graph, just after the graph
structure has actually been changed.
|
void |
afterEdgeRemoved(GraphRemoveEdgeEvent event)
Called when an edge is being removed from a graph, just after the
graph structure has actually been changed.
|
void |
afterVertexAdded(GraphAddVertexEvent event)
Called when a vertex is being added to a graph, just after the graph
structure has actually been changed.
|
void |
afterVertexRemoved(GraphRemoveVertexEvent event)
Called when a vertex is being removed from a graph, just after the
graph structure has actually been changed.
|
void |
beforeEdgeAdded(GraphAddEdgeEvent event)
Called when an edge is being added to a graph, just before the graph
structure is actually changed.
|
void |
beforeEdgeRemoved(GraphRemoveEdgeEvent event)
Called when an edge is being removed from a graph, just before the
graph structure is actually changed.
|
void |
beforeVertexAdded(GraphAddVertexEvent event)
Called when a vertex is being added to a graph, just before the graph
structure is actually changed.
|
void |
beforeVertexRemoved(GraphRemoveVertexEvent event)
Called when a vertex is being removed from a graph, just before the
graph structure is actually changed.
|
void beforeVertexAdded(GraphAddVertexEvent event) throws Exception
event - the event describing the vertex additionthe - listener may throw any Exception, which will be
propagated to the code which invoked the original graph modification
methodExceptionvoid afterVertexAdded(GraphAddVertexEvent event)
event - the event describing the vertex additionvoid beforeVertexRemoved(GraphRemoveVertexEvent event) throws Exception
event - the event describing the vertex removalthe - listener may throw any Exception, which will be
propagated to the code which invoked the original graph modification
methodExceptionvoid afterVertexRemoved(GraphRemoveVertexEvent event)
event - the event describing the vertex removalvoid beforeEdgeAdded(GraphAddEdgeEvent event) throws Exception
event - the event describing the edge additionthe - listener may throw any Exception, which will be
propagated to the code which invoked the original graph modification
methodExceptionvoid afterEdgeAdded(GraphAddEdgeEvent event)
event - the event describing the edge additionvoid beforeEdgeRemoved(GraphRemoveEdgeEvent event) throws Exception
event - the event describing the edge removalthe - listener may throw any Exception, which will be
propagated to the code which invoked the original graph modification
methodExceptionvoid afterEdgeRemoved(GraphRemoveEdgeEvent event)
event - the event describing the edge removalCopyright © 2019 JULIE Lab, Germany. All rights reserved.