public class TConnection extends Object
Modifier and Type | Class and Description |
---|---|
protected static class |
TConnection.TConnectionState |
class |
TConnection.TEventNameEntry
returned object (array) on an event name list query
|
static interface |
TConnection.TOnDisconnect
Override dispatch to implement a disconnect handler
|
static interface |
TConnection.TOnEventnames
Override dispatch to implement an event names request callback handler
|
static interface |
TConnection.TOnStatusUpdate
Override dispatch to implement a status change handler
|
static interface |
TConnection.TOnSubAndPub |
static interface |
TConnection.TOnVariable
Override dispatch to implement a variable change handler
|
static class |
TConnection.TVarPrefix |
Modifier and Type | Field and Description |
---|---|
boolean |
autoPublish
when true events send on not-publuished events are automatically published
|
static String |
DEFAULT_FEDERATION
value to be used when no specific federation is used
|
static String |
DEFAULT_HUB
value to be used when no specific remote server is used
|
static int |
DEFAULT_PORT
value to be used when no specific port is used
|
static int |
EF_PUBLISHERS
request event name filter: requesting publisher counts
|
static int |
EF_SUBSCRIBERS
request event name filter: requesting subscriber counts
|
static int |
EF_TIMERS
request event name filter: requesting timer counts
|
static String |
EVENT_FILTER_POST_FIX |
static int |
ICE_CONNECTION_CLOSED
command result: the connection is closed
|
static int |
ICE_EVENT_NOT_PUBLISHED
command result: the event was not published
|
boolean |
imb2Compatible
when true IMB2 features are used if possible to emulate IMB3 behavior
|
static byte[] |
MAGIC_BYTES
magic bytes to identify the start of a valid IMB packet
|
static byte[] |
MAGIC_STRING_CHECK
magic bytes to identify the end of the payload on a valid IMB packet (as array of bytes)
|
static int |
MAX_PAYLOAD_SIZE
The maximum size of the payload in a low level IMB command
|
TConnection.TOnDisconnect |
onDisconnect
Handler to be called on a disconnect
|
TConnection.TOnEventnames |
onEventNames
Handler to be called on a event names request callback
|
TConnection.TOnSubAndPub |
onSubAndPub |
static int |
STATUS_BUSY
signal client status: busy (see updateStatus)
|
static int |
STATUS_CALCULATING
signal client status: calculating (see updateStatus)
|
static int |
STATUS_READY
signal client status: ready (see updateStatus)
|
Constructor and Description |
---|
TConnection(String aRemoteHost,
int aRemotePort,
String aOwnerName,
int aOwnerID,
String aFederation)
Create an IMB connection to the framework
|
TConnection(String aRemoteHost,
int aRemotePort,
String aOwnerName,
int aOwnerID,
String aFederation,
boolean aStartReadingThread)
Create an IMB connection to the framework
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the connection and cleans up socket, streams and thread
|
protected void |
finalize() |
int |
getClientHandle()
Returns the client handle the hub assigned to this connection
|
String |
getFederation()
Returns the current federation
|
boolean |
getLinger()
Returns the status of the linger option on the connected socket
|
boolean |
getNoDelay()
Returns the state of the NAGLE algorithm on the connected socket
|
int |
getOwnerID()
Returns the currently specified owner id
|
String |
getOwnerName()
Returns the currently specified owner name
|
String |
getRemoteHost()
Returns the IP address or DNS name of the currently connected hub
|
int |
getRemotePort()
Returns the TCP port of the currently connected hub
|
int |
getUniqueClientID()
Returns the unique client id the hub assigned to this connection
|
protected void |
handleCommandOther(int aCommand,
TByteBuffer aPayload) |
boolean |
isConnected()
Returns the connected state of the connection
|
int |
logWriteLn(String aLogEventName,
String aLine,
TEventEntry.TLogLevel aLevel)
Log an entry to the framework
|
protected boolean |
open(String aHost,
int aPort) |
protected boolean |
open(String aHost,
int aPort,
boolean aStartReadingThread) |
protected String |
prefixFederation(String aName) |
protected String |
prefixFederation(String aName,
boolean aUseFederationPrefix) |
TEventEntry |
publish(String aEventName)
Publishes on the specified event
|
TEventEntry |
publish(String aEventName,
boolean aUseFederationPrefix)
Publishes on the specified event
|
void |
readCommandsNonBlocking()
Manually reading commands when not using a reader thread.
|
void |
readCommandsNonThreaded(int aTimeOut)
Manually reading commands when not using a reader thread.
|
void |
removeStatus()
Removes the current status for this client
|
protected void |
requestAllVariables()
Send a request to the framework to send all variables with their contents to this client
|
int |
requestEventname(String aEventNameFilter,
int aEventFilters)
Query the framework for registered event names
|
void |
setFederation(String aFederation)
Set the current federation.
|
void |
setLinger(boolean aValue)
Sets the status of the linger option on the connected socket
|
void |
setNoDelay(boolean aValue)
Sets the state of the NAGLE algorithm on the socket
|
void |
setOnStatusUpdate(TConnection.TOnStatusUpdate aValue)
Set the callback handler for status updates
|
void |
setOnVariable(TConnection.TOnVariable aValue)
Set the callback handler for framework variable changes
|
void |
setOwnerID(int aValue)
Changes the owner id
|
void |
setOwnerName(String aValue)
Changes the owner name
|
protected void |
setState(TConnection.TConnectionState aState) |
void |
setThrottle(int aThrottle)
Throttle down buffer events send to this client if specific flags are set on events
|
void |
setVariableValue(String aVarName,
String aVarValue)
Set the value of a global framework variable
|
void |
setVariableValue(String aVarName,
String aVarValue,
TConnection.TVarPrefix aVarPrefix)
Set the value of a global framework variable
|
void |
setVariableValue(String aVarName,
TByteBuffer aVarValue)
Set the value of a global framework variable
|
void |
setVariableValue(String aVarName,
TByteBuffer aVarValue,
TConnection.TVarPrefix aVarPrefix)
Set the value of a global framework variable
|
int |
signalBuffer(String aEventName,
int aBufferID,
byte[] aBuffer)
Send a buffer event to the framework.
|
int |
signalBuffer(String aEventName,
int aBufferID,
byte[] aBuffer,
int aEventFlags,
boolean aUseFederationPrefix)
Send a buffer event to the framework.
|
int |
signalChangeFederation(int aNewFederationID,
String aNewFederation)
Signal a new federation to the framework
|
int |
signalChangeObject(String aEventName,
int aAction,
int aObjectID,
String aAttribute)
Send a ChangeObject event to the framework
This is the simple way to send events.
|
int |
signalChangeObject(String aEventName,
int aAction,
int aObjectID,
String aAttribute,
boolean aUseFederationPrefix)
Send a ChangeObject event to the framework
This is the simple way to send events.
|
int |
signalEvent(String aEventName,
int aEventKind,
TByteBuffer aEventPayload)
Send an event to the framework.
|
int |
signalEvent(String aEventName,
int aEventKind,
TByteBuffer aEventPayload,
boolean aUseFederationPrefix)
Send an event to the framework.
|
int |
signalFocus(double aX,
double aY)
Signal a new focus point to the framework
|
int |
signalStream(String aEventName,
String aStreamName,
InputStream aStream)
Send a stream to the framework
|
int |
signalStream(String aEventName,
String aStreamName,
InputStream aStream,
boolean aUseFederationPrefix)
Send a stream to the framework
|
TEventEntry |
subscribe(String aEventName)
Subscribe to the specified event
|
TEventEntry |
subscribe(String aEventName,
boolean aUseFederationPrefix)
Subscribe to the specified event
|
void |
subscribeOnFederationChange(TEventEntry.TOnChangeFederation aOnChangeFederation)
Subscribe to federation change events and register the callback handler for these events
|
void |
subscribeOnFocus(TEventEntry.TOnFocus aOnFocus)
Subscribe to focus events and registers the callback handler for these events.
|
String |
toString() |
void |
unPublish(String aEventName)
Unpublish on the specified event.
|
void |
unPublish(String aEventName,
boolean aUseFederationPrefix)
Unpublish on the specified event.
|
void |
unSubscribe(String aEventName)
Unsubscribe from the specified event
|
void |
unSubscribe(String aEventName,
boolean aUseFederationPrefix)
Unsubscribe from the specified event
|
void |
updateStatus(int aProgress,
int aStatus)
Update the central status for this client
|
protected int |
writeCommand(int aCommand,
byte[] aPayload)
Write a single command to the framework
|
public static final String EVENT_FILTER_POST_FIX
public static final byte[] MAGIC_BYTES
public static final byte[] MAGIC_STRING_CHECK
public static final int MAX_PAYLOAD_SIZE
public static final String DEFAULT_HUB
public static final int DEFAULT_PORT
public static final String DEFAULT_FEDERATION
public static final int ICE_CONNECTION_CLOSED
public static final int ICE_EVENT_NOT_PUBLISHED
public boolean autoPublish
public boolean imb2Compatible
public TConnection.TOnDisconnect onDisconnect
public static final int STATUS_READY
public static final int STATUS_CALCULATING
public static final int STATUS_BUSY
public TConnection.TOnEventnames onEventNames
public TConnection.TOnSubAndPub onSubAndPub
public static final int EF_PUBLISHERS
public static final int EF_SUBSCRIBERS
public static final int EF_TIMERS
public TConnection(String aRemoteHost, int aRemotePort, String aOwnerName, int aOwnerID, String aFederation)
aRemoteHost
- IP address or DNS name of the IMB hub to connect toaRemotePort
- TCP port of the IMB hub to connect toaOwnerName
- optional description of the connecting clientaOwnerID
- optional id of the connecting clientaFederation
- federation to connect with; this is default prefixed to subscribed and published event namespublic TConnection(String aRemoteHost, int aRemotePort, String aOwnerName, int aOwnerID, String aFederation, boolean aStartReadingThread)
aRemoteHost
- IP address or DNS name of the IMB hub to connect toaRemotePort
- TCP port of the IMB hub to connect toaOwnerName
- optional description of the connecting clientaOwnerID
- optional id of the connecting clientaFederation
- federation to connect with; this is default prefixed to subscribed and published event namesaStartReadingThread
- use an internal reader thread for processing events and commands from the connected hubprotected int writeCommand(int aCommand, byte[] aPayload)
aCommand
- aPayload
- protected void handleCommandOther(int aCommand, TByteBuffer aPayload)
protected void setState(TConnection.TConnectionState aState)
protected boolean open(String aHost, int aPort)
protected boolean open(String aHost, int aPort, boolean aStartReadingThread)
public String getFederation()
public void setFederation(String aFederation)
aFederation
- the new federationpublic String getRemoteHost()
public int getRemotePort()
public boolean getNoDelay() throws SocketException
SocketException
public void setNoDelay(boolean aValue) throws SocketException
aValue
- if true the NAGLE algorithm is DISABLED (default false)SocketException
public boolean getLinger() throws SocketException
SocketException
public void setLinger(boolean aValue) throws SocketException
aValue
- if true the linger option is enabled with a linger time of 2 secondsSocketException
public boolean isConnected()
public void close()
public void setThrottle(int aThrottle)
aThrottle
- public void readCommandsNonBlocking() throws IOException
IOException
public void readCommandsNonThreaded(int aTimeOut) throws SocketException
aTimeOut
- SocketException
public int getOwnerID()
public void setOwnerID(int aValue)
aValue
- the new owner idpublic String getOwnerName()
public void setOwnerName(String aValue)
aValue
- the new owner namepublic int getUniqueClientID()
public int getClientHandle()
public TEventEntry subscribe(String aEventName)
aEventName
- the event name to subscribe to (it will be prefixed with the current federation)public TEventEntry subscribe(String aEventName, boolean aUseFederationPrefix)
aEventName
- the event name to subscribe toaUseFederationPrefix
- if true the given event name will be prefixed with the current federationpublic TEventEntry publish(String aEventName)
aEventName
- the event name to publish on (it will be prefixed with the current federation)public TEventEntry publish(String aEventName, boolean aUseFederationPrefix)
aEventName
- the event name to publish onaUseFederationPrefix
- if true the given event name will be prefixed with the current federationpublic void unSubscribe(String aEventName)
aEventName
- the event name to unsubscribe from (it will be prefixed with the current federation)public void unSubscribe(String aEventName, boolean aUseFederationPrefix)
aEventName
- the event name to unsubscribe fromaUseFederationPrefix
- if true the given event name will be prefixed with the current federationpublic void unPublish(String aEventName)
aEventName
- the event name to unpublish on (it will be prefixed with the current federation)public void unPublish(String aEventName, boolean aUseFederationPrefix)
aEventName
- the event name to unpublish onaUseFederationPrefix
- if true the given event name will be prefixed with the current federationpublic int signalEvent(String aEventName, int aEventKind, TByteBuffer aEventPayload)
aEventName
- aEventKind
- aEventPayload
- public int signalEvent(String aEventName, int aEventKind, TByteBuffer aEventPayload, boolean aUseFederationPrefix)
aEventName
- aEventKind
- aEventPayload
- aUseFederationPrefix
- if true the given event name will be prefixed with the current federationpublic int signalBuffer(String aEventName, int aBufferID, byte[] aBuffer)
aEventName
- aBufferID
- aBuffer
- public int signalBuffer(String aEventName, int aBufferID, byte[] aBuffer, int aEventFlags, boolean aUseFederationPrefix)
aEventName
- aBufferID
- aBuffer
- aEventFlags
- aUseFederationPrefix
- if true the given event name will be prefixed with the current federationpublic int signalChangeObject(String aEventName, int aAction, int aObjectID, String aAttribute)
aEventName
- aAction
- aObjectID
- aAttribute
- public int signalChangeObject(String aEventName, int aAction, int aObjectID, String aAttribute, boolean aUseFederationPrefix)
aEventName
- aAction
- aObjectID
- aAttribute
- aUseFederationPrefix
- if true the given event name will be prefixed with the current federationpublic int signalStream(String aEventName, String aStreamName, InputStream aStream)
aEventName
- aStreamName
- name of the stream to identify the stream by the receiveraStream
- public int signalStream(String aEventName, String aStreamName, InputStream aStream, boolean aUseFederationPrefix)
aEventName
- aStreamName
- aStream
- aUseFederationPrefix
- public void setOnVariable(TConnection.TOnVariable aValue)
aValue
- protected void requestAllVariables()
public void setVariableValue(String aVarName, String aVarValue)
aVarName
- aVarValue
- public void setVariableValue(String aVarName, TByteBuffer aVarValue)
aVarName
- aVarValue
- public void setVariableValue(String aVarName, String aVarValue, TConnection.TVarPrefix aVarPrefix)
aVarName
- aVarValue
- aVarPrefix
- public void setVariableValue(String aVarName, TByteBuffer aVarValue, TConnection.TVarPrefix aVarPrefix)
aVarName
- aVarValue
- aVarPrefix
- public void setOnStatusUpdate(TConnection.TOnStatusUpdate aValue)
aValue
- public void updateStatus(int aProgress, int aStatus) throws InterruptedException
aProgress
- the progress, if available, from 0 to 100 or counting down to 0aStatus
- the current status of the client (see STATUS_* constants)InterruptedException
public void removeStatus()
public void subscribeOnFocus(TEventEntry.TOnFocus aOnFocus)
aOnFocus
- callback event handlerpublic int signalFocus(double aX, double aY)
aX
- aY
- public void subscribeOnFederationChange(TEventEntry.TOnChangeFederation aOnChangeFederation)
aOnChangeFederation
- public int signalChangeFederation(int aNewFederationID, String aNewFederation)
aNewFederationID
- aNewFederation
- public int logWriteLn(String aLogEventName, String aLine, TEventEntry.TLogLevel aLevel)
aLogEventName
- aLine
- aLevel
- public int requestEventname(String aEventNameFilter, int aEventFilters)
aEventNameFilter
- aEventFilters
- Copyright © 2014–2016 Delft University of Technology. All rights reserved.