KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > bpe > timer > BPETimerServiceJdk


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * 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  */

17 package org.apache.servicemix.bpe.timer;
18
19 import java.util.Date JavaDoc;
20 import java.util.Timer JavaDoc;
21
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24
25 import org.apache.ode.bpe.event.ITimerEvent;
26 import org.apache.ode.bpe.timerservice.IBPETimer;
27 import org.apache.ode.bpe.timerservice.IBPETimerService;
28 import org.apache.ode.bpe.util.BPEProperties;
29 import org.apache.ode.bpe.util.BPException;
30 import org.apache.servicemix.bpe.BPEEndpoint;
31
32 public class BPETimerServiceJdk implements IBPETimerService {
33
34     private static final Log log = LogFactory.getLog(BPETimerServiceJdk.class);
35     private static Timer JavaDoc timer;
36     
37     public BPETimerServiceJdk() {
38         super();
39     }
40
41     public IBPETimer createTimer(long startDuration, ITimerEvent timerEvent) throws BPException {
42         if (log.isDebugEnabled()) {
43             log.debug("Schedule timer " + timerEvent + " for " + startDuration);
44         }
45         BPETimerJdk tt = new BPETimerJdk(timerEvent, BPEEndpoint.getCurrent());
46         timer.schedule(tt, startDuration);
47         return tt;
48     }
49
50     public IBPETimer createTimer(Date JavaDoc startTime, ITimerEvent timerEvent) throws BPException {
51         if (log.isDebugEnabled()) {
52             log.debug("Schedule timer " + timerEvent + " at " + startTime);
53         }
54         BPETimerJdk tt = new BPETimerJdk(timerEvent, BPEEndpoint.getCurrent());
55         timer.schedule(tt, startTime);
56         return tt;
57     }
58
59     public void removeTimer(IBPETimer timer) throws BPException {
60         if (log.isDebugEnabled()) {
61             log.debug("Timer " + timer.getTimerEvent() + " cancelled");
62         }
63         ((BPETimerJdk) timer).cancel();
64
65     }
66
67     public void init(BPEProperties props) throws BPException {
68         synchronized (BPETimerServiceJdk.class) {
69             if (timer == null) {
70                 timer = new Timer JavaDoc();
71             }
72         }
73     }
74
75 }
76
Popular Tags