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 2015/04/10 00:49:48 UTC
[2/2] tomee git commit: new file
new file
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/ce7d7480
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/ce7d7480
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/ce7d7480
Branch: refs/heads/master
Commit: ce7d7480f841d7cc262d3776d31d1f331083e139
Parents: 32cdf86
Author: Romain Manni-Bucau <rm...@apache.org>
Authored: Fri Apr 10 00:49:36 2015 +0200
Committer: Romain Manni-Bucau <rm...@apache.org>
Committed: Fri Apr 10 00:49:36 2015 +0200
----------------------------------------------------------------------
.../org/apache/openejb/core/timer/Timers.java | 116 +++++++++++++++++++
1 file changed, 116 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/ce7d7480/container/openejb-core/src/main/java/org/apache/openejb/core/timer/Timers.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/core/timer/Timers.java b/container/openejb-core/src/main/java/org/apache/openejb/core/timer/Timers.java
new file mode 100644
index 0000000..273d109
--- /dev/null
+++ b/container/openejb-core/src/main/java/org/apache/openejb/core/timer/Timers.java
@@ -0,0 +1,116 @@
+/*
+ * 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.core.timer;
+
+import org.apache.openejb.BeanContext;
+import org.apache.openejb.BeanType;
+import org.apache.openejb.MethodContext;
+import org.apache.openejb.ModuleContext;
+import org.apache.openejb.core.ThreadContext;
+import org.apache.openejb.util.LogCategory;
+import org.apache.openejb.util.Logger;
+
+import java.lang.reflect.Method;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import javax.ejb.Timer;
+import javax.ejb.TimerService;
+
+public final class Timers {
+ private static final Logger LOGGER = Logger.getInstance(LogCategory.TIMER, TimerServiceWrapper.class);
+
+ private Timers() {
+ // no-op
+ }
+
+ public static Collection<Timer> all() {
+ final ThreadContext threadContext = ThreadContext.getThreadContext();
+ final BeanContext beanContext = threadContext.getBeanContext();
+ final ModuleContext module = beanContext.getModuleContext();
+
+ final Collection<Timer> timers = new HashSet<>();
+ for (final BeanContext c : module.getAppContext().getBeanContexts()) {
+ if (c.getModuleContext() == module) { // filter by module
+ if (c.getComponentType() != BeanType.STATEFUL) {
+ final TimerService timerService = getTimerService(null, c, true);
+ if (timerService == null) {
+ continue;
+ }
+ final Collection<Timer> beanTimers = timerService.getTimers();
+ timers.addAll(beanTimers);
+ } else {
+ // for all instances
+ final TimerService timerService = getTimerService(null, c, true);
+ if (timerService == null) {
+ continue;
+ }
+ final Collection<Timer> beanTimers = timerService.getTimers();
+ timers.addAll(beanTimers);
+ }
+ }
+ }
+ return timers;
+ }
+
+ public static TimerService getTimerService(final Object pk, final BeanContext beanContext, final boolean nullIfNotRelevant) throws IllegalStateException {
+ final EjbTimerService timerService = beanContext.getEjbTimerService();
+ if (timerService == null) {
+ throw new IllegalStateException("This ejb does not support timers " + beanContext.getDeploymentID());
+ } else if (beanContext.getEjbTimeout() == null) {
+
+ HasSchedule hasSchedule = beanContext.get(HasSchedule.class);
+
+ boolean hasSchedules = false;
+
+ if (hasSchedule != null) {
+ hasSchedules = hasSchedule.value;
+ } else {
+ for (final Iterator<Map.Entry<Method, MethodContext>> it = beanContext.iteratorMethodContext(); it.hasNext(); ) {
+ final Map.Entry<Method, MethodContext> entry = it.next();
+ final MethodContext methodContext = entry.getValue();
+ if (methodContext.getSchedules().size() > 0) {
+ hasSchedules = true;
+ }
+ }
+ synchronized (beanContext) { // surely not the best lock instance but works in this context
+ if (beanContext.get(HasSchedule.class) == null) {
+ beanContext.set(HasSchedule.class, new HasSchedule(hasSchedules));
+ }
+ }
+ }
+
+ if (!hasSchedules) {
+ if (nullIfNotRelevant) {
+ return null;
+ }
+ LOGGER.error("This ejb does not support timers " + beanContext.getDeploymentID() + " due to no timeout method nor schedules in methodContext is configured");
+ }
+
+ }
+ return new TimerServiceImpl(timerService, pk, beanContext.getEjbTimeout());
+ }
+
+ private static final class HasSchedule {
+ private final boolean value;
+
+ private HasSchedule(final boolean value) {
+ this.value = value;
+ }
+ }
+}