KickJava   Java API By Example, From Geeks To Geeks.

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


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

23
24 package org.continuent.sequoia.controller.virtualdatabase.protocol;
25
26 import java.io.Serializable JavaDoc;
27 import java.util.ArrayList JavaDoc;
28 import java.util.List JavaDoc;
29
30 import org.continuent.hedera.common.Member;
31 import org.continuent.sequoia.common.jmx.management.BackendInfo;
32 import org.continuent.sequoia.common.log.Trace;
33 import org.continuent.sequoia.controller.backend.DatabaseBackend;
34 import org.continuent.sequoia.controller.virtualdatabase.DistributedVirtualDatabase;
35
36 /**
37  * Send the information that the sender wants to enable the specified backend.
38  *
39  * @author <a HREF="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
40  * @author <a HREF="mailto:Damian.Arregui@continuent.com">Damian Arregui </a>
41  * @version 1.0
42  */

43 public class NotifyEnableBackend extends DistributedVirtualDatabaseMessage
44 {
45   private static final long serialVersionUID = 5783006534850234709L;
46
47   private BackendInfo backendInfo;
48
49   /**
50    * Creates a new EnableBackend object with the specified backend information.
51    *
52    * @param backendInfo information on the backend to enable
53    */

54   public NotifyEnableBackend(BackendInfo backendInfo)
55   {
56     this.backendInfo = backendInfo;
57   }
58
59   /**
60    * @see org.continuent.sequoia.controller.virtualdatabase.protocol.DistributedVirtualDatabaseMessage#handleMessageMultiThreaded(org.continuent.sequoia.controller.virtualdatabase.DistributedVirtualDatabase,
61    * org.continuent.hedera.common.Member, java.lang.Object)
62    */

63   public Serializable JavaDoc handleMessageMultiThreaded(
64       DistributedVirtualDatabase dvdb, Member sender,
65       Object JavaDoc handleMessageSingleThreadedResult)
66   {
67     Trace logger = dvdb.getLogger();
68     List JavaDoc remoteBackends = (List JavaDoc) dvdb.getBackendsPerController().get(sender);
69     if (remoteBackends == null)
70     { // This case was reported by Alessandro Gamboz on April 1, 2005.
71
// It looks like the EnableBackend message arrives before membership
72
// has been properly updated.
73
logger.warn("No information has been found for remote controller "
74           + sender);
75       remoteBackends = new ArrayList JavaDoc();
76       dvdb.addBackendPerController(sender, remoteBackends);
77     }
78     DatabaseBackend enabledBackend = backendInfo.getDatabaseBackend(dvdb);
79     int size = remoteBackends.size();
80     boolean backendFound = false;
81     for (int i = 0; i < size; i++)
82     {
83       DatabaseBackend remoteBackend = (DatabaseBackend) remoteBackends.get(i);
84       if (remoteBackend.equals(enabledBackend))
85       {
86         logger.info("Backend " + remoteBackend.getName()
87             + " enabled on controller " + sender);
88         remoteBackends.set(i, enabledBackend);
89         backendFound = true;
90         break;
91       }
92     }
93     if (!backendFound)
94     {
95       logger.warn("Updating backend list with unknown backend "
96           + enabledBackend.getName() + " enabled on controller " + sender);
97       remoteBackends.add(enabledBackend);
98     }
99     return null;
100   }
101
102   /**
103    * @see org.continuent.sequoia.controller.virtualdatabase.protocol.DistributedVirtualDatabaseMessage#handleMessageSingleThreaded(org.continuent.sequoia.controller.virtualdatabase.DistributedVirtualDatabase,
104    * org.continuent.hedera.common.Member)
105    */

106   public Object JavaDoc handleMessageSingleThreaded(DistributedVirtualDatabase dvdb,
107       Member sender)
108   {
109     return null;
110   }
111
112 }
Popular Tags