/*
 * Copyright 2006-2007 the original author or authors.
 *
 * Licensed 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.openspaces.core.map;

import net.jini.core.transaction.Transaction;

/**
 * A lock handle allowing to perform map operations when the key is locked. Intenally
 * holds the transaction representing the lock and it can be accessed to be passed to
 * any operation that needs to be performed under the same lock.
 *
 * <p>With {@link org.openspaces.core.GigaMap} this is done automatically by just passing
 * the lock handle to an operation.
 *
 * @author kimchy
 */
public class LockHandle {

    private LockManager lockManager;

    private Transaction tx;

    private Object key;

    /**
     * Constructs a new Lock Handle
     */
    LockHandle(LockManager lockManager, Transaction tx, Object key) {
        this.lockManager = lockManager;
        this.tx = tx;
        this.key = key;
    }

    /**
     * Unlocks the given key.
     */
    public void unlock() {
        lockManager.unlock(key);
    }

    /**
     * Returns the transaction representing the lock on the given key.
     */
    public Transaction getTransaction() {
        return tx;
    }

    /**
     * Returns the key that is locked.
     */
    public Object getKey() {
        return key;
    }
}

@@ -696,16 +696,133 @@
 ction;%0A%0A
+import java.io.Externalizable;%0Aimport java.io.IOException;%0Aimport java.io.ObjectInput;%0Aimport java.io.ObjectOutput;%0A%0A
 /**%0A * A
@@ -1232,16 +1232,42 @@
 kHandle 
+implements Externalizable 
 %7B%0A%0A    p
@@ -1916,24 +1916,24 @@
  getKey() %7B%0A
-
         retu
@@ -1945,11 +1945,318 @@
 y;%0A    %7D
+%0A%0A    public void writeExternal(ObjectOutput out) throws IOException %7B%0A        out.writeObject(tx);%0A        out.writeObject(key);%0A    %7D%0A%0A    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException %7B%0A        tx = (Transaction) in.readObject();%0A        key = in.readObject();%0A    %7D
 %0A%7D%0A

make the LockHandle serializable