Package org.apache.activemq.broker
Class TransportConnection
- java.lang.Object
-
- org.apache.activemq.broker.TransportConnection
-
- All Implemented Interfaces:
Connection
,Service
,CommandVisitor
,Task
- Direct Known Subclasses:
ManagedTransportConnection
public class TransportConnection extends Object implements Connection, Task, CommandVisitor
-
-
Field Summary
Fields Modifier and Type Field Description protected Broker
broker
protected Map<ConnectionId,ConnectionState>
brokerConnectionStates
protected BrokerInfo
brokerInfo
protected BrokerService
brokerService
protected TransportConnector
connector
protected List<Command>
dispatchQueue
protected AtomicBoolean
dispatchStopped
protected TaskRunner
taskRunner
protected AtomicReference<Throwable>
transportException
-
Constructor Summary
Constructors Constructor Description TransportConnection(TransportConnector connector, Transport transport, Broker broker, TaskRunnerFactory taskRunnerFactory, TaskRunnerFactory stopTaskRunnerFactory)
-
Method Summary
-
-
-
Field Detail
-
broker
protected final Broker broker
-
brokerService
protected final BrokerService brokerService
-
connector
protected final TransportConnector connector
-
brokerConnectionStates
protected final Map<ConnectionId,ConnectionState> brokerConnectionStates
-
brokerInfo
protected BrokerInfo brokerInfo
-
taskRunner
protected TaskRunner taskRunner
-
transportException
protected final AtomicReference<Throwable> transportException
-
dispatchStopped
protected AtomicBoolean dispatchStopped
-
-
Constructor Detail
-
TransportConnection
public TransportConnection(TransportConnector connector, Transport transport, Broker broker, TaskRunnerFactory taskRunnerFactory, TaskRunnerFactory stopTaskRunnerFactory)
- Parameters:
taskRunnerFactory
- - can be null if you want direct dispatch to the transport else commands are sent async.stopTaskRunnerFactory
- - can not be null, used for stopping this connection.
-
-
Method Detail
-
getDispatchQueueSize
public int getDispatchQueueSize()
Returns the number of messages to be dispatched to this connection- Specified by:
getDispatchQueueSize
in interfaceConnection
- Returns:
- size of dispatch queue
-
serviceTransportException
public void serviceTransportException(IOException e)
-
serviceExceptionAsync
public void serviceExceptionAsync(IOException e)
Calls the serviceException method in an async thread. Since handling a service exception closes a socket, we should not tie up broker threads since client sockets may hang or cause deadlocks.- Specified by:
serviceExceptionAsync
in interfaceConnection
-
serviceException
public void serviceException(Throwable e)
Closes a clients connection due to a detected error. Errors are ignored if: the client is closing or broker is closing. Otherwise, the connection error transmitted to the client before stopping it's transport.- Specified by:
serviceException
in interfaceConnection
-
service
public Response service(Command command)
Description copied from interface:Connection
Services a client command and submits it to the broker.- Specified by:
service
in interfaceConnection
- Returns:
- Response
-
processKeepAlive
public Response processKeepAlive(KeepAliveInfo info) throws Exception
- Specified by:
processKeepAlive
in interfaceCommandVisitor
- Throws:
Exception
-
processRemoveSubscription
public Response processRemoveSubscription(RemoveSubscriptionInfo info) throws Exception
- Specified by:
processRemoveSubscription
in interfaceCommandVisitor
- Throws:
Exception
-
processWireFormat
public Response processWireFormat(WireFormatInfo info) throws Exception
- Specified by:
processWireFormat
in interfaceCommandVisitor
- Throws:
Exception
-
processShutdown
public Response processShutdown(ShutdownInfo info) throws Exception
- Specified by:
processShutdown
in interfaceCommandVisitor
- Throws:
Exception
-
processFlush
public Response processFlush(FlushCommand command) throws Exception
- Specified by:
processFlush
in interfaceCommandVisitor
- Throws:
Exception
-
processBeginTransaction
public Response processBeginTransaction(TransactionInfo info) throws Exception
- Specified by:
processBeginTransaction
in interfaceCommandVisitor
- Throws:
Exception
-
getActiveTransactionCount
public int getActiveTransactionCount()
Description copied from interface:Connection
Returns the number of active transactions established on this Connection.- Specified by:
getActiveTransactionCount
in interfaceConnection
- Returns:
- the number of active transactions established on this Connection..
-
getOldestActiveTransactionDuration
public Long getOldestActiveTransactionDuration()
Description copied from interface:Connection
Returns the number of active transactions established on this Connection.- Specified by:
getOldestActiveTransactionDuration
in interfaceConnection
- Returns:
- the number of active transactions established on this Connection..
-
processEndTransaction
public Response processEndTransaction(TransactionInfo info) throws Exception
- Specified by:
processEndTransaction
in interfaceCommandVisitor
- Throws:
Exception
-
processPrepareTransaction
public Response processPrepareTransaction(TransactionInfo info) throws Exception
- Specified by:
processPrepareTransaction
in interfaceCommandVisitor
- Throws:
Exception
-
processCommitTransactionOnePhase
public Response processCommitTransactionOnePhase(TransactionInfo info) throws Exception
- Specified by:
processCommitTransactionOnePhase
in interfaceCommandVisitor
- Throws:
Exception
-
processCommitTransactionTwoPhase
public Response processCommitTransactionTwoPhase(TransactionInfo info) throws Exception
- Specified by:
processCommitTransactionTwoPhase
in interfaceCommandVisitor
- Throws:
Exception
-
processRollbackTransaction
public Response processRollbackTransaction(TransactionInfo info) throws Exception
- Specified by:
processRollbackTransaction
in interfaceCommandVisitor
- Throws:
Exception
-
processForgetTransaction
public Response processForgetTransaction(TransactionInfo info) throws Exception
- Specified by:
processForgetTransaction
in interfaceCommandVisitor
- Throws:
Exception
-
processRecoverTransactions
public Response processRecoverTransactions(TransactionInfo info) throws Exception
- Specified by:
processRecoverTransactions
in interfaceCommandVisitor
- Throws:
Exception
-
processMessage
public Response processMessage(Message messageSend) throws Exception
- Specified by:
processMessage
in interfaceCommandVisitor
- Throws:
Exception
-
processMessageAck
public Response processMessageAck(MessageAck ack) throws Exception
- Specified by:
processMessageAck
in interfaceCommandVisitor
- Throws:
Exception
-
processMessagePull
public Response processMessagePull(MessagePull pull) throws Exception
- Specified by:
processMessagePull
in interfaceCommandVisitor
- Throws:
Exception
-
processMessageDispatchNotification
public Response processMessageDispatchNotification(MessageDispatchNotification notification) throws Exception
- Specified by:
processMessageDispatchNotification
in interfaceCommandVisitor
- Throws:
Exception
-
processAddDestination
public Response processAddDestination(DestinationInfo info) throws Exception
- Specified by:
processAddDestination
in interfaceCommandVisitor
- Throws:
Exception
-
processRemoveDestination
public Response processRemoveDestination(DestinationInfo info) throws Exception
- Specified by:
processRemoveDestination
in interfaceCommandVisitor
- Throws:
Exception
-
processAddProducer
public Response processAddProducer(ProducerInfo info) throws Exception
- Specified by:
processAddProducer
in interfaceCommandVisitor
- Throws:
Exception
-
processRemoveProducer
public Response processRemoveProducer(ProducerId id) throws Exception
- Specified by:
processRemoveProducer
in interfaceCommandVisitor
- Throws:
Exception
-
processAddConsumer
public Response processAddConsumer(ConsumerInfo info) throws Exception
- Specified by:
processAddConsumer
in interfaceCommandVisitor
- Throws:
Exception
-
processRemoveConsumer
public Response processRemoveConsumer(ConsumerId id, long lastDeliveredSequenceId) throws Exception
- Specified by:
processRemoveConsumer
in interfaceCommandVisitor
- Throws:
Exception
-
processAddSession
public Response processAddSession(SessionInfo info) throws Exception
- Specified by:
processAddSession
in interfaceCommandVisitor
- Throws:
Exception
-
processRemoveSession
public Response processRemoveSession(SessionId id, long lastDeliveredSequenceId) throws Exception
- Specified by:
processRemoveSession
in interfaceCommandVisitor
- Throws:
Exception
-
processAddConnection
public Response processAddConnection(ConnectionInfo info) throws Exception
- Specified by:
processAddConnection
in interfaceCommandVisitor
- Throws:
Exception
-
processRemoveConnection
public Response processRemoveConnection(ConnectionId id, long lastDeliveredSequenceId) throws InterruptedException
- Specified by:
processRemoveConnection
in interfaceCommandVisitor
- Throws:
InterruptedException
-
processProducerAck
public Response processProducerAck(ProducerAck ack) throws Exception
- Specified by:
processProducerAck
in interfaceCommandVisitor
- Throws:
Exception
-
getConnector
public Connector getConnector()
- Specified by:
getConnector
in interfaceConnection
- Returns:
- the connector that created this connection.
-
dispatchSync
public void dispatchSync(Command message)
Description copied from interface:Connection
Sends a message to the client.- Specified by:
dispatchSync
in interfaceConnection
- Parameters:
message
- the message to send to the client.
-
dispatchAsync
public void dispatchAsync(Command message)
Description copied from interface:Connection
Sends a message to the client.- Specified by:
dispatchAsync
in interfaceConnection
-
processDispatch
protected void processDispatch(Command command) throws IOException
- Throws:
IOException
-
getStatistics
public ConnectionStatistics getStatistics()
Returns the statistics for this connection- Specified by:
getStatistics
in interfaceConnection
-
getMessageAuthorizationPolicy
public MessageAuthorizationPolicy getMessageAuthorizationPolicy()
-
setMessageAuthorizationPolicy
public void setMessageAuthorizationPolicy(MessageAuthorizationPolicy messageAuthorizationPolicy)
-
isManageable
public boolean isManageable()
- Specified by:
isManageable
in interfaceConnection
- Returns:
- true if the Connection will process control commands
-
start
public void start() throws Exception
-
stopAsync
public void stopAsync(Throwable cause)
-
stopAsync
public void stopAsync()
-
isBlockedCandidate
public boolean isBlockedCandidate()
- Returns:
- Returns the blockedCandidate.
-
setBlockedCandidate
public void setBlockedCandidate(boolean blockedCandidate)
- Parameters:
blockedCandidate
- The blockedCandidate to set.
-
isMarkedCandidate
public boolean isMarkedCandidate()
- Returns:
- Returns the markedCandidate.
-
setMarkedCandidate
public void setMarkedCandidate(boolean markedCandidate)
- Parameters:
markedCandidate
- The markedCandidate to set.
-
setSlow
public void setSlow(boolean slow)
- Parameters:
slow
- The slow to set.
-
isSlow
public boolean isSlow()
- Specified by:
isSlow
in interfaceConnection
- Returns:
- true if the Connection is slow
-
isMarkedBlockedCandidate
public boolean isMarkedBlockedCandidate()
- Returns:
- true if the Connection is potentially blocked
-
doMark
public void doMark()
Mark the Connection, so we can deem if it's collectable on the next sweep
-
isBlocked
public boolean isBlocked()
- Specified by:
isBlocked
in interfaceConnection
- Returns:
- if after being marked, the Connection is still writing
-
isConnected
public boolean isConnected()
- Specified by:
isConnected
in interfaceConnection
- Returns:
- true if the Connection is connected
-
setBlocked
public void setBlocked(boolean blocked)
- Parameters:
blocked
- The blocked to set.
-
setConnected
public void setConnected(boolean connected)
- Parameters:
connected
- The connected to set.
-
isActive
public boolean isActive()
- Specified by:
isActive
in interfaceConnection
- Returns:
- true if the Connection is active
-
setActive
public void setActive(boolean active)
- Parameters:
active
- The active to set.
-
isStarting
public boolean isStarting()
- Returns:
- true if the Connection is starting
-
isNetworkConnection
public boolean isNetworkConnection()
Description copied from interface:Connection
return true if a network connection- Specified by:
isNetworkConnection
in interfaceConnection
- Returns:
- if this is a network connection
-
isFaultTolerantConnection
public boolean isFaultTolerantConnection()
- Specified by:
isFaultTolerantConnection
in interfaceConnection
- Returns:
- true if a fault tolerant connection
-
isPendingStop
public boolean isPendingStop()
- Returns:
- true if the Connection needs to stop
-
processBrokerInfo
public Response processBrokerInfo(BrokerInfo info)
- Specified by:
processBrokerInfo
in interfaceCommandVisitor
-
dispatch
protected void dispatch(Command command) throws IOException
- Throws:
IOException
-
getRemoteAddress
public String getRemoteAddress()
- Specified by:
getRemoteAddress
in interfaceConnection
- Returns:
- the source address for this connection
-
getTransport
public Transport getTransport()
-
getConnectionId
public String getConnectionId()
- Specified by:
getConnectionId
in interfaceConnection
-
updateClient
public void updateClient(ConnectionControl control)
- Specified by:
updateClient
in interfaceConnection
-
getProducerBrokerExchangeIfExists
public ProducerBrokerExchange getProducerBrokerExchangeIfExists(ProducerInfo producerInfo)
-
getProtocolVersion
public int getProtocolVersion()
-
processControlCommand
public Response processControlCommand(ControlCommand command) throws Exception
- Specified by:
processControlCommand
in interfaceCommandVisitor
- Throws:
Exception
-
processMessageDispatch
public Response processMessageDispatch(MessageDispatch dispatch) throws Exception
- Specified by:
processMessageDispatch
in interfaceCommandVisitor
- Throws:
Exception
-
processConnectionControl
public Response processConnectionControl(ConnectionControl control) throws Exception
- Specified by:
processConnectionControl
in interfaceCommandVisitor
- Throws:
Exception
-
processConnectionError
public Response processConnectionError(ConnectionError error) throws Exception
- Specified by:
processConnectionError
in interfaceCommandVisitor
- Throws:
Exception
-
processConsumerControl
public Response processConsumerControl(ConsumerControl control) throws Exception
- Specified by:
processConsumerControl
in interfaceCommandVisitor
- Throws:
Exception
-
registerConnectionState
protected TransportConnectionState registerConnectionState(ConnectionId connectionId, TransportConnectionState state)
-
unregisterConnectionState
protected TransportConnectionState unregisterConnectionState(ConnectionId connectionId)
-
listConnectionStates
protected List<TransportConnectionState> listConnectionStates()
-
lookupConnectionState
protected TransportConnectionState lookupConnectionState(String connectionId)
-
lookupConnectionState
protected TransportConnectionState lookupConnectionState(ConsumerId id)
-
lookupConnectionState
protected TransportConnectionState lookupConnectionState(ProducerId id)
-
lookupConnectionState
protected TransportConnectionState lookupConnectionState(SessionId id)
-
lookupConnectionState
public TransportConnectionState lookupConnectionState(ConnectionId connectionId)
-
setDuplexNetworkConnectorId
protected void setDuplexNetworkConnectorId(String duplexNetworkConnectorId)
-
getDuplexNetworkConnectorId
protected String getDuplexNetworkConnectorId()
-
isStopping
public boolean isStopping()
-
getStopped
protected CountDownLatch getStopped()
-
getRemoteWireFormatInfo
public WireFormatInfo getRemoteWireFormatInfo()
-
processBrokerSubscriptionInfo
public Response processBrokerSubscriptionInfo(BrokerSubscriptionInfo info) throws Exception
- Specified by:
processBrokerSubscriptionInfo
in interfaceCommandVisitor
- Throws:
Exception
-
-