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 se...@apache.org on 2001/08/06 06:15:16 UTC
cvs commit: jakarta-james/src/java/org/apache/james/util Lock.java
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 <fe...@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
Re: cvs commit: jakarta-james/src/java/org/apache/james/util Lock.java
Posted by Serge Knystautas <se...@lokitech.com>.
----- Original Message -----
From: "Harmeet" <ha...@kodemuse.com>
> Proposal:
> - james.util.Lock should be renamed to james.util.LockMap. Expresses the
> intent better
+1
> - james.util.LockMap should reuse the avalon.excalibur.concurrent
> facilities.
+1 (but is it really so complicated as to need this dependency)
> - if it is useful to have james.util.LockMap outside James, maybe that
class
> or equivalent could be added to avalon.excalibur.concurrent.
Up to Avalon folks I guess.
Serge Knystautas
Loki Technologies
http://www.lokitech.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: james-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: james-dev-help@jakarta.apache.org
Re: cvs commit: jakarta-james/src/java/org/apache/james/util Lock.java
Posted by Harmeet <ha...@kodemuse.com>.
> 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.
o.a.j.util.Lock is exactly the same as old Avalon Lock. Original code was a
lock map - multiple locks, each identified by a key. This was used by
Mail/Spool repository. The Lock API in Avalon changed. This caused problems
in James repositories. I had copied the old class to James to have
successful builds and allow work to continue.
At this point there does not seem to be a Lock Map equivalent in
o.a.avalon.excalibur.concurrent, but it should be easy to add.
Proposal:
- james.util.Lock should be renamed to james.util.LockMap. Expresses the
intent better
- james.util.LockMap should reuse the avalon.excalibur.concurrent
facilities.
- if it is useful to have james.util.LockMap outside James, maybe that class
or equivalent could be added to avalon.excalibur.concurrent.
what do you say ?
Harmeet
---------------------------------------------------------------------
To unsubscribe, e-mail: james-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: james-dev-help@jakarta.apache.org
Re: cvs commit: jakarta-james/src/java/org/apache/james/util Lock.java
Posted by Charles Benett <ch...@benett1.demon.co.uk>.
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 <fe...@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