org.apache.activemq.broker.region
Class RegionBroker

java.lang.Object
  extended by org.apache.activemq.broker.EmptyBroker
      extended by org.apache.activemq.broker.region.RegionBroker
All Implemented Interfaces:
Broker, Region, Service
Direct Known Subclasses:
ManagedRegionBroker

public class RegionBroker
extends EmptyBroker

Routes Broker operations to the correct messaging regions for processing.

Version:
$Revision$

Field Summary
protected  BrokerService brokerService
           
protected  Map<ConnectionId,ConnectionState> connectionStates
           
protected  DestinationFactory destinationFactory
           
protected  DestinationStatistics destinationStatistics
           
 
Constructor Summary
RegionBroker(BrokerService brokerService, TaskRunnerFactory taskRunnerFactory, SystemUsage memoryManager, DestinationFactory destinationFactory, DestinationInterceptor destinationInterceptor)
           
 
Method Summary
 void acknowledge(ConsumerBrokerExchange consumerExchange, MessageAck ack)
          Used to acknowledge the receipt of a message by a client.
 void addBroker(Connection connection, BrokerInfo info)
          A remote Broker connects
 void addConnection(ConnectionContext context, ConnectionInfo info)
          A client is establishing a connection with the broker.
 Subscription addConsumer(ConnectionContext context, ConsumerInfo info)
          Adds a consumer.
 Destination addDestination(ConnectionContext context, ActiveMQDestination destination)
          Used to create a destination.
 void addDestinationInfo(ConnectionContext context, DestinationInfo info)
          Add and process a DestinationInfo object
 void addProducer(ConnectionContext context, ProducerInfo info)
          Adds a producer.
 void beginTransaction(ConnectionContext context, TransactionId xid)
          Starts a transaction.
 void brokerServiceStarted()
          called when the brokerService starts
 void commitTransaction(ConnectionContext context, TransactionId xid, boolean onePhase)
          Commits a transaction.
protected  Region createQueueRegion(SystemUsage memoryManager, TaskRunnerFactory taskRunnerFactory, DestinationFactory destinationFactory)
           
protected  Region createTempQueueRegion(SystemUsage memoryManager, TaskRunnerFactory taskRunnerFactory, DestinationFactory destinationFactory)
           
protected  Region createTempTopicRegion(SystemUsage memoryManager, TaskRunnerFactory taskRunnerFactory, DestinationFactory destinationFactory)
           
protected  Region createTopicRegion(SystemUsage memoryManager, TaskRunnerFactory taskRunnerFactory, DestinationFactory destinationFactory)
           
protected  JMSException createUnknownDestinationTypeException(ActiveMQDestination destination)
           
protected  void doStop(ServiceStopper ss)
           
 void forgetTransaction(ConnectionContext context, TransactionId transactionId)
          Forgets a transaction.
 void gc()
           
 Broker getAdaptor(Class type)
          Get a Broker from the Broker Stack that is a particular class
 ConnectionContext getAdminConnectionContext()
           
 BrokerId getBrokerId()
          Get the id of the broker
 String getBrokerName()
          Get the name of the broker
 long getBrokerSequenceId()
           
 BrokerService getBrokerService()
           
 Connection[] getClients()
           
 Map<ConnectionId,ConnectionState> getConnectionStates()
           
 DestinationInterceptor getDestinationInterceptor()
           
 Map<ActiveMQDestination,Destination> getDestinationMap()
          Returns a copy of the current destinations available in the region
 PolicyMap getDestinationPolicy()
           
 ActiveMQDestination[] getDestinations()
           
 Set<Destination> getDestinations(ActiveMQDestination destination)
          Provide an exact or wildcard lookup of destinations in the region
 DestinationStatistics getDestinationStatistics()
           
 Set<ActiveMQDestination> getDurableDestinations()
           
 BrokerInfo[] getPeerBrokerInfos()
          Get the BrokerInfo's of any connected Brokers
 TransactionId[] getPreparedTransactions(ConnectionContext context)
          Gets a list of all the prepared xa transactions.
 Region getQueueRegion()
           
 Broker getRoot()
          Ensure we get the Broker at the top of the Stack
 Store getTempDataStore()
           
 Region getTempQueueRegion()
           
 Region getTempTopicRegion()
           
 Region getTopicRegion()
           
 URI getVmConnectorURI()
           
