You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2013/11/18 07:34:36 UTC

svn commit: r1542915 - in /tomee/tomee/trunk/container/openejb-core/src: main/java/org/apache/openejb/assembler/classic/Assembler.java test/java/org/apache/openejb/timer/TimersOffTest.java

Author: rmannibucau
Date: Mon Nov 18 06:34:36 2013
New Revision: 1542915

URL: http://svn.apache.org/r1542915
Log:
TOMEE-1077 openejb.timers.on property

Added:
    tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/timer/TimersOffTest.java
Modified:
    tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java

Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java?rev=1542915&r1=1542914&r2=1542915&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java (original)
+++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java Mon Nov 18 06:34:36 2013
@@ -215,6 +215,7 @@ public class Assembler extends Assembler
     private static final String GLOBAL_UNIQUE_ID = "global";
     public static final String TIMER_STORE_CLASS = "timerStore.class";
     private static final ReentrantLock lock = new ReentrantLock(true);
+    public static final String OPENEJB_TIMERS_ON = "openejb.timers.on";
 
     private final boolean skipLoaderIfPossible;
 
@@ -957,6 +958,8 @@ public class Assembler extends Assembler
 
     public List<BeanContext> initEjbs(final ClassLoader classLoader, final AppInfo appInfo, final AppContext appContext,
                                       final Set<Injection> injections, final List<BeanContext> allDeployments, final String webappId) throws OpenEJBException {
+        final String globalTimersOn = SystemInstance.get().getProperty(OPENEJB_TIMERS_ON, "true");
+
         final EjbJarBuilder ejbJarBuilder = new EjbJarBuilder(props, appContext);
         for (final EjbJarInfo ejbJar : appInfo.ejbJars) {
             boolean skip = false;
@@ -1020,7 +1023,8 @@ public class Assembler extends Assembler
                             }
                         }
                     }
-                    if (timerServiceRequired) {
+
+                    if (timerServiceRequired && "true".equalsIgnoreCase(appInfo.properties.getProperty(OPENEJB_TIMERS_ON, globalTimersOn))) {
                         // Create the timer
                         final EjbTimerServiceImpl timerService = new EjbTimerServiceImpl(beanContext, newTimerStore(beanContext));
                         //Load auto-start timers

Added: tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/timer/TimersOffTest.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/timer/TimersOffTest.java?rev=1542915&view=auto
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/timer/TimersOffTest.java (added)
+++ tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/timer/TimersOffTest.java Mon Nov 18 06:34:36 2013
@@ -0,0 +1,69 @@
+/**
+ *
+ * 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.timer;
+
+import org.apache.openejb.jee.EnterpriseBean;
+import org.apache.openejb.jee.SingletonBean;
+import org.apache.openejb.junit.ApplicationComposer;
+import org.apache.openejb.testing.Configuration;
+import org.apache.openejb.testing.Module;
+import org.apache.openejb.testng.PropertiesBuilder;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.ejb.EJB;
+import javax.ejb.Schedule;
+
+import java.util.Properties;
+
+import static org.junit.Assert.assertEquals;
+
+@RunWith(ApplicationComposer.class)
+public class TimersOffTest {
+    @Configuration
+    public Properties config() {
+        return new PropertiesBuilder().p("openejb.timers.on", "false").build();
+    }
+
+    @Module
+    public EnterpriseBean bean() {
+        return new SingletonBean(TimerBean.class).localBean();
+    }
+
+    @EJB
+    private TimerBean bean;
+
+    @Test
+    public void checkOff() throws InterruptedException {
+        Thread.sleep(2000);
+        assertEquals(0, bean.getCount());
+    }
+
+    public static class TimerBean {
+        private int count = 0;
+
+        @Schedule(hour = "*", minute = "*", second = "*")
+        public void inc() {
+            count++;
+        }
+
+        public int getCount() {
+            return count;
+        }
+    }
+}