Class Session

java.lang.Object
edu.cmu.tetrad.session.Session
All Implemented Interfaces:
TetradSerializable, Serializable

public final class Session extends Object implements TetradSerializable

Stores a directed graph over models of specific types, where the possible parent relationships between the models are given in the constructors of the model classes themselves. For instance, if a class Model1 has only this constructor:> 0 public Model1(Model2 x, Model3 y)...

then if a SessionNode is constructed with Model.class as argument, it will configure itself as a SessionNode requiring two parents, one capable of implementing models of type Model2 and a second capable of implementing models of type Model3. If SessionNodes capable of implementing models of types Model2 and Model3 are available as parents of Model1, a new object of type Model1 can be constructed using them. If Model1 has more than one constructor, then there is more than one possible set of parents that can be used to construct it. SessionNodes can also support more than one possible type of model. A SessionNode, for instance, can support the construction of graphs in general, even if different graphs are implemented using different classes. The SessionNode can keep track of what its parents are and therefore which of its possible models it's capable of constructing.

The Session itself keeps track of which nodes are in the session and manages adding and removing nodes. Nodes that are added to the session must be freshly constructed. This constraint eliminates a number of problems that might otherwise exist if interconnected SessionNodes were permitted to participate in more than one Session. If the addNode method is called with a node that is not in the freshly constructed state (either because it was actually just constructed or because the reset method was just called on the node), an IllegalArgumentException is thrown.

When a node is removed from a session, all of its connections to other objects are eliminated and its models destroyed. This has consequences for other objects, since destroying the model of a session node may result in the destruction of models downstream and the elimination of parent/child relationships between nodes is mutual.> 0

The Session organizes events coming from the nodes in the session so that a listener to the Session receives all events from the Session. This is convenience service so that listeners do not need to pay attention to all of the different nodes in the session individually. See SessionEvent for the types of events that are sent.> 0

It is intended for the Session to be serializable. For the Session and SessionNode classes, this can be checked directly in unit tests. For the various models that the Session can construct, this has to be tested separately.> 0

Author:
josephramsey
See Also:
  • Constructor Details

    • Session

      public Session(String name)
      Constructs a new session with the given name. (The name cannot be null.)
  • Method Details

    • serializableInstance

      public static Session serializableInstance()
      Generates a simple exemplar of this class to test serialization.
    • getName

      public String getName()
      Gets the name.
    • setName

      public void setName(String name)
      Sets the name.
    • addNode

      public void addNode(SessionNode node)

      Adds the given node to the session, provided the node is in a freshly created state.> 0

      Throws:
      NullPointerException - if the node is null.
      IllegalArgumentException - if the node is not in a freshly created state. There are two ways to put a SessionNode into a freshly created state. One is to freshly create it, using one of the constructors. The other was is to call the reset method on the SessionNode.
      See Also:
    • addNodeList

      public void addNodeList(List<SessionNode> nodes)
      Adds a list of nodes to the session. Each item in the list must be a SessionNode, and none of them may have a name that already exists in the session. Upon being added to the session, if any node has a parent that is not in the list, the parent is removed, the node's model is destroyed, and any models downstream are destroyed as well. Any children not in the list are removed. Also, any listeners that are not SessionNodes are removed from each node.
    • removeNode

      public void removeNode(SessionNode node)

      Removes the given node from the session, removing any connectivity the node might have to other objects.> 0

      Parameters:
      node - the SessionNode to be removed.
      Throws:
      IllegalArgumentException - if the specified node is not in the session.
      See Also:
    • getNodes

      public Set<SessionNode> getNodes()
      Returns:
      the getModel set of session nodes.
    • clearNodes

      public void clearNodes()
      Removes all nodes.
    • contains

      public boolean contains(SessionNode node)
    • addSessionListener

      public void addSessionListener(SessionListener l)
      Adds a session listener.
    • removeSessionListener

      public void removeSessionListener(SessionListener l)
      Removes a session listener.
    • isSessionChanged

      public boolean isSessionChanged()
    • setSessionChanged

      public void setSessionChanged(boolean sessionChanged)
    • isNewSession

      public boolean isNewSession()
    • setNewSession

      public void setNewSession(boolean newSession)
    • isEmpty

      public boolean isEmpty()