jgroup.relacs.gmi.protocols
Class Leadercast

java.lang.Object
  extended by jgroup.relacs.gmi.protocols.BasicDispatcher
      extended by jgroup.relacs.gmi.protocols.Leadercast
All Implemented Interfaces:
MulticastListener, ProtocolDispatcher

public class Leadercast
extends BasicDispatcher
implements MulticastListener

Leadercast represents a protocol that will always try to invoke the the group leader first. The group leader will pass the servers post-invocation state to the other members of the group, if the invocation resulted in a state change. If a client tries to invoke a non-leader (follower) replica, that replica will forward the invocation to the leader, and will also mediate the result back to the client. In such failover scenarios, the client will invoke the leader directly on the next interaction.

Author:
Hein Meling

Constructor Summary
Leadercast(GroupInvocationDispatcher dispatcher, MulticastService mcast, MembershipService pgms)
           
 
Method Summary
 java.lang.Object deliverObject(java.lang.Object msg, MemberId sender, int seqNo)
          Upcall that is invoked by Jgroup to deliver a message msg, corresponding to a single serialized object.
 java.lang.Object deliverStream(java.io.InputStream msg, MemberId sender, int seqNo)
          Upcall that is invoked by Jgroup to deliver a message msg, corresponding to an input stream from which the message may be read.
 InvocationResult dispatch(java.io.InputStream in)
          Handle inbound request to the local endpoint with leadercast invocation semantics.
 java.lang.String getProtocolName()
          Returns a string naming the protocol implemented by this multicast listener.
 void setServer(java.lang.Object server)
          Set the server object for use by the Leadercast protocol.
 
Methods inherited from class jgroup.relacs.gmi.protocols.BasicDispatcher
getIdentifier
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Leadercast

public Leadercast(GroupInvocationDispatcher dispatcher,
                  MulticastService mcast,
                  MembershipService pgms)
Method Detail

dispatch

public InvocationResult dispatch(java.io.InputStream in)
                          throws java.io.IOException
Handle inbound request to the local endpoint with leadercast invocation semantics. If the local endpoint is the group leader, then just compute the result value and return it to the client (GroupInvocationHandler). Otherwise, if the local endpoint is a follower, then we multicast the request to all group members, allowing the leader to pick it up (@see deliverStream below) and provide a return value back to this endpoint whom will pass it back to the client (GroupInvocationHandler).

Specified by:
dispatch in interface ProtocolDispatcher
Overrides:
dispatch in class BasicDispatcher
Parameters:
in - the method to invoke, encoded in the provided InputStream.
Returns:
the result of the method invocation.
Throws:
java.io.IOException - Raised if the method invocation read from the InputStream could not be executed for some reason.
See Also:
ProtocolDispatcher.dispatch(java.io.InputStream)

setServer

public void setServer(java.lang.Object server)
Set the server object for use by the Leadercast protocol.

This allows the leadercast protocol to obtain access to the StateListener interface of the server. This overrides the empty implementation in BasicDispatcher. If the provided server does not implement a StateListener interface, the call is ignored. This allows the server to use the leadercast protocol without having its state (if any) passed to the followers.

Specified by:
setServer in interface ProtocolDispatcher
Overrides:
setServer in class BasicDispatcher
Throws:
java.lang.IllegalStateException - If the server has already been set. The method should not be called multiple times.
See Also:
ProtocolDispatcher.setServer(java.lang.Object)

getProtocolName

public java.lang.String getProtocolName()
Description copied from interface: MulticastListener
Returns a string naming the protocol implemented by this multicast listener.

Specified by:
getProtocolName in interface MulticastListener

deliverStream

public java.lang.Object deliverStream(java.io.InputStream msg,
                                      MemberId sender,
                                      int seqNo)
Description copied from interface: MulticastListener
Upcall that is invoked by Jgroup to deliver a message msg, corresponding to an input stream from which the message may be read.

Specified by:
deliverStream in interface MulticastListener
Parameters:
msg - the input stream from which the message can be read.
sender - the sender of the multicast message
seqNo - the sequence number of this multicast message
Returns:
an object that will be delivered to the invoker through the AckListener object specified when multicasting the message.

deliverObject

public java.lang.Object deliverObject(java.lang.Object msg,
                                      MemberId sender,
                                      int seqNo)
Description copied from interface: MulticastListener
Upcall that is invoked by Jgroup to deliver a message msg, corresponding to a single serialized object.

Specified by:
deliverObject in interface MulticastListener
Parameters:
msg - the object that was multicasted.
sender - the sender of the multicast message
seqNo - the sequence number of this multicast message
Returns:
an object that will be delivered to the invoker through the AckListener object specified when multicasting the message.


Copyright © 1998-2006 The Jgroup/ARM development team. All Rights Reserved.