|
|||||||||
| Home >> All >> org >> jgroups >> [ stack overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.jgroups.stack
Class Protocol

java.lang.Objectorg.jgroups.stack.Protocol
- Direct Known Subclasses:
- MessageProtocol, ProtocolStack
- public abstract class Protocol
- extends java.lang.Object
The Protocol class provides a set of common services for protocol layers. Each layer has to
be a subclass of Protocol and override a number of methods (typically just up(),
Down and getName. Layers are stacked in a certain order to form
a protocol stack. Events are passed from lower
layers to upper ones and vice versa. E.g. a Message received by the UDP layer at the bottom
will be passed to its higher layer as an Event. That layer will in turn pass the Event to
its layer and so on, until a layer handles the Message and sends a response or discards it,
the former resulting in another Event being passed down the stack.
Each layer has 2 FIFO queues, one for up Events and one for down Events. When an Event is
received by a layer (calling the internal upcall ReceiveUpEvent), it is placed
in the up-queue where it will be retrieved by the up-handler thread which will invoke method
Up of the layer. The same applies for Events traveling down the stack. Handling
of the up-handler and down-handler threads and the 2 FIFO queues is donw by the Protocol
class, subclasses will almost never have to override this behavior.
The important thing to bear in mind is that Events have to passed on between layers in FIFO order which is guaranteed by the Protocol implementation and must be guranteed by subclasses implementing their on Event queuing.
Note that each class implementing interface Protocol MUST provide an empty, public constructor !
| Field Summary | |
protected DownHandler |
down_handler
|
protected Protocol |
down_prot
|
protected org.jgroups.util.Queue |
down_queue
|
protected boolean |
down_thread
|
protected int |
down_thread_prio
|
protected org.apache.commons.logging.Log |
log
|
protected ProtocolObserver |
observer
|
protected java.util.Properties |
props
|
protected ProtocolStack |
stack
|
protected boolean |
stats
|
private static long |
THREAD_JOIN_TIMEOUT
|
protected boolean |
trace
|
protected UpHandler |
up_handler
|
protected Protocol |
up_prot
|
protected org.jgroups.util.Queue |
up_queue
|
protected boolean |
up_thread
|
protected int |
up_thread_prio
|
protected boolean |
warn
|
| Constructor Summary | |
Protocol()
|
|
| Method Summary | |
void |
destroy()
This method is called on a Channel.close()> Channel.close() 55 . |
void |
down(org.jgroups.Event evt)
An event is to be sent down the stack. |
boolean |
downThreadEnabled()
|
java.util.Map |
dumpStats()
|
void |
enableStats(boolean flag)
|
Protocol |
getDownProtocol()
|
org.jgroups.util.Queue |
getDownQueue()
|
abstract java.lang.String |
getName()
|
java.util.Properties |
getProperties()
|
Protocol |
getUpProtocol()
|
org.jgroups.util.Queue |
getUpQueue()
|
protected boolean |
handleSpecialDownEvent(org.jgroups.Event evt)
These are special internal events that should not be handled by protocols |
void |
init()
Called after instance has been created (null constructor) and before protocol is started. |
boolean |
isTrace()
|
boolean |
isWarn()
|
void |
passDown(org.jgroups.Event evt)
Causes the event to be forwarded to the next layer down in the hierarchy.Typically called by the implementation of Down (when done). |
void |
passUp(org.jgroups.Event evt)
Causes the event to be forwarded to the next layer up in the hierarchy. |
java.lang.String |
printStats()
|
java.util.Vector |
providedDownServices()
List of events that are provided to layers below (they will be handled when sent down from below). |
java.util.Vector |
providedUpServices()
List of events that are provided to layers above (they will be handled when sent down from above). |
protected void |
receiveDownEvent(org.jgroups.Event evt)
Internal method, should not be called by clients. |
protected void |
receiveUpEvent(org.jgroups.Event evt)
Internal method, should not be called by clients. |
java.util.Vector |
requiredDownServices()
List of events that are required to be answered by some layer below. |
java.util.Vector |
requiredUpServices()
List of events that are required to be answered by some layer above. |
void |
resetStats()
|
void |
setDownProtocol(Protocol down_prot)
|
void |
setObserver(ProtocolObserver observer)
|
boolean |
setProperties(java.util.Properties props)
Configures the protocol initially. |
boolean |
setPropertiesInternal(java.util.Properties props)
Called by Configurator. |
void |
setProtocolStack(ProtocolStack stack)
|
void |
setTrace(boolean trace)
|
void |
setUpProtocol(Protocol up_prot)
|
void |
setWarn(boolean warn)
|
void |
start()
This method is called on a Channel.connect(String)> Channel.connect(String) 55 . |
void |
startDownHandler()
Used internally. |
void |
startUpHandler()
Used internally. |
boolean |
statsEnabled()
|
void |
stop()
This method is called on a Channel.disconnect()> Channel.disconnect() 55 . |
void |
stopInternal()
Used internally. |
void |
up(org.jgroups.Event evt)
An event was received from the layer below. |
boolean |
upThreadEnabled()
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
props
protected final java.util.Properties props
up_prot
protected Protocol up_prot
down_prot
protected Protocol down_prot
stack
protected ProtocolStack stack
up_queue
protected final org.jgroups.util.Queue up_queue
down_queue
protected final org.jgroups.util.Queue down_queue
up_handler
protected UpHandler up_handler
up_thread_prio
protected int up_thread_prio
down_handler
protected DownHandler down_handler
down_thread_prio
protected int down_thread_prio
observer
protected ProtocolObserver observer
THREAD_JOIN_TIMEOUT
private static final long THREAD_JOIN_TIMEOUT
- See Also:
- Constant Field Values
down_thread
protected boolean down_thread
up_thread
protected boolean up_thread
stats
protected boolean stats
log
protected final org.apache.commons.logging.Log log
trace
protected boolean trace
warn
protected boolean warn
| Constructor Detail |
Protocol
public Protocol()
| Method Detail |
setProperties
public boolean setProperties(java.util.Properties props)
- Configures the protocol initially. A configuration string consists of name=value
items, separated by a ';' (semicolon), e.g.:
"loopback=false;unicast_inport=4444"
setPropertiesInternal
public boolean setPropertiesInternal(java.util.Properties props)
- Called by Configurator. Removes 2 properties which are used by the Protocol directly and then
calls setProperties(), which might invoke the setProperties() method of the actual protocol instance.
getProperties
public java.util.Properties getProperties()
isTrace
public boolean isTrace()
setTrace
public void setTrace(boolean trace)
isWarn
public boolean isWarn()
setWarn
public void setWarn(boolean warn)
upThreadEnabled
public boolean upThreadEnabled()
downThreadEnabled
public boolean downThreadEnabled()
statsEnabled
public boolean statsEnabled()
enableStats
public void enableStats(boolean flag)
resetStats
public void resetStats()
printStats
public java.lang.String printStats()
dumpStats
public java.util.Map dumpStats()
setObserver
public void setObserver(ProtocolObserver observer)
init
public void init()
throws java.lang.Exception
- Called after instance has been created (null constructor) and before protocol is started.
Properties are already set. Other protocols are not yet connected and events cannot yet be sent.
start
public void start()
throws java.lang.Exception
- This method is called on a Channel.connect(String)>
Channel.connect(String)55 . Starts work. Protocols are connected and queues are ready to receive events. Will be called from bottom to top. This call will replace the START and START_OK events.
stop
public void stop()
- This method is called on a Channel.disconnect()>
Channel.disconnect()55 . Stops work (e.g. by closing multicast socket). Will be called from top to bottom. This means that at the time of the method invocation the neighbor protocol below is still working. This method will replace the STOP, STOP_OK, CLEANUP and CLEANUP_OK events. The ProtocolStack guarantees that when this method is called all messages in the down queue will have been flushed
destroy
public void destroy()
- This method is called on a Channel.close()>
Channel.close()55 . Does some cleanup; after the call the VM will terminate
getUpQueue
public org.jgroups.util.Queue getUpQueue()
getDownQueue
public org.jgroups.util.Queue getDownQueue()
requiredUpServices
public java.util.Vector requiredUpServices()
- List of events that are required to be answered by some layer above.
requiredDownServices
public java.util.Vector requiredDownServices()
- List of events that are required to be answered by some layer below.
providedUpServices
public java.util.Vector providedUpServices()
- List of events that are provided to layers above (they will be handled when sent down from
above).
providedDownServices
public java.util.Vector providedDownServices()
- List of events that are provided to layers below (they will be handled when sent down from
below).
getName
public abstract java.lang.String getName()
getUpProtocol
public Protocol getUpProtocol()
getDownProtocol
public Protocol getDownProtocol()
setUpProtocol
public void setUpProtocol(Protocol up_prot)
setDownProtocol
public void setDownProtocol(Protocol down_prot)
setProtocolStack
public void setProtocolStack(ProtocolStack stack)
startUpHandler
public void startUpHandler()
- Used internally. If overridden, call this method first. Only creates the up_handler thread
if down_thread is true
startDownHandler
public void startDownHandler()
- Used internally. If overridden, call this method first. Only creates the down_handler thread
if down_thread is true
stopInternal
public void stopInternal()
- Used internally. If overridden, call parent's method first
receiveUpEvent
protected void receiveUpEvent(org.jgroups.Event evt)
- Internal method, should not be called by clients. Used by ProtocolStack. I would have
used the 'friends' modifier, but this is available only in C++ ... If the up_handler thread
is not available (down_thread == false), then directly call the up() method: we will run on the
caller's thread (e.g. the protocol layer below us).
receiveDownEvent
protected void receiveDownEvent(org.jgroups.Event evt)
- Internal method, should not be called by clients. Used by ProtocolStack. I would have
used the 'friends' modifier, but this is available only in C++ ... If the down_handler thread
is not available (down_thread == false), then directly call the down() method: we will run on the
caller's thread (e.g. the protocol layer above us).
passUp
public void passUp(org.jgroups.Event evt)
- Causes the event to be forwarded to the next layer up in the hierarchy. Typically called
by the implementation of
Up(when done).
passDown
public void passDown(org.jgroups.Event evt)
- Causes the event to be forwarded to the next layer down in the hierarchy.Typically called
by the implementation of
Down(when done).
up
public void up(org.jgroups.Event evt)
- An event was received from the layer below. Usually the current layer will want to examine
the event type and - depending on its type - perform some computation
(e.g. removing headers from a MSG event type, or updating the internal membership list
when receiving a VIEW_CHANGE event).
Finally the event is either a) discarded, or b) an event is sent down
the stack using
passDown()or c) the event (or another event) is sent up the stack usingpassUp().
down
public void down(org.jgroups.Event evt)
- An event is to be sent down the stack. The layer may want to examine its type and perform
some action on it, depending on the event's type. If the event is a message MSG, then
the layer may need to add a header to it (or do nothing at all) before sending it down
the stack using
passDown(). In case of a GET_ADDRESS event (which tries to retrieve the stack's address from one of the bottom layers), the layer may need to send a new response event back up the stack usingpassUp().
handleSpecialDownEvent
protected boolean handleSpecialDownEvent(org.jgroups.Event evt)
- These are special internal events that should not be handled by protocols
|
|||||||||
| Home >> All >> org >> jgroups >> [ stack overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
org.jgroups.stack.Protocol