KickJava   Java API By Example, From Geeks To Geeks.

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


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

22
23 package org.continuent.sequoia.controller.virtualdatabase.protocol;
24
25 import java.io.Serializable JavaDoc;
26 import java.sql.SQLException JavaDoc;
27
28 import org.continuent.hedera.common.Member;
29 import org.continuent.sequoia.common.exceptions.VirtualDatabaseStartingException;
30 import org.continuent.sequoia.common.log.Trace;
31 import org.continuent.sequoia.controller.requestmanager.distributed.DistributedRequestManager;
32 import org.continuent.sequoia.controller.virtualdatabase.DistributedVirtualDatabase;
33
34 /**
35  * This class defines a DistributedTransactionMarker which is used to transport
36  * commit/rollback/savepoint type of commands.
37  *
38  * @author <a HREF="mailto:emmanuel.cecchet@emicnetworks.com">Emmanuel Cecchet
39  * </a>
40  * @version 1.0
41  */

42 public abstract class DistributedTransactionMarker
43     extends DistributedVirtualDatabaseMessage
44 {
45
46   protected long transactionId;
47
48   /**
49    * Creates a new <code>DistributedTransactionMarker</code> object
50    *
51    * @param transactionId the transaction identifier
52    */

53   public DistributedTransactionMarker(long transactionId)
54   {
55     this.transactionId = transactionId;
56   }
57
58   /**
59    * Schedule the command (i.e. commit or rollback). This method blocks until
60    * the command is scheduled.
61    *
62    * @param drm a distributed request manager
63    * @return the object inserted in the total order queue
64    * @throws SQLException if an error occurs.
65    */

66   public abstract Object JavaDoc scheduleCommand(DistributedRequestManager drm)
67       throws SQLException JavaDoc;
68
69   /**
70    * Code to be executed by the distributed request manager receiving the
71    * command.
72    *
73    * @param drm a distributed request manager
74    * @return a Serializable object to be sent back to the caller
75    * @throws SQLException if an error occurs.
76    */

77   public abstract Serializable JavaDoc executeCommand(DistributedRequestManager drm)
78       throws SQLException JavaDoc;
79
80   /**
81    * Returns the transactionId value.
82    *
83    * @return Returns the transactionId.
84    */

85   public long getTransactionId()
86   {
87     return transactionId;
88   }
89
90   /**
91    * @see org.continuent.sequoia.controller.virtualdatabase.protocol.DistributedVirtualDatabaseMessage#handleMessageSingleThreaded(org.continuent.sequoia.controller.virtualdatabase.DistributedVirtualDatabase,
92    * org.continuent.hedera.common.Member)
93    */

94   public Object JavaDoc handleMessageSingleThreaded(DistributedVirtualDatabase dvdb,
95       Member sender)
96   {
97     if (!dvdb.isVirtualDatabaseStarted())
98       return new VirtualDatabaseStartingException();
99
100     Trace distributedRequestLogger = dvdb.getDistributedRequestLogger();
101     if (distributedRequestLogger.isInfoEnabled())
102       distributedRequestLogger.info(toString());
103
104     try
105     {
106       return scheduleCommand((DistributedRequestManager) dvdb
107           .getRequestManager());
108     }
109     catch (SQLException JavaDoc e)
110     {
111       return e;
112     }
113   }
114
115   /**
116    * @see org.continuent.sequoia.controller.virtualdatabase.protocol.DistributedVirtualDatabaseMessage#handleMessageMultiThreaded(org.continuent.sequoia.controller.virtualdatabase.DistributedVirtualDatabase,
117    * org.continuent.hedera.common.Member, java.lang.Object)
118    */

119   public Serializable JavaDoc handleMessageMultiThreaded(
120       DistributedVirtualDatabase dvdb, Member sender,
121       Object JavaDoc handleMessageSingleThreadedResult)
122   {
123     if (handleMessageSingleThreadedResult != null)
124     {
125       if (handleMessageSingleThreadedResult instanceof Exception JavaDoc)
126         return (Serializable JavaDoc) handleMessageSingleThreadedResult;
127     }
128
129     try
130     {
131       return executeCommand((DistributedRequestManager) dvdb
132           .getRequestManager());
133     }
134     catch (SQLException JavaDoc e)
135     {
136       return e;
137     }
138   }
139
140   /**
141    * @see java.lang.Object#hashCode()
142    */

143   public int hashCode()
144   {
145     return (int) transactionId;
146   }
147
148   /**
149    * @see java.lang.Object#equals(java.lang.Object)
150    */

151   public boolean equals(Object JavaDoc obj)
152   {
153     if (obj == null)
154       return false;
155     if (obj.getClass().equals(this.getClass()))
156       return transactionId == ((DistributedTransactionMarker) obj)
157           .getTransactionId();
158     else
159       return false;
160   }
161 }
162
Popular Tags