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 org.apache.openejb.loader.SystemInstance;
19: import org.apache.openejb.spi.ContainerSystem;
20: import org.apache.openejb.DeploymentInfo;
21:
22: import javax.ejb.NoSuchObjectLocalException;
23: import javax.ejb.Timer;
24: import javax.ejb.TimerHandle;
25: import java.io.Serializable;
26:
27: public class TimerHandleImpl implements TimerHandle, Serializable {
28: private static final long serialVersionUID = 9198316188404706377L;
29: private final long id;
30: private final String deploymentId;
31:
32: public TimerHandleImpl(long id, String deploymentId) {
33: this .id = id;
34: this .deploymentId = deploymentId;
35: }
36:
37: public Timer getTimer() {
38: ContainerSystem containerSystem = SystemInstance.get()
39: .getComponent(ContainerSystem.class);
40: if (containerSystem == null) {
41: throw new NoSuchObjectLocalException(
42: "OpenEJb container system is not running");
43: }
44: DeploymentInfo deploymentInfo = containerSystem
45: .getDeploymentInfo(deploymentId);
46: if (deploymentInfo == null) {
47: throw new NoSuchObjectLocalException(
48: "Deployment info not found " + deploymentId);
49: }
50: EjbTimerService timerService = deploymentInfo
51: .getEjbTimerService();
52: if (timerService == null) {
53: throw new NoSuchObjectLocalException(
54: "Deployment no longer supports ejbTimout "
55: + deploymentId
56: + ". Has this ejb been redeployed?");
57: }
58: Timer timer = timerService.getTimer(id);
59: if (timer == null) {
60: throw new NoSuchObjectLocalException(
61: "Timer not found for ejb " + deploymentId);
62: }
63: return timer;
64: }
65: }
|