001: /**
002: * Sequoia: Database clustering technology.
003: * Copyright (C) 2002-2004 French National Institute For Research In Computer
004: * Science And Control (INRIA).
005: * Copyright (C) 2005 AmicoSoft, Inc. dba Emic Networks
006: * Contact: sequoia@continuent.org
007: *
008: * Licensed under the Apache License, Version 2.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: * Initial developer(s): Emmanuel Cecchet.
021: * Contributor(s): Damian Arregui.
022: */package org.continuent.sequoia.controller.virtualdatabase.protocol;
023:
024: import java.io.Serializable;
025: import java.util.ArrayList;
026: import java.util.List;
027:
028: import org.continuent.hedera.common.Member;
029: import org.continuent.sequoia.common.jmx.management.BackendInfo;
030: import org.continuent.sequoia.common.log.Trace;
031: import org.continuent.sequoia.controller.backend.DatabaseBackend;
032: import org.continuent.sequoia.controller.virtualdatabase.DistributedVirtualDatabase;
033:
034: /**
035: * Send the information that the sender wants to enable the specified backend.
036: *
037: * @author <a href="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
038: * @author <a href="mailto:Damian.Arregui@continuent.com">Damian Arregui </a>
039: * @version 1.0
040: */
041: public class NotifyEnableBackend extends
042: DistributedVirtualDatabaseMessage {
043: private static final long serialVersionUID = 5783006534850234709L;
044:
045: private BackendInfo backendInfo;
046:
047: /**
048: * Creates a new EnableBackend object with the specified backend information.
049: *
050: * @param backendInfo information on the backend to enable
051: */
052: public NotifyEnableBackend(BackendInfo backendInfo) {
053: this .backendInfo = backendInfo;
054: }
055:
056: /**
057: * @see org.continuent.sequoia.controller.virtualdatabase.protocol.DistributedVirtualDatabaseMessage#handleMessageMultiThreaded(org.continuent.sequoia.controller.virtualdatabase.DistributedVirtualDatabase,
058: * org.continuent.hedera.common.Member, java.lang.Object)
059: */
060: public Serializable handleMessageMultiThreaded(
061: DistributedVirtualDatabase dvdb, Member sender,
062: Object handleMessageSingleThreadedResult) {
063: Trace logger = dvdb.getLogger();
064: List remoteBackends = (List) dvdb.getBackendsPerController()
065: .get(sender);
066: if (remoteBackends == null) { // This case was reported by Alessandro Gamboz on April 1, 2005.
067: // It looks like the EnableBackend message arrives before membership
068: // has been properly updated.
069: logger
070: .warn("No information has been found for remote controller "
071: + sender);
072: remoteBackends = new ArrayList();
073: dvdb.addBackendPerController(sender, remoteBackends);
074: }
075: DatabaseBackend enabledBackend = backendInfo
076: .getDatabaseBackend();
077: int size = remoteBackends.size();
078: boolean backendFound = false;
079: for (int i = 0; i < size; i++) {
080: DatabaseBackend remoteBackend = (DatabaseBackend) remoteBackends
081: .get(i);
082: if (remoteBackend.equals(enabledBackend)) {
083: logger.info("Backend " + remoteBackend.getName()
084: + " enabled on controller " + sender);
085: remoteBackends.set(i, enabledBackend);
086: backendFound = true;
087: break;
088: }
089: }
090: if (!backendFound) {
091: logger.warn("Updating backend list with unknown backend "
092: + enabledBackend.getName()
093: + " enabled on controller " + sender);
094: remoteBackends.add(enabledBackend);
095: }
096: return null;
097: }
098:
099: /**
100: * @see org.continuent.sequoia.controller.virtualdatabase.protocol.DistributedVirtualDatabaseMessage#handleMessageSingleThreaded(org.continuent.sequoia.controller.virtualdatabase.DistributedVirtualDatabase,
101: * org.continuent.hedera.common.Member)
102: */
103: public Object handleMessageSingleThreaded(
104: DistributedVirtualDatabase dvdb, Member sender) {
105: return null;
106: }
107:
108: }
|