Class AbstractConnection
- java.lang.Object
-
- org.processmining.framework.connections.impl.AbstractConnection
-
- All Implemented Interfaces:
Connection
- Direct Known Subclasses:
AbstractStrongReferencingConnection
public abstract class AbstractConnection extends java.lang.Object implements Connection
Note that for all implementations of Connection, it is essential to consider memory consumption. Connections are kept in the framework for as long as the isRemoved() method returns false, hence this method should return true at the earliest occasion. The AbstractConnection keeps weak references to the objects added through the put methods. As soon as one of these objects is collected by the garbage collector, then this connection becomes removed. Therefore, it is essential that subclasses of the AbstractConnection do not keep pointers to these objects, or at least only keep weak references. This class is annotated with @ConnectionAnnotation. Therefore, none of the implementing classes have to do so explicitly.- Author:
- bfvdonge
-
-
Field Summary
Fields Modifier and Type Field Description protected ConnectionManagermanager
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractConnection(java.lang.String label)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontainsObjects(java.lang.Object... objects)Return true if all objects given as parameter are contained in the connection.booleancontainsObjects(java.util.Collection<?> objects)Return true if all objects given as parameter are contained in the connection.booleanequals(java.lang.Object o)protected java.lang.Objectget(java.lang.String role)ConnectionIDgetID()Return the ID of the connection.java.lang.StringgetLabel()Return the label of the connectionprotected java.util.Map<java.lang.String,java.lang.ref.WeakReference<?>>getMapping()MultiSet<java.lang.Object>getObjects()Return all objects contained in this connection, without their labels.<T> TgetObjectWithRole(java.lang.String role)Return the object with the given role in this connection The type of the returned object is T.java.util.Set<java.lang.String>getRoles()Return the roles of all objects in this connectioninthashCode()booleanisRemoved()Return true if one of the objects connected by this connection no longer exists, i.e.protected <T> java.lang.ref.WeakReference<T>put(java.lang.String role, T o)voidremove()Removes the connection.protected voidremove(java.lang.String role)voidsetLabel(java.lang.String name)sets the label of the connection to the new namevoidsetManager(ConnectionManager manager)Sets the manager for the connection.java.lang.StringtoString()voidupdated()This method should be called as soon as the connection is changed, for example if the label changed, or if the contents of one of the connected objects changes.
-
-
-
Field Detail
-
manager
protected transient ConnectionManager manager
-
-
Method Detail
-
setManager
public void setManager(ConnectionManager manager)
Description copied from interface:ConnectionSets the manager for the connection. This method is called by the connection manager as soon as this connection is added to that manager. A connection should keep a reference to the manager only in a transient field.- Specified by:
setManagerin interfaceConnection
-
getLabel
public java.lang.String getLabel()
Description copied from interface:ConnectionReturn the label of the connection- Specified by:
getLabelin interfaceConnection- Returns:
-
containsObjects
public boolean containsObjects(java.lang.Object... objects)
Description copied from interface:ConnectionReturn true if all objects given as parameter are contained in the connection. Multiplicities are taken into account, however order is abstracted from- Specified by:
containsObjectsin interfaceConnection- Parameters:
objects- the objects to check for- Returns:
-
containsObjects
public boolean containsObjects(java.util.Collection<?> objects)
Description copied from interface:ConnectionReturn true if all objects given as parameter are contained in the connection. Multiplicities are taken into account, i.e. each object should occur as often as it is returned by the iterator of the given collection however order is abstracted from- Specified by:
containsObjectsin interfaceConnection- Parameters:
objects- the objects as a collection- Returns:
-
isRemoved
public boolean isRemoved()
Description copied from interface:ConnectionReturn true if one of the objects connected by this connection no longer exists, i.e. it is collected by the garbage collector.- Specified by:
isRemovedin interfaceConnection- Returns:
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
getObjects
public MultiSet<java.lang.Object> getObjects()
Description copied from interface:ConnectionReturn all objects contained in this connection, without their labels. By contract, this method should always return the same set of objects after the connections was created, i.e. connections may only be changed by changing the contents of the objects, but not by changing the pointers.- Specified by:
getObjectsin interfaceConnection- Returns:
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
getID
public ConnectionID getID()
Description copied from interface:ConnectionReturn the ID of the connection.- Specified by:
getIDin interfaceConnection- Returns:
-
getObjectWithRole
public <T> T getObjectWithRole(java.lang.String role)
Description copied from interface:ConnectionReturn the object with the given role in this connection The type of the returned object is T. However, no checks have to be performed to see if the cast can be made. It is up to the calling method to ensure this cast is safe.- Specified by:
getObjectWithRolein interfaceConnection- Type Parameters:
T- The type of object that should be returned.- Parameters:
role- the role the returned object has to have- Returns:
- the object attached to this role (not null).
-
getRoles
public java.util.Set<java.lang.String> getRoles()
Description copied from interface:ConnectionReturn the roles of all objects in this connection- Specified by:
getRolesin interfaceConnection- Returns:
-
put
protected <T> java.lang.ref.WeakReference<T> put(java.lang.String role, T o)
-
remove
protected void remove(java.lang.String role)
-
get
protected java.lang.Object get(java.lang.String role)
-
getMapping
protected java.util.Map<java.lang.String,java.lang.ref.WeakReference<?>> getMapping()
-
remove
public void remove()
Removes the connection. After calling this method, isRemoved()returns true;- Specified by:
removein interfaceConnection
-
setLabel
public void setLabel(java.lang.String name)
sets the label of the connection to the new name- Specified by:
setLabelin interfaceConnection- Parameters:
name-
-
updated
public void updated()
Description copied from interface:ConnectionThis method should be called as soon as the connection is changed, for example if the label changed, or if the contents of one of the connected objects changes. By calling this method, the connection manager should be notified.- Specified by:
updatedin interfaceConnection
-
-