You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by hb...@apache.org on 2001/04/08 02:41:53 UTC

cvs commit: jakarta-james/src/org/apache/james/util Lock.java

hbedi       01/04/07 17:41:53

  Added:       src/org/apache/james/util Lock.java
  Log:
  fixed compilation problem due to changes in the Lock API.
  Added previous version of org.apache.avalon.util.Lock to package org.apache.avalon.james.util
  
  Revision  Changes    Path
  1.1                  jakarta-james/src/org/apache/james/util/Lock.java
  
  Index: Lock.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.james.util;
  
  import java.util.Hashtable;
  
  /**
   * @author Federico Barbieri <fe...@apache.org>
   */
  public class Lock
  {
      private Hashtable locks = new Hashtable();
  
      public boolean isLocked( final Object key )
      {
          return (locks.get(key) != null);
      }
  
      public boolean canI( final Object key )
      {
          Object o = locks.get( key );
  
          if( null == o || o == this.getCallerId() )
          {
              return true;
          }
  
          return false;
      }
  
      public boolean lock( final Object key )
      {
          Object theLock;
          
          synchronized( this )
          {
              theLock = locks.get( key );
  
              if( null == theLock )
              {
                  locks.put( key, getCallerId() );
                  return true;
              } 
              else if( getCallerId() == theLock )
              {
                  return true;
              } 
              else
              {
                  return false;
              }
          }
      }
  
      public boolean unlock( final Object key ) 
      {
          Object theLock;
          synchronized( this )
          {
              theLock = locks.get( key );
  
              if( null == theLock )
              {
                  return true;
              } 
              else if( getCallerId() == theLock )
              {
                  locks.remove( key );
                  return true;
              } 
              else
              {
                  return false;
              }
          }
      }
  
      private Object getCallerId() 
      {
          return Thread.currentThread();
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: james-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: james-dev-help@jakarta.apache.org