01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.openejb.core.timer;
17:
18: import javax.ejb.EJBException;
19: import javax.ejb.Timer;
20: import javax.ejb.TimerService;
21:
22: import org.apache.openejb.DeploymentInfo;
23: import org.apache.openejb.core.ThreadContext;
24:
25: import java.io.Serializable;
26: import java.util.Collection;
27: import java.util.Date;
28:
29: public class TimerServiceWrapper implements TimerService {
30:
31: public TimerServiceWrapper() {
32: }
33:
34: public Timer createTimer(Date initialExpiration,
35: long intervalDuration, Serializable info)
36: throws IllegalArgumentException, IllegalStateException,
37: EJBException {
38: return getTimerService().createTimer(initialExpiration,
39: intervalDuration, info);
40: }
41:
42: public Timer createTimer(Date expiration, Serializable info)
43: throws IllegalArgumentException, IllegalStateException,
44: EJBException {
45: return getTimerService().createTimer(expiration, info);
46: }
47:
48: public Timer createTimer(long initialDuration,
49: long intervalDuration, Serializable info)
50: throws IllegalArgumentException, IllegalStateException,
51: EJBException {
52: return getTimerService().createTimer(initialDuration,
53: intervalDuration, info);
54: }
55:
56: public Timer createTimer(long duration, Serializable info)
57: throws IllegalArgumentException, IllegalStateException,
58: EJBException {
59: return getTimerService().createTimer(duration, info);
60: }
61:
62: public Collection getTimers() throws IllegalStateException,
63: EJBException {
64: return getTimerService().getTimers();
65: }
66:
67: private TimerService getTimerService() throws IllegalStateException {
68: ThreadContext threadContext = ThreadContext.getThreadContext();
69: DeploymentInfo deploymentInfo = threadContext
70: .getDeploymentInfo();
71: EjbTimerService timerService = deploymentInfo
72: .getEjbTimerService();
73: if (timerService == null) {
74: throw new IllegalStateException(
75: "This ejb does not support timers "
76: + deploymentInfo.getDeploymentID());
77: }
78: return new TimerServiceImpl(timerService, threadContext
79: .getPrimaryKey());
80: }
81: }
|