KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > deployment > scheduler > SchedulerTask


1 /*
2  * Copyright 2004,2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.axis2.deployment.scheduler;
18
19 import org.apache.axis2.deployment.DeploymentEngine;
20 import org.apache.axis2.deployment.listener.RepositoryListener;
21 import org.apache.axis2.deployment.listener.RepositoryListenerImpl;
22
23 import java.util.TimerTask JavaDoc;
24
25 public class SchedulerTask implements Runnable JavaDoc {
26
27     final Object JavaDoc lock = new Object JavaDoc();
28
29     private RepositoryListener wsListener;
30
31     int state = 0;
32     static final int SCHEDULED = 1;
33     static final int CANCELLED = 2;
34
35     TimerTask JavaDoc timerTask;
36
37     /**
38      * Creates a new scheduler task.
39      */

40
41     public SchedulerTask(DeploymentEngine deploy_engine, String JavaDoc folderName) {
42         wsListener = new RepositoryListenerImpl(folderName, deploy_engine);
43     }
44
45     /**
46      * The action to be performed by this scheduler task.
47      */

48
49     public void run() {
50         checkRepositary();
51     }
52
53     private void checkRepositary() {
54         ((RepositoryListenerImpl) wsListener).startListent();
55     }
56
57     /**
58      * Cancels this scheduler task.
59      * <p/>
60      * This method may be called repeatedly; the second and subsequent calls have no effect.
61      *
62      * @return true if this task was already scheduled to run
63      */

64
65     public boolean cancel() {
66         synchronized (lock) {
67             if (timerTask != null) {
68                 timerTask.cancel();
69             }
70             boolean result = (state == SCHEDULED);
71             state = CANCELLED;
72             return result;
73         }
74     }
75
76 }
77
Popular Tags