public class RelayHandler
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
protected java.util.Map<java.lang.Byte,jadex.bridge.service.types.message.ICodec> |
codecs
The available codecs for awareness infos (cached for speed).
|
protected jadex.platform.service.message.transport.httprelaymtp.RelayConnectionManager |
conman
The connection manager for communicating with remote peers.
|
protected jadex.bridge.service.types.message.ICodec[] |
defcodecs
The default codecs (used for relay-to-relay communication).
|
protected java.util.Map<java.lang.String,jadex.commons.collection.IBlockingQueue<Message>> |
map
The relay map (id -> queue for pending requests).
|
protected PeerList |
peers
The peer list.
|
protected java.util.Map<java.lang.Object,PlatformInfo> |
platforms
Info about connected platforms.
|
protected RelayServerSettings |
settings
The settings loaded from file.
|
protected StatsDB |
statsdb
The statistics database (if any).
|
static java.io.File |
SYSTEMDIR
The directory for settings and statistics.
|
| Constructor and Description |
|---|
RelayHandler()
Initialize the handler.
|
| Modifier and Type | Method and Description |
|---|---|
void |
dispose()
Cleanup on shutdown.
|
jadex.platform.service.message.transport.httprelaymtp.RelayConnectionManager |
getConnectionManager()
Get the connection manager.
|
PeerHandler[] |
getCurrentPeers()
Get the current peers.
|
PlatformInfo[] |
getCurrentPlatforms()
Get the current platforms
|
static java.util.logging.Logger |
getLogger()
Get the logger.
|
PeerList |
getPeerList()
Get the peer list.
|
RelayServerSettings |
getSettings()
Get the settings.
|
StatsDB |
getStatisticsDB()
Get the statistics database (if any).
|
void |
handleAwareness(java.io.InputStream in)
Called when an awareness info is received from a connected platform.
|
void |
handleConnection(java.lang.String id,
java.io.OutputStream out)
Called when a platform registers itself at the relay.
|
void |
handleMessage(java.io.InputStream in,
java.lang.String protocol)
Called when a message should be sent.
|
void |
handleOffline(java.lang.String hostip,
java.io.InputStream in)
Called when an offline status change is posted by a platform.
|
void |
handlePlatform(java.io.InputStream in)
Called when a single platform info is received from a peer relay server.
|
void |
handlePlatforms(java.io.InputStream in)
Called when platform infos are received from a peer relay server.
|
java.lang.String |
handleServersRequest(java.lang.String requesturl,
java.lang.String peerurl,
java.lang.String peerid,
int peerstate,
boolean initial)
Get the available servers as comma-separated list of URLs.
|
void |
handleSyncRequest(java.lang.String peerid,
int startid,
int cnt,
java.io.OutputStream out)
Send requested db entries.
|
void |
initConnection(java.lang.String id,
java.lang.String hostip,
java.lang.String hostname,
java.lang.String protocol)
Called when a platform registers itself at the relay.
|
protected static byte[] |
readData(java.io.InputStream is,
int length)
Read data into a byte array.
|
static java.lang.String |
readString(java.io.InputStream in)
Read a string from the given stream.
|
protected void |
sendAwarenessInfos(jadex.bridge.service.types.awareness.AwarenessInfo awainfo,
jadex.bridge.service.types.message.ICodec[] pcodecs,
boolean local,
boolean initial)
Send awareness messages for a new or changed awareness info.
|
void |
sendPlatformInfo(PlatformInfo info)
Send a single platform info to all peer relay servers.
|
void |
sendPlatformInfos(PeerHandler peer,
PlatformInfo[] infos)
Send platform infos to a peer relay server.
|
public static final java.io.File SYSTEMDIR
protected RelayServerSettings settings
protected java.util.Map<java.lang.String,jadex.commons.collection.IBlockingQueue<Message>> map
protected java.util.Map<java.lang.Object,PlatformInfo> platforms
protected java.util.Map<java.lang.Byte,jadex.bridge.service.types.message.ICodec> codecs
protected jadex.bridge.service.types.message.ICodec[] defcodecs
protected PeerList peers
protected StatsDB statsdb
protected jadex.platform.service.message.transport.httprelaymtp.RelayConnectionManager conman
public void dispose()
public RelayServerSettings getSettings()
public jadex.platform.service.message.transport.httprelaymtp.RelayConnectionManager getConnectionManager()
public PeerList getPeerList()
public void initConnection(java.lang.String id,
java.lang.String hostip,
java.lang.String hostname,
java.lang.String protocol)
public void handleConnection(java.lang.String id,
java.io.OutputStream out)
public void handleMessage(java.io.InputStream in,
java.lang.String protocol)
throws java.lang.Exception
java.lang.Exceptionpublic void handleAwareness(java.io.InputStream in)
throws java.lang.Exception
java.lang.Exceptionpublic void handleOffline(java.lang.String hostip,
java.io.InputStream in)
throws java.lang.Exception
java.lang.Exceptionpublic void handlePlatform(java.io.InputStream in)
throws java.lang.Exception
java.lang.Exceptionpublic void handlePlatforms(java.io.InputStream in)
throws java.lang.Exception
java.lang.Exceptionpublic void handleSyncRequest(java.lang.String peerid,
int startid,
int cnt,
java.io.OutputStream out)
throws java.lang.Exception
java.lang.Exceptionpublic PlatformInfo[] getCurrentPlatforms()
public StatsDB getStatisticsDB()
public PeerHandler[] getCurrentPeers()
public java.lang.String handleServersRequest(java.lang.String requesturl,
java.lang.String peerurl,
java.lang.String peerid,
int peerstate,
boolean initial)
requesturl - Public URL of this relay server as known from the received request.peerurl - URL of a remote peer if sent as part of the request (or null).peerstate - Latest DB id if sent as part of the request (or -1).initial - True when remote peer recovers from failure (or false).public void sendPlatformInfo(PlatformInfo info)
public void sendPlatformInfos(PeerHandler peer, PlatformInfo[] infos)
protected void sendAwarenessInfos(jadex.bridge.service.types.awareness.AwarenessInfo awainfo,
jadex.bridge.service.types.message.ICodec[] pcodecs,
boolean local,
boolean initial)
public static java.lang.String readString(java.io.InputStream in)
throws java.io.IOException
in - The input stream.java.io.IOException - when the stream is closed.protected static byte[] readData(java.io.InputStream is,
int length)
throws java.io.IOException
java.io.IOExceptionpublic static java.util.logging.Logger getLogger()