Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 31771 invoked from network); 3 Mar 2008 10:17:22 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 3 Mar 2008 10:17:22 -0000 Received: (qmail 61029 invoked by uid 500); 3 Mar 2008 10:17:18 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 61004 invoked by uid 500); 3 Mar 2008 10:17:18 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 60993 invoked by uid 99); 3 Mar 2008 10:17:18 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Mar 2008 02:17:18 -0800 X-ASF-Spam-Status: No, hits=-1998.8 required=10.0 tests=ALL_TRUSTED,FS_REPLICA X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Mar 2008 10:16:38 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 4EC751A9838; Mon, 3 Mar 2008 02:16:58 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r633026 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/services/replication/net/ engine/org/apache/derby/loc/ shared/org/apache/derby/shared/common/reference/ Date: Mon, 03 Mar 2008 10:16:57 -0000 To: derby-commits@db.apache.org From: oysteing@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080303101658.4EC751A9838@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: oysteing Date: Mon Mar 3 02:16:56 2008 New Revision: 633026 URL: http://svn.apache.org/viewvc?rev=633026&view=rev Log: DERBY-3454:All the public methods of ReplicationMessageTransmit and ReplicationMessageReceive should ensure that the socket connection exists (is not null) before performing the respective operations. Contributed by V Narayanan Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/replication/net/ReplicationMessageReceive.java db/derby/code/trunk/java/engine/org/apache/derby/impl/services/replication/net/ReplicationMessageTransmit.java db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/MessageId.java Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/replication/net/ReplicationMessageReceive.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/replication/net/ReplicationMessageReceive.java?rev=633026&r1=633025&r2=633026&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/replication/net/ReplicationMessageReceive.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/replication/net/ReplicationMessageReceive.java Mon Mar 3 02:16:56 2008 @@ -236,7 +236,7 @@ if (masterVersion == ReplicationMessage.serialVersionUID) { ack = new ReplicationMessage (ReplicationMessage.TYPE_ACK, "UID OK"); - socketConn.writeMessage(ack); + sendMessage(ack); } else { //If the UID's are not equal send an error message. The //object of a TYPE_ERROR message must be a String[] @@ -244,7 +244,7 @@ (ReplicationMessage.TYPE_ERROR, new String[]{SQLState. REPLICATION_MASTER_SLAVE_VERSION_MISMATCH}); - socketConn.writeMessage(ack); + sendMessage(ack); //The UID's do not match. throw StandardException.newException @@ -294,7 +294,7 @@ // Notify the master that the logs are in synch ack = new ReplicationMessage (ReplicationMessage.TYPE_ACK, "Instant OK"); - socketConn.writeMessage(ack); + sendMessage(ack); } else { // Notify master that the logs are out of synch // See ReplicationMessage#TYPE_ERROR @@ -311,7 +311,7 @@ exception[5] = SQLState.REPLICATION_LOG_OUT_OF_SYNCH; ack = new ReplicationMessage(ReplicationMessage.TYPE_ERROR, exception); - socketConn.writeMessage(ack); + sendMessage(ack); throw StandardException. newException(SQLState.REPLICATION_LOG_OUT_OF_SYNCH, exception); @@ -344,7 +344,7 @@ ReplicationMessage ack = new ReplicationMessage(ReplicationMessage.TYPE_ERROR, exception); - socketConn.writeMessage(ack); + sendMessage(ack); throw StandardException. newException(SQLState.REPLICATION_UNEXPECTED_MESSAGEID, exception); @@ -357,10 +357,12 @@ * @param message a ReplicationMessage object that contains * the message to be transmitted. * - * @throws IOException if an exception occurs while transmitting - * the message. + * @throws IOException 1) if an exception occurs while transmitting + * the message, + * 2) if the connection handle is invalid. */ public void sendMessage(ReplicationMessage message) throws IOException { + checkSocketConnection(); socketConn.writeMessage(message); } @@ -375,11 +377,13 @@ * @throws ClassNotFoundException Class of a serialized object cannot * be found. * - * @throws IOException if an exception occurs while reading from the - * stream. + * @throws IOException 1) if an exception occurs while reading from the + * stream, + * 2) if the connection handle is invalid. */ public ReplicationMessage readMessage() throws ClassNotFoundException, IOException { + checkSocketConnection(); return (ReplicationMessage)socketConn.readMessage(); } @@ -402,4 +406,17 @@ public int getPort() { return slaveAddress.getPortNumber(); } + + /** + * Verifies if the SocketConnection is valid. + * + * @throws IOException If the socket connection object is not + * valid (is null). + */ + private void checkSocketConnection() throws IOException { + if (socketConn == null) { + throw new IOException + (MessageId.REPLICATION_INVALID_CONNECTION_HANDLE); + } + } } Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/replication/net/ReplicationMessageTransmit.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/replication/net/ReplicationMessageTransmit.java?rev=633026&r1=633025&r2=633026&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/replication/net/ReplicationMessageTransmit.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/replication/net/ReplicationMessageTransmit.java Mon Mar 3 02:16:56 2008 @@ -30,6 +30,7 @@ import javax.net.SocketFactory; import org.apache.derby.iapi.error.StandardException; import org.apache.derby.iapi.reference.SQLState; +import org.apache.derby.shared.common.reference.MessageId; /** * Used to send replication messages to the slave. Called by the @@ -140,7 +141,9 @@ * down the network connection */ public void tearDown() throws IOException { - socketConn.tearDown(); + if(socketConn != null) { + socketConn.tearDown(); + } } /** @@ -149,10 +152,12 @@ * @param message a ReplicationMessage object that contains * the message to be transmitted. * - * @throws IOException if an exception occurs while transmitting - * the message. + * @throws IOException 1) if an exception occurs while transmitting + * the message. + * 2) if the connection handle is invalid. */ public void sendMessage(ReplicationMessage message) throws IOException { + checkSocketConnection(); socketConn.writeMessage(message); } @@ -166,11 +171,13 @@ * @throws ClassNotFoundException Class of a serialized object cannot * be found. * - * @throws IOException if an exception occurs while reading from the - * stream. + * @throws IOException 1) if an exception occurs while reading from the + * stream. + * 2) if the connection handle is invalid. */ public ReplicationMessage readMessage() throws ClassNotFoundException, IOException { + checkSocketConnection(); return (ReplicationMessage)socketConn.readMessage(); } @@ -245,6 +252,19 @@ //an unexpected exception. throw StandardException.newException (SQLState.REPLICATION_UNEXPECTED_EXCEPTION); + } + } + + /** + * Verifies if the SocketConnection is valid. + * + * @throws IOException If the socket connection object is not + * valid (is null). + */ + private void checkSocketConnection() throws IOException { + if (socketConn == null) { + throw new IOException + (MessageId.REPLICATION_INVALID_CONNECTION_HANDLE); } } } Modified: db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml?rev=633026&r1=633025&r2=633026&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml Mon Mar 3 02:16:56 2008 @@ -7723,6 +7723,11 @@ + R012 + Replication connection handle invalid. + + + R020 Failover perfomed successfully for database '{0}'. dbname Modified: db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/MessageId.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/MessageId.java?rev=633026&r1=633025&r2=633026&view=diff ============================================================================== --- db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/MessageId.java (original) +++ db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/MessageId.java Mon Mar 3 02:16:56 2008 @@ -189,6 +189,7 @@ String REPLICATION_LOGSHIPPER_EXCEPTION = "R009"; String REPLICATION_MASTER_RECONN = "R010"; String REPLICATION_SLAVE_NETWORK_LISTEN = "R011"; + String REPLICATION_INVALID_CONNECTION_HANDLE = "R012"; String REPLICATION_FAILOVER_SUCCESSFUL = "R020"; }