01: /**
02: * Sequoia: Database clustering technology.
03: * Copyright (C) 2006 Continuent, Inc.
04: * Contact: sequoia@continuent.org
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
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: */package org.continuent.sequoia.controller.virtualdatabase.protocol;
21:
22: import java.io.Serializable;
23: import java.util.LinkedList;
24:
25: import org.continuent.hedera.common.Member;
26: import org.continuent.sequoia.controller.loadbalancer.AbstractLoadBalancer;
27: import org.continuent.sequoia.controller.virtualdatabase.DistributedVirtualDatabase;
28:
29: /**
30: * This class defines a FlushGroupCommunicationMessages used to flush the
31: * messages in the group communication and make sure that controller failover
32: * can be started.
33: *
34: * @author <a href="mailto:emmanuel.cecchet@continuent.com">Emmanuel Cecchet</a>
35: * @version 1.0
36: */
37: public class FlushGroupCommunicationMessages extends
38: DistributedVirtualDatabaseMessage {
39: private static final long serialVersionUID = 468790279514578158L;
40:
41: private long failedControllerId;
42:
43: /**
44: * Create a new <code>FlushGroupCommunicationMessages</code> instance for
45: * the given failed controller id
46: *
47: * @param id failed controller id
48: */
49: public FlushGroupCommunicationMessages(long id) {
50: failedControllerId = id;
51: }
52:
53: /**
54: * @see org.continuent.sequoia.controller.virtualdatabase.protocol.DistributedVirtualDatabaseMessage#handleMessageSingleThreaded(org.continuent.sequoia.controller.virtualdatabase.DistributedVirtualDatabase,
55: * org.continuent.hedera.common.Member)
56: */
57: public Object handleMessageSingleThreaded(
58: DistributedVirtualDatabase dvdb, Member sender) {
59: LinkedList totalOrderQueue = dvdb.getTotalOrderQueue();
60: synchronized (totalOrderQueue) {
61: totalOrderQueue.addLast(this );
62: }
63: return null;
64: }
65:
66: /**
67: * Wait for our turn in the total order queue to be sure that all previous
68: * messages have been processed.
69: *
70: * @see org.continuent.sequoia.controller.virtualdatabase.protocol.DistributedVirtualDatabaseMessage#handleMessageMultiThreaded(org.continuent.sequoia.controller.virtualdatabase.DistributedVirtualDatabase,
71: * org.continuent.hedera.common.Member, java.lang.Object)
72: */
73: public Serializable handleMessageMultiThreaded(
74: DistributedVirtualDatabase dvdb, Member sender,
75: Object handleMessageSingleThreadedResult) {
76: AbstractLoadBalancer loadBalancer = dvdb.getRequestManager()
77: .getLoadBalancer();
78: loadBalancer.waitForTotalOrder(this , true);
79: loadBalancer.removeObjectFromAndNotifyTotalOrderQueue(this );
80: return Boolean.TRUE;
81: }
82:
83: /**
84: * @see java.lang.Object#equals(java.lang.Object)
85: */
86: public boolean equals(Object obj) {
87: if (!(obj instanceof FlushGroupCommunicationMessages))
88: return false;
89:
90: FlushGroupCommunicationMessages fgcm = (FlushGroupCommunicationMessages) obj;
91: return failedControllerId == fgcm.failedControllerId;
92: }
93:
94: }
|