darx
Class ReplicationStrategy

java.lang.Object
  extended by darx.ReplicationStrategy
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable
Direct Known Subclasses:
ActiveReplicationStrategy, PassiveReplicationStrategy

public abstract class ReplicationStrategy
extends java.lang.Object
implements java.io.Serializable, java.lang.Comparable

This is the component, used alongside each TaskShell, which defines a task's replication group.
This class provides methods to manage the information a specific task possesses about its replication group in terms of replicant (un)registration, that is it maintains up to date the number of replicants for this particular task and the location of each replicant.

NB: EVERY replicant, independently of its being leader of the replication group or not, carries and maintains this information up to date so as to be available to take the leadership in case of the current leader's failure.

NB2: This class is abstract; its specialisations define the current replication policy within the task's group, and therefore the message passing and runtime management schemes.

See Also:
ActiveReplicationStrategy, PassiveReplicationStrategy, Serialized Form

Field Summary
static int ACTIVE_STRATEGY
          The constant used to define the strategy type as active.
static int BACKUP
          The constant used to define the role of the strategy owner as backup.
static int EMPTY_STRATEGY
          The constant used to define the strategy type as empty.
protected  ReplicantInfo info
          The information concerning the replication group leader
static int LEADER
          The constant used to define the role of the strategy owner as leader.
static int PASSIVE_STRATEGY
          The constant used to define the strategy type as passive.
static int QUORUM_STRATEGY
          The constant used to define the strategy type as quorum-based.
protected  int rep_number
          The unique number used in the darx-pathname of the latest created replicant.
protected  java.util.Hashtable replicants
          The list of remote replicants participating to the current replication group, the owner of this instance not included.
protected  int role
          The role of the strategy owner (leader, active or passive)
protected  int type
          The strategy type, that is whether it is active or passive.
 
Constructor Summary
protected ReplicationStrategy()
          Constructs an empty information container to be filled in with data about the task's replication group.
 
Method Summary
 int compareTo(java.lang.Object o)
          Compares this replication strategy to an object.
abstract  int compareTo(ReplicationStrategy other_strategy)
          Compares this replication strategy to another.
 boolean contains(ReplicantInfo rep_info)
           
abstract  void deliverAsyncMessage(TaskShell shell, DarxMessage msg)
          Spreads the delivery of an asynchronous message throughout the replication group.
abstract  java.io.Serializable deliverSyncMessage(TaskShell shell, DarxMessage msg)
          Spreads the delivery of a synchronous message throughout the replication group.
(package private)  void display()
           
 boolean equals(java.lang.Object o)
          Compares the specified Object with this strategy for equality.
 ReplicantInfo findReplicantAt(java.lang.String url, int port_nb)
          Finds the info concerning a replicant at a given location
protected  TaskShellHandle getRemoteShellHandle(ReplicantInfo rep_info)
          Retrieves the stub of a given replicant.
 TaskShellHandle getReplicantHandle(ReplicantInfo rep_info)
          Gets the handle for a remote replicant within the group.
 ReplicantInfo getReplicantInfo()
           
 int getReplicantRole()
           
 java.util.Hashtable getReplicants()
           
 int getReplicationNumber()
           
 int getReplicationType()
           
 void handleUnreachableReplicant(ReplicantInfo dead, java.rmi.RemoteException re)
          Handles situations where a replicant fails to be contacted.
 int hashCode()
          Who knows when THIS might come in handy...
 void registerReplicant(ReplicantInfo rep, TaskShellHandle sh)
          Adds a member to the replication group.
abstract  void resume()
          Spreads the resumption of the encapsulated task execution throughout the replication group.
 void setLeaderInfo(ReplicantInfo new_info)
          Sets the info about the replication group leader
 void setReplicantRole(int new_role)
          Sets the role of the strategy owner (leader or backup).
 void setReplicants(java.util.Hashtable new_replicants_list)
          Sets the list of tasks belonging to this replication group.
 void setReplicantType(int type)
          Sets the type of the strategy (active or passive).
 void setReplicationNumber(int new_rep_number)
          Sets the serial number of the last created replicant.
 void stop()
          Stops the activity regarding consistency maintenance within the replication group (e.g. updater thread in the passive strategy.)
abstract  void suspend()
          Spreads the suspension of the encapsulated task execution throughout the replication group.
 void terminate()
          Spreads the termination of the task execution throughout the replication group.
 TaskShellHandle unregisterReplicant(ReplicantInfo doomed_rep_info)
          Removes a member from the replication group.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_STRATEGY

public static final int EMPTY_STRATEGY
The constant used to define the strategy type as empty. This is used as a comparative element, e.g.for the hashcode calculation.

See Also:
Constant Field Values

ACTIVE_STRATEGY

public static final int ACTIVE_STRATEGY
The constant used to define the strategy type as active.

See Also:
Constant Field Values

PASSIVE_STRATEGY

public static final int PASSIVE_STRATEGY
The constant used to define the strategy type as passive.

See Also:
Constant Field Values

QUORUM_STRATEGY

public static final int QUORUM_STRATEGY
The constant used to define the strategy type as quorum-based.

See Also:
Constant Field Values

LEADER

public static final int LEADER
The constant used to define the role of the strategy owner as leader.

See Also:
Constant Field Values

BACKUP

public static final int BACKUP
The constant used to define the role of the strategy owner as backup.

See Also:
Constant Field Values

type

protected int type
The strategy type, that is whether it is active or passive.


role

protected int role
The role of the strategy owner (leader, active or passive)


info

protected ReplicantInfo info
The information concerning the replication group leader


replicants

protected java.util.Hashtable replicants
The list of remote replicants participating to the current replication group, the owner of this instance not included. key: replicant info value: remote replicant handle