protected  boolean isEqual(ConnectionId connectionId, ConnectionId connectionId2)
           
 boolean isExpired(MessageReference messageReference)
          Determine if a message has expired -allows default behaviour to be overriden - as the timestamp set by the producer can be out of sync with the broker
 boolean isKeepDurableSubsActive()
           
 boolean isSlaveBroker()
           
 boolean isStopped()
           
 void messageExpired(ConnectionContext context, MessageReference node)
          A Message has Expired
 Response messagePull(ConnectionContext context, MessagePull pull)
          Allows a consumer to pull a message from a queue
 void postProcessDispatch(MessageDispatch messageDispatch)
          Notify the Broker that a dispatch has happened
 int prepareTransaction(ConnectionContext context, TransactionId xid)
          Prepares a transaction.
 void preProcessDispatch(MessageDispatch messageDispatch)
          Notify the Broker that a dispatch is going to happen
 void processDispatchNotification(MessageDispatchNotification messageDispatchNotification)
          Process a notification of a dispatch - used by a Slave Broker
 void removeBroker(Connection connection, BrokerInfo info)
          Remove a BrokerInfo
 void removeConnection(ConnectionContext context, ConnectionInfo info, Throwable error)
          A client is disconnecting from the broker.
 void removeConsumer(ConnectionContext context, ConsumerInfo info)
          Removes a consumer.
 void removeDestination(ConnectionContext context, ActiveMQDestination destination, long timeout)
          Used to destroy a destination.
 void removeDestinationInfo(ConnectionContext context, DestinationInfo info)
          Remove and process a DestinationInfo object
 void removeProducer(ConnectionContext context, ProducerInfo info)
          Removes a producer.
 void removeSubscription(ConnectionContext context, RemoveSubscriptionInfo info)
          Deletes a durable subscription.
 void rollbackTransaction(ConnectionContext context, TransactionId xid)
          Rollsback a transaction.
 void send(ProducerBrokerExchange producerExchange, Message message)
          Send a message to the broker to using the specified destination.
 void sendToDeadLetterQueue(ConnectionContext context, MessageReference node)
          A message needs to go the a DLQ
 void setAdminConnectionContext(ConnectionContext adminConnectionContext)
          Sets the default administration connection context used when configuring the broker on startup or via JMX
 void setBrokerId(BrokerId brokerId)
           
 void setBrokerName(String brokerName)
           
 void setKeepDurableSubsActive(boolean keepDurableSubsActive)
           
 void start()
           
 void stop()
           
 
Methods inherited from class org.apache.activemq.broker.EmptyBroker
addSession, fastProducer, isFaultTolerantConfiguration, isFull, messageConsumed, messageDelivered, messageDiscarded, nowMasterBroker, removeSession, slowConsumer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

destinationStatistics

protected final DestinationStatistics destinationStatistics

destinationFactory

protected DestinationFactory destinationFactory

connectionStates

protected final Map<ConnectionId,ConnectionState> connectionStates

brokerService

protected final BrokerService brokerService
Constructor Detail

RegionBroker

public RegionBroker(BrokerService brokerService,
                    TaskRunnerFactory taskRunnerFactory,
                    SystemUsage memoryManager,
                    DestinationFactory destinationFactory,
                    DestinationInterceptor destinationInterceptor)
             throws IOException
Throws:
IOException
Method Detail

getDestinationMap

public Map<ActiveMQDestination,Destination> getDestinationMap()
Description copied from interface: Region
Returns a copy of the current destinations available in the region

Specified by:
getDestinationMap in interface Region
Overrides:
getDestinationMap in class EmptyBroker
Returns:
a copy of the regions currently active at the time of the call with the key the destination and the value the Destination.

getDestinations

