Class 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
    • 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
      • 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
      • 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()
      • 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 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)
      • 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