db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From oyste...@apache.org
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 GMT
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 <code>ReplicationMessage</code> 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 <code>SocketConnection</code> 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 <code>ReplicationMessage</code> 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 <code>SocketConnection</code> 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 @@
             </msg>
             
             <msg>
+                <name>R012</name>
+                <text>Replication connection handle invalid.</text>
+            </msg>
+            
+            <msg>
                 <name>R020</name>
                 <text>Failover perfomed successfully for database '{0}'.</text>
                 <arg>dbname</arg>

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";
 
 }



Mime
View raw message