Author: andygumbrecht
Date: Thu Jan 10 14:38:57 2013
New Revision: 1431389
URL: http://svn.apache.org/viewvc?rev=1431389&view=rev
Log:
Cleanup and make ThreadPoolExecutor more robust.
Synchronize on something useful.
Modified:
openejb/trunk/openejb/server/openejb-client/src/main/java/org/apache/openejb/client/EJBInvocationHandler.java
openejb/trunk/openejb/server/openejb-client/src/main/java/org/apache/openejb/client/EJBObjectHandler.java
Modified:
openejb/trunk/openejb/server/openejb-client/src/main/java/org/apache/openejb/client/EJBInvocationHandler.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/server/openejb-client/src/main/java/org/apache/openejb/client/EJBInvocationHandler.java?rev=1431389&r1=1431388&r2=1431389&view=diff
==============================================================================
---
openejb/trunk/openejb/server/openejb-client/src/main/java/org/apache/openejb/client/EJBInvocationHandler.java
(original)
+++
openejb/trunk/openejb/server/openejb-client/src/main/java/org/apache/openejb/client/EJBInvocationHandler.java
Thu Jan 10 14:38:57 2013
@@ -16,35 +16,36 @@
*/
package org.apache.openejb.client;
+import org.apache.openejb.client.proxy.InvocationHandler;
+
+import javax.ejb.AccessLocalException;
+import javax.ejb.EJBAccessException;
+import javax.ejb.EJBException;
+import javax.ejb.EJBHome;
+import javax.ejb.EJBObject;
+import javax.ejb.EJBTransactionRolledbackException;
+import javax.ejb.NoSuchEJBException;
+import javax.ejb.TransactionRequiredLocalException;
+import javax.ejb.TransactionRolledbackLocalException;
+import javax.transaction.TransactionRequiredException;
+import javax.transaction.TransactionRolledbackException;
import java.io.Serializable;
-import java.lang.reflect.Method;
import java.lang.ref.WeakReference;
+import java.lang.reflect.Method;
+import java.rmi.AccessException;
import java.rmi.NoSuchObjectException;
import java.rmi.RemoteException;
-import java.rmi.AccessException;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicBoolean;
-
-import org.apache.openejb.client.proxy.InvocationHandler;
-
-import javax.transaction.TransactionRequiredException;
-import javax.transaction.TransactionRolledbackException;
-import javax.ejb.TransactionRequiredLocalException;
-import javax.ejb.TransactionRolledbackLocalException;
-import javax.ejb.AccessLocalException;
-import javax.ejb.EJBException;
-import javax.ejb.EJBAccessException;
-import javax.ejb.EJBObject;
-import javax.ejb.EJBHome;
-import javax.ejb.NoSuchEJBException;
-import javax.ejb.EJBTransactionRolledbackException;
-import javax.validation.ValidationException;
+import java.util.concurrent.locks.ReentrantLock;
public abstract class EJBInvocationHandler implements InvocationHandler,
Serializable {
+ private static final ReentrantLock lock = new ReentrantLock();
+
protected static final Method EQUALS = getMethod(Object.class, "equals",
Object.class);
protected static final Method HASHCODE = getMethod(Object.class,
"hashCode");
protected static final Method TOSTRING = getMethod(Object.class,
"toString");
@@ -74,15 +75,15 @@ public abstract class EJBInvocationHandl
remote = false;
}
- public EJBInvocationHandler(EJBMetaDataImpl ejb, ServerMetaData server,
ClientMetaData client) {
+ public EJBInvocationHandler(final EJBMetaDataImpl ejb, final
ServerMetaData server, final ClientMetaData client) {
this.ejb = ejb;
this.server = server;
this.client = client;
- Class remoteInterface = ejb.getRemoteInterfaceClass();
+ final Class remoteInterface = ejb.getRemoteInterfaceClass();
remote = remoteInterface != null &&
(EJBObject.class.isAssignableFrom(remoteInterface) ||
EJBHome.class.isAssignableFrom(remoteInterface));
}
- public EJBInvocationHandler(EJBMetaDataImpl ejb, ServerMetaData server,
ClientMetaData client, Object primaryKey) {
+ public EJBInvocationHandler(final EJBMetaDataImpl ejb, final
ServerMetaData server, final ClientMetaData client, final Object primaryKey) {
this(ejb, server, client);
this.primaryKey = primaryKey;
}
@@ -103,37 +104,37 @@ public abstract class EJBInvocationHandl
return primaryKey;
}
- protected static Method getMethod(Class c, String method, Class... params)
{
+ @SuppressWarnings("unchecked")
+ protected static Method getMethod(final Class c, final String method,
final Class... params) {
try {
return c.getMethod(method, params);
} catch (NoSuchMethodException nse) {
- throw new IllegalStateException("Cannot find method:
"+c.getName()+"."+method, nse);
+ throw new IllegalStateException("Cannot find method: " +
c.getName() + "." + method, nse);
}
}
- public Object invoke(Object proxy, Method method, Object... args) throws
Throwable {
+ @Override
+ public Object invoke(final Object proxy, final Method method, final
Object... args) throws Throwable {
if (isInvalidReference.get()) {
- if (remote ||
java.rmi.Remote.class.isAssignableFrom(method.getDeclaringClass())){
+ if (remote ||
java.rmi.Remote.class.isAssignableFrom(method.getDeclaringClass())) {
throw new NoSuchObjectException("reference is invalid");
} else {
throw new NoSuchEJBException("reference is invalid");
}
}
- // BREAKPOINT -- nice place for a breakpoint
- Object returnObj = _invoke(proxy, method, args);
- return returnObj;
+ return _invoke(proxy, method, args);
}
protected abstract Object _invoke(Object proxy, Method method, Object[]
args) throws Throwable;
- protected EJBResponse request(EJBRequest req) throws Exception {
+ protected EJBResponse request(final EJBRequest req) throws Exception {
req.setClientIdentity(getClientIdentity());
req.setServerHash(server.buildHash());
- EJBResponse response = new EJBResponse();
+ final EJBResponse response = new EJBResponse();
Client.request(req, response, server);
if (null != response.getServer()) {
server.merge(response.getServer());
@@ -141,7 +142,7 @@ public abstract class EJBInvocationHandl
return response;
}
- protected EJBResponse request(EJBRequest req, EJBResponse res) throws
Exception {
+ protected EJBResponse request(final EJBRequest req, final EJBResponse res)
throws Exception {
req.setClientIdentity(getClientIdentity());
req.setServerHash(server.buildHash());
@@ -155,7 +156,7 @@ public abstract class EJBInvocationHandl
protected Object getClientIdentity() {
if (client != null) {
- Object identity = client.getClientIdentity();
+ final Object identity = client.getClientIdentity();
if (identity != null) {
return identity;
}
@@ -168,44 +169,57 @@ public abstract class EJBInvocationHandl
this.isInvalidReference.set(true);
}
- protected static void invalidateAllHandlers(Object key) {
+ protected static void invalidateAllHandlers(final Object key) {
- Set<WeakReference<EJBInvocationHandler>> set =
liveHandleRegistry.remove(key);
- if (set == null) return;
+ final Set<WeakReference<EJBInvocationHandler>> set =
liveHandleRegistry.remove(key);
+ if (set == null)
+ return;
- synchronized (set) {
- for (WeakReference<EJBInvocationHandler> ref : set) {
- EJBInvocationHandler handler = ref.get();
+ final ReentrantLock l = lock;
+ l.lock();
+
+ try {
+ for (final WeakReference<EJBInvocationHandler> ref : set) {
+ final EJBInvocationHandler handler = ref.get();
if (handler != null) {
handler.invalidateReference();
}
}
set.clear();
+ } finally {
+ l.unlock();
}
}
- protected static void registerHandler(Object key, EJBInvocationHandler
handler) {
+ protected static void registerHandler(final Object key, final
EJBInvocationHandler handler) {
Set<WeakReference<EJBInvocationHandler>> set =
liveHandleRegistry.get(key);
if (set == null) {
set = new HashSet<WeakReference<EJBInvocationHandler>>();
- Set<WeakReference<EJBInvocationHandler>> current =
liveHandleRegistry.putIfAbsent(key, set);
+ final Set<WeakReference<EJBInvocationHandler>> current =
liveHandleRegistry.putIfAbsent(key, set);
// someone else added the set
- if (current != null) set = current;
+ if (current != null)
+ set = current;
}
- synchronized (set) {
+ final ReentrantLock l = lock;
+ l.lock();
+
+ try {
set.add(new WeakReference<EJBInvocationHandler>(handler));
+ } finally {
+ l.unlock();
}
}
/**
* Renamed method so it shows up with a much more understandable purpose
as it
* will be the top element in the stacktrace
- * @param e
- * @param method
+ *
+ * @param e Throwable
+ * @param method Method
*/
- protected Throwable convertException(Throwable e, Method method) {
+ protected Throwable convertException(final Throwable e, final Method
method) {
if (!remote && e instanceof RemoteException) {
if (e instanceof TransactionRequiredException) {
return new
TransactionRequiredLocalException(e.getMessage()).initCause(getCause(e));
@@ -222,7 +236,7 @@ public abstract class EJBInvocationHandl
* See EJB 3.0, section 4.4
*/
if (e instanceof NoSuchObjectException) {
- if
(java.rmi.Remote.class.isAssignableFrom(method.getDeclaringClass())){
+ if
(java.rmi.Remote.class.isAssignableFrom(method.getDeclaringClass())) {
return e;
} else {
return new
NoSuchEJBException(e.getMessage()).initCause(getCause(e));
@@ -248,7 +262,7 @@ public abstract class EJBInvocationHandl
return e;
}
- protected static Throwable getCause(Throwable e) {
+ protected static Throwable getCause(final Throwable e) {
if (e != null && e.getCause() != null) {
return e.getCause();
}
Modified:
openejb/trunk/openejb/server/openejb-client/src/main/java/org/apache/openejb/client/EJBObjectHandler.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/server/openejb-client/src/main/java/org/apache/openejb/client/EJBObjectHandler.java?rev=1431389&r1=1431388&r2=1431389&view=diff
==============================================================================
---
openejb/trunk/openejb/server/openejb-client/src/main/java/org/apache/openejb/client/EJBObjectHandler.java
(original)
+++
openejb/trunk/openejb/server/openejb-client/src/main/java/org/apache/openejb/client/EJBObjectHandler.java
Thu Jan 10 14:38:57 2013
@@ -26,42 +26,99 @@ import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
-import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Callable;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.RejectedExecutionException;
+import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+@SuppressWarnings("NullArgumentToVariableArgMethod")
public abstract class EJBObjectHandler extends EJBInvocationHandler {
protected static final Method GETEJBHOME = getMethod(EJBObject.class,
"getEJBHome", null);
protected static final Method GETHANDLE = getMethod(EJBObject.class,
"getHandle", null);
protected static final Method GETPRIMARYKEY = getMethod(EJBObject.class,
"getPrimaryKey", null);
- protected static final Method ISIDENTICAL = getMethod(EJBObject.class,
"isIdentical", new Class []{EJBObject.class});
+ protected static final Method ISIDENTICAL = getMethod(EJBObject.class,
"isIdentical", EJBObject.class);
protected static final Method REMOVE = getMethod(EJBObject.class,
"remove", null);
-
protected static final Method GETHANDLER = getMethod(EJBObjectProxy.class,
"getEJBObjectHandler", null);
-
protected static final Method CANCEL = getMethod(Future.class, "cancel",
boolean.class);
- //TODO figure out how to configure and manage the thread pool on the
client side
- protected static final BlockingQueue<Runnable> blockingQueue = new
LinkedBlockingQueue<Runnable>();
- protected static final ExecutorService executorService = new
ThreadPoolExecutor(10, 20, 60, TimeUnit.SECONDS, blockingQueue, new
ThreadFactory() {
- @Override
- public Thread newThread(Runnable runnable) {
- final Thread thread = new Thread(runnable, "EJB Client");
- thread.setDaemon(true);
- return thread;
- }
- });
+ //TODO figure out how to configure and manage the thread pool on the
client side, this will do for now...
+ private static final int threads =
Integer.parseInt(System.getProperty("openejb.client.invoker.threads", "10"));
+ private static final int queue =
Integer.parseInt(System.getProperty("openejb.client.invoker.queue", "50000"));
+ private static final LinkedBlockingQueue<Runnable> blockingQueue = new
LinkedBlockingQueue<Runnable>((queue < 2 ? 2 : queue));
+
+ protected static final ThreadPoolExecutor executorService;
+
+ static {
+ /**
+ This thread pool starts with 2 core threads and can grow to the limit
defined by 'threads'.
+ If a pool thread is idle for more than 1 minute it will be discarded,
unless the core size is reached.
+ It can accept upto the number of processes defined by 'queue'.
+ If the queue is full then an attempt is made to add the process to
the queue for 10 seconds.
+ Failure to add to the queue in this time will either result in a
logged rejection, or if 'block'
+ is true then a final attempt is made to run the process in the
current thread (the service thread).
+ */
+
+ executorService = new ThreadPoolExecutor(2, (threads < 2 ? 2 :
threads), 1, TimeUnit.MINUTES, blockingQueue);
+ executorService.setThreadFactory(new ThreadFactory() {
+
+ private final AtomicInteger i = new AtomicInteger(0);
+
+ @Override
+ public Thread newThread(final Runnable r) {
+ final Thread t = new Thread(r, "OpenEJB.Client." +
i.incrementAndGet());
+ t.setDaemon(true);
+ t.setUncaughtExceptionHandler(new
Thread.UncaughtExceptionHandler() {
+ @Override
+ public void uncaughtException(final Thread t, final
Throwable e) {
+
Logger.getLogger(EJBObjectHandler.class.getName()).log(Level.SEVERE, "Uncaught
error in: " + t.getName(), e);
+ }
+ });
+
+ return t;
+ }
+
+ });
+
+ executorService.setRejectedExecutionHandler(new
RejectedExecutionHandler() {
+ @Override
+ public void rejectedExecution(final Runnable r, final
ThreadPoolExecutor tpe) {
+
+ if (null == r || null == tpe || tpe.isShutdown() ||
tpe.isTerminated() || tpe.isTerminating()) {
+ return;
+ }
+
+ final Logger log =
Logger.getLogger(EJBObjectHandler.class.getName());
+
+ if (log.isLoggable(Level.WARNING)) {
+ log.log(Level.WARNING, "EJBObjectHandler ExecutorService
at capicity for process: " + r);
+ }
+
+ boolean offer = false;
+ try {
+ offer = tpe.getQueue().offer(r, 10, TimeUnit.SECONDS);
+ } catch (InterruptedException e) {
+ //Ignore
+ }
+
+ if (!offer) {
+ log.log(Level.SEVERE, "EJBObjectHandler ExecutorService
failed to run asynchronous process: " + r);
+ }
+ }
+ });
+ }
+
/*
* The registryId is a logical identifier that is used as a key when
placing EntityEJBObjectHandler into
* the BaseEjbProxyHanlder's liveHandleRegistry. EntityEJBObjectHandlers
that represent the same
@@ -78,19 +135,19 @@ public abstract class EJBObjectHandler e
public EJBObjectHandler() {
}
- public EJBObjectHandler(EJBMetaDataImpl ejb, ServerMetaData server,
ClientMetaData client) {
+ public EJBObjectHandler(final EJBMetaDataImpl ejb, final ServerMetaData
server, final ClientMetaData client) {
super(ejb, server, client);
}
- public EJBObjectHandler(EJBMetaDataImpl ejb, ServerMetaData server,
ClientMetaData client, Object primaryKey) {
+ public EJBObjectHandler(final EJBMetaDataImpl ejb, final ServerMetaData
server, final ClientMetaData client, final Object primaryKey) {
super(ejb, server, client, primaryKey);
}
- protected void setEJBHomeProxy(EJBHomeProxy ejbHome) {
+ protected void setEJBHomeProxy(final EJBHomeProxy ejbHome) {
this.ejbHome = ejbHome;
}
- public static EJBObjectHandler createEJBObjectHandler(EJBMetaDataImpl ejb,
ServerMetaData server, ClientMetaData client, Object primaryKey) {
+ public static EJBObjectHandler createEJBObjectHandler(final
EJBMetaDataImpl ejb, final ServerMetaData server, final ClientMetaData client,
final Object primaryKey) {
switch (ejb.type) {
case EJBMetaDataImpl.BMP_ENTITY:
@@ -111,7 +168,7 @@ public abstract class EJBObjectHandler e
return new SingletonEJBObjectHandler(ejb, server, client,
primaryKey);
}
- throw new IllegalStateException("Uknown bean type code '"+ejb.type +"'
: "+ejb.toString());
+ throw new IllegalStateException("Uknown bean type code '" + ejb.type +
"' : " + ejb.toString());
}
public abstract Object getRegistryId();
@@ -121,7 +178,7 @@ public abstract class EJBObjectHandler e
EJBObjectProxy ejbObject = null;
try {
- List<Class> interfaces = new ArrayList<Class>();
+ final List<Class> interfaces = new ArrayList<Class>();
// Interface class must be listed first, before EJBObjectProxy,
// otherwise the proxy code will select the openejb system class
// loader for proxy creation instead of the application class
loader
@@ -132,8 +189,8 @@ public abstract class EJBObjectHandler e
}
interfaces.add(EJBObjectProxy.class);
- ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
- boolean parent =
ClassLoaderUtil.isParent(getClass().getClassLoader(), oldCl);
+ final ClassLoader oldCl =
Thread.currentThread().getContextClassLoader();
+ final boolean parent =
ClassLoaderUtil.isParent(getClass().getClassLoader(), oldCl);
if (!parent) {
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
}
@@ -148,43 +205,58 @@ public abstract class EJBObjectHandler e
return ejbObject;
}
- public Object _invoke(Object p, Method m, Object[] a) throws Throwable {
+ @Override
+ public Object _invoke(final Object p, final Method m, final Object[] a)
throws Throwable {
try {
if (m.getDeclaringClass().equals(Object.class)) {
- if (m.equals(TOSTRING)) return "proxy=" + this;
+ if (m.equals(TOSTRING))
+ return "proxy=" + this;
- else if (m.equals(EQUALS)) return equals(m, a, p);
+ else if (m.equals(EQUALS))
+ return equals(m, a, p);
- else if (m.equals(HASHCODE)) return new
Integer(this.hashCode());
+ else if (m.equals(HASHCODE))
+ return this.hashCode();
- else throw new UnsupportedOperationException("Unkown method: "
+ m);
+ else
+ throw new UnsupportedOperationException("Unkown method: "
+ m);
} else if (m.getDeclaringClass() == EJBObjectProxy.class) {
- if (m.equals(GETHANDLER)) return this;
+ if (m.equals(GETHANDLER))
+ return this;
- else if (m.getName().equals("writeReplace")) return new
EJBObjectProxyHandle(this);
+ else if (m.getName().equals("writeReplace"))
+ return new EJBObjectProxyHandle(this);
- else if (m.getName().equals("readResolve")) return null;
+ else if (m.getName().equals("readResolve"))
+ return null;
- else throw new UnsupportedOperationException("Unkown method: "
+ m);
+ else
+ throw new UnsupportedOperationException("Unkown method: "
+ m);
} else if (m.getDeclaringClass() == javax.ejb.EJBObject.class) {
- if (m.equals(GETHANDLE)) return getHandle(m, a, p);
+ if (m.equals(GETHANDLE))
+ return getHandle(m, a, p);
- else if (m.equals(GETPRIMARYKEY)) return getPrimaryKey(m, a,
p);
+ else if (m.equals(GETPRIMARYKEY))
+ return getPrimaryKey(m, a, p);
- else if (m.equals(ISIDENTICAL)) return isIdentical(m, a, p);
+ else if (m.equals(ISIDENTICAL))
+ return isIdentical(m, a, p);
- else if (m.equals(GETEJBHOME)) return getEJBHome(m, a, p);
+ else if (m.equals(GETEJBHOME))
+ return getEJBHome(m, a, p);
- else if (m.equals(REMOVE)) return remove(m, a, p);
+ else if (m.equals(REMOVE))
+ return remove(m, a, p);
- else throw new UnsupportedOperationException("Unkown method: "
+ m);
+ else
+ throw new UnsupportedOperationException("Unkown method: "
+ m);
} else {
@@ -214,23 +286,25 @@ public abstract class EJBObjectHandler e
}
} catch (Throwable throwable) {
if (remote) {
- if (throwable instanceof RemoteException) throw throwable;
+ if (throwable instanceof RemoteException)
+ throw throwable;
throw new RemoteException("Unknown Container Exception: " +
throwable.getClass().getName() + ": " + throwable.getMessage(),
getCause(throwable));
} else {
- if (throwable instanceof EJBException) throw throwable;
+ if (throwable instanceof EJBException)
+ throw throwable;
throw new EJBException("Unknown Container Exception: " +
throwable.getClass().getName() + ": " +
throwable.getMessage()).initCause(getCause(throwable));
}
}
}
- protected Object getEJBHome(Method method, Object[] args, Object proxy)
throws Throwable {
+ protected Object getEJBHome(final Method method, final Object[] args,
final Object proxy) throws Throwable {
if (ejbHome == null) {
ejbHome = EJBHomeHandler.createEJBHomeHandler(ejb, server,
client).createEJBHomeProxy();
}
return ejbHome;
}
- protected Object getHandle(Method method, Object[] args, Object proxy)
throws Throwable {
+ protected Object getHandle(final Method method, final Object[] args, final
Object proxy) throws Throwable {
return new EJBObjectHandle((EJBObjectProxy) proxy);
}
@@ -242,13 +316,14 @@ public abstract class EJBObjectHandler e
protected abstract Object remove(Method method, Object[] args, Object
proxy) throws Throwable;
- protected Object businessMethod(Method method, Object[] args, Object
proxy) throws Throwable {
+ @SuppressWarnings("unchecked")
+ protected Object businessMethod(final Method method, final Object[] args,
final Object proxy) throws Throwable {
if (ejb.isAsynchronousMethod(method)) {
try {
- String requestId = UUID.randomUUID().toString();
- EJBResponse response = new EJBResponse();
- AsynchronousCall asynchronousCall = new
AsynchronousCall(method, args, proxy, requestId, response);
+ final String requestId = UUID.randomUUID().toString();
+ final EJBResponse response = new EJBResponse();
+ final AsynchronousCall asynchronousCall = new
AsynchronousCall(method, args, proxy, requestId, response);
return new
FutureAdapter(executorService.submit(asynchronousCall), response, requestId);
} catch (RejectedExecutionException e) {
throw new EJBException("failed to allocate internal resource
to execute the target task", e);
@@ -258,25 +333,25 @@ public abstract class EJBObjectHandler e
}
}
- private Object _businessMethod(Method method, Object[] args, Object proxy,
String requestId) throws Throwable {
- EJBRequest req = new
EJBRequest(RequestMethodCode.EJB_OBJECT_BUSINESS_METHOD, ejb, method, args,
primaryKey);
+ private Object _businessMethod(final Method method, final Object[] args,
final Object proxy, final String requestId) throws Throwable {
+ final EJBRequest req = new
EJBRequest(RequestMethodCode.EJB_OBJECT_BUSINESS_METHOD, ejb, method, args,
primaryKey);
//Currently, we only set the requestId while the asynchronous
invocation is called
req.getBody().setRequestId(requestId);
- EJBResponse res = request(req);
+ final EJBResponse res = request(req);
return _handleBusinessMethodResponse(res);
}
- private Object _businessMethod(Method method, Object[] args, Object proxy,
String requestId, EJBResponse response) throws Throwable {
- EJBRequest req = new
EJBRequest(RequestMethodCode.EJB_OBJECT_BUSINESS_METHOD, ejb, method, args,
primaryKey);
+ private Object _businessMethod(final Method method, final Object[] args,
final Object proxy, final String requestId, final EJBResponse response) throws
Throwable {
+ final EJBRequest req = new
EJBRequest(RequestMethodCode.EJB_OBJECT_BUSINESS_METHOD, ejb, method, args,
primaryKey);
//Currently, we only set the request while the asynchronous invocation
is called
req.getBody().setRequestId(requestId);
- EJBResponse res = request(req, response);
+ final EJBResponse res = request(req, response);
return _handleBusinessMethodResponse(res);
}
- private Object _handleBusinessMethodResponse(EJBResponse res) throws
Throwable{
+ private Object _handleBusinessMethodResponse(final EJBResponse res) throws
Throwable {
switch (res.getResponseCode()) {
case ResponseCodes.EJB_ERROR:
throw new SystemError((ThrowableArtifact) res.getResult());
@@ -303,7 +378,7 @@ public abstract class EJBObjectHandler e
private EJBResponse response;
- public AsynchronousCall(Method method, Object[] args, Object proxy,
String requestId, EJBResponse response) {
+ public AsynchronousCall(final Method method, final Object[] args,
final Object proxy, final String requestId, final EJBResponse response) {
this.method = method;
this.args = args;
this.proxy = proxy;
@@ -335,14 +410,15 @@ public abstract class EJBObjectHandler e
private AtomicBoolean lastMayInterruptIfRunningValue = new
AtomicBoolean(false);
- public FutureAdapter(Future<T> target, EJBResponse response, String
requestId) {
+ public FutureAdapter(final Future<T> target, final EJBResponse
response, final String requestId) {
this.target = target;
this.requestId = requestId;
this.response = response;
}
+ @SuppressWarnings({"SuspiciousMethodCalls", "UnnecessaryBoxing"})
@Override
- public boolean cancel(boolean mayInterruptIfRunning) {
+ public boolean cancel(final boolean mayInterruptIfRunning) {
/* In EJB 3.1 spec 3.4.8.1.1
* a. If a client calls cancel on its Future object, the container
will attempt to cancel
* the associated asynchronous invocation only if that
invocation has not already been dispatched.
@@ -375,11 +451,11 @@ public abstract class EJBObjectHandler e
if
(lastMayInterruptIfRunningValue.getAndSet(mayInterruptIfRunning) ==
mayInterruptIfRunning) {
return false;
}
- EJBRequest req = new
EJBRequest(RequestMethodCode.FUTURE_CANCEL, ejb, CANCEL, new Object[] {
Boolean.valueOf(mayInterruptIfRunning) }, primaryKey);
+ final EJBRequest req = new
EJBRequest(RequestMethodCode.FUTURE_CANCEL, ejb, CANCEL, new
Object[]{Boolean.valueOf(mayInterruptIfRunning)}, primaryKey);
req.getBody().setRequestId(requestId);
try {
- EJBResponse res = request(req);
- if(res.getResponseCode() != ResponseCodes.EJB_OK) {
+ final EJBResponse res = request(req);
+ if (res.getResponseCode() != ResponseCodes.EJB_OK) {
//TODO how do we notify the user that we fail to
configure the value ?
}
} catch (Exception e) {
@@ -400,7 +476,7 @@ public abstract class EJBObjectHandler e
}
@Override
- public T get(long timeout, TimeUnit unit) throws InterruptedException,
ExecutionException, TimeoutException {
+ public T get(final long timeout, final TimeUnit unit) throws
InterruptedException, ExecutionException, TimeoutException {
if (canceled) {
throw new CancellationException();
}
@@ -420,4 +496,4 @@ public abstract class EJBObjectHandler e
return target.isDone();
}
}
-}
+}
\ No newline at end of file