Class ProtonConnection
java.lang.Object
org.apache.qpid.protonj2.engine.impl.ProtonEndpoint<Connection>
org.apache.qpid.protonj2.engine.impl.ProtonConnection
- All Implemented Interfaces:
Connection
,Endpoint<Connection>
,AMQPHeader.HeaderHandler<ProtonEngine>
,Performative.PerformativeHandler<ProtonEngine>
public class ProtonConnection
extends ProtonEndpoint<Connection>
implements Connection, AMQPHeader.HeaderHandler<ProtonEngine>, Performative.PerformativeHandler<ProtonEngine>
Implements the proton Connection API
-
Field Summary
Fields inherited from class org.apache.qpid.protonj2.engine.impl.ProtonEndpoint
engine
-
Method Summary
Modifier and TypeMethodDescriptionclose()
Close the end point locally and send the closing performative immediately if possible or holds it until the Connection / Engine state allows it.int
Symbol[]
long
long
Symbol[]
Gets the parent of thisEndpoint
which can be itself forConnection
instance.Symbol[]
long
long
Symbol[]
getState()
void
handleAMQPHeader
(AMQPHeader header, ProtonEngine context) void
handleAttach
(Attach attach, ProtonBuffer payload, int channel, ProtonEngine context) void
handleBegin
(Begin begin, ProtonBuffer payload, int channel, ProtonEngine context) void
handleClose
(Close close, ProtonBuffer payload, int channel, ProtonEngine context) void
handleDetach
(Detach detach, ProtonBuffer payload, int channel, ProtonEngine context) void
handleDisposition
(Disposition disposition, ProtonBuffer payload, int channel, ProtonEngine context) void
handleEnd
(End end, ProtonBuffer payload, int channel, ProtonEngine context) void
handleFlow
(Flow flow, ProtonBuffer payload, int channel, ProtonEngine context) void
handleOpen
(Open open, ProtonBuffer payload, int channel, ProtonEngine context) void
handleSASLHeader
(AMQPHeader header, ProtonEngine context) void
handleTransfer
(Transfer transfer, ProtonBuffer payload, int channel, ProtonEngine context) boolean
Returns true if thisEndpoint
is currently locally closed meaning that a call to theEndpoint.close()
method has occurred.boolean
Returns true if thisEndpoint
is currently locally open meaning that theEndpoint.open()
has been called but theEndpoint.close()
has not.boolean
boolean
If not already negotiated this method initiates the AMQP protocol negotiation phase of the connection process sending theAMQPHeader
to the remote peer.negotiate
(EventHandler<AMQPHeader> remoteAMQPHeaderHandler) If not already negotiated this method initiates the AMQP protocol negotiation phase of the connection process sending theAMQPHeader
to the remote peer.open()
Open the end point locally, sending the Open performative immediately if possible or holding it until SASL negotiations or the AMQP header exchange and other required performative exchanges has completed.receiverOpenHandler
(EventHandler<Receiver> remoteReceiverOpenEventHandler) Sets aEventHandler
for when an AMQP Attach frame is received from the remote peer for a receiving link.senderOpenHandler
(EventHandler<Sender> remoteSenderOpenEventHandler) Sets aEventHandler
for when an AMQP Attach frame is received from the remote peer for a sending link.session()
Creates a new Session linked to this ConnectionsessionOpenHandler
(EventHandler<Session> remoteSessionOpenEventHandler) Sets aEventHandler
for when an AMQP Begin frame is received from the remote peer.sessions()
Returns an unmodifiableSet
of Sessions that are tracked by the Connection.setChannelMax
(int channelMax) Set the channel max value for this Connection.setContainerId
(String containerId) Sets the Container Id to be used when opening this Connection.setDesiredCapabilities
(Symbol... capabilities) Sets the capabilities that are desired from the remote when thisEndpoint
is opened.setHostname
(String hostname) Set the name of the host (either fully qualified or relative) to which this connection is connecting to.setIdleTimeout
(long idleTimeout) Set the idle timeout value for this Connection.setMaxFrameSize
(long maxFrameSize) Sets the maximum frame size allowed for this connection, which is the largest single frame that the remote can send to thisConnection
before it will close the connection with an error condition indicating the violation.setOfferedCapabilities
(Symbol... capabilities) Sets the capabilities to be offered on to the remote when thisEndpoint
is opened.setProperties
(Map<Symbol, Object> properties) Sets the properties to be sent to the remote when thisEndpoint
is Opened.long
tick
(long current) Performs a tick operation on the connection which checks that Connection Idle timeout processing is run.tickAuto
(ScheduledExecutorService executor) Convenience method which is the same as callingEngine.tickAuto(ScheduledExecutorService)
.Convenience method which is the same as callingEngine.tickAuto(Scheduler)
.transactionManagerOpenHandler
(EventHandler<TransactionManager> remoteTxnManagerOpenEventHandler) Sets aEventHandler
for when an AMQP Attach frame is received from the remote peer for a transaction coordination link.Methods inherited from class org.apache.qpid.protonj2.engine.impl.ProtonEndpoint
closeHandler, engineShutdownHandler, getAttachments, getCondition, getEngine, getLinkedResource, getLinkedResource, getRemoteCondition, localCloseHandler, localOpenHandler, openHandler, setCondition, setLinkedResource
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.qpid.protonj2.engine.Endpoint
closeHandler, engineShutdownHandler, getAttachments, getCondition, getEngine, getLinkedResource, getLinkedResource, getRemoteCondition, localCloseHandler, localOpenHandler, openHandler, setCondition, setLinkedResource
-
Method Details
-
getParent
Description copied from interface:Endpoint
Gets the parent of thisEndpoint
which can be itself forConnection
instance.- Specified by:
getParent
in interfaceConnection
- Specified by:
getParent
in interfaceEndpoint<Connection>
- Returns:
- this
Connection
as it is the root of theEndpoint
hierarchy.
-
getState
- Specified by:
getState
in interfaceConnection
- Returns:
- the local connection state only
-
open
Description copied from interface:Endpoint
Open the end point locally, sending the Open performative immediately if possible or holding it until SASL negotiations or the AMQP header exchange and other required performative exchanges has completed. The end point will signal any registered handler of the remote opening the Connection once the remote performative that signals open completion arrives.- Specified by:
open
in interfaceEndpoint<Connection>
- Returns:
- this
Endpoint
instance. - Throws:
EngineStateException
- if an error occurs opening the Connection or the Engine is shutdown.
-
close
Description copied from interface:Endpoint
Close the end point locally and send the closing performative immediately if possible or holds it until the Connection / Engine state allows it. If the engine encounters an error writing the performative or the engine is in a failed state from a previous error then this method will throw an exception. If the engine has been shutdown then this method will close out the local end of theEndpoint
and clean up any local resources before returning normally.- Specified by:
close
in interfaceEndpoint<Connection>
- Returns:
- this
Endpoint
instance. - Throws:
EngineFailedException
- if an error occurs closing the end point or the Engine is in a failed state.
-
negotiate
Description copied from interface:Connection
If not already negotiated this method initiates the AMQP protocol negotiation phase of the connection process sending theAMQPHeader
to the remote peer. For a client application this could mean requesting the server to indicate if it supports the version of the protocol this client speaks. In rare cases a server could use this to preemptively send its AMQP header. Once a header is sent the remote should respond with the AMQP Header that indicates what protocol level it supports and if there is a mismatch the the engine will be failed with a error indicating the protocol support was not successfully negotiated. If the engine has a configured SASL layer then by starting the AMQP Header exchange this will implicitly first attempt the SASL authentication step of the connection process.- Specified by:
negotiate
in interfaceConnection
- Returns:
- this
Connection
instance.
-
negotiate
Description copied from interface:Connection
If not already negotiated this method initiates the AMQP protocol negotiation phase of the connection process sending theAMQPHeader
to the remote peer. For a client application this could mean requesting the server to indicate if it supports the version of the protocol this client speaks. In rare cases a server could use this to preemptively send its AMQP header. Once a header is sent the remote should respond with the AMQP Header that indicates what protocol level it supports and if there is a mismatch the the engine will be failed with a error indicating the protocol support was not successfully negotiated. If the engine has a configured SASL layer then by starting the AMQP Header exchange this will implicitly first attempt the SASL authentication step of the connection process. The provided remote AMQP Header handler will be called once the remote sends its AMQP Header to the either preemptively or as a response to offered AMQP Header from this peer, even if that has already happened prior to this call.- Specified by:
negotiate
in interfaceConnection
- Parameters:
remoteAMQPHeaderHandler
- Handler to be called when an AMQP Header response has arrived.- Returns:
- this
Connection
instance.
-
tick
public long tick(long current) Description copied from interface:Connection
Performs a tick operation on the connection which checks that Connection Idle timeout processing is run. This method is a convenience method that delegates the work to theEngine.tick(long)
method. It is an error to call this method ifConnection.tickAuto(ScheduledExecutorService)
was called.- Specified by:
tick
in interfaceConnection
- Parameters:
current
- Current time value usually taken fromSystem.nanoTime()
- Returns:
- the absolute deadline in milliseconds to next call tick by/at, or 0 if there is none.
- See Also:
-
tickAuto
Description copied from interface:Connection
Convenience method which is the same as callingEngine.tickAuto(ScheduledExecutorService)
.- Specified by:
tickAuto
in interfaceConnection
- Parameters:
executor
- The single threaded execution context where all engine work takes place.- Returns:
- this
Connection
instance. - See Also:
-
tickAuto
Description copied from interface:Connection
Convenience method which is the same as callingEngine.tickAuto(Scheduler)
.- Specified by:
tickAuto
in interfaceConnection
- Parameters:
scheduler
- The single threaded execution context where all engine work takes place.- Returns:
- this
Connection
instance. - See Also:
-
isLocallyClosed
public boolean isLocallyClosed()Description copied from interface:Endpoint
Returns true if thisEndpoint
is currently locally closed meaning that a call to theEndpoint.close()
method has occurred.- Specified by:
isLocallyClosed
in interfaceEndpoint<Connection>
- Returns:
true
if theEndpoint
is locally closed.- See Also:
-
isRemotelyClosed
public boolean isRemotelyClosed()Description copied from interface:Endpoint
Returns true if thisEndpoint
is currently remotely closed meaning that the AMQP performative that completes the close phase of thisEndpoint
's lifetime has arrived.- Specified by:
isRemotelyClosed
in interfaceEndpoint<Connection>
- Returns:
true
if theEndpoint
is remotely closed.- See Also:
-
setContainerId
Description copied from interface:Connection
Sets the Container Id to be used when opening this Connection. The container Id can only be modified prior to a call toEndpoint.open()
, once the connection has been opened locally an error will be thrown if this method is called.- Specified by:
setContainerId
in interfaceConnection
- Parameters:
containerId
- The Container Id used for this end of the Connection.- Returns:
- this connection.
-
getContainerId
- Specified by:
getContainerId
in interfaceConnection
- Returns:
- the Container ID assigned to this Connection
-
setHostname
Description copied from interface:Connection
Set the name of the host (either fully qualified or relative) to which this connection is connecting to. This information may be used by the remote peer to determine the correct back-end service to connect the client to. This value will be sent in the Open performative. Note that it is illegal to set the host name to a numeric IP address or include a port number. The host name value can only be modified prior to a call toEndpoint.open()
, once the connection has been opened locally an error will be thrown if this method is called.- Specified by:
setHostname
in interfaceConnection
- Parameters:
hostname
- the RFC1035 compliant host name.- Returns:
- this connection.
-
getHostname
- Specified by:
getHostname
in interfaceConnection
- Returns:
- returns the host name assigned to this Connection.
- See Also:
-
setMaxFrameSize
Description copied from interface:Connection
Sets the maximum frame size allowed for this connection, which is the largest single frame that the remote can send to thisConnection
before it will close the connection with an error condition indicating the violation. The legal range for this value is defined as (512 - 2^32-1) bytes. The max frame size value can only be modified prior to a call toEndpoint.open()
, once the connection has been opened locally an error will be thrown if this method is called.- Specified by:
setMaxFrameSize
in interfaceConnection
- Parameters:
maxFrameSize
- The maximum number of bytes allowed for a single- Returns:
- this connection.
-
getMaxFrameSize
public long getMaxFrameSize()- Specified by:
getMaxFrameSize
in interfaceConnection
- Returns:
- the currently configured max frame size this connection will accept.
-
setChannelMax
Description copied from interface:Connection
Set the channel max value for this Connection. The channel max value can only be modified prior to a call toEndpoint.open()
, once the connection has been opened locally an error will be thrown if this method is called.- Specified by:
setChannelMax
in interfaceConnection
- Parameters:
channelMax
- The value to set for channel max when opening the connection.- Returns:
- this connection.
-
getChannelMax
public int getChannelMax()- Specified by:
getChannelMax
in interfaceConnection
- Returns:
- the currently configured channel max for this
Connection
-
setIdleTimeout
Description copied from interface:Connection
Set the idle timeout value for this Connection. The idle timeout value can only be modified prior to a call toEndpoint.open()
, once the connection has been opened locally an error will be thrown if this method is called.- Specified by:
setIdleTimeout
in interfaceConnection
- Parameters:
idleTimeout
- The value to set for the idle timeout when opening the connection.- Returns:
- this connection.
-
getIdleTimeout
public long getIdleTimeout()- Specified by:
getIdleTimeout
in interfaceConnection
- Returns:
- the currently configured idle timeout for this
Connection
-
setOfferedCapabilities
Description copied from interface:Endpoint
Sets the capabilities to be offered on to the remote when thisEndpoint
is opened. The offered capabilities value can only be modified prior to a call toEndpoint.open()
, once theEndpoint
has been opened locally an error will be thrown if this method is called.- Specified by:
setOfferedCapabilities
in interfaceEndpoint<Connection>
- Parameters:
capabilities
- The capabilities to be offered to the remote when theEndpoint
is opened.- Returns:
- this
Endpoint
instance.
-
getOfferedCapabilities
- Specified by:
getOfferedCapabilities
in interfaceEndpoint<Connection>
- Returns:
- the configured capabilities that are offered to the remote when the
Endpoint
is opened.
-
setDesiredCapabilities
Description copied from interface:Endpoint
Sets the capabilities that are desired from the remote when thisEndpoint
is opened. The desired capabilities value can only be modified prior to a call toEndpoint.open()
, once theEndpoint
has been opened locally an error will be thrown if this method is called.- Specified by:
setDesiredCapabilities
in interfaceEndpoint<Connection>
- Parameters:
capabilities
- The capabilities desired from the remote when theEndpoint
is opened.- Returns:
- this
Endpoint
instance.
-
getDesiredCapabilities
- Specified by:
getDesiredCapabilities
in interfaceEndpoint<Connection>
- Returns:
- the configured desired capabilities that are sent to the remote when the Connection is opened.
-
setProperties
Description copied from interface:Endpoint
Sets the properties to be sent to the remote when thisEndpoint
is Opened. TheEndpoint
properties value can only be modified prior to a call toEndpoint.open()
, once theEndpoint
has been opened locally an error will be thrown if this method is called.- Specified by:
setProperties
in interfaceEndpoint<Connection>
- Parameters:
properties
- The properties that will be sent to the remote when this Connection is opened.- Returns:
- this
Endpoint
instance.
-
getProperties
- Specified by:
getProperties
in interfaceEndpoint<Connection>
- Returns:
- the configured properties sent to the remote when this Connection is opened.
-
isLocallyOpen
public boolean isLocallyOpen()Description copied from interface:Endpoint
Returns true if thisEndpoint
is currently locally open meaning that theEndpoint.open()
has been called but theEndpoint.close()
has not.- Specified by:
isLocallyOpen
in interfaceEndpoint<Connection>
- Returns:
true
if theEndpoint
is locally open.- See Also:
-
isRemotelyOpen
public boolean isRemotelyOpen()Description copied from interface:Endpoint
Returns true if thisEndpoint
is currently remotely open meaning that the AMQP performative that completes the open phase of thisEndpoint
's lifetime has arrived but the performative that closes it has not.- Specified by:
isRemotelyOpen
in interfaceEndpoint<Connection>
- Returns:
true
if theEndpoint
is remotely open.- See Also:
-
getRemoteContainerId
- Specified by:
getRemoteContainerId
in interfaceConnection
- Returns:
- the Container Id assigned to the remote end of the Connection.
-
getRemoteHostname
- Specified by:
getRemoteHostname
in interfaceConnection
- Returns:
- the host name assigned to the remote end of this Connection.
-
getRemoteMaxFrameSize
public long getRemoteMaxFrameSize()- Specified by:
getRemoteMaxFrameSize
in interfaceConnection
- Returns:
- the remote set max frame size limit.
-
getRemoteIdleTimeout
public long getRemoteIdleTimeout()- Specified by:
getRemoteIdleTimeout
in interfaceConnection
- Returns:
- the idle timeout value provided by the remote end of this Connection.
-
getRemoteOfferedCapabilities
- Specified by:
getRemoteOfferedCapabilities
in interfaceEndpoint<Connection>
- Returns:
- the capabilities offered by the remote when it opened its end of the
Endpoint
.
-
getRemoteDesiredCapabilities
- Specified by:
getRemoteDesiredCapabilities
in interfaceEndpoint<Connection>
- Returns:
- the capabilities desired by the remote when it opened its end of the
Endpoint
.
-
getRemoteProperties
- Specified by:
getRemoteProperties
in interfaceEndpoint<Connection>
- Returns:
- the properties sent by the remote when it opened its end of the
Endpoint
.
-
getRemoteState
- Specified by:
getRemoteState
in interfaceConnection
- Returns:
- the remote state (as last communicated)
-
session
Description copied from interface:Connection
Creates a new Session linked to this Connection- Specified by:
session
in interfaceConnection
- Returns:
- a newly created
Session
linked to thisConnection
. - Throws:
IllegalStateException
- if theConnection
has already been closed.
-
sessions
Description copied from interface:Connection
Returns an unmodifiableSet
of Sessions that are tracked by the Connection. TheSession
instances returned from this method will be locally or remotely open or both which gives the caller full view of the complete set of knownSession
instances.- Specified by:
sessions
in interfaceConnection
- Returns:
- an unmodifiable
Set
of Sessions tracked by this Connection. - Throws:
IllegalStateException
-
handleAMQPHeader
- Specified by:
handleAMQPHeader
in interfaceAMQPHeader.HeaderHandler<ProtonEngine>
-
handleSASLHeader
- Specified by:
handleSASLHeader
in interfaceAMQPHeader.HeaderHandler<ProtonEngine>
-
handleOpen
- Specified by:
handleOpen
in interfacePerformative.PerformativeHandler<ProtonEngine>
-
handleClose
- Specified by:
handleClose
in interfacePerformative.PerformativeHandler<ProtonEngine>
-
handleBegin
- Specified by:
handleBegin
in interfacePerformative.PerformativeHandler<ProtonEngine>
-
handleEnd
- Specified by:
handleEnd
in interfacePerformative.PerformativeHandler<ProtonEngine>
-
handleAttach
- Specified by:
handleAttach
in interfacePerformative.PerformativeHandler<ProtonEngine>
-
handleDetach
- Specified by:
handleDetach
in interfacePerformative.PerformativeHandler<ProtonEngine>
-
handleFlow
- Specified by:
handleFlow
in interfacePerformative.PerformativeHandler<ProtonEngine>
-
handleTransfer
public void handleTransfer(Transfer transfer, ProtonBuffer payload, int channel, ProtonEngine context) - Specified by:
handleTransfer
in interfacePerformative.PerformativeHandler<ProtonEngine>
-
handleDisposition
public void handleDisposition(Disposition disposition, ProtonBuffer payload, int channel, ProtonEngine context) - Specified by:
handleDisposition
in interfacePerformative.PerformativeHandler<ProtonEngine>
-
sessionOpenHandler
Description copied from interface:Connection
Sets aEventHandler
for when an AMQP Begin frame is received from the remote peer. Used to process remotely initiated Sessions. Locally initiated sessions have their own EventHandler invoked instead. This method is Typically used by servers to listen for remote Session creation.- Specified by:
sessionOpenHandler
in interfaceConnection
- Parameters:
remoteSessionOpenEventHandler
- the EventHandler that will be signaled when a session is remotely opened.- Returns:
- this connection
-
senderOpenHandler
Description copied from interface:Connection
Sets aEventHandler
for when an AMQP Attach frame is received from the remote peer for a sending link. Used to process remotely initiated sending link. Locally initiated links have their own EventHandler invoked instead. This method is Typically used by servers to listen for remote Receiver creation. If an event handler for remote sender open is registered on the Session that the link is owned by then that handler will be invoked instead of this one.- Specified by:
senderOpenHandler
in interfaceConnection
- Parameters:
remoteSenderOpenEventHandler
- the EventHandler that will be signaled when a sender link is remotely opened.- Returns:
- this connection
-
receiverOpenHandler
Description copied from interface:Connection
Sets aEventHandler
for when an AMQP Attach frame is received from the remote peer for a receiving link. Used to process remotely initiated receiving link. Locally initiated links have their own EventHandler invoked instead. This method is Typically used by servers to listen for remote Sender creation. If an event handler for remote receiver open is registered on the Session that the link is owned by then that handler will be invoked instead of this one.- Specified by:
receiverOpenHandler
in interfaceConnection
- Parameters:
remoteReceiverOpenEventHandler
- the EventHandler that will be signaled when a receiver link is remotely opened.- Returns:
- this connection
-
transactionManagerOpenHandler
public ProtonConnection transactionManagerOpenHandler(EventHandler<TransactionManager> remoteTxnManagerOpenEventHandler) Description copied from interface:Connection
Sets aEventHandler
for when an AMQP Attach frame is received from the remote peer for a transaction coordination link. Used to process remotely initiated transaction manager link. Locally initiated links have their own EventHandler invoked instead. This method is Typically used by servers to listen for remoteTransactionController
creation. If an event handler for remoteTransactionController
open is registered on the Session that the link is owned by then that handler will be invoked instead of this one.- Specified by:
transactionManagerOpenHandler
in interfaceConnection
- Parameters:
remoteTxnManagerOpenEventHandler
- the EventHandler that will be signaled when aTransactionController
link is remotely opened.- Returns:
- this connection
-