Package com.swiftmq.amqp.v100.client
Class Connection
java.lang.Object
com.swiftmq.amqp.v100.client.Connection
- All Implemented Interfaces:
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 Summary
ConstructorsConstructorDescriptionConnection
(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).Connection
(AMQPContext ctx, String hostname, int port, String userName, String password) Creates a Connection and uses SASL for authentication. -
Method Summary
Modifier and TypeMethodDescriptionvoid
cancel()
Internal use onlyvoid
close()
Close this connection and all sessions created from it.protected void
void
connect()
Performs the actual connect to the remote host, negotiates the protocol and authenticates the usercreateSession
(long incomingWindowSize, long outgoingWindowSize) Creates a new Session.Returns the container idReturns the exception listenerint
Returns the input buffer extend sizeint
Returns the input buffer sizelong
Returns the maximum frame sizeReturns the hostname set in the open frame.protected OutboundHandler
int
Returns the output buffer extend sizeint
Returns the output buffer sizeprotected Session
getSessionForLocalChannel
(int localChannel) protected Session
getSessionForRemoteChannel
(int remoteChannel) Returns the exception listenerReturns the user nameprotected void
mapSessionToRemoteChannel
(Session session, int remoteChannel) void
Internal use.protected void
removeSession
(Session session) void
setContainerId
(String containerId) Sets the container id.void
setExceptionListener
(ExceptionListener exceptionListener) Sets the exception listener.void
setIdleTimeout
(long idleTimeout) Sets the idle timeout.void
setInputBufferExtendSize
(int inputBufferExtendSize) Sets the input buffer extend size.void
setInputBufferSize
(int inputBufferSize) Sets the input buffer size.void
setMaxFrameSize
(long maxFrameSize) Sets the maximum frame size.void
setMechanism
(String mechanism) Sets the SASL mechanisms to use for authentication.void
setOpenHostname
(String openHostname) Sets (overwrites) the hostname that will be set in the open frame.void
setOutputBufferExtendSize
(int outputBufferExtendSize) Sets the output buffer extend size.void
setOutputBufferSize
(int outputBufferSize) Sets the output buffer size.void
setSocketFactory
(SocketFactory socketFactory) Sets the socket factory.protected void
unmapSessionFromRemoteChannel
(int remoteChannel)
-
Constructor Details
-
Connection
Creates a Connection and uses SASL for authentication.- Parameters:
ctx
- AMQP contexthostname
- Hostname.port
- PortuserName
- Usernamepassword
- Password
-
Connection
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 contexthostname
- Hostnameport
- PortdoAuth
- do authentication as anonymous via SASL or do not use SASL at all
-
-
Method Details
-
getExceptionListener
Returns the exception listener- Returns:
- exception listener
-
setExceptionListener
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
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
Returns the container id- Returns:
- container id
-
setContainerId
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
Returns the hostname set in the open frame.- Returns:
- hostname
-
setOpenHostname
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
Returns the exception listener- Returns:
- exception listener
-
setSocketFactory
Sets the socket factory. Default is com.swiftmq.net.PlainSocketFactory. To use SSL/TLS, specify com.swiftmq.net.JSSESocketFactory.- Parameters:
socketFactory
- socket factory
-
getUserName
Returns the user name- Returns:
- user name
-
connect
public void connect() throws IOException, UnsupportedProtocolVersionException, AuthenticationException, ConnectionClosedExceptionPerforms the actual connect to the remote host, negotiates the protocol and authenticates the user- Throws:
IOException
- if an IOExcption occursUnsupportedProtocolVersionException
- if the AMQP/SASL protocol version is not supported by the remote hostAuthenticationException
- if the user cannot be authenticatedConnectionClosedException
- if the connection was closed
-
onException
Internal use.- Specified by:
onException
in interfaceExceptionHandler
- 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 handshakeConnectionClosedException
- The connection was closed
-
removeSession
-
getSessionForLocalChannel
-
mapSessionToRemoteChannel
-
unmapSessionFromRemoteChannel
protected void unmapSessionFromRemoteChannel(int remoteChannel) -
getSessionForRemoteChannel
-
getOutboundHandler
-
cancel
public void cancel()Internal use only -
close
public void close()Close this connection and all sessions created from it. -
close
-