Package org.apache.activemq.network
Class DemandForwardingBridgeSupport
- java.lang.Object
-
- org.apache.activemq.network.DemandForwardingBridgeSupport
-
- All Implemented Interfaces:
BrokerServiceAware
,NetworkBridge
,org.apache.activemq.Service
- Direct Known Subclasses:
CompositeDemandForwardingBridge
,DemandForwardingBridge
public abstract class DemandForwardingBridgeSupport extends Object implements NetworkBridge, BrokerServiceAware
A useful base class for implementing demand forwarding bridges.
-
-
Field Summary
Fields Modifier and Type Field Description protected AtomicBoolean
bridgeFailed
protected BrokerService
brokerService
protected NetworkBridgeConfiguration
configuration
protected org.apache.activemq.util.LongSequenceGenerator
consumerIdGenerator
protected NetworkBridgeFilterFactory
defaultFilterFactory
protected int
demandConsumerDispatched
protected org.apache.activemq.command.ConsumerInfo
demandConsumerInfo
protected AtomicBoolean
disposed
protected static String
DURABLE_SUB_PREFIX
protected org.apache.activemq.command.ActiveMQDestination[]
durableDestinations
protected org.apache.activemq.command.ActiveMQDestination[]
dynamicallyIncludedDestinations
protected org.apache.activemq.command.ActiveMQDestination[]
excludedDestinations
protected Set<org.apache.activemq.command.ConsumerId>
forcedDurableRemoteId
protected org.apache.activemq.util.IdGenerator
idGenerator
protected AtomicBoolean
lastConnectSucceeded
protected AtomicBoolean
localBridgeStarted
protected org.apache.activemq.transport.Transport
localBroker
protected org.apache.activemq.command.BrokerId
localBrokerId
protected org.apache.activemq.command.BrokerId[]
localBrokerPath
protected String
localClientId
protected org.apache.activemq.command.ConnectionInfo
localConnectionInfo
protected org.apache.activemq.command.SessionInfo
localSessionInfo
protected CountDownLatch
localStartedLatch
protected NetworkBridgeStatistics
networkBridgeStatistics
protected org.apache.activemq.command.ProducerInfo
producerInfo
protected AtomicBoolean
remoteBridgeStarted
protected org.apache.activemq.transport.Transport
remoteBroker
protected org.apache.activemq.command.BrokerId
remoteBrokerId
protected String
remoteBrokerName
protected org.apache.activemq.command.BrokerId[]
remoteBrokerPath
protected org.apache.activemq.command.ConnectionInfo
remoteConnectionInfo
protected CountDownLatch
startedLatch
protected org.apache.activemq.command.ActiveMQDestination[]
staticallyIncludedDestinations
protected CountDownLatch
staticDestinationsLatch
protected ConcurrentMap<org.apache.activemq.command.ConsumerId,DemandSubscription>
subscriptionMapByLocalId
protected ConcurrentMap<org.apache.activemq.command.ConsumerId,DemandSubscription>
subscriptionMapByRemoteId
-
Constructor Summary
Constructors Constructor Description DemandForwardingBridgeSupport(NetworkBridgeConfiguration configuration, org.apache.activemq.transport.Transport localBroker, org.apache.activemq.transport.Transport remoteBroker)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addConsumerInfo(org.apache.activemq.command.ConsumerInfo consumerInfo)
protected void
addProxyNetworkSubscriptionBrokerPath(DemandSubscription sub, org.apache.activemq.command.BrokerId[] path, String subName)
Add a durable remote proxy subscription when we can generate via the BrokerId path This is the most common scenarioprotected void
addProxyNetworkSubscriptionClientId(DemandSubscription sub, String clientId, String subName)
This scenaior is primarily used for durable sync on broker restartsprotected void
addRemoteBrokerToBrokerPath(org.apache.activemq.command.ConsumerInfo info)
protected void
addSubscription(DemandSubscription sub)
protected org.apache.activemq.command.BrokerId[]
appendToBrokerPath(org.apache.activemq.command.BrokerId[] brokerPath, org.apache.activemq.command.BrokerId idToAppend)
protected org.apache.activemq.command.BrokerId[]
appendToBrokerPath(org.apache.activemq.command.BrokerId[] brokerPath, org.apache.activemq.command.BrokerId[] pathsToAppend)
protected boolean
canDuplexDispatch(org.apache.activemq.command.Message message)
protected void
configureConsumerPrefetch(org.apache.activemq.command.ConsumerInfo consumerInfo)
protected void
configureDemandSubscription(org.apache.activemq.command.ConsumerInfo info, DemandSubscription sub)
protected org.apache.activemq.command.Message
configureMessage(org.apache.activemq.command.MessageDispatch md)
static boolean
contains(org.apache.activemq.command.BrokerId[] brokerPath, org.apache.activemq.command.BrokerId brokerId)
protected DemandSubscription
createDemandSubscription(org.apache.activemq.command.ActiveMQDestination destination, String subscriptionName)
protected DemandSubscription
createDemandSubscription(org.apache.activemq.command.ConsumerInfo info)
protected org.apache.activemq.command.NetworkBridgeFilter
createNetworkBridgeFilter(org.apache.activemq.command.ConsumerInfo info)
protected DemandSubscription
doCreateDemandSubscription(org.apache.activemq.command.ConsumerInfo info)
void
duplexStart(TransportConnection connection, org.apache.activemq.command.BrokerInfo localBrokerInfo, org.apache.activemq.command.BrokerInfo remoteBrokerInfo)
protected org.apache.activemq.Service
getControllingService()
long
getDequeueCounter()
org.apache.activemq.command.ActiveMQDestination[]
getDurableDestinations()
org.apache.activemq.command.ActiveMQDestination[]
getDynamicallyIncludedDestinations()
long
getEnqueueCounter()
org.apache.activemq.command.ActiveMQDestination[]
getExcludedDestinations()
String
getLocalAddress()
org.apache.activemq.transport.Transport
getLocalBroker()
String
getLocalBrokerName()
ConcurrentMap<org.apache.activemq.command.ConsumerId,DemandSubscription>
getLocalSubscriptionMap()
ObjectName
getMbeanObjectName()
NetworkBridgeStatistics
getNetworkBridgeStatistics()
protected Collection<Subscription>
getRegionSubscriptions(org.apache.activemq.command.ActiveMQDestination dest)
String
getRemoteAddress()
org.apache.activemq.transport.Transport
getRemoteBroker()
String
getRemoteBrokerId()
String
getRemoteBrokerName()
protected org.apache.activemq.command.BrokerId[]
getRemoteBrokerPath()
org.apache.activemq.command.ActiveMQDestination[]
getStaticallyIncludedDestinations()
protected long
getStoredSequenceIdForMessage(org.apache.activemq.command.MessageId messageId)
boolean
isCreatedByDuplex()
protected boolean
isDirectBridgeConsumer(org.apache.activemq.command.ConsumerInfo info)
Checks whether or not this consumer is a direct bridge network subscriptionprotected boolean
isDuplex()
protected boolean
isPermissableDestination(org.apache.activemq.command.ActiveMQDestination destination)
protected boolean
isPermissableDestination(org.apache.activemq.command.ActiveMQDestination destination, boolean allowTemporary)
protected boolean
isProxyBridgeSubscription(String clientId, String subName)
protected boolean
isProxyNSConsumerBrokerPath(org.apache.activemq.command.ConsumerInfo info)
protected boolean
isProxyNSConsumerClientId(String clientId)
protected void
removeDemandSubscription(org.apache.activemq.command.ConsumerId id)
protected boolean
removeDemandSubscriptionByLocalId(org.apache.activemq.command.ConsumerId consumerId)
protected void
removeSubscription(DemandSubscription sub)
void
resetStats()
protected boolean
safeWaitUntilStarted()
Performs a timed wait on the started latch and then checks for disposed before performing another wait each time the the started wait times out.protected void
serviceInboundMessage(org.apache.activemq.command.Message message)
protected void
serviceLocalCommand(org.apache.activemq.command.Command command)
void
serviceLocalException(Throwable error)
Service an exception received from the Local Broker connection.void
serviceLocalException(org.apache.activemq.command.MessageDispatch messageDispatch, Throwable error)
protected void
serviceOutbound(org.apache.activemq.command.Message message)
protected void
serviceRemoteCommand(org.apache.activemq.command.Command command)
void
serviceRemoteException(Throwable error)
Service an exception received from the Remote Broker connection.void
setBrokerService(BrokerService brokerService)
void
setCreatedByDuplex(boolean createdByDuplex)
void
setDurableDestinations(org.apache.activemq.command.ActiveMQDestination[] durableDestinations)
void
setDynamicallyIncludedDestinations(org.apache.activemq.command.ActiveMQDestination[] dynamicallyIncludedDestinations)
void
setExcludedDestinations(org.apache.activemq.command.ActiveMQDestination[] excludedDestinations)
void
setMbeanObjectName(ObjectName objectName)
void
setNetworkBridgeListener(NetworkBridgeListener listener)
Set the NetworkBridgeFailedListenervoid
setStaticallyIncludedDestinations(org.apache.activemq.command.ActiveMQDestination[] staticallyIncludedDestinations)
protected void
setupStaticDestinations()
Subscriptions for these destinations are always createdvoid
start()
protected void
startRemoteBridge()
void
stop()
protected void
triggerStartAsyncNetworkBridgeCreation()
-
-
-
Field Detail
-
DURABLE_SUB_PREFIX
protected static final String DURABLE_SUB_PREFIX
- See Also:
- Constant Field Values
-
localBroker
protected final org.apache.activemq.transport.Transport localBroker
-
remoteBroker
protected final org.apache.activemq.transport.Transport remoteBroker
-
idGenerator
protected org.apache.activemq.util.IdGenerator idGenerator
-
consumerIdGenerator
protected final org.apache.activemq.util.LongSequenceGenerator consumerIdGenerator
-
localConnectionInfo
protected org.apache.activemq.command.ConnectionInfo localConnectionInfo
-
remoteConnectionInfo
protected org.apache.activemq.command.ConnectionInfo remoteConnectionInfo
-
localSessionInfo
protected org.apache.activemq.command.SessionInfo localSessionInfo
-
producerInfo
protected org.apache.activemq.command.ProducerInfo producerInfo
-
remoteBrokerName
protected String remoteBrokerName
-
localClientId
protected String localClientId
-
demandConsumerInfo
protected org.apache.activemq.command.ConsumerInfo demandConsumerInfo
-
demandConsumerDispatched
protected int demandConsumerDispatched
-
localBridgeStarted
protected final AtomicBoolean localBridgeStarted
-
remoteBridgeStarted
protected final AtomicBoolean remoteBridgeStarted
-
bridgeFailed
protected final AtomicBoolean bridgeFailed
-
disposed
protected final AtomicBoolean disposed
-
localBrokerId
protected org.apache.activemq.command.BrokerId localBrokerId
-
excludedDestinations
protected org.apache.activemq.command.ActiveMQDestination[] excludedDestinations
-
dynamicallyIncludedDestinations
protected org.apache.activemq.command.ActiveMQDestination[] dynamicallyIncludedDestinations
-
staticallyIncludedDestinations
protected org.apache.activemq.command.ActiveMQDestination[] staticallyIncludedDestinations
-
durableDestinations
protected org.apache.activemq.command.ActiveMQDestination[] durableDestinations
-
subscriptionMapByLocalId
protected final ConcurrentMap<org.apache.activemq.command.ConsumerId,DemandSubscription> subscriptionMapByLocalId
-
subscriptionMapByRemoteId
protected final ConcurrentMap<org.apache.activemq.command.ConsumerId,DemandSubscription> subscriptionMapByRemoteId
-
forcedDurableRemoteId
protected final Set<org.apache.activemq.command.ConsumerId> forcedDurableRemoteId
-
localBrokerPath
protected final org.apache.activemq.command.BrokerId[] localBrokerPath
-
startedLatch
protected final CountDownLatch startedLatch
-
localStartedLatch
protected final CountDownLatch localStartedLatch
-
staticDestinationsLatch
protected final CountDownLatch staticDestinationsLatch
-
lastConnectSucceeded
protected final AtomicBoolean lastConnectSucceeded
-
configuration
protected NetworkBridgeConfiguration configuration
-
defaultFilterFactory
protected final NetworkBridgeFilterFactory defaultFilterFactory
-
remoteBrokerPath
protected final org.apache.activemq.command.BrokerId[] remoteBrokerPath
-
remoteBrokerId
protected org.apache.activemq.command.BrokerId remoteBrokerId
-
networkBridgeStatistics
protected final NetworkBridgeStatistics networkBridgeStatistics
-
brokerService
protected BrokerService brokerService
-
-
Constructor Detail
-
DemandForwardingBridgeSupport
public DemandForwardingBridgeSupport(NetworkBridgeConfiguration configuration, org.apache.activemq.transport.Transport localBroker, org.apache.activemq.transport.Transport remoteBroker)
-
-
Method Detail
-
duplexStart
public void duplexStart(TransportConnection connection, org.apache.activemq.command.BrokerInfo localBrokerInfo, org.apache.activemq.command.BrokerInfo remoteBrokerInfo) throws Exception
- Throws:
Exception
-
start
public void start() throws Exception
- Specified by:
start
in interfaceorg.apache.activemq.Service
- Throws:
Exception
-
stop
public void stop() throws Exception
- Specified by:
stop
in interfaceorg.apache.activemq.Service
- Throws:
Exception
-
triggerStartAsyncNetworkBridgeCreation
protected void triggerStartAsyncNetworkBridgeCreation() throws IOException
- Throws:
IOException
-
serviceRemoteException
public void serviceRemoteException(Throwable error)
Description copied from interface:NetworkBridge
Service an exception received from the Remote Broker connection.- Specified by:
serviceRemoteException
in interfaceNetworkBridge
-
isDirectBridgeConsumer
protected boolean isDirectBridgeConsumer(org.apache.activemq.command.ConsumerInfo info)
Checks whether or not this consumer is a direct bridge network subscription- Parameters:
info
-- Returns:
-
isProxyBridgeSubscription
protected boolean isProxyBridgeSubscription(String clientId, String subName)
-
addProxyNetworkSubscriptionClientId
protected void addProxyNetworkSubscriptionClientId(DemandSubscription sub, String clientId, String subName)
This scenaior is primarily used for durable sync on broker restarts- Parameters:
sub
-clientId
-subName
-
-
addProxyNetworkSubscriptionBrokerPath
protected void addProxyNetworkSubscriptionBrokerPath(DemandSubscription sub, org.apache.activemq.command.BrokerId[] path, String subName)
Add a durable remote proxy subscription when we can generate via the BrokerId path This is the most common scenario- Parameters:
sub
-path
-subName
-
-
isProxyNSConsumerBrokerPath
protected boolean isProxyNSConsumerBrokerPath(org.apache.activemq.command.ConsumerInfo info)
-
isProxyNSConsumerClientId
protected boolean isProxyNSConsumerClientId(String clientId)
-
serviceRemoteCommand
protected void serviceRemoteCommand(org.apache.activemq.command.Command command)
-
serviceLocalException
public void serviceLocalException(Throwable error)
Description copied from interface:NetworkBridge
Service an exception received from the Local Broker connection.- Specified by:
serviceLocalException
in interfaceNetworkBridge
-
serviceLocalException
public void serviceLocalException(org.apache.activemq.command.MessageDispatch messageDispatch, Throwable error)
-
getControllingService
protected org.apache.activemq.Service getControllingService()
-
addSubscription
protected void addSubscription(DemandSubscription sub) throws IOException
- Throws:
IOException
-
removeSubscription
protected void removeSubscription(DemandSubscription sub) throws IOException
- Throws:
IOException
-
configureMessage
protected org.apache.activemq.command.Message configureMessage(org.apache.activemq.command.MessageDispatch md) throws IOException
- Throws:
IOException
-
serviceLocalCommand
protected void serviceLocalCommand(org.apache.activemq.command.Command command)
-
contains
public static boolean contains(org.apache.activemq.command.BrokerId[] brokerPath, org.apache.activemq.command.BrokerId brokerId)
-
appendToBrokerPath
protected org.apache.activemq.command.BrokerId[] appendToBrokerPath(org.apache.activemq.command.BrokerId[] brokerPath, org.apache.activemq.command.BrokerId[] pathsToAppend)
-
appendToBrokerPath
protected org.apache.activemq.command.BrokerId[] appendToBrokerPath(org.apache.activemq.command.BrokerId[] brokerPath, org.apache.activemq.command.BrokerId idToAppend)
-
isPermissableDestination
protected boolean isPermissableDestination(org.apache.activemq.command.ActiveMQDestination destination)
-
isPermissableDestination
protected boolean isPermissableDestination(org.apache.activemq.command.ActiveMQDestination destination, boolean allowTemporary)
-
setupStaticDestinations
protected void setupStaticDestinations()
Subscriptions for these destinations are always created
-
addConsumerInfo
protected void addConsumerInfo(org.apache.activemq.command.ConsumerInfo consumerInfo) throws IOException
- Throws:
IOException
-
getRegionSubscriptions
protected final Collection<Subscription> getRegionSubscriptions(org.apache.activemq.command.ActiveMQDestination dest)
-
createDemandSubscription
protected DemandSubscription createDemandSubscription(org.apache.activemq.command.ConsumerInfo info) throws IOException
- Throws:
IOException
-
doCreateDemandSubscription
protected DemandSubscription doCreateDemandSubscription(org.apache.activemq.command.ConsumerInfo info) throws IOException
- Throws:
IOException
-
createDemandSubscription
protected final DemandSubscription createDemandSubscription(org.apache.activemq.command.ActiveMQDestination destination, String subscriptionName)
-
configureDemandSubscription
protected void configureDemandSubscription(org.apache.activemq.command.ConsumerInfo info, DemandSubscription sub) throws IOException
- Throws:
IOException
-
removeDemandSubscription
protected void removeDemandSubscription(org.apache.activemq.command.ConsumerId id) throws IOException
- Throws:
IOException
-
removeDemandSubscriptionByLocalId
protected boolean removeDemandSubscriptionByLocalId(org.apache.activemq.command.ConsumerId consumerId)
-
safeWaitUntilStarted
protected boolean safeWaitUntilStarted() throws InterruptedException
Performs a timed wait on the started latch and then checks for disposed before performing another wait each time the the started wait times out.- Throws:
InterruptedException
-
createNetworkBridgeFilter
protected org.apache.activemq.command.NetworkBridgeFilter createNetworkBridgeFilter(org.apache.activemq.command.ConsumerInfo info) throws IOException
- Throws:
IOException
-
addRemoteBrokerToBrokerPath
protected void addRemoteBrokerToBrokerPath(org.apache.activemq.command.ConsumerInfo info) throws IOException
- Throws:
IOException
-
getRemoteBrokerPath
protected org.apache.activemq.command.BrokerId[] getRemoteBrokerPath()
-
setNetworkBridgeListener
public void setNetworkBridgeListener(NetworkBridgeListener listener)
Description copied from interface:NetworkBridge
Set the NetworkBridgeFailedListener- Specified by:
setNetworkBridgeListener
in interfaceNetworkBridge
-
getDynamicallyIncludedDestinations
public org.apache.activemq.command.ActiveMQDestination[] getDynamicallyIncludedDestinations()
- Returns:
- Returns the dynamicallyIncludedDestinations.
-
setDynamicallyIncludedDestinations
public void setDynamicallyIncludedDestinations(org.apache.activemq.command.ActiveMQDestination[] dynamicallyIncludedDestinations)
- Parameters:
dynamicallyIncludedDestinations
- The dynamicallyIncludedDestinations to set.
-
getExcludedDestinations
public org.apache.activemq.command.ActiveMQDestination[] getExcludedDestinations()
- Returns:
- Returns the excludedDestinations.
-
setExcludedDestinations
public void setExcludedDestinations(org.apache.activemq.command.ActiveMQDestination[] excludedDestinations)
- Parameters:
excludedDestinations
- The excludedDestinations to set.
-
getStaticallyIncludedDestinations
public org.apache.activemq.command.ActiveMQDestination[] getStaticallyIncludedDestinations()
- Returns:
- Returns the staticallyIncludedDestinations.
-
setStaticallyIncludedDestinations
public void setStaticallyIncludedDestinations(org.apache.activemq.command.ActiveMQDestination[] staticallyIncludedDestinations)
- Parameters:
staticallyIncludedDestinations
- The staticallyIncludedDestinations to set.
-
getDurableDestinations
public org.apache.activemq.command.ActiveMQDestination[] getDurableDestinations()
- Returns:
- Returns the durableDestinations.
-
setDurableDestinations
public void setDurableDestinations(org.apache.activemq.command.ActiveMQDestination[] durableDestinations)
- Parameters:
durableDestinations
- The durableDestinations to set.
-
getLocalBroker
public org.apache.activemq.transport.Transport getLocalBroker()
- Returns:
- Returns the localBroker.
-
getRemoteBroker
public org.apache.activemq.transport.Transport getRemoteBroker()
- Returns:
- Returns the remoteBroker.
-
isCreatedByDuplex
public boolean isCreatedByDuplex()
- Returns:
- the createdByDuplex
-
setCreatedByDuplex
public void setCreatedByDuplex(boolean createdByDuplex)
- Parameters:
createdByDuplex
- the createdByDuplex to set
-
getRemoteAddress
public String getRemoteAddress()
- Specified by:
getRemoteAddress
in interfaceNetworkBridge
- Returns:
- the network address of the remote broker connection.
-
getLocalAddress
public String getLocalAddress()
- Specified by:
getLocalAddress
in interfaceNetworkBridge
- Returns:
- the network address of the local broker connection.
-
getRemoteBrokerName
public String getRemoteBrokerName()
- Specified by:
getRemoteBrokerName
in interfaceNetworkBridge
- Returns:
- the name of the remote broker this bridge is connected to.
-
getRemoteBrokerId
public String getRemoteBrokerId()
- Specified by:
getRemoteBrokerId
in interfaceNetworkBridge
- Returns:
- the id of the remote broker this bridge is connected to.
-
getLocalBrokerName
public String getLocalBrokerName()
- Specified by:
getLocalBrokerName
in interfaceNetworkBridge
- Returns:
- the name of the local broker this bridge is connected to.
-
getDequeueCounter
public long getDequeueCounter()
- Specified by:
getDequeueCounter
in interfaceNetworkBridge
- Returns:
- the current number of dequeues this bridge has.
-
getEnqueueCounter
public long getEnqueueCounter()
- Specified by:
getEnqueueCounter
in interfaceNetworkBridge
- Returns:
- the current number of enqueues this bridge has.
-
getNetworkBridgeStatistics
public NetworkBridgeStatistics getNetworkBridgeStatistics()
- Specified by:
getNetworkBridgeStatistics
in interfaceNetworkBridge
- Returns:
- the statistics for this NetworkBridge
-
isDuplex
protected boolean isDuplex()
-
getLocalSubscriptionMap
public ConcurrentMap<org.apache.activemq.command.ConsumerId,DemandSubscription> getLocalSubscriptionMap()
-
setBrokerService
public void setBrokerService(BrokerService brokerService)
- Specified by:
setBrokerService
in interfaceBrokerServiceAware
-
setMbeanObjectName
public void setMbeanObjectName(ObjectName objectName)
- Specified by:
setMbeanObjectName
in interfaceNetworkBridge
- Parameters:
objectName
- The ObjectName assigned to this bridge in the MBean server.
-
getMbeanObjectName
public ObjectName getMbeanObjectName()
- Specified by:
getMbeanObjectName
in interfaceNetworkBridge
- Returns:
- the MBean name used to identify this bridge in the MBean server.
-
resetStats
public void resetStats()
- Specified by:
resetStats
in interfaceNetworkBridge
-
serviceOutbound
protected void serviceOutbound(org.apache.activemq.command.Message message)
-
serviceInboundMessage
protected void serviceInboundMessage(org.apache.activemq.command.Message message)
-
canDuplexDispatch
protected boolean canDuplexDispatch(org.apache.activemq.command.Message message)
-
getStoredSequenceIdForMessage
protected long getStoredSequenceIdForMessage(org.apache.activemq.command.MessageId messageId)
-
configureConsumerPrefetch
protected void configureConsumerPrefetch(org.apache.activemq.command.ConsumerInfo consumerInfo)
-
-