uka.karmi.rmi.server
Class ReplicatedServerRef

java.lang.Object
  extended byuka.karmi.rmi.server.RemoteServerRef
      extended byuka.karmi.rmi.server.ReplicatedServerRef
All Implemented Interfaces:
uka.graph.Channel, Printable

public class ReplicatedServerRef
extends RemoteServerRef
implements uka.graph.Channel, Printable

Author:
Bernhard Haumacher

Nested Class Summary
static class ReplicatedServerRef.CollectiveOperation
           
(package private)  class ReplicatedServerRef.CollectiveUpdate
           
(package private)  class ReplicatedServerRef.CollectiveUpdateNode
          Implementation of the GraphNode interface.
 class ReplicatedServerRef.ExclusiveLock
          Note: The exclusive lock process extends the regular call protocol to:
(package private) static class ReplicatedServerRef.Wakeup
           
 
Field Summary
(package private)  int applyCnt
           
(package private)  int[] applyFirstID
           
(package private)  int[] applyRank
           
(package private)  int barrierChildCnt
           
(package private)  ServerConnection[] barrierChilds
           
(package private)  Connection[] collectiveConnections
          Contains connections to all other participants of a collective operation.
private  ReplicatedServerRef.CollectiveOperation collectiveUpdate
           
(package private)  uka.graph.ColoringAlgorithm coloring
          Algorithm object for coloring the update graph of a partially replicated object.
(package private)  ReplicaDiagnostics diagnostics
           
(package private)  java.util.HashMap exclusiveLockSpace
           
(package private)  int exclusiveTicket
           
(package private)  boolean isNotified
           
(package private)  ReplicatedServerRef.ExclusiveLock lock
          The lock of the thread that currently holds an exclusive lock on the corresponding replicated object.
(package private)  ReplicatedServerRef.CollectiveUpdateNode node
          A helper object that implements the GraphNode interface for distributed coloring of the replicas for optimized collective updates.
(package private)  PatchAdapterImpl objectAdapter
          The local replica.
(package private)  PartitionedObjectSpace objects
           
(package private)  MultiplexPatchWriter patchWriter
           
(package private)  int rank
          This replica is at position rank in the replica array.
(package private)  SingleRemoteClientRef[] replica
          Remote references of all replicas of this replicated server.
(package private)  java.util.HashMap replicatedWaitSet
          The thread waiting in a replicatedWait() only wants to be woken up by a call to replicatedNotify().
(package private)  int updateTicket
           
private  boolean useColoring
          Determines wether the graph coloring optimization is used during collective updates.
(package private)  int validExclusiveTicket
           
(package private)  int validUpdateTicket
           
 
Fields inherited from class uka.karmi.rmi.server.RemoteServerRef
callCounter, ep, objectId, objectId2
 
Constructor Summary
ReplicatedServerRef(PartitionedObjectSpace objects, java.lang.Object root, int rank)
          Create an initial server reference for a single replica that is part of a replicated object.
 
Method Summary
 void appendTo(ToString s)
          This method should append the contents of each instance variable of the current object to the given ToString object.
protected  void awaitWakeUp(ClientConnection[] wakeUpConnections)
           
 void barrier(int fanout)
           
private  void checkDistribute(java.lang.Object obj)
          Throw an IllegalArgumentException, if the passed object is set to read-only state.
protected  void clearReplicatedWaitSet()
           
private  void closeCollectiveConnections()
           
protected  void closeWakeUpConnections(ClientConnection[] wakeUpConnections)
           
(package private)  int createTicket()
           
 void deliverMessage(int rank, uka.graph.Message message)
          Deliver message to some rank.
 void distributeTo(java.lang.Object obj, boolean[] ranks)
          With this method, you can assign parts of an replicated object to some of replicas of this replicated object.
 void distributeTo(java.lang.Object obj, int[] ranks)
          With this method, you can assign parts of an replicated object to some of replicas of this replicated object.
 void doApplicationCall(ServerConnection c)
          The entry-point into the method dispatch process.
