KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > continuent > sequoia > controller > virtualdatabase > protocol > FlushGroupCommunicationMessages


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

21
22 package org.continuent.sequoia.controller.virtualdatabase.protocol;
23
24 import java.io.Serializable JavaDoc;
25 import java.util.LinkedList JavaDoc;
26
27 import org.continuent.hedera.common.Member;
28 import org.continuent.sequoia.controller.loadbalancer.AbstractLoadBalancer;
29 import org.continuent.sequoia.controller.virtualdatabase.DistributedVirtualDatabase;
30
31 /**
32  * This class defines a FlushGroupCommunicationMessages used to flush the
33  * messages in the group communication and make sure that controller failover
34  * can be started.
35  *
36  * @author <a HREF="mailto:emmanuel.cecchet@continuent.com">Emmanuel Cecchet</a>
37  * @version 1.0
38  */

39 public class FlushGroupCommunicationMessages
40     extends DistributedVirtualDatabaseMessage
41 {
42   private static final long serialVersionUID = 468790279514578158L;
43
44   private long failedControllerId;
45
46   /**
47    * Create a new <code>FlushGroupCommunicationMessages</code> instance for
48    * the given failed controller id
49    *
50    * @param id failed controller id
51    */

52   public FlushGroupCommunicationMessages(long id)
53   {
54     failedControllerId = id;
55   }
56
57   /**
58    * @see org.continuent.sequoia.controller.virtualdatabase.protocol.DistributedVirtualDatabaseMessage#handleMessageSingleThreaded(org.continuent.sequoia.controller.virtualdatabase.DistributedVirtualDatabase,
59    * org.continuent.hedera.common.Member)
60    */

61   public Object JavaDoc handleMessageSingleThreaded(DistributedVirtualDatabase dvdb,
62       Member sender)
63   {
64     LinkedList JavaDoc totalOrderQueue = dvdb.getTotalOrderQueue();
65     synchronized (totalOrderQueue)
66     {
67       totalOrderQueue.addLast(this);
68     }
69     return null;
70   }
71
72   /**
73    * Wait for our turn in the total order queue to be sure that all previous
74    * messages have been processed.
75    *
76    * @see org.continuent.sequoia.controller.virtualdatabase.protocol.DistributedVirtualDatabaseMessage#handleMessageMultiThreaded(org.continuent.sequoia.controller.virtualdatabase.DistributedVirtualDatabase,
77    * org.continuent.hedera.common.Member, java.lang.Object)
78    */

79   public Serializable JavaDoc handleMessageMultiThreaded(
80       DistributedVirtualDatabase dvdb, Member sender,
81       Object JavaDoc handleMessageSingleThreadedResult)
82   {
83     AbstractLoadBalancer loadBalancer = dvdb.getRequestManager()
84         .getLoadBalancer();
85     loadBalancer.waitForTotalOrder(this, true);
86     loadBalancer.removeObjectFromAndNotifyTotalOrderQueue(this);
87     return Boolean.TRUE;
88   }
89
90   /**
91    * @see java.lang.Object#equals(java.lang.Object)
92    */

93   public boolean equals(Object JavaDoc obj)
94   {
95     if (!(obj instanceof FlushGroupCommunicationMessages))
96       return false;
97
98     FlushGroupCommunicationMessages fgcm = (FlushGroupCommunicationMessages) obj;
99     return failedControllerId == fgcm.failedControllerId;
100   }
101
102 }
103
Popular Tags