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 ConnectionManager
manager
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractConnection(java.lang.String label)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
containsObjects(java.lang.Object... objects)
Return true if all objects given as parameter are contained in the connection.boolean
containsObjects(java.util.Collection<?> objects)
Return true if all objects given as parameter are contained in the connection.boolean
equals(java.lang.Object o)
protected java.lang.Object
get(java.lang.String role)
ConnectionID
getID()
Return the ID of the connection.java.lang.String
getLabel()
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> T
getObjectWithRole(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 connectionint
hashCode()
boolean
isRemoved()
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)
void
remove()
Removes the connection.protected void
remove(java.lang.String role)
void
setLabel(java.lang.String name)
sets the label of the connection to the new namevoid
setManager(ConnectionManager manager)
Sets the manager for the connection.java.lang.String
toString()
void
updated()
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:Connection
Sets 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:
setManager
in interfaceConnection
-
getLabel
public java.lang.String getLabel()
Description copied from interface:Connection
Return the label of the connection- Specified by:
getLabel
in interfaceConnection
- Returns:
-
containsObjects
public boolean containsObjects(java.lang.Object... objects)
Description copied from interface:Connection
Return true if all objects given as parameter are contained in the connection. Multiplicities are taken into account, however order is abstracted from- Specified by:
containsObjects
in interfaceConnection
- Parameters:
objects
- the objects to check for- Returns:
-
containsObjects
public boolean containsObjects(java.util.Collection<?> objects)
Description copied from interface:Connection
Return 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:
containsObjects
in interfaceConnection
- Parameters:
objects
- the objects as a collection- Returns:
-
isRemoved
public boolean isRemoved()
Description copied from interface:Connection
Return true if one of the objects connected by this connection no longer exists, i.e. it is collected by the garbage collector.- Specified by:
isRemoved
in interfaceConnection
- Returns:
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
getObjects
public MultiSet<java.lang.Object> getObjects()
Description copied from interface:Connection
Return 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:
getObjects
in interfaceConnection
- Returns:
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
getID
public ConnectionID getID()
Description copied from interface:Connection
Return the ID of the connection.- Specified by:
getID
in interfaceConnection
- Returns:
-
getObjectWithRole
public <T> T getObjectWithRole(java.lang.String role)
Description copied from interface:Connection
Return 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:
getObjectWithRole
in 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:Connection
Return the roles of all objects in this connection- Specified by:
getRoles
in 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:
remove
in interfaceConnection
-
setLabel
public void setLabel(java.lang.String name)
sets the label of the connection to the new name- Specified by:
setLabel
in interfaceConnection
- Parameters:
name
-
-
updated
public void updated()
Description copied from interface:Connection
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. By calling this method, the connection manager should be notified.- Specified by:
updated
in interfaceConnection
-
-