private  void doCollectiveOperation(int mid, ReplicatedServerRef.CollectiveOperation op)
           
 java.lang.Object[] exchange(java.lang.Object[] args)
          Exchange data among cooperating threads.
 ReplicaDiagnostics getDiagnostics()
           
 java.lang.Object getObject()
           
 PatchAdapter getObjectAdapter()
           
 SingleRemoteClientRef[] getReplicas()
           
 SingleRemoteClientRef getSelfReference()
           
 RemoteStub getStub()
          Returns a corresponding stub object.
 void init()
          Called from the ColoringAlgorithm before computing a new graph coloring.
 boolean isReadOnly(java.lang.Object obj)
           
protected  boolean isThreadRegistered()
           
private  void openCollectiveConnections(int mid, IntIterator ranks)
           
 void postAcquireExclusiveLock(ReplicatedServerRef.ExclusiveLock lock)
           
 void postReleaseExclusiveLock(ReplicatedServerRef.ExclusiveLock lock)
           
 ReplicatedServerRef.ExclusiveLock preAcquireExclusiveLock()
          First part of the protocol necessary to acquire an exclusive lock on a replicated object.
 void preReleaseExclusiveLock(ReplicatedServerRef.ExclusiveLock lock)
           
private  void receiveBarrier(ServerConnection c)
           
 void receiveCollectiveConnection(ServerConnection c)
          Called from ServerConnection.dispatch(boolean) for connections marked with the command ID Constants.COLLECTIVE_OPERATION.
(package private)  void receiveExclusiveLock(ServerConnection c)
           
 void receiveExclusiveUpdate(ServerConnection c)
           
 uka.graph.Message receiveMessage(int rank)
          Receive a message from some rank.
(package private)  void receiveTicketRequest(ServerConnection c)
           
(package private)  void receiveWait(ServerConnection c)
           
(package private)  void receiveWakeUp(ServerConnection c)
           
protected  void registerWaitingThread()
           
 boolean remoteEquals(RemoteStub obj)
          Determines if a stub object references this server object.
 void replicatedNotify()
           
 void replicatedWait()
           
 void sendCollectiveUpdate()
           
 void sendExclusiveUpdate()
           
protected  ClientConnection[] sendWakeUp(int ticket)
           
 void setReadOnly(java.lang.Object obj, boolean value)
           
 void setReplica(int replicaRank, SingleRemoteClientRef replicaRef)
          The the reference to replica at index replicaRank.
 void synchronize(RMACallback cb)
          Synchronize on the local replica that is the root of objectAdapter and call the given callback method.
 java.lang.String toStringMembers()
           
 void unreferenced()
          Called whenever the last remote reference to this server implementation is garbage collected.
private  void updateFinished()
          Called at the end of each update after an exclusive or collective synchronization.
 void updateReferences(SingleRemoteClientRef[] refs)
           
 
Methods inherited from class uka.karmi.rmi.server.RemoteServerRef
createSkeletonFor, createStubFor, decCallCounter, getClientHost, incCallCounter, newInstanceRelative, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

replica

SingleRemoteClientRef[] replica
Remote references of all replicas of this replicated server.


collectiveConnections

Connection[] collectiveConnections
Contains connections to all other participants of a collective operation.


rank

int rank
This replica is at position rank in the replica array.


objects

PartitionedObjectSpace objects

objectAdapter

PatchAdapterImpl objectAdapter
The local replica.


patchWriter

MultiplexPatchWriter patchWriter

applyRank

int[] applyRank

applyFirstID

int[] applyFirstID

applyCnt

int applyCnt

updateTicket

int updateTicket

validUpdateTicket

int validUpdateTicket

exclusiveTicket

int exclusiveTicket

validExclusiveTicket

int validExclusiveTicket

isNotified

boolean isNotified

useColoring

private boolean useColoring
Determines wether the graph coloring optimization is used during collective updates.

See Also:
updateFinished()

lock

ReplicatedServerRef.ExclusiveLock lock
The lock of the thread that currently holds an exclusive lock on the corresponding replicated object.


replicatedWaitSet

java.util.HashMap replicatedWaitSet