public Set<Destination> getDestinations(ActiveMQDestination destination)
Description copied from interface: Region
Provide an exact or wildcard lookup of destinations in the region

Specified by:
getDestinations in interface Region
Overrides:
getDestinations in class EmptyBroker
Returns:
a set of matching destination objects.

getAdaptor

public Broker getAdaptor(Class type)
Description copied from interface: Broker
Get a Broker from the Broker Stack that is a particular class

Specified by:
getAdaptor in interface Broker
Overrides:
getAdaptor in class EmptyBroker
Returns:

getQueueRegion

public Region getQueueRegion()

getTempQueueRegion

public Region getTempQueueRegion()

getTempTopicRegion

public Region getTempTopicRegion()

getTopicRegion

public Region getTopicRegion()

createTempTopicRegion

protected Region createTempTopicRegion(SystemUsage memoryManager,
                                       TaskRunnerFactory taskRunnerFactory,
                                       DestinationFactory destinationFactory)

createTempQueueRegion

protected Region createTempQueueRegion(SystemUsage memoryManager,
                                       TaskRunnerFactory taskRunnerFactory,
                                       DestinationFactory destinationFactory)

createTopicRegion

protected Region createTopicRegion(SystemUsage memoryManager,
                                   TaskRunnerFactory taskRunnerFactory,
                                   DestinationFactory destinationFactory)

createQueueRegion

protected Region createQueueRegion(SystemUsage memoryManager,
                                   TaskRunnerFactory taskRunnerFactory,
                                   DestinationFactory destinationFactory)

start

public void start()
           throws Exception
Specified by:
start in interface Service
Overrides:
start in class EmptyBroker
Throws:
Exception

stop

public void stop()
          throws Exception
Specified by:
stop in interface Service
Overrides:
stop in class EmptyBroker
Throws:
Exception

getDestinationPolicy

public PolicyMap getDestinationPolicy()

addConnection

public void addConnection(ConnectionContext context,
                          ConnectionInfo info)
                   throws Exception
Description copied from interface: Broker
A client is establishing a connection with the broker.

Specified by:
addConnection in interface Broker
Overrides:
addConnection in class EmptyBroker
Throws:
Exception - TODO

removeConnection

public void removeConnection(ConnectionContext context,
                             ConnectionInfo info,
                             Throwable error)
                      throws Exception
Description copied from interface: Broker
A client is disconnecting from the broker.

Specified by:
removeConnection in interface Broker
Overrides:
removeConnection in class EmptyBroker
Parameters:
context - the environment the operation is being executed under.
error - null if the client requested the disconnect or the error that caused the client to disconnect.
Throws:
Exception - TODO

isEqual

protected boolean isEqual(ConnectionId connectionId,
                          ConnectionId connectionId2)

getClients

public Connection[] getClients()
                        throws Exception
Specified by:
getClients in interface Broker
Overrides:
getClients in class EmptyBroker
Returns:
all clients added to the Broker.
Throws:
Exception - TODO

addDestination

public Destination addDestination(ConnectionContext context,
                                  ActiveMQDestination destination)
                           throws Exception
Description copied from interface: Region
Used to create a destination. Usually, this method is invoked as a side-effect of sending a message to a destination that does not exist yet.

Specified by:
addDestination in interface Region
Overrides:
addDestination in class EmptyBroker
destination - the destination to create.
Returns:
TODO
Throws:
Exception - TODO

removeDestination

public void removeDestination(ConnectionContext context,
                              ActiveMQDestination destination,
                              long timeout)
                       throws Exception
Description copied from interface: Region
Used to destroy a destination. This should try to quiesce use of the destination up to the timeout allotted time before removing the destination. This will remove all persistent messages associated with the destination.

Specified by:
removeDestination in interface Region
Overrides:
removeDestination in class EmptyBroker
Parameters:
context - the environment the operation is being executed under.
destination - what is being removed from the broker.
timeout - the max amount of time to wait for the destination to quiesce
Throws:
Exception - TODO

addDestinationInfo

public void addDestinationInfo(ConnectionContext context,
                               DestinationInfo info)
                        throws Exception
