public abstract class Protocol extends 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 String |
after_creation_hook |
protected Protocol |
down_prot |
protected boolean |
ergonomics |
protected short |
id |
protected Log |
log |
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. |
String |
afterCreationHook() |
void |
destroy()
This method is called on a
JChannel.close() . |
Object |
down(Event evt)
An event is to be sent down the stack.
|
Object |
down(Message msg)
A message is sent down the stack.
|
void |
enableStats(boolean flag) |
protected List<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.
|
<T extends Protocol> |
getDownProtocol() |
List<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)
|
String |
getLevel() |
Log |
getLog() |
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() |
<T extends Protocol> |
getUpProtocol() |
List<Integer> |
getUpServices()
Returns all services provided by the protocols above the current protocol
|
Object |
getValue(String name) |
void |
init()
Called after instance has been created (null constructor) and before protocol is started.
|
boolean |
isErgonomics() |
<T extends Protocol> |
level(String level) |
void |
parse(Node node)
Called by the XML parser when subelements are found in the configuration of a protocol.
|
List<Integer> |
providedDownServices()
List of events that are provided to layers below (they will be handled when sent from down below)
|
List<Integer> |
providedUpServices()
List of events that are provided to layers above (they will be handled when sent down from above)
|
List<Integer> |
requiredDownServices()
List of events that are required to be answered by some layer below
|
List<Integer> |
requiredUpServices()
List of events that are required to be answered by some layer above
|
void |
resetStatistics() |
void |
resetStats() |
<T extends Protocol> |
setDownProtocol(Protocol prot) |
<T extends Protocol> |
setErgonomics(boolean ergonomics) |
<T extends Protocol> |
setId(short id) |
<T extends Protocol> |
setLevel(String level)
Sets the level of a logger.
|
<T extends Protocol> |
setProperties(Map<String,String> properties)
Resolves and applies the specified properties to this protocol.
|
<T extends Protocol> |
setProtocolStack(ProtocolStack s) |
void |
setSocketFactory(SocketFactory factory)
Sets a SocketFactory.
|
<T extends Protocol> |
setUpProtocol(Protocol prot) |
<T extends Protocol> |
setValue(String name,
Object value) |
void |
start()
This method is called on a
JChannel.connect(String) . |
boolean |
statsEnabled() |
void |
stop()
This method is called on a
JChannel.disconnect() . |
Object |
up(Event evt)
An event was received from the protocol below.
|
Object |
up(Message msg)
A single message was received.
|
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 String after_creation_hook
protected short id
protected final Log log
public <T extends Protocol> T setLevel(String level)
level
- The new level. Valid values are "fatal", "error", "warn", "info", "debug", "trace"
(capitalization not relevant)public String getLevel()
public boolean isErgonomics()
public <T extends Protocol> T setErgonomics(boolean ergonomics)
public ProtocolStack getProtocolStack()
public boolean statsEnabled()
public void enableStats(boolean flag)
public String getName()
public short getId()
public <T extends Protocol> T setId(short id)
public <T extends Protocol> T getUpProtocol()
public <T extends Protocol> T getDownProtocol()
public <T extends Protocol> T setProtocolStack(ProtocolStack s)
public String afterCreationHook()
public Log getLog()
public <T extends Protocol> T setProperties(Map<String,String> properties) throws Exception
properties
- a map of property string valuesException
- if any of the specified properties are unresolvable or unrecognized.protected List<Object> getConfigurableObjects()
public void parse(Node node) throws Exception
Exception
public short[] getIdsAbove()
protected TP getTransport()
public ThreadFactory getThreadFactory()
public SocketFactory getSocketFactory()
public void setSocketFactory(SocketFactory factory)
TP
)factory
- public void resetStatistics()
public void resetStats()
public void init() throws Exception
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 Exception
JChannel.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.Exception
- Thrown if protocol cannot be started successfully. This will cause the ProtocolStack
to fail, so JChannel.connect(String)
will throw an exceptionpublic void stop()
JChannel.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()
JChannel.close()
.
Does some cleanup; after the call the VM will terminatepublic List<Integer> requiredUpServices()
public List<Integer> requiredDownServices()
public List<Integer> providedUpServices()
public List<Integer> providedDownServices()
public final List<Integer> getDownServices()
public final List<Integer> getUpServices()
public Object down(Event evt)
down_prot.down()
.public Object down(Message msg)
public Object up(Event evt)
down_prot.down()
or c) the event (or another event) is sent up the stack using up_prot.up()
.public Object up(Message msg)
public 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 batchprotected 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-nullCopyright © 2018 JBoss, a division of Red Hat. All rights reserved.