KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * Sequoia: Database clustering technology.
3  * Copyright (C) 2006 Continuent, Inc.
4  * Contact: sequoia@continuent.org
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
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  */

21
22 package org.continuent.sequoia.controller.virtualdatabase.protocol;
23
24 import java.io.Serializable JavaDoc;
25 import java.util.LinkedList JavaDoc;
26
27 import org.continuent.hedera.common.Member;
28 import org.continuent.sequoia.common.exceptions.VirtualDatabaseStartingException;
29 import org.continuent.sequoia.controller.virtualdatabase.DistributedVirtualDatabase;
30
31 /**
32  * This class defines a DistributedClosePersistentConnection
33  *
34  * @author <a HREF="mailto:emmanuel.cecchet@continuent.com">Emmanuel Cecchet</a>
35  * @version 1.0
36  */

37 public class DistributedClosePersistentConnection
38     extends DistributedVirtualDatabaseMessage
39 {
40   private static final long serialVersionUID = -693544521730643721L;
41   private String JavaDoc login;
42   private long persistentConnectionId;
43
44   /**
45    * Creates a new <code>DistributedClosePersistentConnection</code> object
46    *
47    * @param login login to retrieve the connection manager
48    * @param persistentConnectionId persistent connection id
49    */

50   public DistributedClosePersistentConnection(String JavaDoc login,
51       long persistentConnectionId)
52   {
53     this.login = login;
54     this.persistentConnectionId = persistentConnectionId;
55   }
56
57   /**
58    * Returns the login value.
59    *
60    * @return Returns the login.
61    */

62   public final String JavaDoc getLogin()
63   {
64     return login;
65   }
66
67   /**
68    * Returns the persistentConnectionId value.
69    *
70    * @return Returns the persistentConnectionId.
71    */

72   public final long getPersistentConnectionId()
73   {
74     return persistentConnectionId;
75   }
76
77   /**
78    * @see org.continuent.sequoia.controller.virtualdatabase.protocol.DistributedVirtualDatabaseMessage#handleMessageSingleThreaded(org.continuent.sequoia.controller.virtualdatabase.DistributedVirtualDatabase,
79    * org.continuent.hedera.common.Member)
80    */

81   public Object JavaDoc handleMessageSingleThreaded(DistributedVirtualDatabase dvdb,
82       Member sender)
83   {
84     if (!dvdb.isVirtualDatabaseStarted())
85       return new VirtualDatabaseStartingException();
86
87     LinkedList JavaDoc totalOrderQueue = dvdb.getTotalOrderQueue();
88     synchronized (totalOrderQueue)
89     {
90       totalOrderQueue.addLast(this);
91     }
92     return this;
93   }
94
95   /**
96    * @see org.continuent.sequoia.controller.virtualdatabase.protocol.DistributedVirtualDatabaseMessage#handleMessageMultiThreaded(org.continuent.sequoia.controller.virtualdatabase.DistributedVirtualDatabase,
97    * org.continuent.hedera.common.Member, java.lang.Object)
98    */

99   public Serializable JavaDoc handleMessageMultiThreaded(
100       DistributedVirtualDatabase dvdb, Member sender,
101       Object JavaDoc handleMessageSingleThreadedResult)
102   {
103     if (handleMessageSingleThreadedResult instanceof Exception JavaDoc)
104       return (Serializable JavaDoc) handleMessageSingleThreadedResult;
105
106     dvdb.getRequestManager().getLoadBalancer().waitForTotalOrder(this, true);
107     dvdb.getRequestManager().closePersistentConnection(login,
108         persistentConnectionId);
109
110     return null;
111   }
112
113   /**
114    * @see java.lang.Object#equals(java.lang.Object)
115    */

116   public boolean equals(Object JavaDoc obj)
117   {
118     if (obj instanceof DistributedClosePersistentConnection)
119     {
120       DistributedClosePersistentConnection other = (DistributedClosePersistentConnection) obj;
121       return persistentConnectionId == other.persistentConnectionId;
122     }
123     return false;
124   }
125
126   /**
127    * @see java.lang.Object#hashCode()
128    */

129   public int hashCode()
130   {
131     return (int) persistentConnectionId;
132   }
133 }
134
Popular Tags