Description copied from interface: Broker
Add and process a DestinationInfo object

Specified by:
addDestinationInfo in interface Broker
Overrides:
addDestinationInfo in class EmptyBroker
Throws:
Exception

removeDestinationInfo

public void removeDestinationInfo(ConnectionContext context,
                                  DestinationInfo info)
                           throws Exception
Description copied from interface: Broker
Remove and process a DestinationInfo object

Specified by:
removeDestinationInfo in interface Broker
Overrides:
removeDestinationInfo in class EmptyBroker
Throws:
Exception

getDestinations

public ActiveMQDestination[] getDestinations()
                                      throws Exception
Specified by:
getDestinations in interface Broker
Overrides:
getDestinations in class EmptyBroker
Returns:
all destinations added to the Broker.
Throws:
Exception - TODO

addProducer

public void addProducer(ConnectionContext context,
                        ProducerInfo info)
                 throws Exception
Description copied from interface: Broker
Adds a producer.

Specified by:
addProducer in interface Broker
Specified by:
addProducer in interface Region
Overrides:
addProducer in class EmptyBroker
Parameters:
context - the enviorment the operation is being executed under.
Throws:
Exception - TODO

removeProducer

public void removeProducer(ConnectionContext context,
                           ProducerInfo info)
                    throws Exception
Description copied from interface: Broker
Removes a producer.

Specified by:
removeProducer in interface Broker
Specified by:
removeProducer in interface Region
Overrides:
removeProducer in class EmptyBroker
Parameters:
context - the enviorment the operation is being executed under.
Throws:
Exception - TODO

addConsumer

public Subscription addConsumer(ConnectionContext context,
                                ConsumerInfo info)
                         throws Exception
Description copied from interface: Region
Adds a consumer.

Specified by:
addConsumer in interface Region
Overrides:
addConsumer in class EmptyBroker
Parameters:
context - the environment the operation is being executed under.
Returns:
TODO
Throws:
Exception - TODO

removeConsumer

public void removeConsumer(ConnectionContext context,
                           ConsumerInfo info)
                    throws Exception
Description copied from interface: Region
Removes a consumer.

Specified by:
removeConsumer in interface Region
Overrides:
removeConsumer in class EmptyBroker
Parameters:
context - the environment the operation is being executed under.
Throws:
Exception - TODO

removeSubscription

public void removeSubscription(ConnectionContext context,
                               RemoveSubscriptionInfo info)
                        throws Exception
Description copied from interface: Region
Deletes a durable subscription.

Specified by:
removeSubscription in interface Region
Overrides:
removeSubscription in class EmptyBroker
Parameters:
context - the environment the operation is being executed under.
info - TODO
Throws:
Exception - TODO

send

public void send(ProducerBrokerExchange producerExchange,
                 Message message)
          throws Exception
Description copied from interface: Region
Send a message to the broker to using the specified destination. The destination specified in the message does not need to match the destination the message is sent to. This is handy in case the message is being sent to a dead letter destination.

Specified by:
send in interface Region
Overrides:
send in class EmptyBroker
Parameters:
producerExchange - the environment the operation is being executed under.
Throws:
Exception - TODO

acknowledge

public void acknowledge(ConsumerBrokerExchange consumerExchange,
                        MessageAck ack)
                 throws Exception
Description copied from interface: Region
Used to acknowledge the receipt of a message by a client.

Specified by:
acknowledge in interface Region
Overrides:
acknowledge in class EmptyBroker
Parameters:
consumerExchange - the environment the operation is being executed under.
Throws:
Exception - TODO

messagePull

public Response messagePull(ConnectionContext context,
                            MessagePull pull)
                     throws Exception
Description copied from interface: Region
Allows a consumer to pull a message from a queue

Specified by:
messagePull in interface Region
Overrides:
messagePull in class EmptyBroker
Throws:
Exception

getPreparedTransactions

public TransactionId[] getPreparedTransactions(ConnectionContext context)
                                        throws Exception
Description copied from interface: Broker
Gets a list of all the prepared xa transactions.

