KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > beanflow > Activity


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.beanflow;
18
19 import java.util.Timer JavaDoc;
20 import java.util.concurrent.TimeUnit JavaDoc;
21
22 /**
23  * Represents an activity (step) in a workflow written typically using regular
24  * Java code. An activity typically monitors various {@link State} objects and
25  * takes action when things change. Activities are designed to be thread safe
26  * and are intended for use in highly concurrent or distributed applications so
27  * that the state can be changed from any thread. <br>
28  * The Processing of notifications of state changes should generally be quick;
29  * if lots of work is required when some state changes it is advisable to use a
30  * thread pool to do the work.
31  *
32  * @version $Revision: $
33  */

34 public interface Activity {
35
36     /**
37      * The core transition states of the activity
38      *
39      * @version $Revision: 1.1 $
40      */

41     public enum Transitions {
42         Initialised, Starting, Started, Stopping, Stopped, Failed
43     };
44
45     /**
46      * Starts the activity. Once it is started it can take an arbitrary amount
47      * of time to complete. The execution of an activity is usually asynchronous
48      * in nature (though its not mandatory)
49      */

50     public void start();
51
52     /**
53      * For activities that support timeout based operation this helper method
54      * starts the activity and registers the timeout
55      */

56     public void startWithTimeout(Timer JavaDoc timer, long timeout);
57
58     /**
59      * Stops the activity, setting the status to {@link Stopped}
60      */

61     public void stop();
62
63     /**
64      * Stops the activity with a failed state, giving the reason for the failure
65      */

66     public void fail(String JavaDoc reason);
67
68     /**
69      * Returns the current running state of this activity
70      */

71     public State<Transitions> getState();
72
73     /**
74      * Returns true if the activity has stopped running either successfully or
75      * if it failed
76      */

77     public boolean isStopped();
78
79     /**
80      * Returns true if the activity has failed to complete succesfully
81      */

82     public boolean isFailed();
83
84     /**
85      * If this activity has failed then return a reason for the failure
86      */

87     public String JavaDoc getFailedReason();
88
89     /**
90      * Returns the exception which caused the failure
91      */

92     public Throwable JavaDoc getFailedException();
93
94     /**
95      * A helper method to add a task to fire when the activity is completed
96      */

97     public void onStop(Runnable JavaDoc runnable);
98
99     /**
100      * A helper method to add a task to fire when the activity fails
101      */

102     public void onFailure(Runnable JavaDoc runnable);
103
104     /**
105      * A helper method to block the calling thread until the activity completes. Behaves
106      * similar to {@link Thread#join()}
107      */

108     public void join();
109
110     /**
111      * A helper method to block the calling thread up until some maximum timeout until the activity
112      * completes or the timeout expires
113      *
114      * @return true if the activity stopped within the given time or false if not.
115      */

116     public boolean join(int time, TimeUnit JavaDoc unit);
117 }
118
Popular Tags