Package org.hcjf.cloud
Class Cloud
- java.lang.Object
-
- org.hcjf.service.Service<CloudConsumer>
-
- org.hcjf.cloud.Cloud
-
public final class Cloud extends Service<CloudConsumer>
This class is a singleton that provides the generics cloud interface, the implementation of this interface depends of the system property 'hcjf.cloud.impl'- Author:
- javaito
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.hcjf.service.Service
Service.RunnableWrapperComparator, Service.ShutdownStage, Service.StaticServiceThread, Service.ThreadPoolAgent, Service.ThreadPoolAgentMBean
-
-
Field Summary
-
Fields inherited from class org.hcjf.service.Service
SERVICE_LOG_TAG
-
-
Method Summary
Modifier and Type Method Description static voidcreateCache(java.lang.String cacheName, java.util.Set<CloudCacheStrategy> strategies)Creates a instance of cache into the cloud using the specific strategy to specify the behavior of the cache instance.static voidcreateTimerTask(CloudTimerTask timerTask)Schedule into the cloud service an instance of timer task.static voiddispatchEvent(DistributedEvent event)Dispatch the event instance to the cloud.static voidforkWorker(java.util.Map<java.lang.String,java.lang.Object> workerConfig)This method start a worker over the cloud implementation to make a task and finish.static CloudCachegetCache(java.lang.String cacheName)Return the instance of cache named with specific name.static java.util.concurrent.locks.ConditiongetCondition(java.lang.String conditionName, java.util.concurrent.locks.Lock lock)Return the distributed lock condition over specific lock object.static CountergetCounter(java.lang.String counterName)This method provides an implementation of distributed counter.static java.util.concurrent.locks.LockgetLock(java.lang.String lockName)Return the implementation of the Lock interface distributed.static <K,V>
java.util.Map<K,V>getMap(java.lang.String mapName)This method provides an implementation of distributed map.static <V> java.util.Queue<V>getQueue(java.lang.String queueName)This method provides an implementation of distributed queue.static java.lang.StringgetRegexFromDistributedLayer(java.lang.Class<? extends LayerInterface> layerClass, java.lang.String implName)Returns the object that represent the distributed layer.static <V> java.util.Set<V>getSet(java.lang.String setName)This method provides an implementation of distributed set.static booleanisLayerPublished(java.lang.Class<? extends LayerInterface> layerClass, java.lang.String implName)This method verifies if the layer and name indicated are published into the cloud.static <O> OlayerInvoke(java.lang.Class<? extends LayerInterface> layerClass, java.lang.String implName, java.lang.reflect.Method method, java.lang.Object... parameters)Invokes the remote instance of a layer.static voidlock(java.lang.String resourceName)This method takes a resource an lock this for all the thread around the cluster and this resource has locked for all the thread for execution.static voidpublishDistributedLayer(java.lang.Class<? extends LayerInterface> layerClass, java.lang.String implName, java.lang.String regex)Publish a distributed layer into the cloud.static voidpublishMe()This method must start the process of interaction with other services.static voidpublishPlugin(byte[] jarFile)This method send the plugin for all the nodes into the cloud.voidregisterConsumer(CloudConsumer consumer)Register some consumer to use the cloud service.protected voidshutdown(Service.ShutdownStage stage)This method is listening the shutdown signal and must start the shutdown process of the cloud implementation.static voidunlock(java.lang.String resourceName)This method unlocks a previously locked resource.voidunregisterConsumer(CloudConsumer consumer)Unregister consumer.-
Methods inherited from class org.hcjf.service.Service
call, call, fork, fork, fork, fork, getPriority, getServiceName, init, run, run, shutdownExecutor, systemShutdown
-
-
-
-
Method Detail
-
getMap
public static <K,V> java.util.Map<K,V> getMap(java.lang.String mapName)
This method provides an implementation of distributed map. All the nodes on the cluster shares this instance.- Type Parameters:
K- Type of the map's key.V- Type of the map's values.- Parameters:
mapName- Name of the map.- Returns:
- Return the instance of the distributed map.
-
getQueue
public static <V> java.util.Queue<V> getQueue(java.lang.String queueName)
This method provides an implementation of distributed queue. All the nodes on the cluster shares this instance.- Type Parameters:
V- Type of the queue's values.- Parameters:
queueName- Name of the queue.- Returns:
- Return the instance of the distributed queue.
-
getSet
public static <V> java.util.Set<V> getSet(java.lang.String setName)
This method provides an implementation of distributed set. All the nodes on the cloud shares this instance.- Type Parameters:
V- Type of the set's values.- Parameters:
setName- Name of the set.- Returns:
- Return the instance of the distributed set.
-
getCounter
public static Counter getCounter(java.lang.String counterName)
This method provides an implementation of distributed counter. All the nodes on the cloud shares this instance.- Parameters:
counterName- Name of the counter.- Returns:
- Return thr instance of the counter.
-
lock
public static void lock(java.lang.String resourceName) throws java.lang.InterruptedExceptionThis method takes a resource an lock this for all the thread around the cluster and this resource has locked for all the thread for execution. This method is blocked until you can get the lock.- Parameters:
resourceName- The name of the resource to lock.- Throws:
java.lang.InterruptedException- Interrupted exception
-
unlock
public static void unlock(java.lang.String resourceName) throws java.lang.InterruptedExceptionThis method unlocks a previously locked resource.- Parameters:
resourceName- The name of the resource locked.- Throws:
java.lang.InterruptedException- Interrupted exception
-
getLock
public static java.util.concurrent.locks.Lock getLock(java.lang.String lockName)
Return the implementation of the Lock interface distributed.- Parameters:
lockName- Name of the lock.- Returns:
- Distributed lock implementation.
-
getCondition
public static java.util.concurrent.locks.Condition getCondition(java.lang.String conditionName, java.util.concurrent.locks.Lock lock)Return the distributed lock condition over specific lock object.- Parameters:
conditionName- Lock condition name.lock- Specific lock object.- Returns:
- Return the lock condition.
-
createCache
public static void createCache(java.lang.String cacheName, java.util.Set<CloudCacheStrategy> strategies)Creates a instance of cache into the cloud using the specific strategy to specify the behavior of the cache instance.- Parameters:
cacheName- Name of the cache instance.strategies- Set with the strategies for the cache instance.
-
getCache
public static CloudCache getCache(java.lang.String cacheName)
Return the instance of cache named with specific name.- Parameters:
cacheName- Name of the instance of cache.- Returns:
- Instance of cache.
-
dispatchEvent
public static void dispatchEvent(DistributedEvent event)
Dispatch the event instance to the cloud.- Parameters:
event- Event instance.
-
createTimerTask
public static void createTimerTask(CloudTimerTask timerTask)
Schedule into the cloud service an instance of timer task.- Parameters:
timerTask- Timer task instance.
-
publishDistributedLayer
public static void publishDistributedLayer(java.lang.Class<? extends LayerInterface> layerClass, java.lang.String implName, java.lang.String regex)
Publish a distributed layer into the cloud.- Parameters:
layerClass- Layer class.implName- Layer implementation name.regex- Regex to match the layer.
-
publishPlugin
public static void publishPlugin(byte[] jarFile)
This method send the plugin for all the nodes into the cloud.- Parameters:
jarFile- Byte array that represents the jar file.
-
isLayerPublished
public static boolean isLayerPublished(java.lang.Class<? extends LayerInterface> layerClass, java.lang.String implName)
This method verifies if the layer and name indicated are published into the cloud.- Parameters:
layerClass- Layer class.implName- Layer implementation name.- Returns:
- Returns true if the layer is published and false in the otherwise.
-
getRegexFromDistributedLayer
public static java.lang.String getRegexFromDistributedLayer(java.lang.Class<? extends LayerInterface> layerClass, java.lang.String implName)
Returns the object that represent the distributed layer.- Parameters:
layerClass- Layer class.implName- Layer implementation name.- Returns:
- Regex if exist or null.
-
layerInvoke
public static <O> O layerInvoke(java.lang.Class<? extends LayerInterface> layerClass, java.lang.String implName, java.lang.reflect.Method method, java.lang.Object... parameters)
Invokes the remote instance of a layer.- Type Parameters:
O- Expected return data type.- Parameters:
layerClass- Layer interface class.implName- Implementation name.method- Method to invoke.parameters- Parameters to invoke.- Returns:
- Invocation result.
-
publishMe
public static void publishMe()
This method must start the process of interaction with other services.
-
forkWorker
public static void forkWorker(java.util.Map<java.lang.String,java.lang.Object> workerConfig)
This method start a worker over the cloud implementation to make a task and finish.- Parameters:
workerConfig- Map with all the parameters to configure a worker instance.
-
shutdown
protected void shutdown(Service.ShutdownStage stage)
This method is listening the shutdown signal and must start the shutdown process of the cloud implementation.- Overrides:
shutdownin classService<CloudConsumer>- Parameters:
stage- Shutdown stage.
-
registerConsumer
public void registerConsumer(CloudConsumer consumer)
Register some consumer to use the cloud service.- Specified by:
registerConsumerin classService<CloudConsumer>- Parameters:
consumer- Object with the logic to consume the service.
-
unregisterConsumer
public void unregisterConsumer(CloudConsumer consumer)
Unregister consumer.- Specified by:
unregisterConsumerin classService<CloudConsumer>- Parameters:
consumer- Consumer to unregister.
-
-