The thread waiting in a replicatedWait() only wants to be woken up by a call to replicatedNotify(). All other calls to Object.notify() and Object.notifyAll() are used for internal signaling and should not trigger the replicated wakeup sequence.

In 'replicatedWait()' every thread registers itself at the replicatedWaitSet. replicatedNotify() empties this set and calls Object.notifyAll(). All awaking threads can test, whether they are still in the set. If they are still in there, they keep on sleeping. If they are not, they start their wake up process.


exclusiveLockSpace

java.util.HashMap exclusiveLockSpace

coloring

uka.graph.ColoringAlgorithm coloring
Algorithm object for coloring the update graph of a partially replicated object.


node

ReplicatedServerRef.CollectiveUpdateNode node
A helper object that implements the GraphNode interface for distributed coloring of the replicas for optimized collective updates.


diagnostics

ReplicaDiagnostics diagnostics

collectiveUpdate

private final ReplicatedServerRef.CollectiveOperation collectiveUpdate

barrierChildCnt

int barrierChildCnt

barrierChilds

ServerConnection[] barrierChilds
Constructor Detail

ReplicatedServerRef

public ReplicatedServerRef(PartitionedObjectSpace objects,
                           java.lang.Object root,
                           int rank)
                    throws RemoteException
Create an initial server reference for a single replica that is part of a replicated object. This constructor is invoked from the constructor of ReplicatedObject and is used to export the initial replica of a new ReplicatedObject. After creation, this server reference is not yet completely initialized, because it is not yet connected to the other replicas.

Method Detail

getSelfReference

public SingleRemoteClientRef getSelfReference()

setReplica

public void setReplica(int replicaRank,
                       SingleRemoteClientRef replicaRef)
The the reference to replica at index replicaRank.


getReplicas

public SingleRemoteClientRef[] getReplicas()

updateReferences

public void updateReferences(SingleRemoteClientRef[] refs)
                      throws RemoteException
Throws:
RemoteException
See Also:
Technology.serviceUpdateReferencesBody(uka.karmi.rmi.server.ReplicatedServerRef, uka.karmi.rmi.SingleRemoteClientRef[])

getDiagnostics

public ReplicaDiagnostics getDiagnostics()

distributeTo

public void distributeTo(java.lang.Object obj,
                         int[] ranks)
With this method, you can assign parts of an replicated object to some of replicas of this replicated object. In the 'collective'-synchronization-process, these objects are only replicated to these replicas.


distributeTo

public void distributeTo(java.lang.Object obj,
                         boolean[] ranks)
With this method, you can assign parts of an replicated object to some of replicas of this replicated object. In the 'collective'-synchronization-process, these objects are only replicated to these replicas. For every object, which is a parameter to this method, you can call this method only once.


checkDistribute

private void checkDistribute(java.lang.Object obj)
Throw an IllegalArgumentException, if the passed object is set to read-only state. The distribution of a read-only object cannot be changed, because the update to the distribution specification must be propagated to other replicas during update. This propagation might be impossible for a read-only object, because replicas of this object might exist at ranks that are not in the active group. Since communication links are only established with replicas in the active group, an inconsistency of the specified distribution might occur.

Throws:
java.lang.IllegalArgumentException

getObjectAdapter

public PatchAdapter getObjectAdapter()

preAcquireExclusiveLock

public ReplicatedServerRef.ExclusiveLock preAcquireExclusiveLock()
                                                          throws RemoteException

First part of the protocol necessary to acquire an exclusive lock on a replicated object. To acquire an exclusive lock on a replicated object, all locks of its local replicas have to be acquired. The acquisition has to be done in an ordered way to prevent deadlocks. First, a ticket for exclusive update is requested from replica #0. Second, lock requests using the received ticket are sent to all replicas, except the local one. Third, the local lock is acquired. Forth, the acknowledgment from all other nodes is awaited.

The acquisition of all locks works as follows: First, the lock is requested in a synchronized block. Second, the thread waits, until its current ticket become valid.

