KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > continuent > sequoia > controller > loadbalancer > policies > WaitForCompletionPolicy


1 /**
2  * Sequoia: Database clustering technology.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: sequoia@continuent.org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  * Initial developer(s): Emmanuel Cecchet.
20  * Contributor(s): ______________________________________.
21  */

22
23 package org.continuent.sequoia.controller.loadbalancer.policies;
24
25 import org.continuent.sequoia.common.xml.DatabasesXmlTags;
26
27 /**
28  * Defines the policy to adopt before returning a result to the client.
29  *
30  * @author <a HREF="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet</a>
31  * @version 1.0
32  */

33 public class WaitForCompletionPolicy
34 {
35   /** Return as soon as one node has completed the request. */
36   public static final int FIRST = 0;
37
38   /**
39    * Return as soon as a majority (n/2+1) of nodes has completed the request.
40    */

41   public static final int MAJORITY = 1;
42
43   /** Wait for all nodes to complete the request before returning the result. */
44   public static final int ALL = 2;
45
46   /** Policy (default is {@link #FIRST}). */
47   private int policy = FIRST;
48
49   /** True if strict table based locking must be enforced */
50   private boolean enforceTableLocking;
51
52   /** Deadlock detection timeout in ms */
53   private long deadlockTimeoutInMs;
54
55   /**
56    * Creates a new <code>WaitForCompletionPolicy</code> object
57    *
58    * @param policy the default policy to use
59    * @param enforceTableLocking true if strict table based locking must be
60    * enforced
61    * @param deadlockTimeoutInMs deadlock detection timeout in ms
62    */

63   public WaitForCompletionPolicy(int policy, boolean enforceTableLocking,
64       long deadlockTimeoutInMs)
65   {
66     this.policy = policy;
67     this.enforceTableLocking = enforceTableLocking;
68     this.deadlockTimeoutInMs = deadlockTimeoutInMs;
69   }
70
71   /**
72    * Returns the deadlockTimeoutInMs value.
73    *
74    * @return Returns the deadlockTimeoutInMs.
75    */

76   public final long getDeadlockTimeoutInMs()
77   {
78     return deadlockTimeoutInMs;
79   }
80
81   /**
82    * Sets the deadlockTimeoutInMs value.
83    *
84    * @param deadlockTimeoutInMs The deadlockTimeoutInMs to set.
85    */

86   public final void setDeadlockTimeoutInMs(long deadlockTimeoutInMs)
87   {
88     this.deadlockTimeoutInMs = deadlockTimeoutInMs;
89   }
90
91   /**
92    * Returns the enforceTableLocking value.
93    *
94    * @return Returns the enforceTableLocking.
95    */

96   public boolean isEnforceTableLocking()
97   {
98     return enforceTableLocking;
99   }
100
101   /**
102    * Returns the policy.
103    *
104    * @return an <code>int</code> value
105    */

106   public int getPolicy()
107   {
108     return policy;
109   }
110
111   /**
112    * Sets the policy.
113    *
114    * @param policy the policy to set
115    */

116   public void setPolicy(int policy)
117   {
118     this.policy = policy;
119   }
120
121   /**
122    * Gives information about the current policy.
123    *
124    * @return a <code>String</code> value
125    */

126   public String JavaDoc getInformation()
127   {
128     switch (policy)
129     {
130       case FIRST :
131         return "return when first node completes";
132       case MAJORITY :
133         return "return when a majority of nodes completes";
134       case ALL :
135         return "return when all nodes have completed";
136       default :
137         return "unknown policy";
138     }
139   }
140
141   /**
142    * Returns this wait policy in xml format.
143    *
144    * @return xml formatted string
145    */

146   public String JavaDoc getXml()
147   {
148     StringBuffer JavaDoc info = new StringBuffer JavaDoc();
149     info.append("<" + DatabasesXmlTags.ELT_WaitForCompletion + " "
150         + DatabasesXmlTags.ATT_policy + "=\"");
151     switch (policy)
152     {
153       case FIRST :
154         info.append(DatabasesXmlTags.VAL_first);
155         break;
156       case ALL :
157         info.append(DatabasesXmlTags.VAL_all);
158         break;
159       case MAJORITY :
160         info.append(DatabasesXmlTags.VAL_majority);
161         break;
162       default :
163     }
164     info.append("\" " + DatabasesXmlTags.ATT_enforceTableLocking + "=\""
165         + enforceTableLocking + "\" "
166         + DatabasesXmlTags.ATT_deadlockTimeoutInMs + "=\""
167         + deadlockTimeoutInMs + "\"/>");
168     return info.toString();
169   }
170 }
171
Popular Tags