Specified by:
getPreparedTransactions in interface Broker
Overrides:
getPreparedTransactions in class EmptyBroker
Parameters:
context - transaction ids
Returns:
Throws:
Exception - TODO

beginTransaction

public void beginTransaction(ConnectionContext context,
                             TransactionId xid)
                      throws Exception
Description copied from interface: Broker
Starts a transaction.

Specified by:
beginTransaction in interface Broker
Overrides:
beginTransaction in class EmptyBroker
Throws:
Exception - TODO

prepareTransaction

public int prepareTransaction(ConnectionContext context,
                              TransactionId xid)
                       throws Exception
Description copied from interface: Broker
Prepares a transaction. Only valid for xa transactions.

Specified by:
prepareTransaction in interface Broker
Overrides:
prepareTransaction in class EmptyBroker
Returns:
id
Throws:
Exception - TODO

rollbackTransaction

public void rollbackTransaction(ConnectionContext context,
                                TransactionId xid)
                         throws Exception
Description copied from interface: Broker
Rollsback a transaction.

Specified by:
rollbackTransaction in interface Broker
Overrides:
rollbackTransaction in class EmptyBroker
Throws:
Exception - TODO

commitTransaction

public void commitTransaction(ConnectionContext context,
                              TransactionId xid,
                              boolean onePhase)
                       throws Exception
Description copied from interface: Broker
Commits a transaction.

Specified by:
commitTransaction in interface Broker
Overrides:
commitTransaction in class EmptyBroker
Throws:
Exception - TODO

forgetTransaction

public void forgetTransaction(ConnectionContext context,
                              TransactionId transactionId)
                       throws Exception
Description copied from interface: Broker
Forgets a transaction.

Specified by:
forgetTransaction in interface Broker
Overrides:
forgetTransaction in class EmptyBroker
Throws:
Exception

gc

public void gc()
Specified by:
gc in interface Region
Overrides:
gc in class EmptyBroker

getBrokerId

public BrokerId getBrokerId()
Description copied from interface: Broker
Get the id of the broker

Specified by:
getBrokerId in interface Broker
Overrides:
getBrokerId in class EmptyBroker

setBrokerId

public void setBrokerId(BrokerId brokerId)

getBrokerName

public String getBrokerName()
Description copied from interface: Broker
Get the name of the broker

Specified by:
getBrokerName in interface Broker
Overrides:
getBrokerName in class EmptyBroker

setBrokerName

public void setBrokerName(String brokerName)

getDestinationStatistics

public DestinationStatistics getDestinationStatistics()

createUnknownDestinationTypeException

protected JMSException createUnknownDestinationTypeException(ActiveMQDestination destination)

addBroker

public void addBroker(Connection connection,
                      BrokerInfo info)
Description copied from interface: Broker
A remote Broker connects

Specified by:
addBroker in interface Broker
Overrides:
addBroker in class EmptyBroker

removeBroker

public void removeBroker(Connection connection,
                         BrokerInfo info)
Description copied from interface: Broker
Remove a BrokerInfo

Specified by:
removeBroker in interface Broker
Overrides:
removeBroker in class EmptyBroker

getPeerBrokerInfos

public BrokerInfo[] getPeerBrokerInfos()
Description copied from interface: Broker
Get the BrokerInfo's of any connected Brokers

Specified by:
getPeerBrokerInfos in interface Broker
Overrides:
getPeerBrokerInfos in class EmptyBroker
Returns:
array of peer BrokerInfos

preProcessDispatch

public void preProcessDispatch(MessageDispatch messageDispatch)
Description copied from interface: Broker
Notify the Broker that a dispatch is going to happen

Specified by:
preProcessDispatch in interface Broker
Overrides:
preProcessDispatch in class EmptyBroker

postProcessDispatch

public void postProcessDispatch(MessageDispatch messageDispatch)
Description copied from interface: Broker
Notify the Broker that a dispatch has happened

Specified by:
postProcessDispatch in interface Broker
Overrides:
postProcessDispatch in class EmptyBroker

processDispatchNotification

