org.springframework.integration.bus
Class MessageBus

java.lang.Object
  extended by org.springframework.integration.bus.MessageBus
All Implemented Interfaces:
java.util.EventListener, org.springframework.context.ApplicationContextAware, org.springframework.context.ApplicationListener, org.springframework.context.Lifecycle, ChannelRegistry, EndpointRegistry

public class MessageBus
extends java.lang.Object
implements ChannelRegistry, EndpointRegistry, org.springframework.context.ApplicationContextAware, org.springframework.context.ApplicationListener, org.springframework.context.Lifecycle

The messaging bus. Serves as a registry for channels and endpoints, manages their lifecycle, and activates subscriptions.

Author:
Mark Fisher, Marius Bogoevici

Field Summary
private  boolean autoCreateChannels
           
private  boolean autoStartup
           
private  ChannelFactory channelFactory
           
private  ChannelRegistry channelRegistry
           
private  boolean configureAsyncEventMulticaster
           
private static int DEFAULT_DISPATCHER_POOL_SIZE
           
private  ConcurrencyPolicy defaultConcurrencyPolicy
           
private  EndpointRegistry endpointRegistry
           
static java.lang.String ERROR_CHANNEL_NAME
           
private  java.util.concurrent.ScheduledExecutorService executor
           
private  boolean initialized
           
private  boolean initializing
           
private  java.util.List<org.springframework.context.Lifecycle> lifecycleEndpoints
           
private  java.lang.Object lifecycleMonitor
           
private  org.apache.commons.logging.Log logger
           
private  boolean running
           
private  boolean starting
           
private  java.util.Map<MessageChannel,SubscriptionManager> subscriptionManagers
           
private  MessagingTaskScheduler taskScheduler
           
 
Constructor Summary
MessageBus()
           
 
Method Summary
private  void activateEndpoint(MessageEndpoint endpoint)
           
private  void activateEndpoints()
           
private  void activateSubscription(MessageChannel channel, Target target, Schedule schedule)
           
private  void activateTargetEndpoint(TargetEndpoint endpoint)
           
private  void doConfigureAsyncEventMulticaster(org.springframework.context.ApplicationContext context)
           
private  void doRegisterEndpoint(java.lang.String name, TargetEndpoint endpoint, Subscription subscription, ConcurrencyPolicy concurrencyPolicy)
           
 ChannelFactory getChannelFactory()
           
 java.util.Set<java.lang.String> getEndpointNames()
           
 MessageChannel getErrorChannel()
           
 void initialize()
           
 boolean isRunning()
           
 MessageChannel lookupChannel(java.lang.String channelName)
           
 MessageEndpoint lookupEndpoint(java.lang.String endpointName)
           
 void onApplicationEvent(org.springframework.context.ApplicationEvent event)
           
 void registerChannel(java.lang.String name, MessageChannel channel)
           
private  void registerChannels(org.springframework.context.ApplicationContext context)
           
 void registerEndpoint(java.lang.String name, MessageEndpoint endpoint)
           
private  void registerEndpoints(org.springframework.context.ApplicationContext context)
           
 void registerHandler(java.lang.String name, MessageHandler handler, Subscription subscription)
           
 void registerHandler(java.lang.String name, MessageHandler handler, Subscription subscription, ConcurrencyPolicy concurrencyPolicy)
           
private  void registerSourceEndpoint(java.lang.String name, SourceEndpoint endpoint)
           
 void registerTarget(java.lang.String name, Target target, Subscription subscription)
           
 void registerTarget(java.lang.String name, Target target, Subscription subscription, ConcurrencyPolicy concurrencyPolicy)
           
private  void registerTargetEndpoint(java.lang.String name, TargetEndpoint endpoint)
           
 void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
           
 void setAutoCreateChannels(boolean autoCreateChannels)
          Set whether the bus should automatically create a channel when a subscription contains the name of a previously unregistered channel.
 void setAutoStartup(boolean autoStartup)
          Set whether to automatically start the bus after initialization.
 void setChannelFactory(ChannelFactory channelFactory)
          Set the ChannelFactory to use for auto-creating channels.
 void setConfigureAsyncEventMulticaster(boolean configureAsyncEventMulticaster)
          Set whether the bus should configure its asynchronous task executor to also be used by the ApplicationContext's 'applicationEventMulticaster'.
 void setDefaultConcurrencyPolicy(ConcurrencyPolicy defaultConcurrencyPolicy)
          Specify the default concurrency policy to be used for any endpoint that is registered without an explicitly provided policy of its own.
 void setErrorChannel(MessageChannel errorChannel)
           
 void setScheduledExecutorService(java.util.concurrent.ScheduledExecutorService executor)
          Set the ScheduledExecutorService to use for scheduling message dispatchers.
 void start()
           
 void stop()
           
 MessageChannel unregisterChannel(java.lang.String name)
           
 MessageEndpoint unregisterEndpoint(java.lang.String name)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ERROR_CHANNEL_NAME

public static final java.lang.String ERROR_CHANNEL_NAME
See Also:
Constant Field Values

DEFAULT_DISPATCHER_POOL_SIZE

private static final int DEFAULT_DISPATCHER_POOL_SIZE
See Also:
Constant Field Values

logger

private final org.apache.commons.logging.Log logger

channelFactory

private volatile ChannelFactory channelFactory

channelRegistry

private final ChannelRegistry channelRegistry

endpointRegistry

private final EndpointRegistry endpointRegistry

subscriptionManagers

private final java.util.Map<MessageChannel,SubscriptionManager> subscriptionManagers

lifecycleEndpoints

private final java.util.List<org.springframework.context.Lifecycle> lifecycleEndpoints

