[jboss-cvs] JBossAS SVN: r105972 - in projects/ejb3/trunk/core: src/main/java/org/jboss/ejb3 and 5 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Jun 11 12:34:20 EDT 2010
Author: jaikiran
Date: 2010-06-11 12:34:18 -0400 (Fri, 11 Jun 2010)
New Revision: 105972
Added:
projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/common/timerservice/MockTimerService.java
projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree2113/
projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree2113/TimerServiceJNDITester.java
projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree2113/TimerServiceSLSB.java
projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree2113/unit/
projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree2113/unit/TimerServiceENCBindingTestCase.java
Modified:
projects/ejb3/trunk/core/pom.xml
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainer.java
projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/common/timerservice/MockTimerServiceFactory.java
projects/ejb3/trunk/core/src/test/resources/container-beans.xml
Log:
EJBTHREE-2113 Make available TimerService at java:comp/TimerService
Modified: projects/ejb3/trunk/core/pom.xml
===================================================================
--- projects/ejb3/trunk/core/pom.xml 2010-06-11 15:35:43 UTC (rev 105971)
+++ projects/ejb3/trunk/core/pom.xml 2010-06-11 16:34:18 UTC (rev 105972)
@@ -44,6 +44,7 @@
<version.org.jboss.ejb3.context>0.1.1</version.org.jboss.ejb3.context>
<version.org.jboss.jboss-as>5.1.0.GA</version.org.jboss.jboss-as>
<version.org.jboss.security>2.0.3.SP1</version.org.jboss.security>
+ <version.org.jboss.ejb3_timerservice-naming>1.0.0-SNAPSHOT</version.org.jboss.ejb3_timerservice-naming>
<version.sun-jaxws>2.1.1</version.sun-jaxws>
</properties>
@@ -401,6 +402,14 @@
<artifactId>jboss-ejb3-timerservice-spi</artifactId>
<version>1.0.1</version>
</dependency>
+
+ <dependency>
+ <groupId>org.jboss.ejb3</groupId>
+ <artifactId>jboss-ejb3-timerservice-naming</artifactId>
+ <version>${version.org.jboss.ejb3_timerservice-naming}</version>
+ <scope>test</scope>
+ </dependency>
+
<dependency>
<groupId>org.jboss.ejb3</groupId>
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainer.java 2010-06-11 15:35:43 UTC (rev 105971)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainer.java 2010-06-11 16:34:18 UTC (rev 105972)
@@ -21,6 +21,44 @@
*/
package org.jboss.ejb3;
+import java.lang.annotation.Annotation;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.Proxy;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.Condition;
+import java.util.concurrent.locks.Lock;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.ejb.EJBException;
+import javax.ejb.Local;
+import javax.ejb.Remote;
+import javax.ejb.Timeout;
+import javax.ejb.Timer;
+import javax.ejb.TimerService;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.LinkRef;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+import javax.transaction.TransactionManager;
+
import org.jboss.aop.Advisor;
import org.jboss.aop.Domain;
import org.jboss.aop.MethodInfo;
@@ -93,42 +131,6 @@
import org.jboss.util.StringPropertyReplacer;
import org.jboss.util.naming.Util;
-import javax.annotation.PostConstruct;
-import javax.annotation.PreDestroy;
-import javax.ejb.EJBException;
-import javax.ejb.Local;
-import javax.ejb.Remote;
-import javax.ejb.Timeout;
-import javax.ejb.Timer;
-import javax.management.MalformedObjectNameException;
-import javax.management.ObjectName;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.LinkRef;
-import javax.naming.NameNotFoundException;
-import javax.naming.NamingException;
-import javax.transaction.TransactionManager;
-import java.lang.annotation.Annotation;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.reflect.AccessibleObject;
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.lang.reflect.Proxy;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.Semaphore;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.locks.Condition;
-import java.util.concurrent.locks.Lock;
-
/**
* Comment
*
@@ -333,6 +335,20 @@
}
}
+ /**
+ * Creates a {@link LinkRef} for java:comp/TimerService to
+ * an internal jndi name for {@link TimerService}
+ * @throws NamingException
+ */
+ private void bindTimerService() throws NamingException
+ {
+ // link to java:internal/TimerService (which is setup by
+ // org.jboss.ejb3.timerservice.naming.TimerServiceBinder)
+ LinkRef timerServiceLinkRef = new LinkRef("java:internal/TimerService");
+ // bind to java:comp/TimerService
+ Util.rebind(getEnc(), "TimerService", timerServiceLinkRef);
+ }
+
@Deprecated
public boolean canResolveEJB()
{
@@ -955,7 +971,8 @@
}
bindORB();
bindEJBContext();
-
+ // bind the timerservice to java:comp/TimerService
+ bindTimerService();
/*
initializeClassContainer();
for (int i = 0; i < constructors.length; i++)
Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/common/timerservice/MockTimerService.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/common/timerservice/MockTimerService.java (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/common/timerservice/MockTimerService.java 2010-06-11 16:34:18 UTC (rev 105972)
@@ -0,0 +1,75 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.core.test.common.timerservice;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.Date;
+
+import javax.ejb.EJBException;
+import javax.ejb.Timer;
+import javax.ejb.TimerService;
+
+/**
+ * Mock implementation of {@link TimerService}
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class MockTimerService implements TimerService
+{
+
+ @Override
+ public Timer createTimer(long duration, Serializable info) throws IllegalArgumentException, IllegalStateException,
+ EJBException
+ {
+ throw new UnsupportedOperationException("Not yet implemented in " + this.getClass().getName());
+ }
+
+ @Override
+ public Timer createTimer(Date expiration, Serializable info) throws IllegalArgumentException, IllegalStateException,
+ EJBException
+ {
+ throw new UnsupportedOperationException("Not yet implemented in " + this.getClass().getName());
+ }
+
+ @Override
+ public Timer createTimer(long initialDuration, long intervalDuration, Serializable info)
+ throws IllegalArgumentException, IllegalStateException, EJBException
+ {
+ throw new UnsupportedOperationException("Not yet implemented in " + this.getClass().getName());
+ }
+
+ @Override
+ public Timer createTimer(Date initialExpiration, long intervalDuration, Serializable info)
+ throws IllegalArgumentException, IllegalStateException, EJBException
+ {
+ throw new UnsupportedOperationException("Not yet implemented in " + this.getClass().getName());
+ }
+
+ @Override
+ public Collection getTimers() throws IllegalStateException, EJBException
+ {
+ throw new UnsupportedOperationException("Not yet implemented in " + this.getClass().getName());
+ }
+
+}
Modified: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/common/timerservice/MockTimerServiceFactory.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/common/timerservice/MockTimerServiceFactory.java 2010-06-11 15:35:43 UTC (rev 105971)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/common/timerservice/MockTimerServiceFactory.java 2010-06-11 16:34:18 UTC (rev 105972)
@@ -37,8 +37,7 @@
public TimerService createTimerService(TimedObjectInvoker invoker)
{
- log.warn("Running without a TimerService");
- return null;
+ return new MockTimerService();
}
public void restoreTimerService(TimerService timerService)
Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree2113/TimerServiceJNDITester.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree2113/TimerServiceJNDITester.java (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree2113/TimerServiceJNDITester.java 2010-06-11 16:34:18 UTC (rev 105972)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.core.test.ejbthree2113;
+
+/**
+ * TimerServiceJNDITester
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public interface TimerServiceJNDITester
+{
+
+ boolean isTimerServiceAvailableInENC();
+
+ boolean isTimerServiceInjected();
+}
Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree2113/TimerServiceSLSB.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree2113/TimerServiceSLSB.java (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree2113/TimerServiceSLSB.java 2010-06-11 16:34:18 UTC (rev 105972)
@@ -0,0 +1,84 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.core.test.ejbthree2113;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.Resource;
+import javax.ejb.Local;
+import javax.ejb.Stateless;
+import javax.ejb.TimerService;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+/**
+ * TimerServiceSLSB
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+ at Stateless
+ at Local(TimerServiceJNDITester.class)
+public class TimerServiceSLSB implements TimerServiceJNDITester
+{
+
+ @Resource
+ private TimerService injectedTimerService;
+
+ @PostConstruct
+ public void postConstruct()
+ {
+ this.lookupTimerServiceInENC();
+ }
+
+ @Override
+ public boolean isTimerServiceInjected()
+ {
+ return this.injectedTimerService != null;
+ }
+
+ @Override
+ public boolean isTimerServiceAvailableInENC()
+ {
+ return this.lookupTimerServiceInENC() != null;
+
+ }
+
+ /**
+ * Lookup {@link TimerService} at java:comp/TimerService
+ * @return
+ */
+ private TimerService lookupTimerServiceInENC()
+ {
+ try
+ {
+ Context ctx = new InitialContext();
+ TimerService timerService = (TimerService) ctx.lookup("java:comp/TimerService");
+ return timerService;
+ }
+ catch (NamingException ne)
+ {
+ throw new RuntimeException(ne);
+ }
+ }
+
+}
Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree2113/unit/TimerServiceENCBindingTestCase.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree2113/unit/TimerServiceENCBindingTestCase.java (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree2113/unit/TimerServiceENCBindingTestCase.java 2010-06-11 16:34:18 UTC (rev 105972)
@@ -0,0 +1,80 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.core.test.ejbthree2113.unit;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.jboss.ejb3.core.test.common.AbstractEJB3TestCase;
+import org.jboss.ejb3.core.test.ejbthree2113.TimerServiceJNDITester;
+import org.jboss.ejb3.core.test.ejbthree2113.TimerServiceSLSB;
+import org.jboss.ejb3.session.SessionContainer;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * TimerServiceENCBindingTestCase
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class TimerServiceENCBindingTestCase extends AbstractEJB3TestCase
+{
+
+ private static SessionContainer container;
+
+ @BeforeClass
+ public static void beforeClass() throws Exception
+ {
+ AbstractEJB3TestCase.beforeClass();
+
+ // Deploy the test SLSB
+ container = deploySessionEjb(TimerServiceSLSB.class);
+ }
+
+ @AfterClass
+ public static void afterClass() throws Exception
+ {
+ // Undeploy the test SLSB
+ undeployEjb(container);
+
+ AbstractEJB3TestCase.afterClass();
+ }
+
+ @Test
+ public void testTimerServiceInENC() throws Exception
+ {
+ Context ctx = new InitialContext();
+ TimerServiceJNDITester timerServiceBean = (TimerServiceJNDITester) ctx.lookup(TimerServiceSLSB.class
+ .getSimpleName()
+ + "/local");
+ // check ENC
+ Assert.assertTrue("Timerservice was *not* available at java:comp/TimerService", timerServiceBean
+ .isTimerServiceAvailableInENC());
+ // check injection
+ Assert.assertTrue("Timerservice was *not* injected into bean", timerServiceBean.isTimerServiceInjected());
+
+ }
+
+}
Modified: projects/ejb3/trunk/core/src/test/resources/container-beans.xml
===================================================================
--- projects/ejb3/trunk/core/src/test/resources/container-beans.xml 2010-06-11 15:35:43 UTC (rev 105971)
+++ projects/ejb3/trunk/core/src/test/resources/container-beans.xml 2010-06-11 16:34:18 UTC (rev 105972)
@@ -12,4 +12,6 @@
<bean name="JNDIKernelRegistryPlugin" class="org.jboss.ejb3.kernel.JNDIKernelRegistryPlugin"/>
<bean name="EJBContextBinder" class="org.jboss.ejb3.context.naming.EJBContextBinder"/>
+
+ <bean name="TimerServiceBinder" class="org.jboss.ejb3.timerservice.naming.TimerServiceBinder"/>
</deployment>
More information about the jboss-cvs-commits
mailing list