Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source
   * Copyright 2006, Red Hat Middleware LLC, and individual contributors 
   * as indicated by the @author tags. 
   * See the copyright.txt in the distribution for a
   * full listing of individual contributors. 
   * This copyrighted material is made available to anyone wishing to use,
   * modify, copy, or redistribute it subject to the terms and conditions
   * of the GNU Lesser General Public License, v. 2.1.
  * This program is distributed in the hope that it will be useful, but WITHOUT A 
  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
  * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
  * You should have received a copy of the GNU Lesser General Public License,
  * v.2.1 along with this distribution; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
  * MA  02110-1301, USA.
  * 
  * (C) 2005-2006,
  * @author JBoss Inc.
  */
 /*
  * Copyright (C) 1998, 1999, 2000,
  *
  * Arjuna Solutions Limited,
  * Newcastle upon Tyne,
  * Tyne and Wear,
  * UK.  
  *
  * $Id: Lock.java 2342 2006-03-30 13:06:17Z  $
  */
 
 package com.arjuna.ats.txoj;
 
 
Instances of this class (or derived user classes) are used when trying to set a lock. The default implementation provides a single-write/multiple-reader policy. However, by overridding the appropriate methods, other, type-specific concurrency control locks can be implemented.

Author(s):
Mark Little (mark@arjuna.com)
Version:
$Id: Lock.java 2342 2006-03-30 13:06:17Z $
Since:
JTS 1.0.
 
 
 public class Lock extends StateManager
 {

    
Create a new lock.
 
 
     public Lock()
     {
         super(.);
 
          = .;
          = null;
          = .;
          = new ActionHierarchy(0);
     }

    
Create a new Lock object and initialise it. Mode is based upon argument. The value of BasicAction.Current determines the values of the remainder of the fields. If there is no action running the owner field is set to be the application uid created when the application starts.
 
 
     public Lock(int lm)
     {
         super(.);
 
         if (..isTraceEnabled()) {
             ..trace("Lock::Lock(" + lm
                     + ")");
         }
 
          = .;
          = null;
          = lm;
          = new ActionHierarchy(0);
 
         BasicAction curr = BasicAction.Current();
 
         if (curr == null)
        {
            int currentPid = Utility.getpid(); // ::getpid();
            ActionHierarchy ah = new ActionHierarchy(1); /* max depth of 1 */
            if ( == null)
            {
                 = new Uid();
            }
            if ( != currentPid)
            {
                /*
                 * Process id change probably due to a fork(). Get new pid and
                 * generate a new Applic_Uid
                 */
                 = currentPid;
                 = new Uid();
            }
            ah.add();
            .copy(ah);
        }
        else
        {
            .copy(curr.getHierarchy());
        }
    }

    
This is used when re-initialising a Lock after retrieval from the object store.
    public Lock(Uid storeUid)
    {
        super(storeUid.);
        if (..isTraceEnabled()) {
            ..trace("Lock::Lock("
                    + storeUid + ")");
        }
         = .;
         = null;
         = .;
         = new ActionHierarchy(0);
    }

    
General clean up as Lock is deleted.
    public void finalize () throws Throwable
    {
        if (..isTraceEnabled()) {
            ..trace("Lock.finalize()");
        }
        super.terminate();
         = null;
        super.finalize();
    }
    /*
     * Public utility operations. Most are sufficiently simple as to be self
     * explanatory!
     */

    

Returns:
the mode this lock is currently in, e.g., LockMode.READ.
    public final int getLockMode ()
    {
        if (..isTraceEnabled()) {
            ..trace("Lock::getLockMode()");
        }
        return ;
    }

    

Returns:
the identity of the lock's current owner (the transaction id).
    public final Uid getCurrentOwner ()
    {
        if (..isTraceEnabled()) {
            ..trace("Lock::getCurrentOwner()");
        }
        return .getDeepestActionUid();
    }

    

Returns:
the transaction hierarchy associated with this lock.
    public final ActionHierarchy getAllOwners ()
    {
        if (..isTraceEnabled()) {
            ..trace("Lock::getAllOwners()");
        }
        return ;
    }

    

Returns:
the lock's current status.
    public final int getCurrentStatus ()
    {
        if (..isTraceEnabled()) {
            ..trace("Lock::getCurrentStatus()");
        }
        return ;
    }

    
Change the transaction hierarchy associated with the lock to that provided.
    public final void changeHierarchy (ActionHierarchy newOwner)
    {
        if (..isTraceEnabled()) {
            ..trace("Lock::getCurrentOwner()");
        }
        .copy(newOwner);
        if ( == .)
             = .;
    }

    
Propagate the lock.
    public final void propagate ()
    {
        if (..isTraceEnabled()) {
            ..trace("Lock::propagate()");
        }
        .forgetDeepest();
    }

    
Does this lock imply a modification of the object it is applied to? For example, a READ lock would return false, but a WRITE lock would return true.

Returns:
true if this lock implies the object's state will be modified, false otherwise.
    public boolean modifiesObject ()
    {
        if (..isTraceEnabled()) {
            ..trace("Lock::modifiesObject()");
        }
        return (( == .) ? true : false);
    }

    
Implementation of Lock conflict check. Returns TRUE if there is conflict FALSE otherwise. Does not take account of relationship in the atomic action hierarchy since this is a function of LockManager.

Returns:
true if this lock conflicts with the parameter, false otherwise.
    public boolean conflictsWith (Lock otherLock)
    {
        if (..isTraceEnabled()) {
            ..trace("Lock::conflictsWith(" + otherLock + ")\n" + "\tLock 1:\n"
                    + this + "\n" + "\tLock 2:\n" + otherLock);
        }
        if (!(getCurrentOwner().equals(otherLock.getCurrentOwner())))
        {
            switch ()
            {
            case .:
                return true/* WRITE conflicts always */
            case .:
                if (otherLock.getLockMode() != .)
                    return true;
                break;
            }
        }
        return false/* no conflict between these locks */
    }

    
Overrides Object.equals()
    public boolean equals (Object otherLock)
    {
        if (otherLock instanceof Lock)
            return equals((LockotherLock);
        else
            return false;
    }

    
Are the two locks equal?

Returns:
true if the locks are equal, false otherwise.
    public boolean equals (Lock otherLock)
    {
        if (..isTraceEnabled()) {
            ..trace("Lock::equals("
                    + otherLock + ")\n" + "\tLock 1:\n" + this + "\n"
                    + "\tLock 2:\n" + otherLock);
        }
        if (this == otherLock)
            return true;
        if (( == otherLock.lMode) && (.equals(otherLock.owners))
                && ( == otherLock.currentStatus))
        {
            return true;
        }
        return false;
    }

    
Overrides Object.toString()
    public String toString ()
    {
        StringWriter strm = new StringWriter();
        strm.write("Lock object : \n");
        strm.write("\tunique id is : " + get_uid() + "\n");
        strm.write("\tcurrent_status : "
                + LockStatus.printString());
        strm.write("\n\tMode : " + LockMode.stringForm());
        strm.write("\n\tOwner List : \n");
        .print(new PrintWriter(strm));
        return strm.toString();
    }

    
functions inherited from StateManager
    public void print (PrintWriter strm)
    {
        strm.print(toString());
    }

    
Carefully restore the state of a Lock.

Returns:
true if successful, false otherwise.
    public boolean restore_state (InputObjectState osint ot)
    {
        if (..isTraceEnabled()) {
            ..trace("Lock::restore_state(" + os + ", " + ot + ")");
        }
        ActionHierarchy ah = new ActionHierarchy(0);
        try
        {
             = os.unpackInt();
             = os.unpackInt();
            ah.unpack(os);
             = ah;
            return true;
        }
        catch (IOException e)
        {
            return false;
        }
    }

    
Save the state of a lock object.

Returns:
true if successful, false otherwise.
    public boolean save_state (OutputObjectState osint ot)
    {
        if (..isTraceEnabled()) {
            ..trace("Lock::save_state("
                    + os + ", " + ot + ")");
        }
        try
        {
            os.packInt();
            os.packInt();
            .pack(os);
            return os.valid();
        }
        catch (IOException e)
        {
            return false;
        }
    }

    
Overrides StateManager.type()
    public String type ()
    {
        return "/StateManager/Lock";
    }

    
Get the next lock in the chain.
    protected Lock getLink ()
    {
        return ;
    }

    
Set the next lock in the chain.
    protected void setLink (Lock pointTo)
    {
         = pointTo;
    }
    private int currentStatus;/* Current status of lock */
    private Lock nextLock;
    private int lMode/* Typically READ or WRITE */
    private ActionHierarchy owners/* Uid of owner action (faked if none) */
    private static Uid applicUid = null/* In case lock set outside AA */
    private static int applicPid = com.arjuna.ats.arjuna.utils.Utility.getpid(); /*
                                                                                  * process
                                                                                  * id
                                                                                  */
New to GrepCode? Check out our FAQ X