Author: dblevins
Date: Wed Jun 2 22:33:22 2010
New Revision: 950801
URL: http://svn.apache.org/viewvc?rev=950801&view=rev
Log:
OPENEJB-1289: Client connection pool timeouts events catchable as
ConnectionPoolTimeoutException
OPENEJB-1291: Stateless ConcurrentAccessTimeoutException
OPENEJB-1290: Stateless @AccessTimeout
Added:
openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/ConnectionPoolTimeoutException.java
(with props)
Modified:
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessInstanceManager.java
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateless/StatelessInstanceManagerPoolingTest.java
openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBInvocationHandler.java
openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBObjectHandler.java
openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/SocketConnectionFactory.java
openejb/trunk/openejb3/server/openejb-ejbd/src/test/java/org/apache/openejb/server/ejbd/MultithreadTest.java
openejb/trunk/openejb3/server/openejb-server/src/main/java/org/apache/openejb/server/ServiceDaemon.java
Modified:
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessInstanceManager.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessInstanceManager.java?rev=950801&r1=950800&r2=950801&view=diff
==============================================================================
---
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessInstanceManager.java
(original)
+++
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessInstanceManager.java
Wed Jun 2 22:33:22 2010
@@ -34,6 +34,7 @@ import java.io.IOException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
+import javax.ejb.ConcurrentAccessTimeoutException;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.xml.ws.WebServiceContext;
@@ -43,6 +44,7 @@ import javax.management.MBeanServer;
import org.apache.openejb.Injection;
import org.apache.openejb.OpenEJBException;
import org.apache.openejb.SystemException;
+import org.apache.openejb.ApplicationException;
import org.apache.openejb.monitoring.StatsInterceptor;
import org.apache.openejb.monitoring.ObjectNameBuilder;
import org.apache.openejb.monitoring.ManagedMBean;
@@ -140,7 +142,10 @@ public class StatelessInstanceManager {
instance.setPoolEntry(entry);
}
} catch (TimeoutException e) {
- throw new IllegalStateException("An invocation of the Stateless
Session Bean "+deploymentInfo.getEjbName()+" has timed-out");
+ ConcurrentAccessTimeoutException timeoutException = new
ConcurrentAccessTimeoutException("No instances available in Stateless Session
Bean pool. Waited " + data.accessTimeout.toString());
+ timeoutException.fillInStackTrace();
+
+ throw new ApplicationException(timeoutException);
} catch (InterruptedException e) {
Thread.interrupted();
throw new OpenEJBException("Unexpected Interruption of current
thread: ", e);
Modified:
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateless/StatelessInstanceManagerPoolingTest.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateless/StatelessInstanceManagerPoolingTest.java?rev=950801&r1=950800&r2=950801&view=diff
==============================================================================
---
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateless/StatelessInstanceManagerPoolingTest.java
(original)
+++
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateless/StatelessInstanceManagerPoolingTest.java
Wed Jun 2 22:33:22 2010
@@ -23,6 +23,7 @@ import java.util.concurrent.atomic.Atomi
import javax.ejb.Remote;
import javax.ejb.Stateless;
+import javax.ejb.ConcurrentAccessTimeoutException;
import javax.naming.InitialContext;
import javax.naming.NamingException;
@@ -148,10 +149,9 @@ public class StatelessInstanceManagerPoo
public void run(){
try{
counter.race(startingLine, startPistol);
- }catch (Exception ex){
+ }catch (ConcurrentAccessTimeoutException ex){
comment("Leap Start");
timeouts.countDown();
- assertEquals("An invocation of the Stateless Session Bean
CounterBean has timed-out", ex.getMessage());
}
}
};
Added:
openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/ConnectionPoolTimeoutException.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/ConnectionPoolTimeoutException.java?rev=950801&view=auto
==============================================================================
---
openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/ConnectionPoolTimeoutException.java
(added)
+++
openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/ConnectionPoolTimeoutException.java
Wed Jun 2 22:33:22 2010
@@ -0,0 +1,35 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.client;
+
+import javax.ejb.ConcurrentAccessException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConnectionPoolTimeoutException extends ConcurrentAccessException {
+ public ConnectionPoolTimeoutException() {
+ }
+
+ public ConnectionPoolTimeoutException(String s, Exception e) {
+ super(s, e);
+ }
+
+ public ConnectionPoolTimeoutException(String s) {
+ super(s);
+ }
+}
Propchange:
openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/ConnectionPoolTimeoutException.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBInvocationHandler.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBInvocationHandler.java?rev=950801&r1=950800&r2=950801&view=diff
==============================================================================
---
openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBInvocationHandler.java
(original)
+++
openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBInvocationHandler.java
Wed Jun 2 22:33:22 2010
@@ -26,6 +26,7 @@ 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;
@@ -51,7 +52,7 @@ public abstract class EJBInvocationHandl
protected transient boolean inProxyMap = false;
- protected transient boolean isInvalidReference = false;
+ protected transient AtomicBoolean isInvalidReference = new
AtomicBoolean(false);
protected transient EJBRequest request;
@@ -105,7 +106,7 @@ public abstract class EJBInvocationHandl
}
public Object invoke(Object proxy, Method method, Object[] args) throws
Throwable {
- if (isInvalidReference) {
+ if (isInvalidReference.get()) {
if (remote ||
java.rmi.Remote.class.isAssignableFrom(method.getDeclaringClass())){
throw new NoSuchObjectException("reference is invalid");
} else {
@@ -145,12 +146,7 @@ public abstract class EJBInvocationHandl
}
protected void invalidateReference() {
- this.server = null;
- this.client = null;
-// this.ejb = null;
- this.inProxyMap = false;
- this.isInvalidReference = true;
- this.primaryKey = null;
+ this.isInvalidReference.set(true);
}
protected static void invalidateAllHandlers(Object key) {
Modified:
openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBObjectHandler.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBObjectHandler.java?rev=950801&r1=950800&r2=950801&view=diff
==============================================================================
---
openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBObjectHandler.java
(original)
+++
openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBObjectHandler.java
Wed Jun 2 22:33:22 2010
@@ -113,7 +113,7 @@ public abstract class EJBObjectHandler e
return ejbObject;
}
- public synchronized Object _invoke(Object p, Method m, Object[] a) throws
Throwable {
+ public Object _invoke(Object p, Method m, Object[] a) throws Throwable {
Object retValue = null;
/*
@@ -179,8 +179,14 @@ public abstract class EJBObjectHandler e
}
} catch (Throwable oe) {
if (remote) {
+ if (oe instanceof RemoteException) {
+ throw (RemoteException) oe;
+ }
throw new RemoteException("Unknown Container Exception: " +
oe.getClass().getName() + ": " + oe.getMessage(), getCause(oe));
} else {
+ if (oe instanceof EJBException) {
+ throw (EJBException) oe;
+ }
throw new EJBException("Unknown Container Exception: " +
oe.getClass().getName() + ": " + oe.getMessage()).initCause(getCause(oe));
}
}
Modified:
openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/SocketConnectionFactory.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/SocketConnectionFactory.java?rev=950801&r1=950800&r2=950801&view=diff
==============================================================================
---
openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/SocketConnectionFactory.java
(original)
+++
openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/SocketConnectionFactory.java
Wed Jun 2 22:33:22 2010
@@ -28,8 +28,8 @@ import java.net.ConnectException;
import java.net.Socket;
import java.net.URI;
import java.util.Map;
-import java.util.Stack;
import java.util.Properties;
+import java.util.Stack;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
@@ -42,18 +42,29 @@ public class SocketConnectionFactory imp
private static Map<URI, Pool> connections = new ConcurrentHashMap<URI,
Pool>();
private int size = 5;
- private int timeout = 120;
+ private long timeout = 1000;
public SocketConnectionFactory() {
+
+ size = getSize();
+ timeout = getTimeout();
+ }
+
+ private long getTimeout() {
Properties p = System.getProperties();
+ long timeout = getLong(p, "openejb.client.connectionpool.timeout",
this.timeout);
+ timeout = getLong(p, "openejb.client.connection.pool.timeout",
timeout);
+ return timeout;
+ }
- size = getInt(p, "openejb.client.connectionpool.size", size);
+ private int getSize() {
+ Properties p = System.getProperties();
+ int size = getInt(p, "openejb.client.connectionpool.size", this.size);
size = getInt(p, "openejb.client.connection.pool.size", size);
- timeout = getInt(p, "openejb.client.connectionpool.timeout", timeout);
- timeout = getInt(p, "openejb.client.connection.pool.timeout", timeout);
+ return size;
}
- public static int getInt(Properties p, String property, int defaultValue){
+ public static int getInt(Properties p, String property, int defaultValue) {
String value = p.getProperty(property);
try {
if (value != null) return Integer.parseInt(value);
@@ -63,6 +74,16 @@ public class SocketConnectionFactory imp
}
}
+ public static long getLong(Properties p, String property, long
defaultValue) {
+ String value = p.getProperty(property);
+ try {
+ if (value != null) return Long.parseLong(value);
+ else return defaultValue;
+ } catch (NumberFormatException e) {
+ return defaultValue;
+ }
+ }
+
public Connection getConnection(URI uri) throws java.io.IOException {
Pool pool = getPool(uri);
@@ -79,9 +100,10 @@ public class SocketConnectionFactory imp
}
try {
- conn.lock.tryLock(60 * 5, TimeUnit.SECONDS);
+ conn.lock.tryLock(2, TimeUnit.SECONDS);
} catch (InterruptedException e) {
Thread.interrupted();
+ pool.put(conn);
throw new IOException("Connection busy");
}
@@ -117,7 +139,7 @@ public class SocketConnectionFactory imp
private Pool getPool(URI uri) {
Pool pool = connections.get(uri);
if (pool == null) {
- pool = new Pool(size, timeout);
+ pool = new Pool(getSize(), getTimeout());
connections.put(uri, pool);
}
return pool;
@@ -277,7 +299,7 @@ public class SocketConnectionFactory imp
this.semaphore = new Semaphore(size);
this.pool = new Stack<SocketConnection>();
this.timeout = timeout;
- this.timeUnit = TimeUnit.SECONDS;
+ this.timeUnit = TimeUnit.MILLISECONDS;
Object[] objects = new Object[size];
for (int i = 0; i < objects.length; i++) {
@@ -294,7 +316,7 @@ public class SocketConnectionFactory imp
Thread.interrupted();
}
- throw new IllegalStateException("No connections available in pool
(size " + size + "). Waited for " + timeout + " seconds for a connection.");
+ throw new ConnectionPoolTimeoutException("No connections available
in pool (size " + size + "). Waited for " + timeout + " seconds for a
connection.");
}
public void put(SocketConnection connection) {
Modified:
openejb/trunk/openejb3/server/openejb-ejbd/src/test/java/org/apache/openejb/server/ejbd/MultithreadTest.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-ejbd/src/test/java/org/apache/openejb/server/ejbd/MultithreadTest.java?rev=950801&r1=950800&r2=950801&view=diff
==============================================================================
---
openejb/trunk/openejb3/server/openejb-ejbd/src/test/java/org/apache/openejb/server/ejbd/MultithreadTest.java
(original)
+++
openejb/trunk/openejb3/server/openejb-ejbd/src/test/java/org/apache/openejb/server/ejbd/MultithreadTest.java
Wed Jun 2 22:33:22 2010
@@ -16,33 +16,173 @@
*/
package org.apache.openejb.server.ejbd;
+import junit.framework.TestCase;
import org.apache.openejb.OpenEJB;
+import org.apache.openejb.client.ConnectionPoolTimeoutException;
+import org.apache.openejb.assembler.classic.Assembler;
+import org.apache.openejb.assembler.classic.StatelessSessionContainerInfo;
+import org.apache.openejb.config.ConfigurationFactory;
+import org.apache.openejb.core.ServerFederation;
import org.apache.openejb.jee.EjbJar;
import org.apache.openejb.jee.StatelessBean;
-import org.apache.openejb.config.ConfigurationFactory;
import org.apache.openejb.loader.SystemInstance;
-import org.apache.openejb.assembler.classic.Assembler;
import org.apache.openejb.server.ServiceDaemon;
import org.apache.openejb.server.ServicePool;
-import org.apache.openejb.core.ServerFederation;
+import javax.ejb.Remote;
+import javax.ejb.Stateless;
+import javax.ejb.ConcurrentAccessException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
-import javax.ejb.Remote;
import java.util.Properties;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
-
-import junit.framework.Assert;
-import junit.framework.TestCase;
+import java.util.concurrent.atomic.AtomicInteger;
/**
* @version $Rev$ $Date$
*/
public class MultithreadTest extends TestCase {
- public void test() throws Exception {
+ private ServiceDaemon serviceDaemon;
+ private Counter counter;
+
+ private static CountDownLatch startPistol;
+ private static CountDownLatch startingLine;
+ private static CountDownLatch invocations;
+
+ public void testStatelessBeanPooling() throws Exception {
+
+ startPistol = new CountDownLatch(1);
+ startingLine = new CountDownLatch(10);
+ final CountDownLatch finishingLine = new CountDownLatch(30);
+
+ // Do a business method...
+ Runnable r = new Runnable() {
+ public void run() {
+ counter.race();
+ finishingLine.countDown();
+ }
+ };
+
+ // -- READY --
+
+ // How much ever the no of client invocations the count should be 10
as only 10 instances will be created.
+ for (int i = 0; i < 30; i++) {
+ Thread t = new Thread(r);
+ t.start();
+ }
+
+ // Wait for the beans to reach the finish line
+ startingLine.await(1000, TimeUnit.MILLISECONDS);
+
+ // -- SET --
+
+ assertEquals(10, CounterBean.instances.get());
+
+ // -- GO --
+
+ startPistol.countDown(); // go
+
+ finishingLine.await(1000, TimeUnit.MILLISECONDS);
+
+ // -- DONE --
+
+ assertEquals(10, CounterBean.instances.get());
+
+ }
+
+ public void testStatelessBeanRelease() throws Exception {
+
+ invocations = new CountDownLatch(30);
+
+ // Do a business method...
+ Runnable r = new Runnable(){
+ public void run(){
+ try{
+ counter.explode();
+ }catch(Exception e){
+
+ }
+ }
+ };
+
+ // -- READY --
+
+ // 30 instances should be created and discarded.
+ for (int i = 0; i < 30; i++) {
+ Thread t = new Thread(r);
+ t.start();
+ }
+
+ boolean success = invocations.await(10000, TimeUnit.MILLISECONDS);
+
+ assertTrue(success);
+
+ assertEquals(30, CounterBean.discardedInstances.get());
+
+ }
+
+
+ public void testStatelessBeanTimeout() throws Exception {
+
+ final CountDownLatch timeouts = new CountDownLatch(10);
+ startPistol = new CountDownLatch(1);
+ startingLine = new CountDownLatch(10);
+
+ // Do a business method...
+ Runnable r = new Runnable(){
+ public void run(){
+ try{
+ counter.race();
+ }catch (ConcurrentAccessException ex){
+ comment("Leap Start");
+ timeouts.countDown();
+ assertEquals("An invocation of the Stateless Session Bean
CounterBean has timed-out", ex.getMessage());
+ } catch (Throwable t) {
+ fail("Unexpected exception" + t.getClass().getName() + " "
+ t.getMessage());
+ }
+ }
+ };
+
+
+ comment("On your mark!");
+
+ for (int i = 0; i < 20; i++) {
+ Thread t = new Thread(r);
+ t.start();
+ }
+
+ // Wait for the beans to reach the start line
+ assertTrue("expected 10 invocations", startingLine.await(3000,
TimeUnit.MILLISECONDS));
+
+ comment("Get Set!");
+
+ // Wait for the other beans timeout
+ assertTrue("expected 10 timeouts", timeouts.await(300000,
TimeUnit.MILLISECONDS));
+
+ assertEquals(10, CounterBean.instances.get());
+
+ comment("Go!");
+
+ startPistol.countDown(); // go
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ serviceDaemon.stop();
+ OpenEJB.destroy();
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ int poolSize = 10;
+
+ System.setProperty("openejb.client.connectionpool.size", "" +
(poolSize*2));
+
EjbServer ejbServer = new EjbServer();
KeepAliveServer keepAliveServer = new KeepAliveServer(ejbServer);
@@ -52,95 +192,113 @@ public class MultithreadTest extends Tes
OpenEJB.init(initProps, new ServerFederation());
ejbServer.init(new Properties());
- ServicePool pool = new ServicePool(keepAliveServer, "ejbd", 10);
- ServiceDaemon serviceDaemon = new ServiceDaemon(pool, 0, "localhost");
+ ServicePool pool = new ServicePool(keepAliveServer, "ejbd",
(poolSize*2));
+ this.serviceDaemon = new ServiceDaemon(pool, 0, "localhost");
serviceDaemon.start();
- try {
+ int port = serviceDaemon.getPort();
- int port = serviceDaemon.getPort();
+ ConfigurationFactory config = new ConfigurationFactory();
+ Assembler assembler =
SystemInstance.get().getComponent(Assembler.class);
- Assembler assembler =
SystemInstance.get().getComponent(Assembler.class);
- ConfigurationFactory config = new ConfigurationFactory();
+ // containers
+ StatelessSessionContainerInfo statelessContainerInfo =
config.configureService(StatelessSessionContainerInfo.class);
+ statelessContainerInfo.properties.setProperty("TimeOut", "100");
+ statelessContainerInfo.properties.setProperty("PoolSize", "" +
poolSize);
+ statelessContainerInfo.properties.setProperty("PoolMin", "2");
+ statelessContainerInfo.properties.setProperty("StrictPooling", "true");
+ assembler.createContainer(statelessContainerInfo);
+
+ // Setup the descriptor information
+
+ StatelessBean bean = new StatelessBean(CounterBean.class);
+ bean.addBusinessLocal(Counter.class.getName());
+ bean.addBusinessRemote(RemoteCounter.class.getName());
+ bean.addPostConstruct("init");
+ bean.addPreDestroy("destroy");
+
+ EjbJar ejbJar = new EjbJar();
+ ejbJar.addEnterpriseBean(bean);
+
+ CounterBean.instances.set(0);
+ assembler.createApplication(config.configureApplication(ejbJar));
+
+ Properties props = new Properties();
+ props.put("java.naming.factory.initial",
"org.apache.openejb.client.RemoteInitialContextFactory");
+ props.put("java.naming.provider.url", "ejbd://127.0.0.1:" + port);
+ Context context = new InitialContext(props);
+ counter = (Counter) context.lookup("CounterBeanRemote");
+ }
- EjbJar ejbJar = new EjbJar();
- ejbJar.addEnterpriseBean(new StatelessBean(EchoBean.class));
- assembler.createApplication(config.configureApplication(ejbJar));
+ public static Object lock = new Object[]{};
- // good creds
+ private static void comment(String x) {
+// synchronized(lock){
+// System.out.println(x);
+// System.out.flush();
+// }
+ }
- int threads = 20;
- CountDownLatch latch = new CountDownLatch(threads);
+ public static interface Counter {
+ int count();
- for (int i = 0; i < threads; i++) {
- Client client = new Client(latch, i, port);
- thread(client, false);
- }
+ void race();
- assertTrue(latch.await(60, TimeUnit.SECONDS));
- } finally {
- serviceDaemon.stop();
- OpenEJB.destroy();
- }
+ void explode();
}
- public static void thread(Runnable runnable, boolean daemon) {
- Thread thread = new Thread(runnable);
- thread.setDaemon(daemon);
- thread.start();
+ @Remote
+ public static interface RemoteCounter extends Counter {
+
}
- public static class Client implements Runnable {
+ @Stateless
+ public static class CounterBean implements Counter, RemoteCounter {
- private final Echo echo;
- private final CountDownLatch latch;
- private final int id;
+ public static AtomicInteger instances = new AtomicInteger();
+ public static AtomicInteger discardedInstances = new AtomicInteger();
- public Client(CountDownLatch latch, int i, int port) throws
NamingException {
- this.latch = latch;
- this.id = i;
+ private int count;
- Properties props = new Properties();
- props.put("java.naming.factory.initial",
"org.apache.openejb.client.RemoteInitialContextFactory");
- props.put("java.naming.provider.url", "ejbd://127.0.0.1:" + port
+"?"+id);
- Context context = new InitialContext(props);
+ public CounterBean() {
+ count = instances.incrementAndGet();
+ }
- this.echo = (Echo) context.lookup("EchoBeanRemote");
+ public int count() {
+ return instances.get();
}
- public void run() {
+ public int discardCount() {
+ return discardedInstances.get();
+ }
+ public void explode() {
try {
- int count = 250;
- for (; count >= 0; count--){
- String message = count + " bottles of beer on the wall";
-
-// Thread.currentThread().setName("client-"+id+": "+count);
-
- String response = echo.echo(message);
- Assert.assertEquals(message, reverse(response));
- }
+ discardedInstances.incrementAndGet();
+ throw new NullPointerException();
} finally {
- latch.countDown();
+ invocations.countDown();
}
}
- private Object reverse(String s) {
- return new StringBuilder(s).reverse().toString();
+ public void race() {
+ comment("ready = " + count);
+ startingLine.countDown();
+ try {
+ startPistol.await();
+ comment("running = " + count);
+ } catch (InterruptedException e) {
+ Thread.interrupted();
+ }
}
- }
+ public void init() {
- public static class EchoBean implements Echo {
- public String echo(String s) {
-// System.out.println(s);
- return new StringBuilder(s).reverse().toString();
}
- }
- @Remote
- public static interface Echo {
- public String echo(String s);
+ public void destroy() {
+
+ }
}
}
Modified:
openejb/trunk/openejb3/server/openejb-server/src/main/java/org/apache/openejb/server/ServiceDaemon.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-server/src/main/java/org/apache/openejb/server/ServiceDaemon.java?rev=950801&r1=950800&r2=950801&view=diff
==============================================================================
---
openejb/trunk/openejb3/server/openejb-server/src/main/java/org/apache/openejb/server/ServiceDaemon.java
(original)
+++
openejb/trunk/openejb3/server/openejb-server/src/main/java/org/apache/openejb/server/ServiceDaemon.java
Wed Jun 2 22:33:22 2010
@@ -53,7 +53,7 @@ public class ServiceDaemon implements Se
private SocketListener socketListener;
- private int timeout;
+ private int timeout = 1000;
private InetAddress address;
@@ -131,7 +131,7 @@ public class ServiceDaemon implements Se
secure = options.get("secure", false);
- timeout = 1000;
+ timeout = options.get("timeout", timeout);
next.init(props);
}