You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@curator.apache.org by ra...@apache.org on 2014/06/07 20:19:12 UTC
[14/50] [abbrv] initial stab at exception support
http://git-wip-us.apache.org/repos/asf/curator/blob/c6229cf2/curator-x-rpc/src/test/java/org/apache/curator/generated/EventService.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/test/java/org/apache/curator/generated/EventService.java b/curator-x-rpc/src/test/java/org/apache/curator/generated/EventService.java
index 3f9f332..9854e0e 100644
--- a/curator-x-rpc/src/test/java/org/apache/curator/generated/EventService.java
+++ b/curator-x-rpc/src/test/java/org/apache/curator/generated/EventService.java
@@ -36,7 +36,7 @@ public class EventService {
public interface Iface {
- public CuratorEvent getNextEvent(CuratorProjection projection) throws org.apache.thrift.TException;
+ public CuratorEvent getNextEvent(CuratorProjection projection) throws CuratorException, org.apache.thrift.TException;
}
@@ -66,7 +66,7 @@ public class EventService {
super(iprot, oprot);
}
- public CuratorEvent getNextEvent(CuratorProjection projection) throws org.apache.thrift.TException
+ public CuratorEvent getNextEvent(CuratorProjection projection) throws CuratorException, org.apache.thrift.TException
{
send_getNextEvent(projection);
return recv_getNextEvent();
@@ -79,13 +79,16 @@ public class EventService {
sendBase("getNextEvent", args);
}
- public CuratorEvent recv_getNextEvent() throws org.apache.thrift.TException
+ public CuratorEvent recv_getNextEvent() throws CuratorException, org.apache.thrift.TException
{
getNextEvent_result result = new getNextEvent_result();
receiveBase(result, "getNextEvent");
if (result.isSetSuccess()) {
return result.success;
}
+ if (result.ex1 != null) {
+ throw result.ex1;
+ }
throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "getNextEvent failed: unknown result");
}
@@ -129,7 +132,7 @@ public class EventService {
prot.writeMessageEnd();
}
- public CuratorEvent getResult() throws org.apache.thrift.TException {
+ public CuratorEvent getResult() throws CuratorException, org.apache.thrift.TException {
if (getState() != org.apache.thrift.async.TAsyncMethodCall.State.RESPONSE_READ) {
throw new IllegalStateException("Method call not finished!");
}
@@ -171,7 +174,11 @@ public class EventService {
public getNextEvent_result getResult(I iface, getNextEvent_args args) throws org.apache.thrift.TException {
getNextEvent_result result = new getNextEvent_result();
- result.success = iface.getNextEvent(args.projection);
+ try {
+ result.success = iface.getNextEvent(args.projection);
+ } catch (CuratorException ex1) {
+ result.ex1 = ex1;
+ }
return result;
}
}
@@ -220,6 +227,12 @@ public class EventService {
byte msgType = org.apache.thrift.protocol.TMessageType.REPLY;
org.apache.thrift.TBase msg;
getNextEvent_result result = new getNextEvent_result();
+ if (e instanceof CuratorException) {
+ result.ex1 = (CuratorException) e;
+ result.setEx1IsSet(true);
+ msg = result;
+ }
+ else
{
msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION;
msg = (org.apache.thrift.TBase)new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.INTERNAL_ERROR, e.getMessage());
@@ -609,6 +622,7 @@ public class EventService {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("getNextEvent_result");
private static final org.apache.thrift.protocol.TField SUCCESS_FIELD_DESC = new org.apache.thrift.protocol.TField("success", org.apache.thrift.protocol.TType.STRUCT, (short)0);
+ private static final org.apache.thrift.protocol.TField EX1_FIELD_DESC = new org.apache.thrift.protocol.TField("ex1", org.apache.thrift.protocol.TType.STRUCT, (short)1);
private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>();
static {
@@ -617,10 +631,12 @@ public class EventService {
}
public CuratorEvent success; // required
+ public CuratorException ex1; // required
/** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
public enum _Fields implements org.apache.thrift.TFieldIdEnum {
- SUCCESS((short)0, "success");
+ SUCCESS((short)0, "success"),
+ EX1((short)1, "ex1");
private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();
@@ -637,6 +653,8 @@ public class EventService {
switch(fieldId) {
case 0: // SUCCESS
return SUCCESS;
+ case 1: // EX1
+ return EX1;
default:
return null;
}
@@ -682,6 +700,8 @@ public class EventService {
Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
tmpMap.put(_Fields.SUCCESS, new org.apache.thrift.meta_data.FieldMetaData("success", org.apache.thrift.TFieldRequirementType.DEFAULT,
new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, CuratorEvent.class)));
+ tmpMap.put(_Fields.EX1, new org.apache.thrift.meta_data.FieldMetaData("ex1", org.apache.thrift.TFieldRequirementType.DEFAULT,
+ new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRUCT)));
metaDataMap = Collections.unmodifiableMap(tmpMap);
org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(getNextEvent_result.class, metaDataMap);
}
@@ -690,10 +710,12 @@ public class EventService {
}
public getNextEvent_result(
- CuratorEvent success)
+ CuratorEvent success,
+ CuratorException ex1)
{
this();
this.success = success;
+ this.ex1 = ex1;
}
/**
@@ -703,6 +725,9 @@ public class EventService {
if (other.isSetSuccess()) {
this.success = new CuratorEvent(other.success);
}
+ if (other.isSetEx1()) {
+ this.ex1 = new CuratorException(other.ex1);
+ }
}
public getNextEvent_result deepCopy() {
@@ -712,6 +737,7 @@ public class EventService {
@Override
public void clear() {
this.success = null;
+ this.ex1 = null;
}
public CuratorEvent getSuccess() {
@@ -738,6 +764,30 @@ public class EventService {
}
}
+ public CuratorException getEx1() {
+ return this.ex1;
+ }
+
+ public getNextEvent_result setEx1(CuratorException ex1) {
+ this.ex1 = ex1;
+ return this;
+ }
+
+ public void unsetEx1() {
+ this.ex1 = null;
+ }
+
+ /** Returns true if field ex1 is set (has been assigned a value) and false otherwise */
+ public boolean isSetEx1() {
+ return this.ex1 != null;
+ }
+
+ public void setEx1IsSet(boolean value) {
+ if (!value) {
+ this.ex1 = null;
+ }
+ }
+
public void setFieldValue(_Fields field, Object value) {
switch (field) {
case SUCCESS:
@@ -748,6 +798,14 @@ public class EventService {
}
break;
+ case EX1:
+ if (value == null) {
+ unsetEx1();
+ } else {
+ setEx1((CuratorException)value);
+ }
+ break;
+
}
}
@@ -756,6 +814,9 @@ public class EventService {
case SUCCESS:
return getSuccess();
+ case EX1:
+ return getEx1();
+
}
throw new IllegalStateException();
}
@@ -769,6 +830,8 @@ public class EventService {
switch (field) {
case SUCCESS:
return isSetSuccess();
+ case EX1:
+ return isSetEx1();
}
throw new IllegalStateException();
}
@@ -795,6 +858,15 @@ public class EventService {
return false;
}
+ boolean this_present_ex1 = true && this.isSetEx1();
+ boolean that_present_ex1 = true && that.isSetEx1();
+ if (this_present_ex1 || that_present_ex1) {
+ if (!(this_present_ex1 && that_present_ex1))
+ return false;
+ if (!this.ex1.equals(that.ex1))
+ return false;
+ }
+
return true;
}
@@ -821,6 +893,16 @@ public class EventService {
return lastComparison;
}
}
+ lastComparison = Boolean.valueOf(isSetEx1()).compareTo(other.isSetEx1());
+ if (lastComparison != 0) {
+ return lastComparison;
+ }
+ if (isSetEx1()) {
+ lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.ex1, other.ex1);
+ if (lastComparison != 0) {
+ return lastComparison;
+ }
+ }
return 0;
}
@@ -848,6 +930,14 @@ public class EventService {
sb.append(this.success);
}
first = false;
+ if (!first) sb.append(", ");
+ sb.append("ex1:");
+ if (this.ex1 == null) {
+ sb.append("null");
+ } else {
+ sb.append(this.ex1);
+ }
+ first = false;
sb.append(")");
return sb.toString();
}
@@ -903,6 +993,15 @@ public class EventService {
org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
}
break;
+ case 1: // EX1
+ if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) {
+ struct.ex1 = new CuratorException();
+ struct.ex1.read(iprot);
+ struct.setEx1IsSet(true);
+ } else {
+ org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
+ }
+ break;
default:
org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
}
@@ -923,6 +1022,11 @@ public class EventService {
struct.success.write(oprot);
oprot.writeFieldEnd();
}
+ if (struct.ex1 != null) {
+ oprot.writeFieldBegin(EX1_FIELD_DESC);
+ struct.ex1.write(oprot);
+ oprot.writeFieldEnd();
+ }
oprot.writeFieldStop();
oprot.writeStructEnd();
}
@@ -944,21 +1048,32 @@ public class EventService {
if (struct.isSetSuccess()) {
optionals.set(0);
}
- oprot.writeBitSet(optionals, 1);
+ if (struct.isSetEx1()) {
+ optionals.set(1);
+ }
+ oprot.writeBitSet(optionals, 2);
if (struct.isSetSuccess()) {
struct.success.write(oprot);
}
+ if (struct.isSetEx1()) {
+ struct.ex1.write(oprot);
+ }
}
@Override
public void read(org.apache.thrift.protocol.TProtocol prot, getNextEvent_result struct) throws org.apache.thrift.TException {
TTupleProtocol iprot = (TTupleProtocol) prot;
- BitSet incoming = iprot.readBitSet(1);
+ BitSet incoming = iprot.readBitSet(2);
if (incoming.get(0)) {
struct.success = new CuratorEvent();
struct.success.read(iprot);
struct.setSuccessIsSet(true);
}
+ if (incoming.get(1)) {
+ struct.ex1 = new CuratorException();
+ struct.ex1.read(iprot);
+ struct.setEx1IsSet(true);
+ }
}
}
http://git-wip-us.apache.org/repos/asf/curator/blob/c6229cf2/curator-x-rpc/src/test/java/org/apache/curator/generated/ExceptionType.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/test/java/org/apache/curator/generated/ExceptionType.java b/curator-x-rpc/src/test/java/org/apache/curator/generated/ExceptionType.java
new file mode 100644
index 0000000..b727f3a
--- /dev/null
+++ b/curator-x-rpc/src/test/java/org/apache/curator/generated/ExceptionType.java
@@ -0,0 +1,48 @@
+/**
+ * Autogenerated by Thrift Compiler (0.9.1)
+ *
+ * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
+ * @generated
+ */
+package org.apache.curator.generated;
+
+
+import java.util.Map;
+import java.util.HashMap;
+import org.apache.thrift.TEnum;
+
+public enum ExceptionType implements org.apache.thrift.TEnum {
+ GENERAL(0),
+ ZOOKEEPER(1),
+ NODE(2);
+
+ private final int value;
+
+ private ExceptionType(int value) {
+ this.value = value;
+ }
+
+ /**
+ * Get the integer value of this enum value, as defined in the Thrift IDL.
+ */
+ public int getValue() {
+ return value;
+ }
+
+ /**
+ * Find a the enum type by its integer value, as defined in the Thrift IDL.
+ * @return null if the value is not found.
+ */
+ public static ExceptionType findByValue(int value) {
+ switch (value) {
+ case 0:
+ return GENERAL;
+ case 1:
+ return ZOOKEEPER;
+ case 2:
+ return NODE;
+ default:
+ return null;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/curator/blob/c6229cf2/curator-x-rpc/src/test/java/org/apache/curator/generated/NodeExceptionType.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/test/java/org/apache/curator/generated/NodeExceptionType.java b/curator-x-rpc/src/test/java/org/apache/curator/generated/NodeExceptionType.java
new file mode 100644
index 0000000..fb2a989
--- /dev/null
+++ b/curator-x-rpc/src/test/java/org/apache/curator/generated/NodeExceptionType.java
@@ -0,0 +1,51 @@
+/**
+ * Autogenerated by Thrift Compiler (0.9.1)
+ *
+ * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
+ * @generated
+ */
+package org.apache.curator.generated;
+
+
+import java.util.Map;
+import java.util.HashMap;
+import org.apache.thrift.TEnum;
+
+public enum NodeExceptionType implements org.apache.thrift.TEnum {
+ NONODE(0),
+ BADVERSION(1),
+ NODEEXISTS(2),
+ NOTEMPTY(3);
+
+ private final int value;
+
+ private NodeExceptionType(int value) {
+ this.value = value;
+ }
+
+ /**
+ * Get the integer value of this enum value, as defined in the Thrift IDL.
+ */
+ public int getValue() {
+ return value;
+ }
+
+ /**
+ * Find a the enum type by its integer value, as defined in the Thrift IDL.
+ * @return null if the value is not found.
+ */
+ public static NodeExceptionType findByValue(int value) {
+ switch (value) {
+ case 0:
+ return NONODE;
+ case 1:
+ return BADVERSION;
+ case 2:
+ return NODEEXISTS;
+ case 3:
+ return NOTEMPTY;
+ default:
+ return null;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/curator/blob/c6229cf2/curator-x-rpc/src/test/java/org/apache/curator/generated/ZooKeeperExceptionType.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/test/java/org/apache/curator/generated/ZooKeeperExceptionType.java b/curator-x-rpc/src/test/java/org/apache/curator/generated/ZooKeeperExceptionType.java
new file mode 100644
index 0000000..2514d30
--- /dev/null
+++ b/curator-x-rpc/src/test/java/org/apache/curator/generated/ZooKeeperExceptionType.java
@@ -0,0 +1,90 @@
+/**
+ * Autogenerated by Thrift Compiler (0.9.1)
+ *
+ * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
+ * @generated
+ */
+package org.apache.curator.generated;
+
+
+import java.util.Map;
+import java.util.HashMap;
+import org.apache.thrift.TEnum;
+
+public enum ZooKeeperExceptionType implements org.apache.thrift.TEnum {
+ SYSTEMERROR(0),
+ RUNTIMEINCONSISTENCY(1),
+ DATAINCONSISTENCY(2),
+ CONNECTIONLOSS(3),
+ MARSHALLINGERROR(4),
+ UNIMPLEMENTED(5),
+ OPERATIONTIMEOUT(6),
+ BADARGUMENTS(7),
+ APIERROR(8),
+ NOAUTH(9),
+ NOCHILDRENFOREPHEMERALS(10),
+ INVALIDACL(11),
+ AUTHFAILED(12),
+ SESSIONEXPIRED(13),
+ INVALIDCALLBACK(14),
+ SESSIONMOVED(15),
+ NOTREADONLY(16);
+
+ private final int value;
+
+ private ZooKeeperExceptionType(int value) {
+ this.value = value;
+ }
+
+ /**
+ * Get the integer value of this enum value, as defined in the Thrift IDL.
+ */
+ public int getValue() {
+ return value;
+ }
+
+ /**
+ * Find a the enum type by its integer value, as defined in the Thrift IDL.
+ * @return null if the value is not found.
+ */
+ public static ZooKeeperExceptionType findByValue(int value) {
+ switch (value) {
+ case 0:
+ return SYSTEMERROR;
+ case 1:
+ return RUNTIMEINCONSISTENCY;
+ case 2:
+ return DATAINCONSISTENCY;
+ case 3:
+ return CONNECTIONLOSS;
+ case 4:
+ return MARSHALLINGERROR;
+ case 5:
+ return UNIMPLEMENTED;
+ case 6:
+ return OPERATIONTIMEOUT;
+ case 7:
+ return BADARGUMENTS;
+ case 8:
+ return APIERROR;
+ case 9:
+ return NOAUTH;
+ case 10:
+ return NOCHILDRENFOREPHEMERALS;
+ case 11:
+ return INVALIDACL;
+ case 12:
+ return AUTHFAILED;
+ case 13:
+ return SESSIONEXPIRED;
+ case 14:
+ return INVALIDCALLBACK;
+ case 15:
+ return SESSIONMOVED;
+ case 16:
+ return NOTREADONLY;
+ default:
+ return null;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/curator/blob/c6229cf2/curator-x-rpc/src/test/java/org/apache/curator/x/rpc/TestClient.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/test/java/org/apache/curator/x/rpc/TestClient.java b/curator-x-rpc/src/test/java/org/apache/curator/x/rpc/TestClient.java
index 5e1451e..dbd5643 100644
--- a/curator-x-rpc/src/test/java/org/apache/curator/x/rpc/TestClient.java
+++ b/curator-x-rpc/src/test/java/org/apache/curator/x/rpc/TestClient.java
@@ -68,6 +68,18 @@ public class TestClient
);
CreateSpec createSpec = new CreateSpec();
+ createSpec.path = "/this/should/fail";
+ createSpec.data = ByteBuffer.wrap("hey".getBytes());
+ try
+ {
+ client.createNode(curatorProjection, createSpec);
+ }
+ catch ( CuratorException e )
+ {
+ System.out.println("Ex: " + e);
+ }
+
+ createSpec = new CreateSpec();
createSpec.path = "/a/b/c";
createSpec.creatingParentsIfNeeded = true;
createSpec.data = ByteBuffer.wrap("hey".getBytes());