The acquisition of an exclusive lock requires the following call protocol:

 preAcquireExclusiveLock();
 synchronized (localReplica) {
 postAcquireExclusiveLock();

 // The exclusive synchronized operation.

 preReleaseExclusiveLock();
 }
 postReleaseExclusiveLock();
 

Throws:
RemoteException

postAcquireExclusiveLock

public void postAcquireExclusiveLock(ReplicatedServerRef.ExclusiveLock lock)
                              throws RemoteException
Throws:
RemoteException
See Also:
preAcquireExclusiveLock()

replicatedNotify

public void replicatedNotify()

registerWaitingThread

protected void registerWaitingThread()

isThreadRegistered

protected boolean isThreadRegistered()

clearReplicatedWaitSet

protected void clearReplicatedWaitSet()

replicatedWait

public void replicatedWait()
                    throws java.lang.InterruptedException,
                           RemoteException
Throws:
java.lang.InterruptedException
RemoteException

preReleaseExclusiveLock

public void preReleaseExclusiveLock(ReplicatedServerRef.ExclusiveLock lock)
                             throws RemoteException
Throws:
RemoteException
See Also:
preAcquireExclusiveLock()

postReleaseExclusiveLock

public void postReleaseExclusiveLock(ReplicatedServerRef.ExclusiveLock lock)
                              throws RemoteException
Throws:
RemoteException
See Also:
preAcquireExclusiveLock()

sendExclusiveUpdate

public void sendExclusiveUpdate()
                         throws java.io.IOException,
                                java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException

setReadOnly

public void setReadOnly(java.lang.Object obj,
                        boolean value)

isReadOnly

public boolean isReadOnly(java.lang.Object obj)

sendWakeUp

protected ClientConnection[] sendWakeUp(int ticket)
                                 throws java.io.IOException,
                                        java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException

awaitWakeUp

protected void awaitWakeUp(ClientConnection[] wakeUpConnections)
                    throws java.io.IOException,
                           java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException

closeWakeUpConnections

protected void closeWakeUpConnections(ClientConnection[] wakeUpConnections)
                               throws java.io.IOException,
                                      java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException

receiveExclusiveUpdate

public void receiveExclusiveUpdate(ServerConnection c)
                            throws java.io.IOException,
                                   java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException

openCollectiveConnections

private void openCollectiveConnections(int mid,
                                       IntIterator ranks)
                                throws java.io.IOException
Throws:
java.io.IOException

init

public void init()
Description copied from interface: uka.graph.Channel
Called from the ColoringAlgorithm before computing a new graph coloring.

Specified by:
init in interface uka.graph.Channel

deliverMessage

public void deliverMessage(int rank,
                           uka.graph.Message message)
                    throws uka.graph.MessageDeliveryException
Description copied from interface: uka.graph.Channel
Deliver message to some rank. The Channel guarantees that one message per sender/receiver-pair can be buffered. That means that a sender may only block, if he already sent one message to a receiver and that receiver has not received that message yet.

Specified by:
deliverMessage in interface uka.graph.Channel
Parameters:
rank - The rank to which the message is delivered.
Throws:
uka.graph.MessageDeliveryException

receiveMessage

public uka.graph.Message receiveMessage(int rank)
                                 throws uka.graph.MessageDeliveryException
Description copied from interface: uka.graph.Channel
Receive a message from some rank.

Specified by:
receiveMessage in interface uka.graph.Channel
Parameters:
rank - The rank that sent the message.
Throws:
uka.graph.MessageDeliveryException

closeCollectiveConnections

private void closeCollectiveConnections()
                                 throws java.io.IOException
Throws:
java.io.IOException

doCollectiveOperation

private void doCollectiveOperation(int mid,
                                   ReplicatedServerRef.CollectiveOperation op)
                            throws java.io.IOException,
                                   java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException

sendCollectiveUpdate

public void sendCollectiveUpdate()
                          throws java.io.IOException,
                                 java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException

updateFinished

private void updateFinished()
Called at the end of each update after an exclusive or collective synchronization.


exchange

