org.axonframework.commandhandling.distributed.jgroups
Class JGroupsConnectorFactoryBean

java.lang.Object
  extended by org.axonframework.commandhandling.distributed.jgroups.JGroupsConnectorFactoryBean
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.FactoryBean, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware, org.springframework.context.Lifecycle, org.springframework.context.Phased, org.springframework.context.SmartLifecycle

public class JGroupsConnectorFactoryBean
extends Object
implements org.springframework.beans.factory.FactoryBean, org.springframework.beans.factory.InitializingBean, org.springframework.context.SmartLifecycle, org.springframework.beans.factory.BeanNameAware, org.springframework.context.ApplicationContextAware

Spring Factory bean that creates a JGroupsConnector and starts it when the application context is started. This bean must be defined as a top-level bean.

Since:
2.0
Author:
Allard Buijze

Constructor Summary
JGroupsConnectorFactoryBean()
           
 
Method Summary
 void afterPropertiesSet()
           
 Object getObject()
           
 Class<?> getObjectType()
           
 int getPhase()
           
 boolean isAutoStartup()
           
 boolean isRunning()
           
 boolean isSingleton()
           
 void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
           
 void setBeanName(String name)
           
 void setChannelName(String channelName)
          Optionally sets the logical channel name of the channel.
 void setClusterName(String clusterName)
          Sets the name of the cluster to subscribe to.
 void setConfiguration(String configuration)
          Sets the JGroups configuration file to load.
 void setHashChangeListener(HashChangeListener hashChangeListener)
          Register a HashChangeListener with the JGroupsConnector.
 void setInterceptors(List<CommandHandlerInterceptor> interceptors)
          Sets the interceptor to use in the default local segment (a SimpleCommandBus).
 void setJoinTimeout(long joinTimeout)
          Sets the number of milliseconds to wait for this member to join the group.
 void setLoadFactor(int loadFactor)
          Sets the load factor for this instance of the Distributed Command Bus.
 void setLocalSegment(CommandBus localSegment)
          Sets the CommandBus instance on which local commands must be dispatched.
 void setPhase(int phase)
          Sets the phase in which this bean must be started.
 void setSerializer(Serializer serializer)
          Sets the serializer used to serialize events before they are dispatched to the destination.
 void start()
           
 void stop()
           
 void stop(Runnable callback)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JGroupsConnectorFactoryBean

public JGroupsConnectorFactoryBean()
Method Detail

getObject

public Object getObject()
                 throws Exception
Specified by:
getObject in interface org.springframework.beans.factory.FactoryBean
Throws:
Exception

getObjectType

public Class<?> getObjectType()
Specified by:
getObjectType in interface org.springframework.beans.factory.FactoryBean

isSingleton

public boolean isSingleton()
Specified by:
isSingleton in interface org.springframework.beans.factory.FactoryBean

afterPropertiesSet

public void afterPropertiesSet()
                        throws Exception
Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
Throws:
Exception

setSerializer

public void setSerializer(Serializer serializer)
Sets the serializer used to serialize events before they are dispatched to the destination. All members connected to the same channel must use compatible serializers.

Default to an autowired Serializer.

Parameters:
serializer - the serializer to serialize commands with

setConfiguration

public void setConfiguration(String configuration)
Sets the JGroups configuration file to load. Defaults to configuration using TCP with multicast discovery (tcp_mcast.xml).

Parameters:
configuration - the JGroups configuration file

setClusterName

public void setClusterName(String clusterName)
Sets the name of the cluster to subscribe to. The Connector will only connect to other instances with the same cluster name. Defaults to the bean name.

Parameters:
clusterName - The name of the cluster to connect to

setChannelName

public void setChannelName(String channelName)
Optionally sets the logical channel name of the channel. If not provided JGroups will generate a default name.

Note that each member of a cluster should have a unique channel name.

Parameters:
channelName - The logical name to give to the channel

setJoinTimeout

public void setJoinTimeout(long joinTimeout)
Sets the number of milliseconds to wait for this member to join the group. Setting this to a non-negative number will cause the start() method to block for at most the given number of milliseconds. After that timeout, attempts to join the cluster will be performed on the background.

Setting a negative value will cause the start() method to wait until the member joined the cluster.

Defaults to -1, which causes the start() to wait indefinitely, until the member has joined the cluster.

Parameters:
joinTimeout - The number of milliseconds to wait for the member to join the cluster

setLocalSegment

public void setLocalSegment(CommandBus localSegment)
Sets the CommandBus instance on which local commands must be dispatched. Defaults to a SimpleCommandBus.

Parameters:
localSegment - the CommandBus instance to dispatch local messages on

setInterceptors

public void setInterceptors(List<CommandHandlerInterceptor> interceptors)
Sets the interceptor to use in the default local segment (a SimpleCommandBus). When providing a custom local segment (setLocalSegment(org.axonframework.commandhandling.CommandBus)), this configuration is ignored.

Parameters:
interceptors - the list of interceptors (in order) for the local segment

setLoadFactor

public void setLoadFactor(int loadFactor)
Sets the load factor for this instance of the Distributed Command Bus. This factor described the relative number of Command messages this instance will handle. Defaults to 100.

Parameters:
loadFactor - The load factor for this instance

setHashChangeListener

public void setHashChangeListener(HashChangeListener hashChangeListener)
Register a HashChangeListener with the JGroupsConnector. The listener will be notified when the consistent hash changes due to members joining or leaving the JGroup.

Parameters:
hashChangeListener -

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

isRunning

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

isAutoStartup

public boolean isAutoStartup()
Specified by:
isAutoStartup in interface org.springframework.context.SmartLifecycle

stop

public void stop(Runnable callback)
Specified by:
stop in interface org.springframework.context.SmartLifecycle

getPhase

public int getPhase()
Specified by:
getPhase in interface org.springframework.context.Phased

setPhase

public void setPhase(int phase)
Sets the phase in which this bean must be started. Defaults to Integer.MAX_VALUE, which ensures the Connector is started when other beans have been initialized.

Parameters:
phase - the phase in which the JGroups connector must be started.
See Also:
SmartLifecycle

setBeanName

public void setBeanName(String name)
Specified by:
setBeanName in interface org.springframework.beans.factory.BeanNameAware

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


Copyright © 2010-2016. All Rights Reserved.