01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19:
20: package org.apache.axis2.deployment.scheduler;
21:
22: import org.apache.axis2.deployment.RepositoryListener;
23:
24: import java.util.TimerTask;
25:
26: public class SchedulerTask implements Runnable {
27: static final int SCHEDULED = 1;
28: static final int CANCELLED = 2;
29: final Object lock = new Object();
30: int state = 0;
31: TimerTask timerTask;
32: private RepositoryListener wsListener;
33:
34: /**
35: * Creates a new scheduler task.
36: */
37: public SchedulerTask(RepositoryListener listener) {
38: this .wsListener = listener;
39: }
40:
41: /**
42: * Cancels this scheduler task.
43: * <p/>
44: * This method may be called repeatedly; the second and subsequent calls have no effect.
45: *
46: * @return Returns true if this task was already scheduled to run.
47: */
48: public boolean cancel() {
49: synchronized (lock) {
50: if (timerTask != null) {
51: timerTask.cancel();
52: }
53:
54: boolean result = (state == SCHEDULED);
55:
56: state = CANCELLED;
57:
58: return result;
59: }
60: }
61:
62: private void checkRepository() {
63: wsListener.startListener();
64: }
65:
66: /**
67: * The action to be performed by this scheduler task.
68: */
69: public void run() {
70: checkRepository();
71: }
72: }
|