Package org.hcjf.cloud.impl
Class DefaultCloudServiceImpl
- java.lang.Object
-
- org.hcjf.cloud.impl.DefaultCloudServiceImpl
-
- All Implemented Interfaces:
CloudServiceImpl
public class DefaultCloudServiceImpl extends java.lang.Object implements CloudServiceImpl
- Author:
- javaito
-
-
Constructor Summary
Constructors Constructor Description DefaultCloudServiceImpl()
-
Method Summary
Modifier and Type Method Description 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.voiddispatchEvent(DistributedEvent event)Dispatch the event instance to the cloud.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.CloudCachegetCache(java.lang.String cacheName)Return the instance of cache named with specific name.java.util.concurrent.locks.ConditiongetCondition(java.lang.String conditionName, java.util.concurrent.locks.Lock lock)Return the distributed lock condition over specific lock object.CountergetCounter(java.lang.String counterName)This method provides an implementation of distributed counter.java.util.concurrent.locks.LockgetLock(java.lang.String lockName)Return the implementation of the Lock interface distributed.<K,V>
java.util.Map<K,V>getMap(java.lang.String mapName)This method provides an implementation of distributed map.<V> java.util.Queue<V>getQueue(java.lang.String queueName)This method provides an implementation of distributed queue.java.lang.StringgetRegexFromDistributedLayer(java.lang.Class<? extends LayerInterface> layerClass, java.lang.String implName)Returns the object that represent the distributed layer.<V> java.util.Set<V>getSet(java.lang.String setName)This method provides an implementation of distributed set.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.<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.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.voidpublishDistributedLayer(java.lang.Class<? extends LayerInterface> layerClass, java.lang.String implName, java.lang.String regex)Publish a distributed layer into the cloud.voidpublishMe()This method must start the process of interaction with other services.voidpublishPlugin(byte[] jarFile)This method send the plugin for all the nodes into the cloud.voidshutdown()Shutdown hookvoidunlock(java.lang.String resourceName)This method unlocks a previously locked resource.
-
-
-
Method Detail
-
getMap
public <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.- Specified by:
getMapin interfaceCloudServiceImpl- 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 <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.- Specified by:
getQueuein interfaceCloudServiceImpl- 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 <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.- Specified by:
getSetin interfaceCloudServiceImpl- 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 Counter getCounter(java.lang.String counterName)
This method provides an implementation of distributed counter. All the nodes on the cloud shares this instance.- Specified by:
getCounterin interfaceCloudServiceImpl- Parameters:
counterName- Name of the counter.- Returns:
- Return thr instance of the counter.
-
lock
public 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.- Specified by:
lockin interfaceCloudServiceImpl- Parameters:
resourceName- The name of the resource to lock.- Throws:
java.lang.InterruptedException- Interrupted exception
-
unlock
public void unlock(java.lang.String resourceName) throws java.lang.InterruptedExceptionThis method unlocks a previously locked resource.- Specified by:
unlockin interfaceCloudServiceImpl- Parameters:
resourceName- The name of the resource locked.- Throws:
java.lang.InterruptedException- Interrupted exception.
-
getLock
public java.util.concurrent.locks.Lock getLock(java.lang.String lockName)
Return the implementation of the Lock interface distributed.- Specified by:
getLockin interfaceCloudServiceImpl- Parameters:
lockName- Name of the lock.- Returns:
- Distributed lock implementation.
-
getCondition
public 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.- Specified by:
getConditionin interfaceCloudServiceImpl- Parameters:
conditionName- Lock condition name.lock- Specific lock object.- Returns:
- Return the lock condition.
-
createCache
public 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.- Specified by:
createCachein interfaceCloudServiceImpl- Parameters:
cacheName- Name of the cache instance.strategies- Set with the strategies for the cache instance.
-
getCache
public CloudCache getCache(java.lang.String cacheName)
Return the instance of cache named with specific name.- Specified by:
getCachein interfaceCloudServiceImpl- Parameters:
cacheName- Name of the instance of cache.- Returns:
- Instance of cache.
-
dispatchEvent
public void dispatchEvent(DistributedEvent event)
Dispatch the event instance to the cloud.- Specified by:
dispatchEventin interfaceCloudServiceImpl- Parameters:
event- Event instance.
-
publishDistributedLayer
public void publishDistributedLayer(java.lang.Class<? extends LayerInterface> layerClass, java.lang.String implName, java.lang.String regex)
Publish a distributed layer into the cloud.- Specified by:
publishDistributedLayerin interfaceCloudServiceImpl- Parameters:
layerClass- Layer class.implName- Layer implementation name.regex- Regex for match the implementation.
-
isLayerPublished
public 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.- Specified by:
isLayerPublishedin interfaceCloudServiceImpl- Parameters:
layerClass- Layer class.implName- Layer implementation name.- Returns:
- Returns true if the layer is published and false in the otherwise.
-
getRegexFromDistributedLayer
public java.lang.String getRegexFromDistributedLayer(java.lang.Class<? extends LayerInterface> layerClass, java.lang.String implName)
Returns the object that represent the distributed layer.- Specified by:
getRegexFromDistributedLayerin interfaceCloudServiceImpl- Parameters:
layerClass- Layer class.implName- Layer implementation name.- Returns:
- Regex if exist or null.
-
publishPlugin
public void publishPlugin(byte[] jarFile)
This method send the plugin for all the nodes into the cloud.- Specified by:
publishPluginin interfaceCloudServiceImpl- Parameters:
jarFile- Byte array that represents the jar file.
-
layerInvoke
public <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.- Specified by:
layerInvokein interfaceCloudServiceImpl- 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 void publishMe()
This method must start the process of interaction with other services.- Specified by:
publishMein interfaceCloudServiceImpl
-
forkWorker
public 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.- Specified by:
forkWorkerin interfaceCloudServiceImpl- Parameters:
workerConfig- Map with all the parameters to configure a worker instance.
-
shutdown
public void shutdown()
Shutdown hook- Specified by:
shutdownin interfaceCloudServiceImpl
-
-