darx
Class ReplicationPolicy

java.lang.Object
  extended by darx.ReplicationPolicy
All Implemented Interfaces:
java.io.Serializable

public class ReplicationPolicy
extends java.lang.Object
implements java.io.Serializable

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, the location of each replicant, the strategies applied within the group, and to which replicants they are applied.

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.
A replication policy must contain a list of strategies, a list of replicas, and a mapping between both lists.

See Also:
ReplicationStrategy, ReplicationManager, Serialized Form

Constructor Summary
ReplicationPolicy(ReplicantInfo leader_info)
          Constructs a new, empty replication policy
 
Method Summary
protected  void addReplicant(ReplicationStrategy rep_strat, ReplicantInfo rep_info, TaskShellHandle rep_handle)
          Adds a replica to the policy.
protected  ReplicationStrategy addStrategy(ReplicationStrategy rep_strat)
          Adds a strategy to the policy.
protected  ReplicantInfo containsReplicant(java.lang.String url, int port_nb)
          Checks whether there exists a replica at a given location.
 void deliverAsyncMessage(TaskShell shell, DarxMessage msg)
           
 java.io.Serializable deliverSyncMessage(TaskShell shell, DarxMessage msg)
           
(package private)  void display()
           
protected  ReplicationStrategy findAppliedStrategy(ReplicantInfo rep_info)
          Finds the strategy which is applied to a given replica.
protected  ReplicantInfo generateNewInfo(java.lang.String url, int port_nb)
          Generates an information object for a new group member.
 void publishReplicationPolicy()
          Spreads the information concerning the addition of a new member throughout the replication group.
protected  TaskShellHandle removeReplicant(ReplicantInfo rep_info)
          Removes a replica from the policy.
protected  void removeStrategy(ReplicationStrategy rep_strat)
          Removes a strategy from the policy.
protected  void resume()
          Spreads the resumption of the encapsulated task execution throughout the replication group.
protected  void suspend()
          Spreads the suspension of the encapsulated task execution throughout the replication group.
protected  void switchAppliedStrategy(ReplicationStrategy rep_strat, ReplicantInfo rep_info)
          Sets the strategy to be applied to a replica at a given location.
protected  void terminate()
          Terminates the activity of the entire replication group.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReplicationPolicy

ReplicationPolicy(ReplicantInfo leader_info)
Constructs a new, empty replication policy

Parameters:
leader_info - the info for the leader of the replication group
Method Detail

addStrategy

protected ReplicationStrategy addStrategy(ReplicationStrategy rep_strat)
Adds a strategy to the policy.
If an equivalent strategy is already present, then the policy remains unchanged.

Parameters:
rep_strat - the strategy to add
Returns:
the reference to the strategy applied in the policy

removeStrategy

protected void removeStrategy(ReplicationStrategy rep_strat)
Removes a strategy from the policy. Additionaly, this method terminates the removed strategy. NB: it is assumed that the whole policy is suspended. NB2: it is also assumed that the strategy is not currently applied to any replica.

Parameters:
rep_strat - the strategy to remove

findAppliedStrategy

protected ReplicationStrategy findAppliedStrategy(ReplicantInfo rep_info)
                                           throws UnknownReplicantException
Finds the strategy which is applied to a given replica. It is mainly used to modify the strategy accordingly to a change of status for the replica (strategy switching, replica removal.)

Parameters:
rep_info - the replica to which the strategy is applied
Returns:
the strategy applied to the replica
Throws:
UnknownReplicantException

switchAppliedStrategy

protected void switchAppliedStrategy(ReplicationStrategy rep_strat,
                                     ReplicantInfo rep_info)
                              throws UnknownReplicantException
Sets the strategy to be applied to a replica at a given location. The location is assumed to host a replica, otherwise an exception is thrown. If the strategy isn't already applied in the group, then it is added to the policy.

Parameters:
rep_strat - the strategy to apply
rep_info - the replica to which the strategy is applied
Throws:
UnknownReplicantException

addReplicant

protected void addReplicant(ReplicationStrategy rep_strat,
                            ReplicantInfo rep_info,
                            TaskShellHandle rep_handle)
Adds a replica to the policy. If a strategy equivalent to the one given in parameter is not applied yet, then it is added also. NB: it is assumed that the whole policy is suspended.

Parameters:
rep_strat - the strategy to apply
rep_info - the info concerning the replica to be added
rep_handle - the remote reference to the added replica

generateNewInfo

protected ReplicantInfo generateNewInfo(java.lang.String url,
                                        int port_nb)
Generates an information object for a new group member.

Parameters:
url - the url of the location for the new member
port_nb - the port nb of the location for the new member
Returns:
the information object for the new member

containsReplicant

protected ReplicantInfo containsReplicant(java.lang.String url,
                                          int port_nb)
                                   throws UnknownReplicantException
Checks whether there exists a replica at a given location.

Parameters:
url - the URL of the checked location
port_nb - the port number of the checked location
Returns:
the reference to the replicant information.
Throws:
UnknownReplicantException - if there is no replica at the given location

removeReplicant

protected TaskShellHandle removeReplicant(ReplicantInfo rep_info)
                                   throws UnknownReplicantException
Removes a replica from the policy. If the corresponding strategy has no replica left to be applied to, then it is removed also. NB: it is assumed that the whole policy is suspended.

Parameters:
rep_info - the replica to remove
Returns:
the remote reference to the removed replica (used by setStrategy)
Throws:
UnknownReplicantException

suspend

protected 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

protected void resume()
Spreads the resumption of the encapsulated task execution throughout the replication group. Additionally this method publishes the replication policy, that is the policy of every replica is updated. This method is used by the leader of the replication group only.


terminate

protected void terminate()
Terminates the activity of the entire replication group. This method is used by the leader of the replication group only.


publishReplicationPolicy

public void publishReplicationPolicy()
Spreads the information concerning the addition of a new member throughout the replication group. This operation includes updating the view that the new member possesses on the replication group.

Parameters:
rep_info - the info concerning the new member

deliverAsyncMessage

public void deliverAsyncMessage(TaskShell shell,
                                DarxMessage msg)
                         throws java.rmi.RemoteException
Throws:
java.rmi.RemoteException

deliverSyncMessage

public java.io.Serializable deliverSyncMessage(TaskShell shell,
                                               DarxMessage msg)
                                        throws java.rmi.RemoteException
Throws:
java.rmi.RemoteException

display

void display()