org.objectweb.jac.core
Class Collaboration

java.lang.Object
  |
  +--org.objectweb.jac.core.Collaboration
All Implemented Interfaces:
Serializable

public class Collaboration
extends Object
implements Serializable

This class represents a set of contextual informations for a given thread of a running JAC system.

For each method call on a JAC object, a new interaction is started on the current collaboration. At any point of the program, the programmer can get the current collaboration for the current thread by using get().

The CollaborationParticipant interface provides a more friendly interface to access the current collaboration. In a clean design, only the classes that implement this interface may access the collaboration.

Author:
Renaud Pawlak, Eddy Truyen
See Also:
get(), CollaborationParticipant, Serialized Form

Field Summary
static Object GLOBAL
          The attribute is global to all the sites (it is serialized and transmitted with the collaboration)
 
Constructor Summary
Collaboration()
          Creates an new collaboration.
Collaboration(Collaboration parent)
          Create a new Collaboration and initialiaze it's attribute from a parent Collaboration.
 
Method Summary
 Object addAttribute(String name, Object att)
          Add a persistent attribute to the collaboration (can be done by any Jac object).
 Collection attributeNames()
          Returns a collection of all attribute names
static Collaboration get()
          Get the collaboration for the current thread.
 Object getAttribute(String name)
          Return the value of an attribute for the current collaboration.
 Map getAttributes()
          Returns the map of attribute's name -> value
 String getCurApp()
           
static Collection globalAttributeNames()
           
static boolean isGlobal(String attrName)
          Returns true if the attribute is global.
 void removeAttribute(String name)
          Removes the attribute from the current collaboration.
 void reset()
          Reset the Collaboration.
static void set(Collaboration collaboration)
          Set a new collaboration for the current thread.
 void setAttributes(Map attributes)
          Set some attributes.
 void setCurApp(String app)
           
static void setGlobal(String attrName)
          Sets an attribute to be global.
 String toString()
          Returns a textual representation of the collaboration.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

GLOBAL

public static Object GLOBAL
The attribute is global to all the sites (it is serialized and transmitted with the collaboration)

Constructor Detail

Collaboration

public Collaboration()
Creates an new collaboration.

The programmer should not explicitly create a new collaboration since this is automatically done by the system for any new thread.

At any point of the program, the programmer can get the current collaboration for the current thread by using Collaboration.get().

See Also:
get()

Collaboration

public Collaboration(Collaboration parent)
Create a new Collaboration and initialiaze it's attribute from a parent Collaboration.

Parameters:
parent - the parent collaboration
Method Detail

isGlobal

public static boolean isGlobal(String attrName)
Returns true if the attribute is global. The attribute is then transmitted to the remote sites reached by the collaboration. Note that a global attribute must always be serializable. If the attribute is not global, it always stays on the site where it has been defined.

By default, if the setGlobal method is not called, all the attributes are local.

See Also:
setGlobal(String)

setGlobal

public static void setGlobal(String attrName)
Sets an attribute to be global.

This method should only be called once for each attribute and before the first initialization of the attribute value in the collaboration since the globality is an inherent caracteristic of an attribute.


get

public static Collaboration get()
Get the collaboration for the current thread.

Returns:
the current collaboration

set

public static void set(Collaboration collaboration)
Set a new collaboration for the current thread.

Parameters:
collaboration - the collaboration

attributeNames

public Collection attributeNames()
Returns a collection of all attribute names


globalAttributeNames

public static Collection globalAttributeNames()

getAttributes

public Map getAttributes()
Returns the map of attribute's name -> value


setAttributes

public void setAttributes(Map attributes)
Set some attributes. Do not override current attributes.

Parameters:
attributes - map of name->value of attributes to set.

reset

public void reset()
Reset the Collaboration.

Clears interactions, and all attributes.


addAttribute

public Object addAttribute(String name,
                           Object att)
Add a persistent attribute to the collaboration (can be done by any Jac object).

NOTE: a persitent attribute is visible for all the objects of a collaboration.

Parameters:
name - the name of the attribute
att - the value of the attribute

getAttribute

public Object getAttribute(String name)
Return the value of an attribute for the current collaboration.

This method first seeks into the persistent attributes. If none matches, it seeks into the transient attributes. If still not found, finally seeks into the transient local attributes. If all the lookups failed, return null.

Parameters:
name - the name of the attribute
Returns:
the value of the attribute

removeAttribute

public void removeAttribute(String name)
Removes the attribute from the current collaboration.


setCurApp

public final void setCurApp(String app)

getCurApp

public final String getCurApp()

toString

public String toString()
Returns a textual representation of the collaboration.

Overrides:
toString in class Object