KickJava   Java API By Example, From Geeks To Geeks.

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


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

24
25 package org.continuent.sequoia.controller.virtualdatabase.protocol;
26
27 import java.io.Serializable JavaDoc;
28 import java.util.LinkedList JavaDoc;
29
30 import org.continuent.hedera.common.Member;
31 import org.continuent.sequoia.common.exceptions.VirtualDatabaseException;
32 import org.continuent.sequoia.common.i18n.Translate;
33 import org.continuent.sequoia.common.jmx.management.BackendInfo;
34 import org.continuent.sequoia.common.log.Trace;
35 import org.continuent.sequoia.controller.backend.DatabaseBackend;
36 import org.continuent.sequoia.controller.virtualdatabase.DistributedVirtualDatabase;
37
38 /**
39  * This class defines a BackendTransfer message used to transfer the backend
40  * information and re-enable the backend on the remote controller (checkpoint
41  * transfer have already been taken care of).
42  *
43  * @author <a HREF="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
44  * @author <a HREF="mailto:emmanuel.cecchet@continuent.com">Emmanuel Cecchet</a>
45  * @version 1.0
46  */

47 public class BackendTransfer extends DistributedVirtualDatabaseMessage
48 {
49   private static final long serialVersionUID = 520265407391630486L;
50
51   private BackendInfo info;
52   private String JavaDoc controllerDest;
53   private String JavaDoc checkpointName;
54
55   private transient LinkedList JavaDoc totalOrderQueue;
56
57   /**
58    * Creates a new <code>BackendTransfer</code> object
59    *
60    * @param info the info on the backend to transfer
61    * @param controllerDest the JMX name of the target controller
62    * @param checkpointName the name of the ckeckpoint from which to restore
63    */

64   public BackendTransfer(String JavaDoc controllerDest, String JavaDoc checkpointName,
65       BackendInfo info)
66   {
67     this.info = info;
68     this.controllerDest = controllerDest;
69     this.checkpointName = checkpointName;
70   }
71
72   /**
73    * Returns the controllerDest value.
74    *
75    * @return Returns the controllerDest.
76    */

77   public String JavaDoc getControllerDest()
78   {
79     return controllerDest;
80   }
81
82   /**
83    * Returns the info value.
84    *
85    * @return Returns the info.
86    */

87   public BackendInfo getInfo()
88   {
89     return info;
90   }
91
92   /**
93    * Returns the checkpointName value.
94    *
95    * @return Returns the checkpointName.
96    */

97   public String JavaDoc getCheckpointName()
98   {
99     return checkpointName;
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     totalOrderQueue = dvdb.getTotalOrderQueue();
110     if (totalOrderQueue == null)
111       return new VirtualDatabaseException(Translate
112           .get("virtualdatabase.no.total.order.queue", dvdb
113               .getVirtualDatabaseName()));
114
115     synchronized (totalOrderQueue)
116     {
117       totalOrderQueue.addLast(this);
118       return this;
119     }
120   }
121
122   /**
123    * @see org.continuent.sequoia.controller.virtualdatabase.protocol.DistributedVirtualDatabaseMessage#handleMessageMultiThreaded(org.continuent.sequoia.controller.virtualdatabase.DistributedVirtualDatabase,
124    * org.continuent.hedera.common.Member, java.lang.Object)
125    */

126   public Serializable JavaDoc handleMessageMultiThreaded(
127       DistributedVirtualDatabase dvdb, Member sender,
128       Object JavaDoc handleMessageSingleThreadedResult)
129   {
130     Trace logger = dvdb.getLogger();
131
132     // Wait for our turn to execute
133
if (!dvdb.waitForTotalOrder(handleMessageSingleThreadedResult, false))
134       logger
135           .error("BackendTransfer was not found in total order queue, posting out of order ("
136               + checkpointName + ")");
137     else
138       synchronized (totalOrderQueue)
139       {
140         totalOrderQueue.removeFirst();
141         totalOrderQueue.notifyAll();
142       }
143
144     if (logger.isInfoEnabled())
145       logger.info(dvdb.getControllerName()
146           + ": Received transfer command. Checkpoint: " + getCheckpointName());
147     DatabaseBackend backend = new DatabaseBackend(dvdb, info);
148
149     try
150     {
151       dvdb.addBackend(backend);
152     }
153     catch (VirtualDatabaseException e)
154     {
155       // No cleanup expected there (if addBackend() behaves). The backend does
156
// not exist here, and still exists (though disabled) on the originating
157
// vdb peer (controller). Just return the exception.
158
return e;
159     }
160
161     try
162     {
163       if (logger.isInfoEnabled())
164         logger.info(dvdb.getControllerName() + ": Enable backend from "
165             + checkpointName);
166       dvdb.enableBackendFromCheckpoint(backend.getName(), getCheckpointName());
167     }
168     catch (VirtualDatabaseException e)
169     {
170       // The backend was added, but could not be enabled. Remove it from this
171
// vdb peer, since it remains (in a disabled state) on the originating
172
// peer.
173
cleanup(dvdb, backend);
174       return e;
175     }
176     return Boolean.TRUE;
177   }
178
179   void cleanup(DistributedVirtualDatabase dvdb, DatabaseBackend backend)
180   {
181     try
182     {
183       dvdb.removeBackend(backend);
184     }
185     catch (VirtualDatabaseException e)
186     {
187       dvdb.getLogger().error(
188           "Could not cleanup vdb after transfer backend failure", e);
189     }
190   }
191 }
Popular Tags