org.jgroups.client
Class StompConnection

java.lang.Object
  extended by 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
static interface StompConnection.Listener
           
 
Field Summary
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  java.util.Set<java.lang.String> subscriptions
           
protected  java.lang.String userid
           
 
Constructor Summary
StompConnection(java.lang.String dest)
           
StompConnection(java.lang.String dest, boolean reconnect, boolean ssl)
           
StompConnection(java.lang.String dest, java.lang.String userid, java.lang.String password, boolean reconnect, boolean ssl)
           
 
Method Summary
 void addListener(StompConnection.Listener listener)
           
protected  void closeConnections()
           
 void connect()
           
protected  void connectToDestination(java.lang.String dest)
           
 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 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 body
protected  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)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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

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
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,
                       java.lang.String userid,
                       java.lang.String password,
                       boolean reconnect,
                       boolean ssl)
Method Detail

getSessionId

public java.lang.String getSessionId()

addListener

public void addListener(StompConnection.Listener listener)

removeListener

public void removeListener(StompConnection.Listener listener)

startRunner

protected void startRunner()

sendConnect

protected void sendConnect()

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 interface java.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)

connect

public void connect()
             throws java.io.IOException
Throws:
java.io.IOException

startReconnectingClient

public void startReconnectingClient()

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


Copyright © 1998-2012 Bela Ban / Red Hat. All Rights Reserved.