rep_number

protected int rep_number
The unique number used in the darx-pathname of the latest created replicant.

Constructor Detail

ReplicationStrategy

protected ReplicationStrategy()
Constructs an empty information container to be filled in with data about the task's replication group. This is the unique class constructor. As this class is abstract, it is only provided here to be extended in specialisation classes.

Method Detail

getReplicationType

public int getReplicationType()
Returns:
the replication type (active or passive)

getReplicantRole

public int getReplicantRole()
Returns:
the role of the replication strategy owner

getReplicantInfo

public ReplicantInfo getReplicantInfo()
Returns:
the info about the strategy owner

getReplicationNumber

public int getReplicationNumber()
Returns:
the ID number of the next replica to be created

getReplicants

public java.util.Hashtable getReplicants()
Returns:
the list of replicants participating to the replication group

contains

public boolean contains(ReplicantInfo rep_info)
Parameters:
rep_info - the replica looked for
Returns:
whether this strategy instance is applied to the given replica

findReplicantAt

public ReplicantInfo findReplicantAt(java.lang.String url,
                                     int port_nb)
                              throws UnknownReplicantException
Finds the info concerning a replicant at a given location

Parameters:
url - the url of server hosting the replicant to look for
port_nb - the port nb of server hosting the replicant to look for
Returns:
the stub of the replicant at the given location
Throws:
UnknownReplicantException

getReplicantHandle

public TaskShellHandle getReplicantHandle(ReplicantInfo rep_info)
                                   throws UnknownReplicantException
Gets the handle for a remote replicant within the group.

Returns:
the handle for the given replicant
Throws:
UnknownReplicantException

setReplicantType

public void setReplicantType(int type)
Sets the type of the strategy (active or passive).


setReplicantRole

public void setReplicantRole(int new_role)
Sets the role of the strategy owner (leader or backup).


setLeaderInfo

public void setLeaderInfo(ReplicantInfo new_info)
Sets the info about the replication group leader


setReplicants

public void setReplicants(java.util.Hashtable new_replicants_list)
Sets the list of tasks belonging to this replication group. The task which corresponds to this manager is not included in this list.


setReplicationNumber

public void setReplicationNumber(int new_rep_number)
Sets the serial number of the last created replicant.


compareTo

public abstract int compareTo(ReplicationStrategy other_strategy)
Compares this replication strategy to another.

Parameters:
other_strategy - the strategy to be compared
Returns:
0 if both strategies are equivalent, a positive integer if this strategy is more pessimistic than the compared strategy, a negative integer otherwise.

compareTo

public int compareTo(java.lang.Object o)
Compares this replication strategy to an object. This method must be defined in order to implement interface Comparable.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
o - the object (strategy) to be compared
Returns:
0 if both strategies are equivalent, a positive integer if this strategy is more pessimistic than the compared strategy, a negative integer otherwise.

equals

public boolean equals(java.lang.Object o)
Compares the specified Object with this strategy for equality.

Overrides:
equals in class java.lang.Object
Parameters:
o - the object to be compared (hopefully a ReplicationStrategy)
Returns:
true if the specified Object is equal to this strategy.

hashCode

public int hashCode()
Who knows when THIS might come in handy...

Overrides:
hashCode in class java.lang.Object

registerReplicant

public void registerReplicant(ReplicantInfo rep,
                              TaskShellHandle sh)
Adds a member to the replication group.

Parameters:
rep - the info concerning the new member
sh - the shell handle for the new member

unregisterReplicant

public TaskShellHandle unregisterReplicant(ReplicantInfo doomed_rep_info)
Removes a member from the replication group.

Parameters:
doomed_rep_info - the info concerning the removed member
Returns:
the handle to which the info had been mapped, null otherwise.

suspend

public abstract void suspend()
Spreads the suspension of the encapsulated task execution throughout the replication group. This method is used by the leader of the replication group only.


resume

public abstract void resume()
Spreads the resumption of the encapsulated task execution throughout the replication group. This method is used by the leader of the replication group only.


stop

public void stop()
Stops the activity regarding consistency maintenance within the replication group (e.g. updater thread in the passive strategy.) This method is used by the leader of the replication group only.


terminate

public void terminate()
               throws java.rmi.RemoteException
Spreads the termination of the task execution throughout the replication group. This method is used by the leader of the replication group only.

Throws:
java.rmi.RemoteException

deliverAsyncMessage

public abstract void deliverAsyncMessage(TaskShell shell,
                                         DarxMessage msg)
Spreads the delivery of an asynchronous message throughout the replication group. This method is used by the leader of the replication group only.

Parameters:
shell - the shell corresponding to the present strategy (used to process the message locally)
msg - the message to deliver

deliverSyncMessage

public abstract java.io.Serializable deliverSyncMessage(TaskShell shell,
                                                        DarxMessage msg)
Spreads the delivery of a synchronous message throughout the replication group. This method is used by the leader of the replication group only.

Parameters:
shell - the shell corresponding to the present strategy (used to process the message locally)
msg - the message to deliver
Returns:
the reply to be sent back

handleUnreachableReplicant

public void handleUnreachableReplicant(ReplicantInfo dead,
                                       java.rmi.RemoteException re)
Handles situations where a replicant fails to be contacted. In this version of DARX, the replicant is considered dead and is thus removed from the replication group.

Parameters:
dead - the information concerning the replicant which fails to respond
re - the exception resulting from the failure

getRemoteShellHandle

protected TaskShellHandle getRemoteShellHandle(ReplicantInfo rep_info)
Retrieves the stub of a given replicant.

Parameters:
rep_info - the information concerning the replicant whose stub is being retrieved
Returns:
the stub of the remote shell for the given replicant

display

void display()