Class Connection

java.lang.Object
com.swiftmq.amqp.v100.client.Connection
All Implemented Interfaces:
ExceptionHandler

public class Connection extends Object implements ExceptionHandler
Representation of an AMQP connection.

The actual connect is done by calling the "connect()" method. Any attribute change, e.g. buffer size, must be done before this method is called.

Author:
IIT Software GmbH, Bremen/Germany, (c) 2011, All Rights Reserved
  • Constructor Details

    • Connection

      public Connection(AMQPContext ctx, String hostname, int port, String userName, String password)
      Creates a Connection and uses SASL for authentication.
      Parameters:
      ctx - AMQP context
      hostname - Hostname.
      port - Port
      userName - Username
      password - Password
    • Connection

      public Connection(AMQPContext ctx, String hostname, int port, boolean doAuth)
      Creates a Connection and either does an anonymous login via SASL (doAuth is true) or avoids SASL and starts directly with the AMQP protocol (doAuth is false).
      Parameters:
      ctx - AMQP context
      hostname - Hostname
      port - Port
      doAuth - do authentication as anonymous via SASL or do not use SASL at all
  • Method Details

    • getExceptionListener

      public ExceptionListener getExceptionListener()
      Returns the exception listener
      Returns:
      exception listener
    • setExceptionListener

      public void setExceptionListener(ExceptionListener exceptionListener)
      Sets the exception listener.
      Parameters:
      exceptionListener - exception listener
    • getMaxFrameSize

      public long getMaxFrameSize()
      Returns the maximum frame size
      Returns:
      max frame size
    • setMaxFrameSize

      public void setMaxFrameSize(long maxFrameSize)
      Sets the maximum frame size. Default is Integer.MAX_VALUE.
      Parameters:
      maxFrameSize - max frame size
    • setMechanism

      public void setMechanism(String mechanism)
      Sets the SASL mechanisms to use for authentication. If SwiftMQ is the remote server, it supports PLAIN, CRAM-MD5, Digest-MD5. For ANONYMOUS (which SwiftMQ supports as well) please use the resp. constructor of this connection.
      Parameters:
      mechanism - the SASL mechanisms to use
    • getContainerId

      public String getContainerId()
      Returns the container id
      Returns:
      container id
    • setContainerId

      public void setContainerId(String containerId)
      Sets the container id. A container id is automatically and randomly generated if it is not set. For SwiftMQ the container id is used to identify durable subscribers. It is the same as the client id in JMS.
      Parameters:
      containerId - container id
    • getOpenHostname

      public String getOpenHostname()
      Returns the hostname set in the open frame.
      Returns:
      hostname
    • setOpenHostname

      public void setOpenHostname(String openHostname)
      Sets (overwrites) the hostname that will be set in the open frame. Some AMQP brokers may use this field to select a backend service and use this field as a "virtual host".
      Parameters:
      openHostname - open hostname
    • setIdleTimeout

      public void setIdleTimeout(long idleTimeout)
      Sets the idle timeout. Default is Long.MAX_VALUE.

      If a connection does not send/receive data within this interval, the connection is closed. The SwiftMQ client sends heart beat messages every idletimeout/2 millisecond.

      Parameters:
      idleTimeout - idle timeout in milliseconds
    • getInputBufferSize

      public int getInputBufferSize()
      Returns the input buffer size
      Returns:
      input buffer size
    • setInputBufferSize

      public void setInputBufferSize(int inputBufferSize)
      Sets the input buffer size. This is the size of the network buffer SwiftMQ uses to receive frames. Default is 131072 bytes.
      Parameters:
      inputBufferSize - input buffer size
    • getInputBufferExtendSize

      public int getInputBufferExtendSize()
      Returns the input buffer extend size
      Returns:
      input buffer extend size
    • setInputBufferExtendSize

      public void setInputBufferExtendSize(int inputBufferExtendSize)
      Sets the input buffer extend size. This is the size on which the input buffer is extended if its size isn't sufficient to receive a frame. Default is 65536 bytes.
      Parameters:
      inputBufferExtendSize - input buffer extend size
    • getOutputBufferSize

      public int getOutputBufferSize()
      Returns the output buffer size
      Returns:
      output buffer size
    • setOutputBufferSize

      public void setOutputBufferSize(int outputBufferSize)
      Sets the output buffer size. This is the size of the network buffer SwiftMQ uses to send frames. Default is 131072 bytes.
      Parameters:
      outputBufferSize - output buffer size
    • getOutputBufferExtendSize

      public int getOutputBufferExtendSize()
      Returns the output buffer extend size
      Returns:
      output buffer extend size
    • setOutputBufferExtendSize

      public void setOutputBufferExtendSize(int outputBufferExtendSize)
      Sets the output buffer extend size. This is the size on which the output buffer is extended if its size isn't sufficient to send a frame. Default is 65536 bytes.
      Parameters:
      outputBufferExtendSize - output buffer extend size
    • getSocketFactory

      public SocketFactory getSocketFactory()
      Returns the exception listener
      Returns:
      exception listener
    • setSocketFactory

      public void setSocketFactory(SocketFactory socketFactory)
      Sets the socket factory. Default is com.swiftmq.net.PlainSocketFactory. To use SSL/TLS, specify com.swiftmq.net.JSSESocketFactory.
      Parameters:
      socketFactory - socket factory
    • getUserName

      public String getUserName()
      Returns the user name
      Returns:
      user name
    • connect

      Performs the actual connect to the remote host, negotiates the protocol and authenticates the user
      Throws:
      IOException - if an IOExcption occurs
      UnsupportedProtocolVersionException - if the AMQP/SASL protocol version is not supported by the remote host
      AuthenticationException - if the user cannot be authenticated
      ConnectionClosedException - if the connection was closed
    • onException

      public void onException(IOException e)
      Internal use.
      Specified by:
      onException in interface ExceptionHandler
      Parameters:
      e - IOException
    • createSession

      public Session createSession(long incomingWindowSize, long outgoingWindowSize) throws SessionHandshakeException, ConnectionClosedException
      Creates a new Session.
      Parameters:
      incomingWindowSize - Incoming Window Size (maxnumber of unsettled incoming transfers)
      outgoingWindowSize - Outgoing Window Size (max number of unsettled outgoing transfers)
      Returns:
      Session
      Throws:
      SessionHandshakeException - An error occured during handshake
      ConnectionClosedException - The connection was closed
    • removeSession

      protected void removeSession(Session session)
    • getSessionForLocalChannel

      protected Session getSessionForLocalChannel(int localChannel)
    • mapSessionToRemoteChannel

      protected void mapSessionToRemoteChannel(Session session, int remoteChannel)
    • unmapSessionFromRemoteChannel

      protected void unmapSessionFromRemoteChannel(int remoteChannel)
    • getSessionForRemoteChannel

      protected Session getSessionForRemoteChannel(int remoteChannel)
    • getOutboundHandler

      protected OutboundHandler getOutboundHandler()
    • cancel

      public void cancel()
      Internal use only
    • close

      public void close()
      Close this connection and all sessions created from it.
    • close

      protected void close(String condition, String description)