You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ode.apache.org by sa...@apache.org on 2015/11/06 11:51:11 UTC

[16/30] ode git commit: Initialization of cluster enabled instance lock manager

Initialization of cluster enabled instance lock manager


Project: http://git-wip-us.apache.org/repos/asf/ode/repo
Commit: http://git-wip-us.apache.org/repos/asf/ode/commit/94f19ed6
Tree: http://git-wip-us.apache.org/repos/asf/ode/tree/94f19ed6
Diff: http://git-wip-us.apache.org/repos/asf/ode/diff/94f19ed6

Branch: refs/heads/ODE-563
Commit: 94f19ed6168b81b8db067bd510c3a7e99aaecc28
Parents: 224dc21
Author: suba <su...@cse.mrt.ac.lk>
Authored: Wed Jul 8 11:30:17 2015 +0530
Committer: suba <su...@cse.mrt.ac.lk>
Committed: Wed Jul 8 11:30:17 2015 +0530

----------------------------------------------------------------------
 .../java/org/apache/ode/axis2/ODEServer.java    |  10 +-
 .../ode/axis2/deploy/DeploymentPoller.java      |  10 +-
 .../ode/axis2/service/DeploymentWebService.java |  10 +-
 .../org/apache/ode/bpel/clapi/ClusterLock.java  |  43 +++++++-
 .../apache/ode/bpel/clapi/ClusterManager.java   |  35 ++----
 .../engine/AbstractInstanceLockManager.java     |  38 +++++++
 .../apache/ode/bpel/engine/BpelEngineImpl.java  |   8 +-
 .../hazelcast/HazelcastClusterImpl.java         |  49 ++++-----
 .../hazelcast/HazelcastDeploymentLock.java      |  60 ++++++++++
 .../hazelcast/HazelcastInstanceLock.java        | 109 +++++++++++++++++++
 10 files changed, 298 insertions(+), 74 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ode/blob/94f19ed6/axis2/src/main/java/org/apache/ode/axis2/ODEServer.java
