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 Protocol |
down_prot |
protected boolean |
ergonomics |
protected short |
id |
protected Log |
log |
protected 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 |
---|---|
void |
destroy()
This method is called on a
Channel.close() . |
Object |
down(Event evt)
An event is to be sent down the stack.
|
Map<String,Object> |
dumpStats() |
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.
|
Protocol |
getDownProtocol() |
short |
getId() |
String |
getLevel() |
String |
getName()
All protocol names have to be unique !
|
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() |
Object |
getValue(String name) |
void |
init()
Called after instance has been created (null constructor) and before protocol is started.
|
boolean |
isErgonomics() |
String |
printStats() |
List<Integer> |
providedDownServices()
List of events that are provided to layers below (they will be handled when sent down from
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() |
void |
setDownProtocol(Protocol down_prot) |
void |
setErgonomics(boolean ergonomics) |
void |
setId(short id) |
void |
setLevel(String level)
Sets the level of a logger.
|
void |
setProtocolStack(ProtocolStack stack) |
void |
setSocketFactory(SocketFactory factory)
Sets a SocketFactory.
|
void |
setUpProtocol(Protocol up_prot) |
Protocol |
setValue(String name,
Object value) |
Protocol |
setValues(Map<String,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() . |
Object |
up(Event evt)
An event was received from the layer below.
|
protected Protocol up_prot
protected Protocol down_prot
protected ProtocolStack stack
protected boolean stats
protected boolean ergonomics
protected String name
protected short id
protected final Log log
public void 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 void setErgonomics(boolean ergonomics)
public ProtocolStack getProtocolStack()
protected List<Object> getConfigurableObjects()
protected TP getTransport()
public ThreadFactory getThreadFactory()
public SocketFactory getSocketFactory()
public void setSocketFactory(SocketFactory factory)
TP
)
or TP.ProtocolAdapter
factory
- public boolean statsEnabled()
public void enableStats(boolean flag)
public void resetStatistics()
public void resetStats()
public String printStats()
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
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.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 List<Integer> requiredUpServices()
public List<Integer> requiredDownServices()
public List<Integer> providedUpServices()
public List<Integer> providedDownServices()
public String getName()
public short getId()
public void setId(short id)
public Protocol getUpProtocol()
public Protocol getDownProtocol()
public void setUpProtocol(Protocol up_prot)
public void setDownProtocol(Protocol down_prot)
public void setProtocolStack(ProtocolStack stack)
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 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 © 2012 JBoss by Red Hat. All Rights Reserved.