|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Object dk.i1.diameter.node.NodeManager
public class NodeManager
A Node manager. The NodeManager class manages a Node instance and keeps track of connections and in-/our-going messages and their end-to-end and hop-by-hop identifiers. You can build proxies, redirect agents, servers and clients on top of it. NodeManager is meant to be subclassed and subclasses should override handleRequest() and handleAnswer()
If your needs are even simpler then have a look at SimpleSyncClient
and SessionManager
NodeManager instances logs with the name "dk.i1.diameter.node", so you can get detailed logging (including hex-dumps of incoming and outgoing packets) by putting "dk.i1.diameter.node.level = ALL" into your log.properties file (or equivalent)
What happens when acting as a server:
Message.prepareAnswer(Message)
What happens when acting as a client:
What happens when acting as a proxy or a relay:
Constructor Summary | |
---|---|
NodeManager(NodeSettings settings)
Constructor for NodeManager. |
|
NodeManager(NodeSettings settings,
NodeValidator node_validator)
Constructor for NodeManager. |
Method Summary | |
---|---|
protected void |
answer(Message answer,
ConnectionKey connkey)
Answer a request. |
protected void |
forwardAnswer(Message answer,
ConnectionKey connkey)
Forward an answer. |
protected void |
forwardRequest(Message request,
ConnectionKey connkey,
Object state)
Forward a request. |
protected void |
forwardRequest(Message request,
ConnectionKey connkey,
Object state,
long timeout)
Forward a request. |
void |
handle(ConnectionKey connkey,
Peer peer,
boolean up)
Handle a a connection state change. |
boolean |
handle(Message msg,
ConnectionKey connkey,
Peer peer)
Handle an incoming message. |
protected void |
handleAnswer(Message answer,
ConnectionKey answer_connkey,
Object state)
Handle an answer. |
protected void |
handleRequest(Message request,
ConnectionKey connkey,
Peer peer)
Handle a request. |
Node |
node()
Returns the embedded node |
void |
sendRequest(Message request,
ConnectionKey connkey,
Object state)
Sends a request. |
void |
sendRequest(Message request,
ConnectionKey connkey,
Object state,
long timeout)
Sends a request. |
void |
sendRequest(Message request,
Peer[] peers,
Object state)
Sends a request. |
void |
sendRequest(Message request,
Peer[] peers,
Object state,
long timeout)
Sends a request. |
NodeSettings |
settings()
Returns the node settings |
void |
start()
Start the node manager. |
void |
stop()
Stop the node manager immediately. |
void |
stop(long grace_time)
Stop the node manager. |
void |
waitForConnection()
Wait until at least one connection has been established. |
void |
waitForConnection(long timeout)
Wait until at least one connection has been established or until the timeout expires. |
void |
waitForConnectionTimeout(long timeout)
Wait until at least one connection has been established or until the timeout expires. |
Methods inherited from class Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public NodeManager(NodeSettings settings)
public NodeManager(NodeSettings settings, NodeValidator node_validator)
Method Detail |
---|
public void start() throws java.io.IOException, UnsupportedTransportProtocolException
UnsupportedTransportProtocolException
see Node.start()
java.io.IOException
UnsupportedTransportProtocolException
public void stop()
public void stop(long grace_time)
grace_time
- Maximum time (milliseconds) to wait for connections to close gracefully.public void waitForConnection() throws InterruptedException
InterruptedException
public void waitForConnection(long timeout) throws InterruptedException
timeout
- The maximum time to wait in milliseconds.
InterruptedException
public void waitForConnectionTimeout(long timeout) throws InterruptedException, ConnectionTimeoutException
timeout
- The maximum time to wait in milliseconds.
InterruptedException
- If the timeout expires without any connection established.
ConnectionTimeoutException
public Node node()
public NodeSettings settings()
protected void handleRequest(Message request, ConnectionKey connkey, Peer peer)
Please note that the handleRequest() method is called by the networking thread and messages from other peers cannot be received until the method returns. If the handleRequest() method needs to do any lengthy processing then it should implement a message queue, put the message into the queue, and return. The requests can then be processed by a worker thread pool without stalling the networking layer.
request
- The incoming request.connkey
- The connection from where the request came.peer
- The peer that sent the request. This is not the originating peer but the peer directly connected to us that sent us the request.protected void handleAnswer(Message answer, ConnectionKey answer_connkey, Object state)
Please note that the handleAnswer() method is called by the networking thread and messages from other peers cannot be received until the method returns. If the handleAnswer() method needs to do any lengthy processing then it should implement a message queue, put the message into the queue, and return. The answers can then be processed by a worker thread pool without stalling the networking layer.
answer
- The answer message. Null if the connection broke.answer_connkey
- The connection from where the answer came.state
- The state object passed to sendRequest() or forwardRequest()protected final void answer(Message answer, ConnectionKey connkey) throws NotAnAnswerException
answer
- The answer message.connkey
- The connection to send the answer to.
NotAnAnswerException
- If the answer has the R bit set in the header.protected final void forwardRequest(Message request, ConnectionKey connkey, Object state) throws StaleConnectionException, NotARequestException, NotProxiableException
request
- The request to forwardconnkey
- The connection to usestate
- A state object that will be passed to handleAnswer() when the answer arrives. You should remember the ingoing connection and hop-by-hop identifier
NotARequestException
- If the request does not have the R bit set in the header.
NotProxiableException
- If the request does not have the P bit set in the header.
StaleConnectionException
- If the ConnectionKey refers to a lost connection.protected final void forwardRequest(Message request, ConnectionKey connkey, Object state, long timeout) throws StaleConnectionException, NotARequestException, NotProxiableException
request
- The request to forwardconnkey
- The connection to usestate
- A state object that will be passed to handleAnswer() when the answer arrives. You should remember the ingoing connection and hop-by-hop identifiertimeout
- Timeout in milliseconds, -1 means no timeout
NotARequestException
- If the request does not have the R bit set in the header.
NotProxiableException
- If the request does not have the P bit set in the header.
StaleConnectionException
- If the ConnectionKey refers to a lost connection.protected final void forwardAnswer(Message answer, ConnectionKey connkey) throws StaleConnectionException, NotAnAnswerException, NotProxiableException
answer
- The answer to forwardconnkey
- The connection to use
NotAnAnswerException
- If the answer has the R bit set in the header.
NotProxiableException
- If the answer does not have the P bit set in the header. This indicates that there is something completely wrong with either the message, the peer or your application
StaleConnectionException
- If the ConnectionKey refers to a lost connection.public final void sendRequest(Message request, ConnectionKey connkey, Object state) throws StaleConnectionException, NotARequestException
request
- The request.connkey
- The connection to use.state
- A state object that will be passed to handleAnswer() when the answer arrives.
NotARequestException
- If the request does not have the R bit set in the header.
StaleConnectionException
- If the ConnectionKey refers to a lost connection.public final void sendRequest(Message request, ConnectionKey connkey, Object state, long timeout) throws StaleConnectionException, NotARequestException
request
- The request.connkey
- The connection to use.state
- A state object that will be passed to handleAnswer() when the answer arrives.timeout
- Timeout in milliseconds, -1 means no timeout
NotARequestException
- If the request does not have the R bit set in the header.
StaleConnectionException
- If the ConnectionKey refers to a lost connection.public final void sendRequest(Message request, Peer[] peers, Object state) throws NotRoutableException, NotARequestException
request
- The request to send.peers
- The candidate peersstate
- A state object to be remembered. This will be passed to the handleAnswer() method when the answer arrives.
NotARequestException
- If the request does not have the R bit set in the header.
NotRoutableException
- If the message could not be sent to any of the peers.public final void sendRequest(Message request, Peer[] peers, Object state, long timeout) throws NotRoutableException, NotARequestException
request
- The request to send.peers
- The candidate peersstate
- A state object to be remembered. This will be passed to the handleAnswer() method when the answer arrives.timeout
- Timeout in milliseconds, -1 means no timeout
NotARequestException
- If the request does not have the R bit set in the header.
NotRoutableException
- If the message could not be sent to any of the peers.public final boolean handle(Message msg, ConnectionKey connkey, Peer peer)
handle
in interface MessageDispatcher
msg
- The incoming messageconnkey
- The connection keypeer
- The peer of the connection. This is not necessarily the host that originated the message (the message can have gone via proxies)
public final void handle(ConnectionKey connkey, Peer peer, boolean up)
handle
in interface ConnectionListener
connkey
- The connection key.peer
- The peer the connection is to.up
- True if the connection has been established. False if the connection has been lost.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |