001: /**
002: * Sequoia: Database clustering technology.
003: * Copyright (C) 2006 Continuent, Inc.
004: * Contact: sequoia@continuent.org
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: *
018: * Initial developer(s): Emmanuel Cecchet.
019: * Contributor(s): ______________________.
020: */package org.continuent.sequoia.controller.virtualdatabase.protocol;
021:
022: import java.io.Serializable;
023: import java.util.LinkedList;
024:
025: import org.continuent.hedera.common.Member;
026: import org.continuent.sequoia.common.exceptions.VirtualDatabaseStartingException;
027: import org.continuent.sequoia.controller.virtualdatabase.DistributedVirtualDatabase;
028: import org.continuent.sequoia.controller.virtualdatabase.VirtualDatabaseWorkerThread;
029:
030: /**
031: * This class defines a DistributedClosePersistentConnection
032: *
033: * @author <a href="mailto:emmanuel.cecchet@continuent.com">Emmanuel Cecchet</a>
034: * @version 1.0
035: */
036: public class DistributedClosePersistentConnection extends
037: DistributedVirtualDatabaseMessage {
038: private static final long serialVersionUID = -693544521730643721L;
039: private String login;
040: private long persistentConnectionId;
041:
042: /**
043: * Creates a new <code>DistributedClosePersistentConnection</code> object
044: *
045: * @param login login to retrieve the connection manager
046: * @param persistentConnectionId persistent connection id
047: */
048: public DistributedClosePersistentConnection(String login,
049: long persistentConnectionId) {
050: this .login = login;
051: this .persistentConnectionId = persistentConnectionId;
052: }
053:
054: /**
055: * Returns the login value.
056: *
057: * @return Returns the login.
058: */
059: public final String getLogin() {
060: return login;
061: }
062:
063: /**
064: * Returns the persistentConnectionId value.
065: *
066: * @return Returns the persistentConnectionId.
067: */
068: public final long getPersistentConnectionId() {
069: return persistentConnectionId;
070: }
071:
072: /**
073: * @see org.continuent.sequoia.controller.virtualdatabase.protocol.DistributedVirtualDatabaseMessage#handleMessageSingleThreaded(org.continuent.sequoia.controller.virtualdatabase.DistributedVirtualDatabase,
074: * org.continuent.hedera.common.Member)
075: */
076: public Object handleMessageSingleThreaded(
077: DistributedVirtualDatabase dvdb, Member sender) {
078: if (!dvdb.isVirtualDatabaseStarted())
079: return new VirtualDatabaseStartingException();
080:
081: LinkedList totalOrderQueue = dvdb.getTotalOrderQueue();
082: synchronized (totalOrderQueue) {
083: totalOrderQueue.addLast(this );
084: }
085: return this ;
086: }
087:
088: /**
089: * @see org.continuent.sequoia.controller.virtualdatabase.protocol.DistributedVirtualDatabaseMessage#handleMessageMultiThreaded(org.continuent.sequoia.controller.virtualdatabase.DistributedVirtualDatabase,
090: * org.continuent.hedera.common.Member, java.lang.Object)
091: */
092: public Serializable handleMessageMultiThreaded(
093: DistributedVirtualDatabase dvdb, Member sender,
094: Object handleMessageSingleThreadedResult) {
095: if (handleMessageSingleThreadedResult instanceof Exception)
096: return (Serializable) handleMessageSingleThreadedResult;
097:
098: dvdb.getRequestManager().getLoadBalancer().waitForTotalOrder(
099: this , true);
100:
101: VirtualDatabaseWorkerThread vdbwt = dvdb
102: .getVirtualDatabaseWorkerThreadForPersistentConnection(persistentConnectionId);
103: if (vdbwt != null)
104: vdbwt.notifyClose(persistentConnectionId);
105:
106: dvdb.getRequestManager().closePersistentConnection(login,
107: persistentConnectionId);
108:
109: return null;
110: }
111:
112: /**
113: * @see java.lang.Object#equals(java.lang.Object)
114: */
115: public boolean equals(Object obj) {
116: if (obj instanceof DistributedClosePersistentConnection) {
117: DistributedClosePersistentConnection other = (DistributedClosePersistentConnection) obj;
118: return persistentConnectionId == other.persistentConnectionId;
119: }
120: return false;
121: }
122:
123: /**
124: * @see java.lang.Object#hashCode()
125: */
126: public int hashCode() {
127: return (int) persistentConnectionId;
128: }
129: }
|