----------------------------------------------------------------------
diff --git a/axis2/src/main/java/org/apache/ode/axis2/ODEServer.java b/axis2/src/main/java/org/apache/ode/axis2/ODEServer.java
index 9b133fc..34e245a 100644
--- a/axis2/src/main/java/org/apache/ode/axis2/ODEServer.java
+++ b/axis2/src/main/java/org/apache/ode/axis2/ODEServer.java
@@ -384,8 +384,14 @@ public class ODEServer {
             }
 
             if (_clusterManager != null) {
-                __log.debug("shutting down cluster manager.");
-                _clusterManager = null;
+                try {
+                    __log.debug("shutting down cluster manager.");
+                    _clusterManager.shutdown();
+                    _clusterManager = null;
+                } catch (Exception ex) {
+                    __log.debug("Cluster manager shutdown failed.", ex);
+
+                }
             }
 
             if (_connector != null) {

http://git-wip-us.apache.org/repos/asf/ode/blob/94f19ed6/axis2/src/main/java/org/apache/ode/axis2/deploy/DeploymentPoller.java
----------------------------------------------------------------------
diff --git a/axis2/src/main/java/org/apache/ode/axis2/deploy/DeploymentPoller.java b/axis2/src/main/java/org/apache/ode/axis2/deploy/DeploymentPoller.java
index 7912db6..98f5f82 100644
--- a/axis2/src/main/java/org/apache/ode/axis2/deploy/DeploymentPoller.java
+++ b/axis2/src/main/java/org/apache/ode/axis2/deploy/DeploymentPoller.java
@@ -41,7 +41,7 @@ package org.apache.ode.axis2.deploy;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.ode.axis2.ODEServer;
-import org.apache.ode.bpel.clapi.ClusterManager;
+import org.apache.ode.bpel.clapi.ClusterLock;
 import org.apache.ode.bpel.engine.cron.CronScheduler;
 import org.apache.ode.bpel.engine.cron.SystemSchedulesConfig;
 import org.apache.ode.utils.WatchDog;
@@ -367,16 +367,16 @@ public class DeploymentPoller {
      */
     private boolean pollerTryLock(String key) {
         if(clusterEnabled) {
-            ClusterManager cm = _odeServer.getBpelServer().getContexts().clusterManager;
-            cm.putIfAbsent(key,key);
-            return _odeServer.getBpelServer().getContexts().clusterManager.tryLock(key);
+            ClusterLock clusterLock = _odeServer.getBpelServer().getContexts().clusterManager.getDeploymentLock();
+            clusterLock.putIfAbsent(key,key);
+            return clusterLock.tryLockMap(key);
         }
         else return true;
     }
 
     private boolean unlock(String key) {
         if(clusterEnabled) {
-            return _odeServer.getBpelServer().getContexts().clusterManager.unlock(key);
+            return _odeServer.getBpelServer().getContexts().clusterManager.getDeploymentLock().unlockMap(key);
         }
         else return true;
     }

http://git-wip-us.apache.org/repos/asf/ode/blob/94f19ed6/axis2/src/main/java/org/apache/ode/axis2/service/DeploymentWebService.java
----------------------------------------------------------------------
diff --git a/axis2/src/main/java/org/apache/ode/axis2/service/DeploymentWebService.java b/axis2/src/main/java/org/apache/ode/axis2/service/DeploymentWebService.java
index 66221dc..7e4b347 100644
--- a/axis2/src/main/java/org/apache/ode/axis2/service/DeploymentWebService.java
+++ b/axis2/src/main/java/org/apache/ode/axis2/service/DeploymentWebService.java
@@ -45,7 +45,7 @@ import org.apache.axiom.om.OMText;
 import org.apache.axiom.soap.SOAPEnvelope;
 import org.apache.axiom.soap.SOAPFactory;
 import org.apache.axis2.AxisFault;
-import org.apache.ode.bpel.clapi.ClusterManager;
+import org.apache.ode.bpel.clapi.ClusterLock;
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.description.AxisService;
 import org.apache.axis2.description.AxisOperation;
@@ -387,9 +387,9 @@ public class DeploymentWebService {
      */
     private boolean lock(String key) {
         if(clusterEnabled) {
-            ClusterManager cm = _odeServer.getBpelServer().getContexts().clusterManager;
-            cm.putIfAbsent(key,key);
-            return cm.lock(key);
+            ClusterLock clusterLock = _odeServer.getBpelServer().getContexts().clusterManager.getDeploymentLock();
+            clusterLock.putIfAbsent(key,key);
+            return clusterLock.lockMap(key);
         }
         else return true;
     }
@@ -399,7 +399,7 @@ public class DeploymentWebService {
      */
     private boolean unlock(String key) {
         if(clusterEnabled) {
-            return _odeServer.getBpelServer().getContexts().clusterManager.unlock(key);
+            return _odeServer.getBpelServer().getContexts().clusterManager.getDeploymentLock().unlockMap(key);
         }
         else return true;
     }

http://git-wip-us.apache.org/repos/asf/ode/blob/94f19ed6/bpel-api/src/main/java/org/apache/ode/bpel/clapi/ClusterLock.java
----------------------------------------------------------------------
diff --git a/bpel-api/src/main/java/org/apache/ode/bpel/clapi/ClusterLock.java b/bpel-api/src/main/java/org/apache/ode/bpel/clapi/ClusterLock.java
index ff17188..9eaf705 100644
--- a/bpel-api/src/main/java/org/apache/ode/bpel/clapi/ClusterLock.java
+++ b/bpel-api/src/main/java/org/apache/ode/bpel/clapi/ClusterLock.java
@@ -1,5 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 package org.apache.ode.bpel.clapi;
 
+import java.util.concurrent.TimeUnit;
+
 public interface ClusterLock {
     /**
      * Acquire the lock for each file in the file system
@@ -7,7 +27,7 @@ public interface ClusterLock {
      * @param key
      * @return
      */
-    boolean lock(String key);
+    boolean lockMap(String key);
 
     /**
      * Release the lock acquired by each file
@@ -15,13 +35,28 @@ public interface ClusterLock {
      * @param key
      * @return
      */
-    boolean unlock(String key);
+    boolean unlockMap(String key);
+
+    /**
+     * Tries to acquire the lock for the specified key ant time period.
+     * @param key
+     * @return
+     */
+    boolean tryLockMap(String key);
 
     /**
-     * Tries to acquire the lock for the specified key.
      *
      * @param key
+     * @param time
+     * @param tu
      * @return
      */
-    boolean tryLock(String key);
+    boolean tryLockMap(String key, int time, TimeUnit tu);
+
+    /**
+     * Check whether the map has a value for given key, if absent put the value to map
+     * @param key
+     * @param keyVal
+     */
+    void putIfAbsent(String key, String keyVal);
 }

http://git-wip-us.apache.org/repos/asf/ode/blob/94f19ed6/bpel-api/src/main/java/org/apache/ode/bpel/clapi/ClusterManager.java
----------------------------------------------------------------------
diff --git a/bpel-api/src/main/java/org/apache/ode/bpel/clapi/ClusterManager.java b/bpel-api/src/main/java/org/apache/ode/bpel/clapi/ClusterManager.java
index c57358c..6f610a4 100644
--- a/bpel-api/src/main/java/org/apache/ode/bpel/clapi/ClusterManager.java
+++ b/bpel-api/src/main/java/org/apache/ode/bpel/clapi/ClusterManager.java
@@ -19,7 +19,6 @@
 package org.apache.ode.bpel.clapi;
 
 import java.io.File;
-import java.util.List;
 
 public interface ClusterManager {
 
@@ -30,31 +29,15 @@ public interface ClusterManager {
     void init(File file);
 
     /**
-     * Return whether the local member is Master or not
-     * @return
+     * shutdown the cluster instance
      */
-    boolean getIsMaster();
+    void shutdwon();
 
     /**
-     * Acquire the lock for each file in the file system
-     * @param key
-     * @return
-     */
-    boolean lock(String key);
-
-    /**
-     * Release the lock acquired by each file
-     * @param key
-     * @return
-     */
-    boolean unlock(String key);
-
-    /**
-     * Tries to acquire the lock for the specified key.
-     * @param key
+     * Return whether the local member is Master or not
      * @return
      */
-    boolean tryLock(String key);
+    boolean getIsMaster();
 
     /**
      * Set the Process Store object which uses for clustering
@@ -69,14 +52,10 @@ public interface ClusterManager {
     void publishProcessStoreClusterEvent(ProcessStoreClusterEvent clusterEvent);
 
     /**
-     * Check whether the map has a value for given key, if absent put the value to map
-     * @param key
-     * @param keyVal
-     */
-    void putIfAbsent(String key, String keyVal);
-
-    /**
      * Register the cluster for message listener
      */
     void registerClusterProcessStoreMessageListener();
+
+    ClusterLock getDeploymentLock();
+    ClusterLock getInstanceLock();
 }

http://git-wip-us.apache.org/repos/asf/ode/blob/94f19ed6/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/AbstractInstanceLockManager.java
----------------------------------------------------------------------
diff --git a/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/AbstractInstanceLockManager.java b/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/AbstractInstanceLockManager.java
new file mode 100644
index 0000000..a534e11
--- /dev/null
+++ b/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/AbstractInstanceLockManager.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ode.bpel.engine;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Abstract class to implement an instance lock manager. Instance lock provide process instance isolation from
+ * concurrent access when entering jacob
+ */
+public abstract class AbstractInstanceLockManager {
+    abstract void unlock(Long iid);
+
+    abstract void lock(Long iid, int i, TimeUnit microseconds) throws InterruptedException,
+            TimeoutException;
+
+    /** Exception class indicating a time-out occured  while obtaining a lock. */
+    public static final class TimeoutException extends Exception {
+        private static final long serialVersionUID = 7247629086692580285L;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ode/blob/94f19ed6/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/BpelEngineImpl.java
----------------------------------------------------------------------
diff --git a/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/BpelEngineImpl.java b/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/BpelEngineImpl.java
index 19bf53e..81d8a4c 100644
--- a/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/BpelEngineImpl.java
+++ b/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/BpelEngineImpl.java
@@ -115,7 +115,7 @@ public class BpelEngineImpl implements BpelEngine {
     private SharedEndpoints _sharedEps;
 
     /** Manage instance-level locks. */
-    private final InstanceLockManager _instanceLockManager = new InstanceLockManager();
+    private final AbstractInstanceLockManager _instanceLockManager;
 
     final Contexts _contexts;
 
@@ -124,8 +124,14 @@ public class BpelEngineImpl implements BpelEngine {
 
     public BpelEngineImpl(Contexts contexts) {
         _contexts = contexts;
+        if(_contexts.clusterManager != null) {
+            _instanceLockManager = _contexts.clusterManager.getInstanceLock();
+        }
+
+        else _instanceLockManager = new InstanceLockManager();
         _sharedEps = new SharedEndpoints();
         _sharedEps.init();
+
     }
 
     public SharedEndpoints getSharedEndpoints() {

http://git-wip-us.apache.org/repos/asf/ode/blob/94f19ed6/clustering/src/main/java/org/apache/ode/clustering/hazelcast/HazelcastClusterImpl.java
----------------------------------------------------------------------
diff --git a/clustering/src/main/java/org/apache/ode/clustering/hazelcast/HazelcastClusterImpl.java b/clustering/src/main/java/org/apache/ode/clustering/hazelcast/HazelcastClusterImpl.java
index 11e1313..aa24947 100644
--- a/clustering/src/main/java/org/apache/ode/clustering/hazelcast/HazelcastClusterImpl.java
+++ b/clustering/src/main/java/org/apache/ode/clustering/hazelcast/HazelcastClusterImpl.java
@@ -43,9 +43,12 @@ public class HazelcastClusterImpl implements ClusterManager {
     private String nodeID;
     private String uuid;
     private Member leader;
-    private IMap<String, String> lock_map;
+    private IMap<String, String> deployment_lock_map;
+    private IMap<String, String> instance_lock_map;
     private ITopic<ProcessStoreClusterEvent> clusterMessageTopic;
     private ClusterProcessStore _clusterProcessStore;
+    private ClusterLock _hazelcastDeploymentLock;
+    private ClusterLock _hazelcastInstanceLock;
 
     public void init(File configRoot) {
 
@@ -74,37 +77,13 @@ public class HazelcastClusterImpl implements ClusterManager {
             uuid = localMember.getUuid();
             __log.info("Registering HZ localMember ID " + nodeID);
             markAsMaster();
-            lock_map = _hazelcastInstance.getMap(HazelcastConstants.ODE_CLUSTER_DEPLOYMENT_LOCK);
+            deployment_lock_map = _hazelcastInstance.getMap(HazelcastConstants.ODE_CLUSTER_DEPLOYMENT_LOCK);
+            instance_lock_map = _hazelcastInstance.getMap(HazelcastConstants.ODE_CLUSTER_PROCESS_INSTANCE_LOCK);
             clusterMessageTopic = _hazelcastInstance.getTopic(HazelcastConstants.ODE_CLUSTER_MSG);
-        }
-    }
-
-    public void putIfAbsent(String key, String keyVal) {
-        lock_map.putIfAbsent(key, keyVal);
-    }
-
-    public boolean lock(String key) {
-        lock_map.lock(key);
-        if (__log.isDebugEnabled()) {
-        __log.debug("ThreadID:" + Thread.currentThread().getId() + " duLocked value for " + key + " file" + " after locking: " + true);
-        }
-        return true;
-    }
-
-    public boolean unlock(String key) {
-        lock_map.unlock(key);
-        if (__log.isDebugEnabled()) {
-        __log.debug("ThreadID:" + Thread.currentThread().getId() + " duLocked value for " + key + " file" + " after unlocking: " + false);
-        }
-        return true;
-    }
 
-    public boolean tryLock(String key) {
-        boolean state = lock_map.tryLock(key);
-        if (__log.isDebugEnabled()) {
-        __log.debug("ThreadID:" + Thread.currentThread().getId() + " duLocked value for " + key + " file" + " after locking: " + state);
+            _hazelcastDeploymentLock = (ClusterLock) new HazelcastDeploymentLock(deployment_lock_map);
+            _hazelcastInstanceLock = (ClusterLock) new HazelcastInstanceLock(instance_lock_map);
         }
-        return state;
     }
 
     class ClusterMemberShipListener implements MembershipListener {
@@ -181,5 +160,17 @@ public class HazelcastClusterImpl implements ClusterManager {
     public void registerClusterProcessStoreMessageListener() {
         clusterMessageTopic.addMessageListener(new ClusterMessageListener());
     }
+
+    public void shutdown() {
+        if(_hazelcastInstance != null) _hazelcastInstance.getLifecycleService().shutdown();
+    }
+
+    public ClusterLock getDeplymentLock(){
+        return _hazelcastDeploymentLock;
+    }
+
+    public ClusterLock getInstanceLock(){
+        return _hazelcastInstanceLock;
+    }
 }
 

http://git-wip-us.apache.org/repos/asf/ode/blob/94f19ed6/clustering/src/main/java/org/apache/ode/clustering/hazelcast/HazelcastDeploymentLock.java
----------------------------------------------------------------------
diff --git a/clustering/src/main/java/org/apache/ode/clustering/hazelcast/HazelcastDeploymentLock.java b/clustering/src/main/java/org/apache/ode/clustering/hazelcast/HazelcastDeploymentLock.java
new file mode 100644
index 0000000..4d0aac1
--- /dev/null
+++ b/clustering/src/main/java/org/apache/ode/clustering/hazelcast/HazelcastDeploymentLock.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ode.clustering.hazelcast;
+
+import com.hazelcast.core.IMap;
+import org.apache.ode.bpel.clapi.ClusterLock;
+
+public class HazelcastDeploymentLock implements ClusterLock{
+    private static final Log __log = LogFactory.getLog(HazelcastDeploymentLock.class);
+
+    private IMap<String, String> _lock_map;
+
+    HazelcastDeploymentLock(IMap<String, String> lock_map) {
+        _lock_map = lock_map;
+    }
+
+    public void putIfAbsent(String key, String keyVal) {
+        _lock_map.putIfAbsent(key, keyVal);
+    }
+
+    public boolean lockMap(String key) {
+        _lock_map.lock(key);
+        if (__log.isDebugEnabled()) {
+            __log.debug("ThreadID:" + Thread.currentThread().getId() + " duLocked value for " + key + " file" + " after locking: " + true);
+        }
+        return true;
+    }
+
+    public boolean unlockMap(String key) {
+        _lock_map.unlock(key);
+        if (__log.isDebugEnabled()) {
+            __log.debug("ThreadID:" + Thread.currentThread().getId() + " duLocked value for " + key + " file" + " after unlocking: " + false);
+        }
+        return true;
+    }
+
+    public boolean tryLockMap(String key) {
+        boolean state = _lock_map.tryLock(key);
+        if (__log.isDebugEnabled()) {
+            __log.debug("ThreadID:" + Thread.currentThread().getId() + " duLocked value for " + key + " file" + " after locking: " + state);
+        }
+        return state;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ode/blob/94f19ed6/clustering/src/main/java/org/apache/ode/clustering/hazelcast/HazelcastInstanceLock.java
----------------------------------------------------------------------
diff --git a/clustering/src/main/java/org/apache/ode/clustering/hazelcast/HazelcastInstanceLock.java b/clustering/src/main/java/org/apache/ode/clustering/hazelcast/HazelcastInstanceLock.java
new file mode 100644
index 0000000..3b8ab41
--- /dev/null
+++ b/clustering/src/main/java/org/apache/ode/clustering/hazelcast/HazelcastInstanceLock.java
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ode.clustering.hazelcast;
+
+import com.hazelcast.core.IMap;
+import org.apache.ode.bpel.clapi.ClusterLock;
+import org.apache.ode.bpel.engine.AbstractInstnaceLockManager;
+
+import java.util.concurrent.TimeUnit;
+
+public class HazelcastInstanceLock extends AbstractInstnaceLockManager implements ClusterLock {
+    private static final Log __log = LogFactory.getLog(HazelcastInstanceLock.class);
+
+    private IMap<String, String> _lock_map;
+
+
+    HazelcastInstanceLock(IMap<String, String> lock_map) {
+        _lock_map = lock_map;
+    }
+
+    private void putIfAbsent(String key, String keyVal) {
+        _lock_map.putIfAbsent(key, keyVal);
+    }
+
+    public void lock(Long iid, int time, TimeUnit tu) throws InterruptedException,
+            AbstractInstanceLockManager.TimeoutException {
+        if (iid == null) {
+            if(__log.isDebugEnabled()) {
+                __log.debug(" Instance Id null at lock[]");
+            }
+            return;
+        }
+
+        String thrd = Thread.currentThread().toString();
+
+        if(__log.isDebugEnabled()) {
+            __log.debug(thrd + ": lock(iid=" + iid + ", time=" + time + tu + ")");
+        }
+
+        putIfAbsent(iid.toString(),iid.toString());
+
+        if (!tryLockMap(iid.toString(),time, tu)) {
+
+            if(__log.isDebugEnabled()) {
+                __log.debug(thrd + ": lock(iid=" + iid + ", " +
+                        "time=" + time + tu + ")-->TIMEOUT");
+            }
+            throw new AbstractInstanceLockManager.TimeoutException();
+        }
+
+    }
+
+    public void unlock(Long iid) {
+        if (iid == null) {
+            if(__log.isDebugEnabled()) {
+                __log.debug(" unlock, instance id is null");
+            }
+            return;
+        }
+
+        String thrd = Thread.currentThread().toString();
+
+        unlockMap(iid.toString());
+
+        if(__log.isDebugEnabled()) {
+            __log.debug(thrd + " unlock(iid=" + iid + ")");
+        }
+    }
+
+    private boolean lockMap(String key) {
+        _lock_map.lock(key);
+        return true;
+    }
+
+    private boolean unlockMap(String key) {
+        if (_lock_map.get(key) == "true") {
+            _lock_map.unlock(key);
+            _lock_map.replace(key,"false");
+        }
+        return true;
+    }
+
+    private boolean tryLockMap(String key) {
+        boolean state = _lock_map.tryLock(key);
+        return state;
+    }
+
+    private boolean tryLockMap(String key,int time, TimeUnit tu) {
+        boolean state = _lock_map.tryLock(key,time,tu);
+        _lock_map.replace(key,"" +state);
+        return state;
+    }
+}