package org.hcjf.cloud;

import org.hcjf.properties.SystemProperties;

import java.util.Map;
import java.util.Queue;

/**
 * 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
 * @mail javaito@gmail.com
 */
public final class Cloud {

    private static Cloud instance;

    private final CloudServiceImpl impl;

    /**
     * Private constructor
     */
    private Cloud() {
        String implClassName = SystemProperties.get(SystemProperties.CLOUD_IMPL);
        if(implClassName == null) {
            throw new IllegalArgumentException("Implementation cloud class is null, see the system property 'hcjf.cloud.impl'");
        }
        try {
            Class<? extends CloudServiceImpl> implClass =
                    (Class<? extends CloudServiceImpl>)
                            Class.forName(implClassName);
            impl = implClass.newInstance();
        } catch (Exception ex) {
            throw new IllegalArgumentException("Unable to create cloud implementation", ex);
        }
    }

    /**
     * Return the instance of the cloud service.
     * @return Instance of the cloud.
     */
    private synchronized static Cloud getInstance() {
        if(instance == null) {
            instance = new Cloud();
        }

        return instance;
    }

    /**
     * This method provides an implementation of distributed map. All the nodes
     * on the cluster shares this instance.
     * @param mapName Name of the map.
     * @param <K> Type of the map's key.
     * @param <V> Type of the map's values.
     * @return Return the instance of the distributed map.
     */
    public static final <K extends Object, V extends Object> Map<K, V> getMap(String mapName) {
        return getInstance().impl.getMap(mapName);
    }

    /**
     * This method provides an implementation of distributed queue. All the nodes
     * on the cluster shares this instance.
     * @param queueName Name of the queue.
     * @param <V> Type of the queue's values.
     * @return Return the instance of the distributed queue.
     */
    public static final <V extends Object> Queue<V> getQueue(String queueName) {
        return getInstance().impl.getQueue(queueName);
    }

    /**
     * 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.
     * This method is blocked until you can get the lock.
     * @param resourceName The name of the resource to lock.
     */
    public static final void lock(String resourceName) throws InterruptedException {
        getInstance().impl.lock(resourceName);
    }

    /**
     * This method unlocks a previously locked resource.
     * @param resourceName The name of the resource locked.
     */
    public static final void unlock(String resourceName) throws InterruptedException {
        getInstance().impl.unlock(resourceName);
    }

}

@@ -109,16 +109,56 @@
 l.Queue;
+%0Aimport java.util.concurrent.locks.Lock;
 %0A%0A/**%0A *
@@ -1779,22 +1779,16 @@
  static 
-final 
 %3CK exten
@@ -2219,22 +2219,16 @@
  static 
-final 
 %3CV exten
@@ -2644,30 +2644,24 @@
 blic static 
-final 
 void lock(St
@@ -2914,22 +2914,16 @@
  static 
-final 
 void unl
@@ -3033,10 +3033,292 @@
 %0A    %7D%0A%0A
+    /**%0A     * Return the implementation of the Lock interface distributed.%0A     * @param lockName Name of the lock.%0A     * @return Distributed lock implementation.%0A     */%0A    public static Lock getLock(String lockName) %7B%0A        return getInstance().impl.getLock(lockName);%0A    %7D%0A
 %7D%0A

Add distributed lock interface