public abstract class Protocol
extends java.lang.Object
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.
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 !
Modifier and Type | Field and Description |
---|---|
protected java.lang.String |
after_creation_hook |
protected Protocol |
down_prot |
protected boolean |
ergonomics |
protected short |
id |
protected Log |
log |
protected java.lang.String |
name
The name of the protocol.
|
protected ProtocolStack |
stack |
protected boolean |
stats |
protected Protocol |
up_prot |
Constructor and Description |
---|
Protocol() |
Modifier and Type | Method and Description |
---|---|
protected boolean |
accept(Message msg)
Called by the default implementation of
up(org.jgroups.util.MessageBatch) for each message to determine
if the message should be removed from the message batch (and handled by the current protocol) or not. |
java.lang.String |
afterCreationHook() |
void |
destroy()
This method is called on a
Channel.close() . |
java.lang.Object |
down(Event evt)
An event is to be sent down the stack.
|
java.util.Map<java.lang.String,java.lang.Object> |
dumpStats() |
void |
enableStats(boolean flag) |
protected java.util.List<java.lang.Object> |
getConfigurableObjects()
After configuring the protocol itself from the properties defined in the XML config, a protocol might have
additional objects which need to be configured.
|
Protocol |
getDownProtocol() |
java.util.List<java.lang.Integer> |
getDownServices()
Returns all services provided by protocols below the current protocol
|
short |
getId() |
short[] |
getIdsAbove()
Returns the protocol IDs of all protocols above this one (excluding the current protocol)
|
java.lang.String |
getLevel() |
Log |
getLog() |
java.lang.String |
getName() |
ProtocolStack |
getProtocolStack() |
SocketFactory |
getSocketFactory()
Returns the SocketFactory associated with this protocol, if overridden in a subclass, or passes the call down
|
ThreadFactory |
getThreadFactory()
Supposed to be overwritten by subclasses.
|
protected TP |
getTransport() |
Protocol |
getUpProtocol() |
java.util.List<java.lang.Integer> |
getUpServices()
Returns all services provided by the protocols above the current protocol
|
java.lang.Object |
getValue(java.lang.String name) |
void |
init()
Called after instance has been created (null constructor) and before protocol is started.
|
boolean |
isErgonomics() |
Protocol |
level(java.lang.String level) |
void |
parse(org.w3c.dom.Node node)
Called by the XML parser when subelements are found in the configuration of a protocol.
|
java.lang.String |
printStats() |
java.util.List<java.lang.Integer> |
providedDownServices()
List of events that are provided to layers below (they will be handled when sent down below)
|
java.util.List<java.lang.Integer> |
providedUpServices()
List of events that are provided to layers above (they will be handled when sent down from above)
|
java.util.List<java.lang.Integer> |
requiredDownServices()
List of events that are required to be answered by some layer below
|
java.util.List<java.lang.Integer> |
requiredUpServices()
List of events that are required to be answered by some layer above
|
void |
resetStatistics() |
void |
resetStats() |
Protocol |
setDownProtocol(Protocol prot) |
Protocol |
setErgonomics(boolean ergonomics) |
Protocol |
setId(short id) |
Protocol |
setLevel(java.lang.String level)
Sets the level of a logger.
|
Protocol |
setProtocolStack(ProtocolStack s) |
void |
setSocketFactory(SocketFactory factory)
Sets a SocketFactory.
|
Protocol |
setUpProtocol(Protocol prot) |
Protocol |
setValue(java.lang.String name,
java.lang.Object value) |
Protocol |
setValues(java.util.Map<java.lang.String,java.lang.Object> values) |
void |
start()
This method is called on a
Channel.connect(String) . |
boolean |
statsEnabled() |
void |
stop()
This method is called on a
Channel.disconnect() . |
java.lang.Object |
up(Event evt)
An event was received from the layer below.
|
void |
up(MessageBatch batch)
Sends up a multiple messages in a
MessageBatch . |
protected Protocol up_prot
protected Protocol down_prot
protected ProtocolStack stack
protected boolean stats
protected boolean ergonomics
protected java.lang.String name
protected java.lang.String after_creation_hook
protected short id
protected final Log log
public Protocol setLevel(java.lang.String level)
level
- The new level. Valid values are "fatal", "error", "warn", "info", "debug", "trace"
(capitalization not relevant)public java.lang.String getLevel()
public Protocol level(java.lang.String level)
public Log getLog()
public boolean isErgonomics()
public Protocol setErgonomics(boolean ergonomics)
public ProtocolStack getProtocolStack()
public boolean statsEnabled()
public void enableStats(boolean flag)
public java.lang.String getName()
public short getId()
public Protocol setId(short id)
public Protocol getUpProtocol()
public Protocol getDownProtocol()
public Protocol setProtocolStack(ProtocolStack s)
public java.lang.String afterCreationHook()
public java.lang.Object getValue(java.lang.String name)
public Protocol setValues(java.util.Map<java.lang.String,java.lang.Object> values)
public Protocol setValue(java.lang.String name, java.lang.Object value)
protected java.util.List<java.lang.Object> getConfigurableObjects()
public void parse(org.w3c.dom.Node node) throws java.lang.Exception
java.lang.Exception
public short[] getIdsAbove()
protected TP getTransport()
public ThreadFactory getThreadFactory()
public SocketFactory getSocketFactory()
public void setSocketFactory(SocketFactory factory)
TP
)
or TP.ProtocolAdapter
factory
- public void resetStatistics()
public void resetStats()
public java.lang.String printStats()
public java.util.Map<java.lang.String,java.lang.Object> dumpStats()
public void init() throws java.lang.Exception
java.lang.Exception
- Thrown if protocol cannot be initialized successfully. This will cause the
ProtocolStack to fail, so the channel constructor will throw an exceptionpublic void start() throws java.lang.Exception
Channel.connect(String)
. 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.java.lang.Exception
- Thrown if protocol cannot be started successfully. This will cause the ProtocolStack
to fail, so Channel.connect(String)
will throw an exceptionpublic void stop()
Channel.disconnect()
. 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 flushedpublic void destroy()
Channel.close()
.
Does some cleanup; after the call the VM will terminatepublic java.util.List<java.lang.Integer> requiredUpServices()
public java.util.List<java.lang.Integer> requiredDownServices()
public java.util.List<java.lang.Integer> providedUpServices()
public java.util.List<java.lang.Integer> providedDownServices()
public final java.util.List<java.lang.Integer> getDownServices()
public final java.util.List<java.lang.Integer> getUpServices()
public java.lang.Object up(Event evt)
down_prot.down()
or c) the event (or another event) is sent up
the stack using up_prot.up()
.protected boolean accept(Message msg)
up(org.jgroups.util.MessageBatch)
for each message to determine
if the message should be removed from the message batch (and handled by the current protocol) or not.msg
- The message. Guaranteed to be non-nullpublic void up(MessageBatch batch)
MessageBatch
. The sender of the batch is always the same, and so is the
destination (null == multicast messages). Messages in a batch can be OOB messages, regular messages, or mixed
messages, although the transport itself will create initial MessageBatches that contain only either OOB or
regular messages.
The default processing below sends messages up the stack individually, based on a matching criteria
(calling accept(org.jgroups.Message)
), and - if true - calls up(org.jgroups.Event)
for that message and removes the message. If the batch is not empty, it is passed up, or else it is dropped.
Subclasses should check if there are any messages destined for them (e.g. using
MessageBatch.getMatchingMessages(short,boolean)
), then possibly remove and process them and finally pass
the batch up to the next protocol. Protocols can also modify messages in place, e.g. ENCRYPT could decrypt all
encrypted messages in the batch, not remove them, and pass the batch up when done.batch
- The message batchpublic java.lang.Object down(Event evt)
down_prot.down()
. 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 using up_prot.up()
.Copyright © 1998-2020 Red Hat. All Rights Reserved.