public java.lang.Object[] exchange(java.lang.Object[] args)
                            throws java.io.IOException,
                                   java.lang.ClassNotFoundException

Exchange data among cooperating threads.

Note: The current implementation has room for improvements: Since the collective exchange does not modify the shared object space of the associated replicated object, there is no need for ordering the send/receive operations. To achieve better overlapping, the server thread that receives the collective connection in receiveCollectiveConnection(uka.karmi.rmi.ServerConnection) could immediately unmarshal the data and store it to a shared array (instead of the connection). Now, each sender could broadcast its data and wait afterwards until all data was received.

Throws:
java.io.IOException
java.lang.ClassNotFoundException

barrier

public void barrier(int fanout)
             throws java.lang.InterruptedException,
                    RemoteException
Throws:
java.lang.InterruptedException
RemoteException

receiveBarrier

private void receiveBarrier(ServerConnection c)
                     throws RemoteException
Throws:
RemoteException

receiveCollectiveConnection

public void receiveCollectiveConnection(ServerConnection c)
                                 throws java.io.IOException,
                                        java.lang.ClassNotFoundException
Called from ServerConnection.dispatch(boolean) for connections marked with the command ID Constants.COLLECTIVE_OPERATION.

Throws:
java.io.IOException
java.lang.ClassNotFoundException

receiveExclusiveLock

void receiveExclusiveLock(ServerConnection c)
                    throws java.io.IOException,
                           java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException

createTicket

int createTicket()

receiveTicketRequest

void receiveTicketRequest(ServerConnection c)
                    throws java.io.IOException,
                           java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException

receiveWakeUp

void receiveWakeUp(ServerConnection c)
             throws java.io.IOException
Throws:
java.io.IOException

receiveWait

void receiveWait(ServerConnection c)
           throws java.io.IOException,
                  java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException

doApplicationCall

public void doApplicationCall(ServerConnection c)
                       throws java.io.IOException,
                              java.lang.ClassNotFoundException
Description copied from class: RemoteServerRef
The entry-point into the method dispatch process. This method is called from the dispatch() method of the server connection. The actual dispatch is done in a sub-class of RemoteServerRef. This abstract method is implemented for unicast servers in the UnicastRemoteServerRef class.

Specified by:
doApplicationCall in class RemoteServerRef
Parameters:
c - the connection, the call came in
Throws:
java.io.IOException
java.lang.ClassNotFoundException
See Also:
ServerConnection.dispatch(boolean), UnicastRemoteServerRef.doApplicationCall(ServerConnection)

unreferenced

public void unreferenced()
Description copied from class: RemoteServerRef
Called whenever the last remote reference to this server implementation is garbage collected.

Specified by:
unreferenced in class RemoteServerRef
See Also:
Unreferenced

getStub

public RemoteStub getStub()
Description copied from class: RemoteServerRef
Returns a corresponding stub object. This method is called from the transport, when a stub object is needed. The returned stub doesn't need to be a newly created stub object. The implementation can also create a stub object on export and always return the same.

This stub is used during passing a remote server as argument or result in a remote method invocation.

Specified by:
getStub in class RemoteServerRef

getObject

public java.lang.Object getObject()

synchronize

public void synchronize(RMACallback cb)
                 throws java.lang.Throwable
Synchronize on the local replica that is the root of objectAdapter and call the given callback method.

Specified by:
synchronize in class RemoteServerRef
Throws:
java.lang.Throwable

remoteEquals

public boolean remoteEquals(RemoteStub obj)
Description copied from class: RemoteServerRef
Determines if a stub object references this server object.

Specified by:
remoteEquals in class RemoteServerRef

appendTo

public void appendTo(ToString s)
Description copied from interface: Printable
This method should append the contents of each instance variable of the current object to the given ToString object. The appended data should be labeled with the name of the corresponding instance variable.

Specified by:
appendTo in interface Printable
See Also:
ToString, ToString.append(String, Object), ToString.append(String, boolean), ToString.append(String, byte), ToString.append(String, int)

toStringMembers

public java.lang.String toStringMembers()
Overrides:
toStringMembers in class RemoteServerRef