james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Charles Benett <char...@benett1.demon.co.uk>
Subject Re: cvs commit: jakarta-james/src/java/org/apache/james/util Lock.java
Date Mon, 06 Aug 2001 09:00:40 GMT
I think the o.a.j.util.Lock class was based on an old Avalon Lock class.
There are new Lock and semaphore classes in
o.a.avalon.excalibur.concurrent which may do the trick better.

Charles

serge@apache.org wrote:
> 
> serge       01/08/05 21:15:16
> 
>   Modified:    src/java/org/apache/james/util Lock.java
>   Log:
>   Updated code formatting to this project's standards.
> 
>   Revision  Changes    Path
>   1.2       +20 -39    jakarta-james/src/java/org/apache/james/util/Lock.java
> 
>   Index: Lock.java
>   ===================================================================
>   RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/util/Lock.java,v
>   retrieving revision 1.1
>   retrieving revision 1.2
>   diff -u -r1.1 -r1.2
>   --- Lock.java 2001/05/11 09:52:30     1.1
>   +++ Lock.java 2001/08/06 04:15:16     1.2
>   @@ -12,76 +12,57 @@
>    /**
>     * @author Federico Barbieri <fede@apache.org>
>     */
>   -public class Lock
>   -{
>   +public class Lock {
>        private Hashtable locks = new Hashtable();
> 
>   -    public boolean isLocked( final Object key )
>   -    {
>   +    public boolean isLocked(final Object key) {
>            return (locks.get(key) != null);
>        }
> 
>   -    public boolean canI( final Object key )
>   -    {
>   +    public boolean canI(final Object key) {
>            Object o = locks.get( key );
> 
>   -        if( null == o || o == this.getCallerId() )
>   -        {
>   +        if (null == o || o == this.getCallerId()) {
>                return true;
>            }
> 
>            return false;
>        }
> 
>   -    public boolean lock( final Object key )
>   -    {
>   +    public boolean lock(final Object key) {
>            Object theLock;
> 
>   -        synchronized( this )
>   -        {
>   -            theLock = locks.get( key );
>   -
>   -            if( null == theLock )
>   -            {
>   -                locks.put( key, getCallerId() );
>   +        synchronized(this) {
>   +            theLock = locks.get(key);
>   +
>   +            if (null == theLock) {
>   +                locks.put(key, getCallerId());
>                    return true;
>   -            }
>   -            else if( getCallerId() == theLock )
>   -            {
>   +            } else if (getCallerId() == theLock) {
>                    return true;
>   -            }
>   -            else
>   -            {
>   +            } else {
>                    return false;
>                }
>            }
>        }
> 
>   -    public boolean unlock( final Object key )
>   -    {
>   +    public boolean unlock(final Object key) {
>            Object theLock;
>   -        synchronized( this )
>   -        {
>   -            theLock = locks.get( key );
>   +        synchronized (this) {
>   +            theLock = locks.get(key);
> 
>   -            if( null == theLock )
>   -            {
>   +            if (null == theLock) {
>                    return true;
>   -            }
>   -            else if( getCallerId() == theLock )
>   -            {
>   -                locks.remove( key );
>   +            } else if (getCallerId() == theLock) {
>   +                locks.remove(key);
>                    return true;
>   -            }
>   -            else
>   -            {
>   +            } else {
>                    return false;
>                }
>            }
>        }
> 
>   -    private Object getCallerId()
>   -    {
>   +    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

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


Mime
View raw message