[jboss-cvs] jboss-seam/src/main/org/jboss/seam/interceptors ...
Gavin King
gavin.king at jboss.com
Thu Oct 12 21:27:32 EDT 2006
User: gavin
Date: 06/10/12 21:27:32
Modified: src/main/org/jboss/seam/interceptors
SynchronizationInterceptor.java
Log:
use Semaphore in @Synchronized
Revision Changes Path
1.2 +22 -3 jboss-seam/src/main/org/jboss/seam/interceptors/SynchronizationInterceptor.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: SynchronizationInterceptor.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/interceptors/SynchronizationInterceptor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- SynchronizationInterceptor.java 10 Oct 2006 04:48:21 -0000 1.1
+++ SynchronizationInterceptor.java 13 Oct 2006 01:27:32 -0000 1.2
@@ -1,6 +1,9 @@
-//$Id: SynchronizationInterceptor.java,v 1.1 2006/10/10 04:48:21 gavin Exp $
+//$Id: SynchronizationInterceptor.java,v 1.2 2006/10/13 01:27:32 gavin Exp $
package org.jboss.seam.interceptors;
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
+
import javax.interceptor.AroundInvoke;
import javax.interceptor.InvocationContext;
@@ -12,15 +15,31 @@
*
* @author Gavin King
*/
- at Interceptor(stateless=true, type=InterceptorType.CLIENT)
+ at Interceptor(type=InterceptorType.CLIENT)
public class SynchronizationInterceptor extends AbstractInterceptor
{
+ private Semaphore semaphore = new Semaphore(1, true);
+
@AroundInvoke
public synchronized Object serialize(InvocationContext invocation) throws Exception
{
+ if ( semaphore.tryAcquire( getComponent().getTimeout(), TimeUnit.MILLISECONDS ) )
+ {
+ try
+ {
return invocation.proceed();
}
+ finally
+ {
+ semaphore.release();
+ }
+ }
+ else
+ {
+ throw new IllegalStateException("could not acquire lock on @Synchronized component: " + getComponent().getName());
+ }
+ }
}
More information about the jboss-cvs-commits
mailing list