taskScheduler

private volatile MessagingTaskScheduler taskScheduler

executor

private volatile java.util.concurrent.ScheduledExecutorService executor

defaultConcurrencyPolicy

private volatile ConcurrencyPolicy defaultConcurrencyPolicy

configureAsyncEventMulticaster

private volatile boolean configureAsyncEventMulticaster

autoCreateChannels

private volatile boolean autoCreateChannels

autoStartup

private volatile boolean autoStartup

initialized

private volatile boolean initialized

initializing

private volatile boolean initializing

starting

private volatile boolean starting

running

private volatile boolean running

lifecycleMonitor

private final java.lang.Object lifecycleMonitor
Constructor Detail

MessageBus

public MessageBus()
Method Detail

setChannelFactory

public void setChannelFactory(ChannelFactory channelFactory)
Set the ChannelFactory to use for auto-creating channels.


getChannelFactory

public ChannelFactory getChannelFactory()

setApplicationContext

public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
                           throws org.springframework.beans.BeansException
Specified by:
setApplicationContext in interface org.springframework.context.ApplicationContextAware
Throws:
org.springframework.beans.BeansException

setScheduledExecutorService

public void setScheduledExecutorService(java.util.concurrent.ScheduledExecutorService executor)
Set the ScheduledExecutorService to use for scheduling message dispatchers.


setDefaultConcurrencyPolicy

public void setDefaultConcurrencyPolicy(ConcurrencyPolicy defaultConcurrencyPolicy)
Specify the default concurrency policy to be used for any endpoint that is registered without an explicitly provided policy of its own.


setAutoStartup

public void setAutoStartup(boolean autoStartup)
Set whether to automatically start the bus after initialization.

Default is 'true'; set this to 'false' to allow for manual startup through the start() method.


setAutoCreateChannels

public void setAutoCreateChannels(boolean autoCreateChannels)
Set whether the bus should automatically create a channel when a subscription contains the name of a previously unregistered channel.


setConfigureAsyncEventMulticaster

public void setConfigureAsyncEventMulticaster(boolean configureAsyncEventMulticaster)
Set whether the bus should configure its asynchronous task executor to also be used by the ApplicationContext's 'applicationEventMulticaster'. This will only apply if the multicaster defined within the context is an instance of SimpleApplicationEventMulticaster (the default). This property is 'false' by default.


registerChannels

private void registerChannels(org.springframework.context.ApplicationContext context)

registerEndpoints

private void registerEndpoints(org.springframework.context.ApplicationContext context)

initialize

public void initialize()

getErrorChannel

public MessageChannel getErrorChannel()

setErrorChannel

public void setErrorChannel(MessageChannel errorChannel)

lookupChannel

public MessageChannel lookupChannel(java.lang.String channelName)
Specified by:
lookupChannel in interface ChannelRegistry

registerChannel

public void registerChannel(java.lang.String name,
                            MessageChannel channel)
Specified by:
registerChannel in interface ChannelRegistry

unregisterChannel

public MessageChannel unregisterChannel(java.lang.String name)
Specified by:
unregisterChannel in interface ChannelRegistry

registerHandler

public void registerHandler(java.lang.String name,
                            MessageHandler handler,
                            Subscription subscription)

registerHandler

public void registerHandler(java.lang.String name,
                            MessageHandler handler,
                            Subscription subscription,
                            ConcurrencyPolicy concurrencyPolicy)

registerTarget

public void registerTarget(java.lang.String name,
                           Target target,
                           Subscription subscription)

registerTarget

public void registerTarget(java.lang.String name,
                           Target target,
                           Subscription subscription,
                           ConcurrencyPolicy concurrencyPolicy)

doRegisterEndpoint

private void doRegisterEndpoint(java.lang.String name,
                                TargetEndpoint endpoint,
                                Subscription subscription,
                                ConcurrencyPolicy concurrencyPolicy)

registerEndpoint

public void registerEndpoint(java.lang.String name,
                             MessageEndpoint endpoint)
Specified by:
registerEndpoint in interface EndpointRegistry

registerTargetEndpoint

private void registerTargetEndpoint(java.lang.String name,
                                    TargetEndpoint endpoint)

unregisterEndpoint

public MessageEndpoint unregisterEndpoint(java.lang.String name)
Specified by:
unregisterEndpoint in interface EndpointRegistry

lookupEndpoint

public MessageEndpoint lookupEndpoint(java.lang.String endpointName)
Specified by:
lookupEndpoint in interface EndpointRegistry

getEndpointNames

public java.util.Set<java.lang.String> getEndpointNames()
Specified by:
getEndpointNames in interface EndpointRegistry

activateEndpoints

private void activateEndpoints()

activateEndpoint

private void activateEndpoint(MessageEndpoint endpoint)

activateTargetEndpoint

private void activateTargetEndpoint(TargetEndpoint endpoint)

registerSourceEndpoint

private void registerSourceEndpoint(java.lang.String name,
                                    SourceEndpoint endpoint)

activateSubscription

private void activateSubscription(MessageChannel channel,
                                  Target target,
                                  Schedule schedule)

isRunning

public boolean isRunning()
Specified by:
isRunning in interface org.springframework.context.Lifecycle

start

public void start()
Specified by:
start in interface org.springframework.context.Lifecycle

stop

public void stop()
Specified by:
stop in interface org.springframework.context.Lifecycle

onApplicationEvent

public void onApplicationEvent(org.springframework.context.ApplicationEvent event)
Specified by:
onApplicationEvent in interface org.springframework.context.ApplicationListener

doConfigureAsyncEventMulticaster

private void doConfigureAsyncEventMulticaster(org.springframework.context.ApplicationContext context)