Package org.marketcetera.cluster
Class SimpleClusterService
- java.lang.Object
-
- org.marketcetera.cluster.service.AbstractClusterService
-
- org.marketcetera.cluster.SimpleClusterService
-
- All Implemented Interfaces:
ClusterListener,ClusterService,org.springframework.beans.factory.Aware,org.springframework.context.ApplicationContextAware
@Service public class SimpleClusterService extends AbstractClusterService implements ClusterService
Provides a single nodeClusterServiceimplementation.- Since:
- $Release$
- Version:
- $Id$
- Author:
- Colin DuPlantis
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classSimpleClusterService.SimpleClusterMemberProvides a basicClusterMemberimplementation.-
Nested classes/interfaces inherited from class org.marketcetera.cluster.service.AbstractClusterService
AbstractClusterService.WorkUnitEvaluationTask
-
-
Field Summary
Fields Modifier and Type Field Description private booleanactiveindicates if the cluster service is active or notprivate org.springframework.context.ApplicationContextapplicationContextprovides access to the application contextprivate static StringattributeMapNamename assigned to the attribute mapprivate Set<ClusterMember>clusterMembersstatic cluster member collectionprivate com.google.common.cache.LoadingCache<String,ExecutorService>executorServicescluster executorsprivate inthostNumberstatic host numberprivate com.google.common.cache.LoadingCache<String,Lock>lockscluster locksprivate com.google.common.cache.LoadingCache<String,Map<String,String>>mapscluster mapsprivate StringmemberUUIDuniquely identifies this memberprivate com.google.common.cache.LoadingCache<String,BlockingDeque<?>>queuescluster queuesprivate ClusterMemberthisClusterMemberidentifies the local cluster member
-
Constructor Summary
Constructors Constructor Description SimpleClusterService()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringaddToMap(String inMapName, String inKey, String inValue)<Clazz extends Serializable>
voidaddToQueue(QueueDescriptor<Clazz> inQueueDescriptor, Clazz inObject)<Clazz extends Serializable>
Map<Object,Future<Clazz>>execute(CallableClusterTask<Clazz> inTask)voidexecute(RunnableClusterTask inTask)StringgetAttribute(String inKey)Map<String,Map<String,String>>getAttributes()Map<String,String>getAttributes(String inUuid)Set<ClusterMember>getClusterMembers()private ExecutorServicegetExecutorService(String inPoolName)Get the executor service for the given pool name.protected intgetHostNumber(String inHostId)LockgetLock(String inLockName)Map<String,String>getMap(String inMapName)protected StringgetMemberUuid()private LockgetPrivateLock(String inLockName)Get the lock with the given name.private Map<String,String>getPrivateMap(String inMapName)Get the map with the given name.private <Clazz extends Serializable>
BlockingDeque<Clazz>getQueue(QueueDescriptor<Clazz> inQueueDescriptor)Get the queue for the given descriptor.protected booleanisActive()<Clazz extends Serializable>
ClazzpeekFromQueue(QueueDescriptor<Clazz> inQueueDescriptor)voidremoveAttribute(String inKey)voidremoveAttribute(String inUuid, String inKey)StringremoveFromMap(String inMapName, String inKey)voidsetAttribute(String inKey, String inValue)voidstart()Validate and start the object.voidstop()Stop the object.<Clazz extends Serializable>
ClazztakeFromQueue(QueueDescriptor<Clazz> inQueueDescriptor)-
Methods inherited from class org.marketcetera.cluster.service.AbstractClusterService
activateWorkUnit, addClusterListener, establishWorkUnitSpecs, evaluateWorkUnits, findAllBeansWith, findAllBeansWith, findAndActivateWorkUnit, findCandidateFor, generateClusterData, generateWorkUnitDescriptor, getAbandonedLockTimeout, getActiveWorkUnitSpecs, getAllClusterData, getInstanceData, getInstanceName, getLockTimeout, getMethod, getTypeAnnotation, getUuid, getWorkUnitEvaluationDelay, logClusterMetaData, marshall, memberAdded, memberChanged, memberRemoved, notifyMemberAdded, notifyMemberChanged, notifyMemberRemoved, register, removeClusterListener, setAbandonedLockTimeout, setApplicationContext, setInstanceName, setLockTimeout, setWorkUnitEvaluationDelay, toString, unmarshall, updateClusterMetaData
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.marketcetera.cluster.service.ClusterService
addClusterListener, getAllClusterData, getInstanceData, removeClusterListener
-
-
-
-
Field Detail
-
hostNumber
private final int hostNumber
static host number- See Also:
- Constant Field Values
-
memberUUID
private final String memberUUID
uniquely identifies this member
-
active
private volatile boolean active
indicates if the cluster service is active or not
-
clusterMembers
private Set<ClusterMember> clusterMembers
static cluster member collection
-
thisClusterMember
private ClusterMember thisClusterMember
identifies the local cluster member
-
applicationContext
@Autowired private org.springframework.context.ApplicationContext applicationContext
provides access to the application context
-
attributeMapName
private static final String attributeMapName
name assigned to the attribute map
-
executorServices
private final com.google.common.cache.LoadingCache<String,ExecutorService> executorServices
cluster executors
-
queues
private final com.google.common.cache.LoadingCache<String,BlockingDeque<?>> queues
cluster queues
-
maps
private final com.google.common.cache.LoadingCache<String,Map<String,String>> maps
cluster maps
-
-
Method Detail
-
start
@PostConstruct public void start()
Validate and start the object.- Overrides:
startin classAbstractClusterService
-
stop
@PreDestroy public void stop()
Stop the object.- Overrides:
stopin classAbstractClusterService
-
getMemberUuid
protected String getMemberUuid()
- Specified by:
getMemberUuidin classAbstractClusterService
-
getHostNumber
protected int getHostNumber(String inHostId)
- Specified by:
getHostNumberin classAbstractClusterService
-
isActive
protected boolean isActive()
- Specified by:
isActivein classAbstractClusterService
-
addToQueue
public <Clazz extends Serializable> void addToQueue(QueueDescriptor<Clazz> inQueueDescriptor, Clazz inObject)
- Specified by:
addToQueuein interfaceClusterService
-
peekFromQueue
public <Clazz extends Serializable> Clazz peekFromQueue(QueueDescriptor<Clazz> inQueueDescriptor)
- Specified by:
peekFromQueuein interfaceClusterService
-
takeFromQueue
public <Clazz extends Serializable> Clazz takeFromQueue(QueueDescriptor<Clazz> inQueueDescriptor) throws InterruptedException
- Specified by:
takeFromQueuein interfaceClusterService- Throws:
InterruptedException
-
execute
public void execute(RunnableClusterTask inTask)
- Specified by:
executein interfaceClusterService
-
execute
public <Clazz extends Serializable> Map<Object,Future<Clazz>> execute(CallableClusterTask<Clazz> inTask) throws Exception
- Specified by:
executein interfaceClusterService- Throws:
Exception
-
getMap
public Map<String,String> getMap(String inMapName)
- Specified by:
getMapin interfaceClusterService
-
addToMap
public String addToMap(String inMapName, String inKey, String inValue)
- Specified by:
addToMapin interfaceClusterService
-
removeFromMap
public String removeFromMap(String inMapName, String inKey)
- Specified by:
removeFromMapin interfaceClusterService
-
setAttribute
public void setAttribute(String inKey, String inValue)
- Specified by:
setAttributein interfaceClusterService
-
getAttribute
public String getAttribute(String inKey)
- Specified by:
getAttributein interfaceClusterService
-
getAttributes
public Map<String,String> getAttributes(String inUuid)
- Specified by:
getAttributesin interfaceClusterService
-
getAttributes
public Map<String,Map<String,String>> getAttributes()
- Specified by:
getAttributesin interfaceClusterService
-
removeAttribute
public void removeAttribute(String inKey)
- Specified by:
removeAttributein interfaceClusterService
-
removeAttribute
public void removeAttribute(String inUuid, String inKey)
- Specified by:
removeAttributein interfaceClusterService
-
getLock
public Lock getLock(String inLockName)
- Specified by:
getLockin interfaceClusterService
-
getClusterMembers
public Set<ClusterMember> getClusterMembers()
- Specified by:
getClusterMembersin interfaceClusterService
-
getQueue
private <Clazz extends Serializable> BlockingDeque<Clazz> getQueue(QueueDescriptor<Clazz> inQueueDescriptor)
Get the queue for the given descriptor.- Parameters:
inQueueDescriptor- aQueueDescriptorvalue- Returns:
- a
BlockingDeque<Clazz>value
-
getPrivateMap
private Map<String,String> getPrivateMap(String inMapName)
Get the map with the given name.- Parameters:
inMapName- aStringvalue- Returns:
- a
Map<String,String>value
-
getExecutorService
private ExecutorService getExecutorService(String inPoolName)
Get the executor service for the given pool name.- Parameters:
inPoolName- aStringvalue- Returns:
- an
ExecutorServicevalue
-
-