Package org.jgroups.client
Class StompConnection
- java.lang.Object
-
- org.jgroups.client.StompConnection
-
- All Implemented Interfaces:
java.lang.Runnable
public class StompConnection extends java.lang.Object implements java.lang.Runnable
STOMP client to access the STOMP [1] protocol. Note that the full STOMP protocol is not implemented, e.g. transactions are currently not supported. The interactive client can be started with -h HOST -p PORT, which are the hostname and port of a JGroups server, running with STOMP in its stack configuration. The interactive client supports automatic failover to a different server if the currently connected-to server crashes, and a simple syntax for sending STOMP messages:subscribe DEST // example: subscribe /topics/a send DEST message // example: send /topics/a Hello world
[1] http://stomp.codehaus.org/Protocol- Author:
- Bela Ban
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
StompConnection.ConnectionCallback
static interface
StompConnection.Listener
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Set<StompConnection.ConnectionCallback>
callbacks
protected java.io.DataInputStream
in
protected java.util.Set<StompConnection.Listener>
listeners
protected Log
log
protected java.io.DataOutputStream
out
protected java.lang.String
password
protected boolean
reconnect
protected java.lang.Thread
runner
protected boolean
running
protected java.util.Set<java.lang.String>
server_destinations
protected java.lang.String
session_id
protected java.net.Socket
sock
protected javax.net.SocketFactory
socket_factory
protected javax.net.ssl.SSLParameters
sslParameters
protected java.util.Set<java.lang.String>
subscriptions
protected java.lang.String
userid
-
Constructor Summary
Constructors Constructor Description StompConnection(java.lang.String dest)
StompConnection(java.lang.String dest, boolean reconnect, boolean ssl)
StompConnection(java.lang.String dest, boolean reconnect, javax.net.ssl.SSLContext ssl)
StompConnection(java.lang.String dest, java.lang.String userid, java.lang.String password, boolean reconnect, boolean ssl)
StompConnection(java.lang.String dest, java.lang.String userid, java.lang.String password, boolean reconnect, javax.net.ssl.SSLContext sslcontext)
StompConnection(java.lang.String dest, java.lang.String userid, java.lang.String password, boolean reconnect, javax.net.ssl.SSLContext sslcontext, javax.net.ssl.SSLParameters sslParameters)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addCallback(StompConnection.ConnectionCallback cb)
void
addListener(StompConnection.Listener listener)
protected java.net.Socket
buildSocket(java.lang.String host, int port)
protected void
closeConnections()
void
connect()
protected void
connectToDestination(java.lang.String dest)
void
connectToSingleDestination(java.lang.String destination)
void
disconnect()
java.lang.String
getSessionId()
boolean
isConnected()
static void
main(java.lang.String[] args)
protected void
notifyListeners(java.util.Map<java.lang.String,java.lang.String> info)
protected void
notifyListeners(java.util.Map<java.lang.String,java.lang.String> headers, byte[] buf, int offset, int length)
void
removeCallback(StompConnection.ConnectionCallback cb)
void
removeListener(StompConnection.Listener listener)
void
run()
void
send(java.lang.String destination, byte[] buf)
void
send(java.lang.String destination, byte[] buf, int offset, int length)
void
send(java.lang.String destination, byte[] buf, int offset, int length, java.lang.String... headers)
void
send(java.lang.String destination, java.lang.String... headers)
Sends an INFO without bodyprotected void
sendConnect()
protected void
sendSubscribe(java.lang.String destination)
protected void
sendUnsubscribe(java.lang.String destination)
void
startReconnectingClient()
protected void
startRunner()
void
subscribe(java.lang.String destination)
void
unsubscribe(java.lang.String destination)
-
-
-
Field Detail
-
socket_factory
protected javax.net.SocketFactory socket_factory
-
sock
protected java.net.Socket sock
-
in
protected java.io.DataInputStream in
-
out
protected java.io.DataOutputStream out
-
server_destinations
protected final java.util.Set<java.lang.String> server_destinations
-
listeners
protected final java.util.Set<StompConnection.Listener> listeners
-
subscriptions
protected final java.util.Set<java.lang.String> subscriptions
-
callbacks
protected final java.util.Set<StompConnection.ConnectionCallback> callbacks
-
runner
protected java.lang.Thread runner
-
running
protected volatile boolean running
-
session_id
protected java.lang.String session_id
-
userid
protected java.lang.String userid
-
password
protected java.lang.String password
-
reconnect
protected boolean reconnect
-
log
protected final Log log
-
sslParameters
protected javax.net.ssl.SSLParameters sslParameters
-
-
Constructor Detail
-
StompConnection
public StompConnection(java.lang.String dest)
- Parameters:
dest
- IP address + ':' + port, e.g. "192.168.1.5:8787"
-
StompConnection
public StompConnection(java.lang.String dest, boolean reconnect, boolean ssl)
-
StompConnection
public StompConnection(java.lang.String dest, boolean reconnect, javax.net.ssl.SSLContext ssl)
-
StompConnection
public StompConnection(java.lang.String dest, java.lang.String userid, java.lang.String password, boolean reconnect, boolean ssl)
-
StompConnection
public StompConnection(java.lang.String dest, java.lang.String userid, java.lang.String password, boolean reconnect, javax.net.ssl.SSLContext sslcontext)
-
StompConnection
public StompConnection(java.lang.String dest, java.lang.String userid, java.lang.String password, boolean reconnect, javax.net.ssl.SSLContext sslcontext, javax.net.ssl.SSLParameters sslParameters)
-
-
Method Detail
-
getSessionId
public java.lang.String getSessionId()
-
addListener
public void addListener(StompConnection.Listener listener)
-
addCallback
public void addCallback(StompConnection.ConnectionCallback cb)
-
removeListener
public void removeListener(StompConnection.Listener listener)
-
removeCallback
public void removeCallback(StompConnection.ConnectionCallback cb)
-
startRunner
protected void startRunner()
-
sendConnect
protected void sendConnect() throws java.io.IOException
- Throws:
java.io.IOException
-
subscribe
public void subscribe(java.lang.String destination)
-
sendSubscribe
protected void sendSubscribe(java.lang.String destination)
-
unsubscribe
public void unsubscribe(java.lang.String destination)
-
sendUnsubscribe
protected void sendUnsubscribe(java.lang.String destination)
-
send
public void send(java.lang.String destination, byte[] buf, int offset, int length, java.lang.String... headers)
-
send
public void send(java.lang.String destination, java.lang.String... headers)
Sends an INFO without body
-
send
public void send(java.lang.String destination, byte[] buf, int offset, int length)
-
send
public void send(java.lang.String destination, byte[] buf)
-
run
public void run()
- Specified by:
run
in interfacejava.lang.Runnable
-
notifyListeners
protected void notifyListeners(java.util.Map<java.lang.String,java.lang.String> headers, byte[] buf, int offset, int length)
-
notifyListeners
protected void notifyListeners(java.util.Map<java.lang.String,java.lang.String> info)
-
connectToSingleDestination
public void connectToSingleDestination(java.lang.String destination) throws java.io.IOException
- Throws:
java.io.IOException
-
connect
public void connect() throws java.io.IOException
- Throws:
java.io.IOException
-
startReconnectingClient
public void startReconnectingClient()
-
buildSocket
protected java.net.Socket buildSocket(java.lang.String host, int port) throws java.io.IOException
- Throws:
java.io.IOException
-
connectToDestination
protected void connectToDestination(java.lang.String dest) throws java.io.IOException
- Throws:
java.io.IOException
-
disconnect
public void disconnect()
-
closeConnections
protected void closeConnections()
-
isConnected
public boolean isConnected()
-
main
public static void main(java.lang.String[] args) throws java.io.IOException
- Throws:
java.io.IOException
-
-