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
`static interface` `StompConnection.Listener`

### Field Summary

Fields
`protected java.io.DataInputStream` `in`
`protected java.util.Set<StompConnection.Listener>` `listeners`
`protected Log` `log`
`protected java.io.DataOutputStream` `out`
`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 java.util.Set<java.lang.String>` `subscriptions`

### Constructor Summary

Constructors
Constructor and Description
`StompConnection(java.lang.String dest)`

### Method Summary

Methods
`void` `addListener(StompConnection.Listener listener)`
`protected void` `close()`
`void` `connect()`
`protected void` `connect(java.lang.String dest)`
`void` `connect(java.lang.String userid, java.lang.String password)`
`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)`
`protected static java.net.SocketAddress` `parse(java.lang.String dest)`
`protected java.lang.String` `pickRandomDestination()`
`void` `reconnect()`
`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` `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

#### 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

#### 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"

### Method Detail

#### getSessionId

    public java.lang.String getSessionId()

#### addListener

    public void addListener(StompConnection.Listener listener)

#### removeListener

    public void removeListener(StompConnection.Listener listener)

#### connect

    public void connect(java.lang.String userid,
               java.lang.String password)
                 throws java.io.IOException

Throws:
  `java.io.IOException`

#### reconnect

    public void reconnect()
                   throws java.io.IOException

Throws:
  `java.io.IOException`

#### connect

    public void connect()
                 throws java.io.IOException

Throws:
  `java.io.IOException`

#### disconnect

    public void disconnect()

#### subscribe

    public void subscribe(java.lang.String destination)

#### unsubscribe

    public void unsubscribe(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)

#### pickRandomDestination

    protected java.lang.String pickRandomDestination()

#### connect

    protected void connect(java.lang.String dest)
                    throws java.io.IOException

Throws:
  `java.io.IOException`

#### parse

    protected static java.net.SocketAddress parse(java.lang.String dest)
                                           throws java.net.UnknownHostException

Throws:
  `java.net.UnknownHostException`

#### close

    protected void close()

#### isConnected

    public boolean isConnected()

#### startRunner

    protected void startRunner()

#### main

    public static void main(java.lang.String[] args)
                     throws java.io.IOException

Throws:
  `java.io.IOException`