public void processDispatchNotification(MessageDispatchNotification messageDispatchNotification)
                                 throws Exception
Description copied from interface: Region
Process a notification of a dispatch - used by a Slave Broker

Specified by:
processDispatchNotification in interface Region
Overrides:
processDispatchNotification in class EmptyBroker
Throws:
Exception - TODO

isSlaveBroker

public boolean isSlaveBroker()

isStopped

public boolean isStopped()
Specified by:
isStopped in interface Broker
Overrides:
isStopped in class EmptyBroker
Returns:
true if the broker has stopped

getDurableDestinations

public Set<ActiveMQDestination> getDurableDestinations()
Specified by:
getDurableDestinations in interface Broker
Overrides:
getDurableDestinations in class EmptyBroker
Returns:
a Set of all durable destinations

doStop

protected void doStop(ServiceStopper ss)

isKeepDurableSubsActive

public boolean isKeepDurableSubsActive()

setKeepDurableSubsActive

public void setKeepDurableSubsActive(boolean keepDurableSubsActive)

getDestinationInterceptor

public DestinationInterceptor getDestinationInterceptor()

getAdminConnectionContext

public ConnectionContext getAdminConnectionContext()
Specified by:
getAdminConnectionContext in interface Broker
Overrides:
getAdminConnectionContext in class EmptyBroker
Returns:
the connection context used to make administration operations on startup or via JMX MBeans

setAdminConnectionContext

public void setAdminConnectionContext(ConnectionContext adminConnectionContext)
Description copied from interface: Broker
Sets the default administration connection context used when configuring the broker on startup or via JMX

Specified by:
setAdminConnectionContext in interface Broker
Overrides:
setAdminConnectionContext in class EmptyBroker

getConnectionStates

public Map<ConnectionId,ConnectionState> getConnectionStates()

getTempDataStore

public Store getTempDataStore()
Specified by:
getTempDataStore in interface Broker
Overrides:
getTempDataStore in class EmptyBroker
Returns:
the temp data store

getVmConnectorURI

public URI getVmConnectorURI()
Specified by:
getVmConnectorURI in interface Broker
Overrides:
getVmConnectorURI in class EmptyBroker
Returns:
the URI that can be used to connect to the local Broker

brokerServiceStarted

public void brokerServiceStarted()
Description copied from interface: Broker
called when the brokerService starts

Specified by:
brokerServiceStarted in interface Broker
Overrides:
brokerServiceStarted in class EmptyBroker

getBrokerService

public BrokerService getBrokerService()
Specified by:
getBrokerService in interface Broker
Overrides:
getBrokerService in class EmptyBroker
Returns:
the BrokerService

isExpired

public boolean isExpired(MessageReference messageReference)
Description copied from interface: Broker
Determine if a message has expired -allows default behaviour to be overriden - as the timestamp set by the producer can be out of sync with the broker

Specified by:
isExpired in interface Broker
Overrides:
isExpired in class EmptyBroker
Returns:
true if the message is expired

messageExpired

public void messageExpired(ConnectionContext context,
                           MessageReference node)
Description copied from interface: Broker
A Message has Expired

Specified by:
messageExpired in interface Broker
Overrides:
messageExpired in class EmptyBroker

sendToDeadLetterQueue

public void sendToDeadLetterQueue(ConnectionContext context,
                                  MessageReference node)
Description copied from interface: Broker
A message needs to go the a DLQ

Specified by:
sendToDeadLetterQueue in interface Broker
Overrides:
sendToDeadLetterQueue in class EmptyBroker

getRoot

public Broker getRoot()
Description copied from interface: Broker
Ensure we get the Broker at the top of the Stack

Specified by:
getRoot in interface Broker
Overrides:
getRoot in class EmptyBroker
Returns:
the broker at the top of the Stack

getBrokerSequenceId

public long getBrokerSequenceId()
Specified by:
getBrokerSequenceId in interface Broker
Overrides:
getBrokerSequenceId in class EmptyBroker
Returns:
the broker sequence id


Copyright © 2009. All Rights Reserved.