More java error codes in thrift
authorMark Slee <mcslee@apache.org>
Wed, 21 Feb 2007 04:54:38 +0000 (04:54 +0000)
committerMark Slee <mcslee@apache.org>
Wed, 21 Feb 2007 04:54:38 +0000 (04:54 +0000)
Reviewed By: aditya

git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665011 13f79535-47bb-0310-9956-ffa450edef68

lib/java/src/TApplicationException.java
lib/java/src/transport/TIOStreamTransport.java
lib/java/src/transport/TServerSocket.java
lib/java/src/transport/TSocket.java
lib/java/src/transport/TTransportException.java

index 0890282..b9c0d3d 100644 (file)
@@ -20,7 +20,7 @@ public class TApplicationException extends TException {
   public static final int BAD_SEQUENCE_ID = 4;
   public static final int MISSING_RESULT = 5;
 
-  protected int type_ = 0;
+  protected int type_ = UNKNOWN;
 
   public TApplicationException() {
     super();
index aa4adf1..a32195b 100644 (file)
@@ -99,12 +99,12 @@ public class TIOStreamTransport extends TTransport {
    */
   public int read(byte[] buf, int off, int len) throws TTransportException {
     if (inputStream_ == null) {
-      throw new TTransportException("Cannot read from null inputStream");
+      throw new TTransportException(TTransportException.NOT_OPEN, "Cannot read from null inputStream");
     }
     try {
       return inputStream_.read(buf, off, len);
     } catch (IOException iox) {
-      throw new TTransportException(iox);
+      throw new TTransportException(TTransportException.UNKNOWN, iox);
     }
   }
 
@@ -113,12 +113,12 @@ public class TIOStreamTransport extends TTransport {
    */
   public void write(byte[] buf, int off, int len) throws TTransportException {
     if (outputStream_ == null) {
-      throw new TTransportException("Cannot write to null outputStream");
+      throw new TTransportException(TTransportException.NOT_OPEN, "Cannot write to null outputStream");
     }
     try {
       outputStream_.write(buf, off, len);
     } catch (IOException iox) {
-      throw new TTransportException(iox);
+      throw new TTransportException(TTransportException.UNKNOWN, iox);
     }
   }
 
@@ -127,12 +127,12 @@ public class TIOStreamTransport extends TTransport {
    */
   public void flush() throws TTransportException {
     if (outputStream_ == null) {
-      throw new TTransportException("Cannot flush null outputStream");
+      throw new TTransportException(TTransportException.NOT_OPEN, "Cannot flush null outputStream");
     }
     try {
       outputStream_.flush();
     } catch (IOException iox) {
-      throw new TTransportException(iox);
+      throw new TTransportException(TTransportException.UNKNOWN, iox);
     }
   }
 }
index ab2b5e7..6cbd0c1 100644 (file)
@@ -82,7 +82,7 @@ public class TServerSocket extends TServerTransport {
   
   protected TSocket acceptImpl() throws TTransportException {
     if (serverSocket_ == null) {
-      throw new TTransportException("No underlying server socket.");
+      throw new TTransportException(TTransportException.NOT_OPEN, "No underlying server socket.");
     }
     try {
       Socket result = serverSocket_.accept();
index 4922b04..a2aa233 100644 (file)
@@ -55,7 +55,7 @@ public class TSocket extends TIOStreamTransport {
         outputStream_ = new BufferedOutputStream(socket_.getOutputStream(), 1024);
       } catch (IOException iox) {
         close();
-        throw new TTransportException(iox);
+        throw new TTransportException(TTransportException.NOT_OPEN, iox);
       }
     }
   }
@@ -139,14 +139,14 @@ public class TSocket extends TIOStreamTransport {
    */
   public void open() throws TTransportException {
     if (isOpen()) {
-      throw new TTransportException("Socket already connected.");
+      throw new TTransportException(TTransportException.ALREADY_OPEN, "Socket already connected.");
     }
 
     if (host_.length() == 0) {
-      throw new TTransportException("Cannot open null host.");
+      throw new TTransportException(TTransportException.NOT_OPEN, "Cannot open null host.");
     }
     if (port_ <= 0) {
-      throw new TTransportException("Cannot open without port.");
+      throw new TTransportException(TTransportException.NOT_OPEN, "Cannot open without port.");
     }
 
     if (socket_ == null) {
@@ -159,7 +159,7 @@ public class TSocket extends TIOStreamTransport {
       outputStream_ = new BufferedOutputStream(socket_.getOutputStream(), 1024);
     } catch (IOException iox) {
       close();
-      throw new TTransportException(iox);
+      throw new TTransportException(TTransportException.NOT_OPEN, iox);
     }
   }
 
index a67b6ed..5d9e371 100644 (file)
@@ -8,14 +8,38 @@ import com.facebook.thrift.TException;
  * @author Mark Slee <mcslee@facebook.com>
  */
 public class TTransportException extends TException {
+
+  public static final int UNKNOWN = 0;
+  public static final int NOT_OPEN = 1;
+  public static final int ALREADY_OPEN = 2;
+  public static final int TIMED_OUT = 3;
+  public static final int END_OF_FILE = 4;
+
+  protected int type_ = UNKNOWN;
+
   public TTransportException() {
     super();
   }
 
+  public TTransportException(int type) {
+    super();
+    type_ = type;
+  }
+
+  public TTransportException(int type, String message) {
+    super(message);
+    type_ = type;
+  }
+
   public TTransportException(String message) {
     super(message);
   }
 
+  public TTransportException(int type, Throwable cause) {
+    super(cause);
+    type_ = type;
+  }
+
   public TTransportException(Throwable cause) {
     super(cause);
   }
@@ -23,4 +47,14 @@ public class TTransportException extends TException {
   public TTransportException(String message, Throwable cause) {
     super(message, cause);
   }
+
+  public TTransportException(int type, String message, Throwable cause) {
+    super(message, cause);
+    type_ = type;
+  }
+
+  public int getType() {
+    return type_;
+  }
+
 }