KickJava   Java API By Example, From Geeks To Geeks.

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


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.List JavaDoc;
20
21 /**
22  * Represents a activity which joins on the completion of a collection of child
23  * activities.
24  *
25  * @version $Revision: $
26  */

27 public class JoinAll extends JoinSupport {
28
29     private boolean failFast;
30
31     public JoinAll() {
32         super();
33     }
34
35     public JoinAll(Activity... activities) {
36         super(activities);
37     }
38
39     public JoinAll(List JavaDoc<Activity> activities) {
40         super(activities);
41     }
42
43     public boolean isFailFast() {
44         return failFast;
45     }
46
47     /**
48      * If fail fast mode is enabled then this activity fails as soon as a child
49      * activity fails. The default is to wait for all the child activities to
50      * complete irrespective of whether they stop succesfully or fail before
51      * completing this activity
52      */

53     public void setFailFast(boolean failFast) {
54         this.failFast = failFast;
55     }
56
57     /**
58      * Decide whether or not we are done based on the number of children, the
59      * number of child activities stopped and the number of failed activities
60      */

61     protected void onChildStateChange(int childCount, int stoppedCount, int failedCount) {
62         //System.out.println("This: " + this + " child: " + childCount + " stopped: " + stoppedCount + " failed: " + failedCount);
63
if (failFast && failedCount > 0) {
64             fail("" + failedCount + " child workactivities have failed");
65         }
66         if (childCount <= stoppedCount) {
67             if (failedCount > 0) {
68                 fail("" + failedCount + " child workactivities have failed");
69             }
70             else {
71                 stop();
72             }
73         }
74     }
75
76 }
77
Popular Tags