|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.inspirel.yami.Agent
public final class Agent
Message broker.
The message broker that encapsulates physical channel management, incoming and outgoing message queues, listeners and resource management.
A single agent object can manage many listeners, which are responsible for accepting remote connections, and many incoming and outgoing connections.
The objects of this class can be safely used by multiple threads, including the threads that execute incoming message callbacks.
Nested Class Summary | |
---|---|
static class |
Agent.OutgoingFlowState
Helper class for returning the state of outgoing flow. |
Constructor Summary | |
---|---|
Agent()
Default constructor, creates an agent object without any active listener and with default option values. |
|
Agent(Parameters options)
Constructor, creates an agent object without any active listener and uses the provided configuration options. |
|
Agent(Parameters options,
ConnectionEventCallback connectionEventCallback,
LogCallback logCallback,
LogCallback.LogLevel logLevel)
Constructor, creates an agent object without any active listener and uses the provided configuration options and log callback. |
|
Agent(Parameters options,
LogCallback logCallback,
LogCallback.LogLevel logLevel)
Constructor, creates an agent object without any active listener and uses the provided configuration options and log callback. |
Method Summary | |
---|---|
java.lang.String |
addListener(java.lang.String target)
Adds a new listener for the given target address. |
void |
close()
Cleans up all resources and stops internal threads. |
void |
closeConnection(java.lang.String target)
Closes the given connection with default (lowest) priority. |
void |
closeConnection(java.lang.String target,
int priority)
Closes the given connection. |
Agent.OutgoingFlowState |
getOutgoingFlowState()
Obtains the state of overall outgoing flow. |
void |
openConnection(java.lang.String target)
Opens the new connection. |
void |
registerObject(java.lang.String objectName,
IncomingMessageCallback callback)
Registers a new logical destination object. |
void |
registerValuePublisher(java.lang.String objectName,
ValuePublisher publisher)
Registers the value publisher as a new logical object. |
void |
removeListener(java.lang.String target)
Removes existing listener. |
OutgoingMessage |
send(OutgoingMessageCallback updateCallback,
java.lang.String target,
java.lang.String objectName,
java.lang.String messageName,
YAMISerializable content)
Sends the new outgoing message to the given destination. |
OutgoingMessage |
send(OutgoingMessageCallback updateCallback,
java.lang.String target,
java.lang.String objectName,
java.lang.String messageName,
YAMISerializable content,
int priority)
Sends the new outgoing message to the given destination. |
OutgoingMessage |
send(OutgoingMessageCallback updateCallback,
java.lang.String target,
java.lang.String objectName,
java.lang.String messageName,
YAMISerializable content,
int priority,
boolean autoConnect)
Sends the new outgoing message to the given destination. |
OutgoingMessage |
send(java.lang.String target,
java.lang.String objectName,
java.lang.String messageName,
YAMISerializable content)
Sends the new outgoing message to the given destination. |
OutgoingMessage |
send(java.lang.String target,
java.lang.String objectName,
java.lang.String messageName,
YAMISerializable content,
int priority)
Sends the new outgoing message to the given destination. |
OutgoingMessage |
send(java.lang.String target,
java.lang.String objectName,
java.lang.String messageName,
YAMISerializable content,
int priority,
boolean autoConnect)
Sends the new outgoing message to the given destination. |
void |
sendOneWay(java.lang.String target,
java.lang.String objectName,
java.lang.String messageName,
YAMISerializable content)
Sends the new outgoing message to the given destination, without the possibility to track its progress. |
void |
sendOneWay(java.lang.String target,
java.lang.String objectName,
java.lang.String messageName,
YAMISerializable content,
int priority)
Sends the new outgoing message to the given destination, without the possibility to track its progress. |
void |
sendOneWay(java.lang.String target,
java.lang.String objectName,
java.lang.String messageName,
YAMISerializable content,
int priority,
boolean autoConnect)
Sends the new outgoing message to the given destination, without the possibility to track its progress. |
void |
unregisterObject(java.lang.String objectName)
Unregisters a given destination object. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Agent() throws YAMIIOException
YAMIIOException
- if the network resources cannot be obtainedpublic Agent(Parameters options) throws YAMIIOException
options
- set of configuration options
YAMIIOException
- if the network resources cannot be obtainedpublic Agent(Parameters options, LogCallback logCallback, LogCallback.LogLevel logLevel) throws YAMIIOException
options
- set of configuration optionslogCallback
- callback object for log eventslogLevel
- requested log level
YAMIIOException
- if the network resources cannot be obtainedpublic Agent(Parameters options, ConnectionEventCallback connectionEventCallback, LogCallback logCallback, LogCallback.LogLevel logLevel) throws YAMIIOException
options
- set of configuration optionsconnectionEventCallback
- monitor for reporting connection eventslogCallback
- callback object for log eventslogLevel
- requested log level
YAMIIOException
- if the network resources cannot be obtainedMethod Detail |
---|
public java.lang.String addListener(java.lang.String target) throws YAMIIOException
The supported target formats are:
- "tcp://host:port" for TCP/IP connections, where host
can be provided in the symbolic or numeric form
- "tcp://*:port" for TCP/IP connections, for "any" local address
- "tcp://port" for TCP/IP connections, for "any" local address
- "udp://host:port" for UDP communication, with rules as for TCP/IP
The port for TCP/IP protocol can be 0
, in which case
the actual port number is assigned by the system.
target
- the target name for the new listener
YAMIIOException
- if the network resources cannot be obtainedpublic void removeListener(java.lang.String target)
Removes the listener denoted by its actual target name.
Note that the actual target name might be different from the name
provided when the listener was created, due to target resolution.
The name which should be used for listener removal is the name
that is returned by the addListener
function.
target
- the (resolved) target name of the listener to be removedpublic void registerObject(java.lang.String objectName, IncomingMessageCallback callback)
Registers the new "object" that can be a logical destination
for incoming messages. The incoming messages that are recognized
as being addressed to this new object will be delivered through
the IncomingMessageCallback
interface, which is
therefore supposed to be implemented by the user.
If an object with the given name is already registered, the registration data is replaced.
objectName
- name of the newly registered objectcallback
- the callback implementationpublic void registerValuePublisher(java.lang.String objectName, ValuePublisher publisher)
If an object with the given name is already registered, the registration data is replaced.
objectName
- name of the newly registered objectpublisher
- value publisher to be registeredpublic void unregisterObject(java.lang.String objectName)
If an object with the given name is not registered, this operation does nothing.
Note: Due to performance and design tradeoffs it is not guaranteed that no more messages will be ever dispatched to the given object when this function returns. In fact, some of the messages that have been received by agent and not yet dispatched might be still dispatched shortly after this function returns. Only those messages that are received by agent after this function returns are guaranteed not to be dispatched to the unregistered object.
objectName
- name of the object to unregisterpublic void openConnection(java.lang.String target) throws YAMIIOException
send
and sendOneWay
.
target
- The name of the target endpoint.
This name should correspond to the listener name
in some target agent object.
YAMIIOException
- if the channel cannot be establishedpublic OutgoingMessage send(java.lang.String target, java.lang.String objectName, java.lang.String messageName, YAMISerializable content) throws YAMIIOException
The content object is serialized and is no longer referenced
after this function returns. If the content is null, an empty
Parameters
object is sent.
Note:
This function implicitly opens a new communication channel
if it is not already open. This channel is kept open until
it is explicitly closed
(see the closeConnection
function)
or until the whole agent is closed or the communication error
is detected.
target
- the name of the target endpoint -
this name should correspond to the listener name
in some target agent objectobjectName
- the name of the logical destination object
in the target agentmessageName
- the name of the messagecontent
- the content of the message
YAMIIOException
- if the channel cannot be establishedpublic OutgoingMessage send(java.lang.String target, java.lang.String objectName, java.lang.String messageName, YAMISerializable content, int priority) throws YAMIIOException
The content object is serialized and is no longer referenced
after this function returns. If the content is null, an empty
Parameters
object is sent.
Note:
This function implicitly opens a new communication channel
if it is not already open. This channel is kept open until
it is explicitly closed
(see the closeConnection
function)
or until the whole agent is closed or the communication error
is detected.
target
- the name of the target endpoint -
this name should correspond to the listener name
in some target agent objectobjectName
- the name of the logical destination object
in the target agentmessageName
- the name of the messagecontent
- the content of the messagepriority
- the priority of the message
YAMIIOException
- if the channel cannot be establishedpublic OutgoingMessage send(java.lang.String target, java.lang.String objectName, java.lang.String messageName, YAMISerializable content, int priority, boolean autoConnect) throws YAMIIOException
The content object is serialized and is no longer referenced
after this function returns. If the content is null, an empty
Parameters
object is sent.
Note:
This function implicitly opens a new communication channel
if it is not already open. This channel is kept open until
it is explicitly closed
(see the closeConnection
function)
or until the whole agent is closed or the communication error
is detected.
target
- the name of the target endpoint -
this name should correspond to the listener name
in some target agent objectobjectName
- the name of the logical destination object
in the target agentmessageName
- the name of the messagecontent
- the content of the messagepriority
- the priority of the messageautoConnect
- the flag controlling automatic (re)connection
YAMIIOException
- if the channel cannot be establishedpublic OutgoingMessage send(OutgoingMessageCallback updateCallback, java.lang.String target, java.lang.String objectName, java.lang.String messageName, YAMISerializable content) throws YAMIIOException
The content object is serialized and is no longer referenced
after this function returns. If the content is null, an empty
Parameters
object is sent.
Note:
This function implicitly opens a new communication channel
if it is not already open. This channel is kept open until
it is explicitly closed
(see the closeConnection
function)
or until the whole agent is closed or the communication error
is detected.
updateCallback
- object that will be called
when the state of outgoing message changestarget
- the name of the target endpoint -
this name should correspond to the listener name
in some target agent objectobjectName
- the name of the logical destination object
in the target agentmessageName
- the name of the messagecontent
- the content of the message
YAMIIOException
- if the channel cannot be establishedpublic OutgoingMessage send(OutgoingMessageCallback updateCallback, java.lang.String target, java.lang.String objectName, java.lang.String messageName, YAMISerializable content, int priority) throws YAMIIOException
The content object is serialized and is no longer referenced
after this function returns. If the content is null, an empty
Parameters
object is sent.
Note:
This function implicitly opens a new communication channel
if it is not already open. This channel is kept open until
it is explicitly closed
(see the closeConnection
function)
or until the whole agent is closed or the communication error
is detected.
updateCallback
- object that will be called
when the state of outgoing message changestarget
- the name of the target endpoint -
this name should correspond to the listener name
in some target agent objectobjectName
- the name of the logical destination object
in the target agentmessageName
- the name of the messagecontent
- the content of the messagepriority
- the priority of the message
YAMIIOException
- if the channel cannot be establishedpublic OutgoingMessage send(OutgoingMessageCallback updateCallback, java.lang.String target, java.lang.String objectName, java.lang.String messageName, YAMISerializable content, int priority, boolean autoConnect) throws YAMIIOException
The content object is serialized and is no longer referenced
after this function returns. If the content is null, an empty
Parameters
object is sent.
Note:
This function implicitly opens a new communication channel
if it is not already open. This channel is kept open until
it is explicitly closed
(see the closeConnection
function)
or until the whole agent is closed or the communication error
is detected.
updateCallback
- object that will be called
when the state of outgoing message changestarget
- the name of the target endpoint -
this name should correspond to the listener name
in some target agent objectobjectName
- the name of the logical destination object
in the target agentmessageName
- the name of the messagecontent
- the content of the messagepriority
- the priority of the messageautoConnect
- the flag controlling automatic (re)connection
YAMIIOException
- if the channel cannot be establishedpublic void sendOneWay(java.lang.String target, java.lang.String objectName, java.lang.String messageName, YAMISerializable content) throws YAMIIOException
The content object is serialized and is no longer referenced
after this function returns. If the content is null, an empty
Parameters
object is sent.
Note:
This function implicitly opens a new communication channel
if it is not already open. This channel is kept open until
it is explicitly closed
(see the closeConnection
function)
or until the whole agent is closed or the communication error
is detected.
target
- the name of the target endpoint -
this name should correspond to the listener name
in some target agent objectobjectName
- the name of the logical destination object
in the target agentmessageName
- the name of the messagecontent
- the content of the message
YAMIIOException
- if the channel cannot be establishedpublic void sendOneWay(java.lang.String target, java.lang.String objectName, java.lang.String messageName, YAMISerializable content, int priority) throws YAMIIOException
The content object is serialized and is no longer referenced
after this function returns. If the content is null, an empty
Parameters
object is sent.
Note:
This function implicitly opens a new communication channel
if it is not already open. This channel is kept open until
it is explicitly closed
(see the closeConnection
function)
or until the agent is closed or the communication error
is detected.
target
- the name of the target endpoint -
this name should correspond to the listener name
in some target agent objectobjectName
- the name of the logical destination object
in the target agentmessageName
- the name of the messagecontent
- the content of the messagepriority
- the priority of the message
YAMIIOException
- if the channel cannot be establishedpublic void sendOneWay(java.lang.String target, java.lang.String objectName, java.lang.String messageName, YAMISerializable content, int priority, boolean autoConnect) throws YAMIIOException
The content object is serialized and is no longer referenced
after this function returns. If the content is null, an empty
Parameters
object is sent.
Note:
This function implicitly opens a new communication channel
if it is not already open. This channel is kept open until
it is explicitly closed
(see the closeConnection
function)
or until the agent is closed or the communication error
is detected.
target
- the name of the target endpoint -
this name should correspond to the listener name
in some target agent objectobjectName
- the name of the logical destination object
in the target agentmessageName
- the name of the messagecontent
- the content of the messagepriority
- the priority of the messageautoConnect
- the flag controlling automatic (re)connection
YAMIIOException
- if the channel cannot be establishedpublic void closeConnection(java.lang.String target)
target
- the name of connection to closepublic void closeConnection(java.lang.String target, int priority)
The priority allows to properly handle the existing outgoing messages that are waiting in the outgoing queue for transmission.
The existing messages with lower priority are abandoned, whereas the existing messages with priority equal or higher to the one provided as parameter are retained in the outgoing queue and are properly pushed for transmission before the channel is physically closed.
The channel is closed immediately only if there are no messages waiting in its outgoing queue.
If the failover group is given then all targets from the group are closed.
Closing the channel that does not exist is a no-op.
target
- the name of connection to closepriority
- proprity of the request, respects existing
messages in the outgoing queuepublic Agent.OutgoingFlowState getOutgoingFlowState()
public void close()
Note: After this function is called the agent should not be used any longer.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |