public class IMCProtocol extends java.lang.Object implements IMessageBus, pt.lsts.neptus.messages.listener.MessageListener<pt.lsts.neptus.messages.listener.MessageInfo,IMCMessage>
Constructor and Description |
---|
IMCProtocol() |
IMCProtocol(int bindPort)
Create a new IMCProtocol instance and bind it to given local port
|
IMCProtocol(java.lang.String localName,
int localPort) |
Modifier and Type | Method and Description |
---|---|
void |
addMessageListener(pt.lsts.neptus.messages.listener.MessageListener<pt.lsts.neptus.messages.listener.MessageInfo,IMCMessage> l)
Add a global message listener that will be call on ALL
incoming messages
|
void |
addMessageListener(pt.lsts.neptus.messages.listener.MessageListener<pt.lsts.neptus.messages.listener.MessageInfo,IMCMessage> l,
java.util.Collection<java.lang.String> typesToListen)
Add a listener to be called whenever messages of certain types are
received
|
void |
addMessageListener(pt.lsts.neptus.messages.listener.MessageListener<pt.lsts.neptus.messages.listener.MessageInfo,IMCMessage> listener,
java.lang.String... typesToListen)
Add a listener to be called whenever messages of certain types are
received
|
void |
addService(java.lang.String service) |
void |
addSingleShotListener(pt.lsts.neptus.messages.listener.MessageListener<pt.lsts.neptus.messages.listener.MessageInfo,IMCMessage> listener,
java.lang.String typeToListen)
Add a listener that will be called once and then removed from the list of
observers
|
long |
announceAgeMillis(java.lang.String name)
Retrieve time elapsed since last announce of given system name
|
boolean |
broadcast(IMCMessage msg)
Send a message to all known (via receiced announces) systems.
|
void |
connect(java.lang.String system) |
void |
disconnect(java.lang.String system) |
int |
getLocalId() |
java.lang.String |
getLocalName() |
java.lang.String[] |
lookupService(java.lang.String serviceName) |
static void |
main(java.lang.String[] args) |
void |
onMessage(pt.lsts.neptus.messages.listener.MessageInfo info,
IMCMessage msg) |
void |
register(java.lang.Object consumer)
Register a POJO consumer.
|
void |
removeMessageListener(pt.lsts.neptus.messages.listener.MessageListener<pt.lsts.neptus.messages.listener.MessageInfo,IMCMessage> l)
Remove a previously added message listener
|
boolean |
sendMessage(java.lang.String sysName,
IMCMessage msg)
Send message to a remote system, specifying its name.
|
boolean |
sendReliably(java.lang.String sysName,
IMCMessage msg,
int timeoutMillis)
This method tries to send a message to given destination with
reliability.
|
boolean |
sendToPeers(IMCMessage msg)
Send a message to the peers that this proto should auto-connect to.
|
void |
setAutoConnect(java.lang.String autoConnect) |
void |
startReplay(java.lang.String dirToReplay,
double speed)
Replay an LSF log folder
|
ImcSystemState |
state(java.lang.String name)
Retrieve the continuously updated state of the given system
|
void |
stop()
Stop this IMCProtocol instance (closes all sockets)
|
void |
stopReplay()
Stop replaying
|
java.lang.String[] |
systems()
Retrieve a list of known system names (from which an announce has been
received)
|
void |
unregister(java.lang.Object consumer)
Unregister a previously registered POJO consumer.
|
java.lang.String |
waitFor(java.lang.String systemExpr,
long timeoutMillis)
This method blocks until a system whose name matches a regular expression
is found on the network or
null if time has expired. |
public IMCProtocol(java.lang.String localName, int localPort)
public IMCProtocol(int bindPort)
bindPort
- The port where to bind for listening to incoming messages
(also advertised using multicast)public IMCProtocol()
public void onMessage(pt.lsts.neptus.messages.listener.MessageInfo info, IMCMessage msg)
onMessage
in interface pt.lsts.neptus.messages.listener.MessageListener<pt.lsts.neptus.messages.listener.MessageInfo,IMCMessage>
public void connect(java.lang.String system)
public void disconnect(java.lang.String system)
public final java.lang.String getLocalName()
public int getLocalId()
public void addService(java.lang.String service)
public long announceAgeMillis(java.lang.String name)
name
- The name of the systempublic boolean broadcast(IMCMessage msg)
msg
- The message to be sent.true
if the message was tentatively sent to at least
one system.public boolean sendToPeers(IMCMessage msg)
msg
- The message to be senttrue
if the message was tentatively sent to at least
one peer.public boolean sendMessage(java.lang.String sysName, IMCMessage msg)
sysName
- The name of the system where to send the messagemsg
- The message to be sent to the systempublic boolean sendReliably(java.lang.String sysName, IMCMessage msg, int timeoutMillis) throws java.lang.Exception
sysName
- The name of the destination of this messagemsg
- The message to send to the destinationtimeoutMillis
- Maximum amount of time, in milliseconds to wait for delivery.true
on success.java.lang.Exception
- In case the destination is not known, is nor currently
reachable or there was an error in the communication.public void register(java.lang.Object consumer)
register
in interface IMessageBus
ImcConsumer
public void unregister(java.lang.Object consumer)
unregister
in interface IMessageBus
public void addMessageListener(pt.lsts.neptus.messages.listener.MessageListener<pt.lsts.neptus.messages.listener.MessageInfo,IMCMessage> listener, java.lang.String... typesToListen)
listener
- The listener to be addedtypesToListen
- The list of message abbreviated names to be observed by this
listenerpublic void addMessageListener(pt.lsts.neptus.messages.listener.MessageListener<pt.lsts.neptus.messages.listener.MessageInfo,IMCMessage> l, java.util.Collection<java.lang.String> typesToListen)
l
- The listener to be addedtypesToListen
- Collection of abbreviated names to be observed by this
listenerpublic void removeMessageListener(pt.lsts.neptus.messages.listener.MessageListener<pt.lsts.neptus.messages.listener.MessageInfo,IMCMessage> l)
l
- The listener to be removed from the observerspublic void addMessageListener(pt.lsts.neptus.messages.listener.MessageListener<pt.lsts.neptus.messages.listener.MessageInfo,IMCMessage> l)
l
- The global listener to be added to the list of observerspublic void addSingleShotListener(pt.lsts.neptus.messages.listener.MessageListener<pt.lsts.neptus.messages.listener.MessageInfo,IMCMessage> listener, java.lang.String typeToListen)
listener
- The listener to be added as a single-shot listenertypeToListen
- The type of message to be listen topublic java.lang.String[] systems()
public java.lang.String[] lookupService(java.lang.String serviceName)
public ImcSystemState state(java.lang.String name)
name
- The system for which to retrieve the statepublic void startReplay(java.lang.String dirToReplay, double speed) throws java.lang.Exception
dirToReplay
- The folder where the files Data.lsf and IMC.xml can be foundspeed
- The time multiplier (1.0 = real time)java.lang.Exception
- In the case the folder cannot be read or any other IO errorspublic void stopReplay()
public void stop()
public void setAutoConnect(java.lang.String autoConnect)
autoConnect
- the autoConnect to setpublic java.lang.String waitFor(java.lang.String systemExpr, long timeoutMillis)
null
if time has expired.systemExpr
- The regular expression to look fortimeoutMillis
- The maximum amount of time to blockpublic static void main(java.lang.String[] args) throws java.lang.Exception
java.lang.Exception