org.objectweb.jac.aspects.distribution.consistency
Class ConsistencyWrapper

java.lang.Object
  extended byorg.objectweb.jac.core.Wrapper
      extended byorg.objectweb.jac.aspects.distribution.consistency.ConsistencyWrapper
All Implemented Interfaces:
Advice, ConstructorInterceptor, Interceptor, MethodInterceptor, Serializable
Direct Known Subclasses:
ClientServerConsistencyWrapper, StrongPullConsistencyWrapper, StrongPushConsistencyWrapper, WeakConsistencyWrapper

public class ConsistencyWrapper
extends Wrapper

This wrapper class is the base class for all the consistency wrappers that implement a consistency protocol.

By default it does nothing and provides no consistency at all between the replicas. A consistency programmer should define the wrapping and role method to implement a specific consistency protocol.

Author:
Renaud Pawlak
See Also:
Serialized Form

Field Summary
static String ALL_GETTERS
          Use to indicate that you need all the getters.
static String ALL_METHODS
          Use to indicate that you need all the methods.
static String ALL_MODIFIERS
          Use to indicate that you need all the modifiers.
protected  Vector knownReplicas
          Storage for known replicas.
protected static String visitedReplicas
          Visited sites global attribute name.
 
Fields inherited from class org.objectweb.jac.core.Wrapper
ac, cr
 
Constructor Summary
ConsistencyWrapper(AspectComponent ac)
          Default constructor.
ConsistencyWrapper(AspectComponent ac, Class type, String[] readMethods, String[] writeMethods, String[] callMethods, String hosts)
          Contructor for initialization.
 
Method Summary
 Object acceptRemoteCall(RemoteRef remoteReplica, Object[] data)
          This role method can called by the whenCall wrapping method of a remote replica.
 Object acceptRemoteRead(Wrappee wrappee, RemoteRef remoteReplica, Object[] data)
          This role method can called by the whenRead wrapping method of a remote replica.
 Object acceptRemoteWrite(Wrappee wrappee, RemoteRef remoteReplica, Object[] data)
          This role method can called by the whenWrite wrapping method of a remote replica.
 void addKnownReplica(RemoteRef newReplica)
          Adds a known replica.
 void addMember(RemoteRef newReplica)
          Add a replica to the knowledge graph.
 Object construct(ConstructorInvocation invocation)
           
protected  String[] expandMethods(String[] methods)
          Construct a real methods array with an array that can contain consistency specific strings (like the one that indicates that we need all the modifiers).
 Class getConsistencyWrapperType()
          The get method for the consistency wrapper actual type.
 Vector getKnownReplicas()
          The getter method for the known replicas.
 String getVisitedReplicas()
          Returns the visited replicas global attribute of the collaboration.
 void invalidateTopology()
          Invalidates the topology.
 Object invoke(MethodInvocation invocation)
           
 void setCallMethods(String[] callMethods)
          Set the call method names (methods that neither write or read the replica state).
 void setKnownReplicas(Vector knownReplicas)
          The setter method for the known replicas.
 void setReadMethods(String[] readMethods)
          Set the read method names (methods that read the replica state).
 void setWriteMethods(String[] writeMethods)
          Set the write method names (methods that change the replica state).
 String toString()
          Returns a string representation of the wrapper.
 void whenBindingNewReplica(RemoteRef newReplica)
          This method is called when new member is bounded to the replication group.
 Object whenCall(Interaction interaction)
          This wrapping method must be defined to implement a given builtin consistency protocol and must wrap the replica methods that need to be consistent with the other replicas.
 void whenNewReplicaBounded(RemoteRef remoteReplica)
          This method is called on the new member when the binding is finished.
 Object whenRead(Interaction interaction)
          This wrapping method must be defined to implement a given builtin consistency protocol and must wrap all the replica methods that read the replica state.
 Object whenWrite(Interaction interaction)
          This wrapping method must be defined to implement a given builtin consistency protocol and must wrap all the replicas methods that provoque a change in this replica state.
static void wrap(Wrappee wrappee, Class wrapperClass, String[] readMethods, String[] writeMethods, String[] callMethods, String hosts)
          Wraps a wrappee with a consistency wrapper.
 
Methods inherited from class org.objectweb.jac.core.Wrapper
attr, attrdef, defines, getAspectComponent, getAspectComponentName, getExceptionHandlers, proceed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

knownReplicas

protected Vector knownReplicas
Storage for known replicas.


visitedReplicas

protected static String visitedReplicas
Visited sites global attribute name.


ALL_METHODS

public static String ALL_METHODS
Use to indicate that you need all the methods.


ALL_MODIFIERS

public static String ALL_MODIFIERS
Use to indicate that you need all the modifiers.


ALL_GETTERS

public static String ALL_GETTERS
Use to indicate that you need all the getters.

Constructor Detail

ConsistencyWrapper

public ConsistencyWrapper(AspectComponent ac)
Default constructor.


ConsistencyWrapper

public ConsistencyWrapper(AspectComponent ac,
                          Class type,
                          String[] readMethods,
                          String[] writeMethods,
                          String[] callMethods,
                          String hosts)
Contructor for initialization.

Parameters:
type - the type of the wrappee
readMethods - the methods that read the wrappee's state
writeMethods - the methods that write the wrappee's state
callMethods - the stateless methods
Method Detail

wrap

public static void wrap(Wrappee wrappee,
                        Class wrapperClass,
                        String[] readMethods,
                        String[] writeMethods,
                        String[] callMethods,
                        String hosts)
Wraps a wrappee with a consistency wrapper.


addMember

public void addMember(RemoteRef newReplica)
Add a replica to the knowledge graph.

The way the member is added to the knowledge graph depends on the knowledge graph.

Parameters:
newReplica - the reference on the replica to add

invalidateTopology

public void invalidateTopology()
Invalidates the topology.

When this method is called, the next consistency protocol run will recalculate the known replica with the new topology.


whenBindingNewReplica

public void whenBindingNewReplica(RemoteRef newReplica)
This method is called when new member is bounded to the replication group.

It is typically used to initialize (in a push manner) the new member state with the data that need to be replicated. By default, this method does nothing.

Parameters:
newReplica - the replica that is beeing added

whenNewReplicaBounded

public void whenNewReplicaBounded(RemoteRef remoteReplica)
This method is called on the new member when the binding is finished.

It is typically used to initialize (in a pull manner) the new member state with the data that need to be replicated. By default, this method does nothing.

Parameters:
remoteReplica - the replica that has just been bounded

getVisitedReplicas

public String getVisitedReplicas()
Returns the visited replicas global attribute of the collaboration.

Returns:
the name of the attribute

toString

public String toString()
Returns a string representation of the wrapper.

Overrides:
toString in class Wrapper
Returns:
a string representation of the wrapper

setReadMethods

public void setReadMethods(String[] readMethods)
Set the read method names (methods that read the replica state).

Parameters:
readMethods - the names of the read methods

setWriteMethods

public void setWriteMethods(String[] writeMethods)
Set the write method names (methods that change the replica state).

Parameters:
writeMethods - the names of the write methods

setCallMethods

public void setCallMethods(String[] callMethods)
Set the call method names (methods that neither write or read the replica state).

Parameters:
callMethods - the names of the call methods

getKnownReplicas

public Vector getKnownReplicas()
The getter method for the known replicas.

The known replicas of a consistency wrapper are remote references on other member of the replication group. With this information, the consistency wrapper can implement consistency protocols. The most usual schemes are to be aware of all the replicas of the group (see for instance StrongPushConsistencyWrapper) or to be aware of ony one replica (see for instance ClientServerConsistencyWrapper.

Returns:
a set of references on the known replicas

addKnownReplica

public void addKnownReplica(RemoteRef newReplica)
Adds a known replica.

Parameters:
newReplica - the known replica to add

getConsistencyWrapperType

public Class getConsistencyWrapperType()
The get method for the consistency wrapper actual type.

Returns:
the class of the wrapper

setKnownReplicas

public void setKnownReplicas(Vector knownReplicas)
The setter method for the known replicas.

The known replicas of a consistency wrapper are remote references on other member of the replication group. With this information, the consistency wrapper can implement consistency protocols. The most usual schemes are to be aware of all the replicas of the group (see for instance StrongPushConsistencyWrapper) or to be aware of ony one replica (see for instance ClientServerConsistencyWrapper.

Parameters:
knownReplicas - the new known replicas

whenCall

public Object whenCall(Interaction interaction)
This wrapping method must be defined to implement a given builtin consistency protocol and must wrap the replica methods that need to be consistent with the other replicas.

It should not wrap a method that is allready wrapped by a WhenWrite or WhenRead method.

Default: do nothing and call the replica.

Returns:
by default the wrapped method return value
See Also:
acceptRemoteCall(RemoteRef,Object[])

whenWrite

public Object whenWrite(Interaction interaction)
This wrapping method must be defined to implement a given builtin consistency protocol and must wrap all the replicas methods that provoque a change in this replica state.

Default: do nothing and call the replica.

Returns:
by default the wrapped method return value
See Also:
acceptRemoteWrite(Wrappee,RemoteRef,Object[])

whenRead

public Object whenRead(Interaction interaction)
This wrapping method must be defined to implement a given builtin consistency protocol and must wrap all the replica methods that read the replica state.

Default: do nothing and call the replica.

Returns:
by default the wrapped method return value
See Also:
acceptRemoteRead(Wrappee,RemoteRef,Object[])

acceptRemoteCall

public Object acceptRemoteCall(RemoteRef remoteReplica,
                               Object[] data)
This role method can called by the whenCall wrapping method of a remote replica.

By overloading this method, the programmer can implement specific consistency protocols.

Default: do nothing.

Parameters:
remoteReplica - expected to be a reference on the remote replica that recieved the call event
data - the data transmittedd by whenCall
Returns:
null by default
See Also:
whenCall(Interaction)

acceptRemoteWrite

public Object acceptRemoteWrite(Wrappee wrappee,
                                RemoteRef remoteReplica,
                                Object[] data)
This role method can called by the whenWrite wrapping method of a remote replica.

By overloading this method, the programmer can implement specific consistency protocols.

Default: do nothing.

Parameters:
remoteReplica - expected to be a reference on the remote replica that recieved the write event
data - the data transmittedd by whenWrite
Returns:
null by default
See Also:
whenWrite(Interaction)

acceptRemoteRead

public Object acceptRemoteRead(Wrappee wrappee,
                               RemoteRef remoteReplica,
                               Object[] data)
This role method can called by the whenRead wrapping method of a remote replica.

By overloading this method, the programmer can implement specific consistency protocols.

Default: do nothing.

Parameters:
remoteReplica - expected to be a reference on the remote replica that recieved the read event
data - the data transmittedd by whenRead
Returns:
null by default
See Also:
whenRead(Interaction)

expandMethods

protected String[] expandMethods(String[] methods)
Construct a real methods array with an array that can contain consistency specific strings (like the one that indicates that we need all the modifiers).

Parameters:
methods - a set of methods to expand (can contain ALL_METHODS, ALL_MODIFIERS, and ALL_GETTERS keywords)
Returns:
a set of methods where the keywords have been expanded with the corresponding method of the type

invoke

public Object invoke(MethodInvocation invocation)
              throws Throwable
Specified by:
invoke in interface MethodInterceptor
Overrides:
invoke in class Wrapper
Throws:
Throwable

construct

public Object construct(ConstructorInvocation invocation)
                 throws Throwable
Specified by:
construct in interface ConstructorInterceptor
Overrides:
construct in class Wrapper
Throws:
Throwable