Closer doesn't need to pass the value to its method. Thus, it also doesn't need to be generic
Project: http://git-wip-us.apache.org/repos/asf/curator/repo Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/10bf3553 Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/10bf3553 Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/10bf3553 Branch: refs/heads/master Commit: 10bf355309ffa4dcf22dfa6205346c804e459647 Parents: 48d3e31 Author: randgalt <randg...@apache.org> Authored: Fri May 30 10:58:49 2014 -0500 Committer: randgalt <randg...@apache.org> Committed: Fri May 30 10:58:49 2014 -0500 ---------------------------------------------------------------------- .../curator/x/rpc/connections/CuratorEntry.java | 4 +- .../projection/CuratorProjectionService.java | 8 +- curator-x-rpc/src/main/thrift/curator.thrift | 1 + .../curator/generated/CuratorService.java | 455 +++++++++++++++++++ 4 files changed, 464 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/curator/blob/10bf3553/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/connections/CuratorEntry.java ---------------------------------------------------------------------- diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/connections/CuratorEntry.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/connections/CuratorEntry.java index 0df0740..bb56cfb 100644 --- a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/connections/CuratorEntry.java +++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/connections/CuratorEntry.java @@ -55,8 +55,7 @@ public class CuratorEntry implements Closeable if ( entry.closer != null ) { log.debug(String.format("Closing left over thing. Type: %s - Id: %s", entry.thing.getClass(), mapEntry.getKey())); - //noinspection unchecked - entry.closer.close(); // lack of generics is safe because addThing() is type-safe + entry.closer.close(); } } things.clear(); @@ -109,7 +108,6 @@ public class CuratorEntry implements Closeable Entry entry = (id != null) ? things.remove(id) : null; if ( entry != null ) { - //noinspection unchecked entry.closer.close(); } return false; http://git-wip-us.apache.org/repos/asf/curator/blob/10bf3553/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/projection/CuratorProjectionService.java ---------------------------------------------------------------------- diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/projection/CuratorProjectionService.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/projection/CuratorProjectionService.java index f82384f..ab9add7 100644 --- a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/projection/CuratorProjectionService.java +++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/projection/CuratorProjectionService.java @@ -91,7 +91,7 @@ public class CuratorProjectionService return projection; } - @ThriftMethod + @ThriftMethod(oneway = true) public void closeCuratorProjection(CuratorProjection projection) { CuratorEntry entry = connectionManager.remove(projection.id); @@ -101,6 +101,12 @@ public class CuratorProjectionService } } + @ThriftMethod(oneway = true) + public void pingCuratorProjection(CuratorProjection projection) + { + connectionManager.get(projection.id); + } + @ThriftMethod public OptionalPath createNode(CuratorProjection projection, CreateSpec spec) throws Exception { http://git-wip-us.apache.org/repos/asf/curator/blob/10bf3553/curator-x-rpc/src/main/thrift/curator.thrift ---------------------------------------------------------------------- diff --git a/curator-x-rpc/src/main/thrift/curator.thrift b/curator-x-rpc/src/main/thrift/curator.thrift index fc51dba..204ef7d 100644 --- a/curator-x-rpc/src/main/thrift/curator.thrift +++ b/curator-x-rpc/src/main/thrift/curator.thrift @@ -213,6 +213,7 @@ service CuratorService { ChildData getPathChildrenCacheDataForPath(1: CuratorProjection projection, 2: PathChildrenCacheProjection cacheProjection, 3: string path); bool isLeader(1: CuratorProjection projection, 2: LeaderProjection leaderProjection); CuratorProjection newCuratorProjection(1: string connectionName); + oneway void pingCuratorProjection(1: CuratorProjection projection); Stat setData(1: CuratorProjection projection, 2: SetDataSpec spec); LeaderResult startLeaderSelector(1: CuratorProjection projection, 2: string path, 3: string participantId, 4: i32 waitForLeadershipMs); NodeCacheProjection startNodeCache(1: CuratorProjection projection, 2: string path, 3: bool dataIsCompressed, 4: bool buildInitial); http://git-wip-us.apache.org/repos/asf/curator/blob/10bf3553/curator-x-rpc/src/test/java/org/apache/curator/generated/CuratorService.java ---------------------------------------------------------------------- diff --git a/curator-x-rpc/src/test/java/org/apache/curator/generated/CuratorService.java b/curator-x-rpc/src/test/java/org/apache/curator/generated/CuratorService.java index d7e52ba..5e85d1e 100644 --- a/curator-x-rpc/src/test/java/org/apache/curator/generated/CuratorService.java +++ b/curator-x-rpc/src/test/java/org/apache/curator/generated/CuratorService.java @@ -64,6 +64,8 @@ public class CuratorService { public CuratorProjection newCuratorProjection(String connectionName) throws org.apache.thrift.TException; + public void pingCuratorProjection(CuratorProjection projection) throws org.apache.thrift.TException; + public Stat setData(CuratorProjection projection, SetDataSpec spec) throws org.apache.thrift.TException; public LeaderResult startLeaderSelector(CuratorProjection projection, String path, String participantId, int waitForLeadershipMs) throws org.apache.thrift.TException; @@ -108,6 +110,8 @@ public class CuratorService { public void newCuratorProjection(String connectionName, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; + public void pingCuratorProjection(CuratorProjection projection, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; + public void setData(CuratorProjection projection, SetDataSpec spec, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; public void startLeaderSelector(CuratorProjection projection, String path, String participantId, int waitForLeadershipMs, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; @@ -472,6 +476,18 @@ public class CuratorService { throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "newCuratorProjection failed: unknown result"); } + public void pingCuratorProjection(CuratorProjection projection) throws org.apache.thrift.TException + { + send_pingCuratorProjection(projection); + } + + public void send_pingCuratorProjection(CuratorProjection projection) throws org.apache.thrift.TException + { + pingCuratorProjection_args args = new pingCuratorProjection_args(); + args.setProjection(projection); + sendBase("pingCuratorProjection", args); + } + public Stat setData(CuratorProjection projection, SetDataSpec spec) throws org.apache.thrift.TException { send_setData(projection, spec); @@ -1136,6 +1152,37 @@ public class CuratorService { } } + public void pingCuratorProjection(CuratorProjection projection, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException { + checkReady(); + pingCuratorProjection_call method_call = new pingCuratorProjection_call(projection, resultHandler, this, ___protocolFactory, ___transport); + this.___currentMethod = method_call; + ___manager.call(method_call); + } + + public static class pingCuratorProjection_call extends org.apache.thrift.async.TAsyncMethodCall { + private CuratorProjection projection; + public pingCuratorProjection_call(CuratorProjection projection, org.apache.thrift.async.AsyncMethodCallback resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException { + super(client, protocolFactory, transport, resultHandler, true); + this.projection = projection; + } + + public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException { + prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("pingCuratorProjection", org.apache.thrift.protocol.TMessageType.CALL, 0)); + pingCuratorProjection_args args = new pingCuratorProjection_args(); + args.setProjection(projection); + args.write(prot); + prot.writeMessageEnd(); + } + + public void getResult() throws org.apache.thrift.TException { + if (getState() != org.apache.thrift.async.TAsyncMethodCall.State.RESPONSE_READ) { + throw new IllegalStateException("Method call not finished!"); + } + org.apache.thrift.transport.TMemoryInputTransport memoryTransport = new org.apache.thrift.transport.TMemoryInputTransport(getFrameBuffer().array()); + org.apache.thrift.protocol.TProtocol prot = client.getProtocolFactory().getProtocol(memoryTransport); + } + } + public void setData(CuratorProjection projection, SetDataSpec spec, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException { checkReady(); setData_call method_call = new setData_call(projection, spec, resultHandler, this, ___protocolFactory, ___transport); @@ -1409,6 +1456,7 @@ public class CuratorService { processMap.put("getPathChildrenCacheDataForPath", new getPathChildrenCacheDataForPath()); processMap.put("isLeader", new isLeader()); processMap.put("newCuratorProjection", new newCuratorProjection()); + processMap.put("pingCuratorProjection", new pingCuratorProjection()); processMap.put("setData", new setData()); processMap.put("startLeaderSelector", new startLeaderSelector()); processMap.put("startNodeCache", new startNodeCache()); @@ -1700,6 +1748,25 @@ public class CuratorService { } } + public static class pingCuratorProjection<I extends Iface> extends org.apache.thrift.ProcessFunction<I, pingCuratorProjection_args> { + public pingCuratorProjection() { + super("pingCuratorProjection"); + } + + public pingCuratorProjection_args getEmptyArgsInstance() { + return new pingCuratorProjection_args(); + } + + protected boolean isOneway() { + return true; + } + + public org.apache.thrift.TBase getResult(I iface, pingCuratorProjection_args args) throws org.apache.thrift.TException { + iface.pingCuratorProjection(args.projection); + return null; + } + } + public static class setData<I extends Iface> extends org.apache.thrift.ProcessFunction<I, setData_args> { public setData() { super("setData"); @@ -1847,6 +1914,7 @@ public class CuratorService { processMap.put("getPathChildrenCacheDataForPath", new getPathChildrenCacheDataForPath()); processMap.put("isLeader", new isLeader()); processMap.put("newCuratorProjection", new newCuratorProjection()); + processMap.put("pingCuratorProjection", new pingCuratorProjection()); processMap.put("setData", new setData()); processMap.put("startLeaderSelector", new startLeaderSelector()); processMap.put("startNodeCache", new startNodeCache()); @@ -2570,6 +2638,34 @@ public class CuratorService { } } + public static class pingCuratorProjection<I extends AsyncIface> extends org.apache.thrift.AsyncProcessFunction<I, pingCuratorProjection_args, Void> { + public pingCuratorProjection() { + super("pingCuratorProjection"); + } + + public pingCuratorProjection_args getEmptyArgsInstance() { + return new pingCuratorProjection_args(); + } + + public AsyncMethodCallback<Void> getResultHandler(final AsyncFrameBuffer fb, final int seqid) { + final org.apache.thrift.AsyncProcessFunction fcall = this; + return new AsyncMethodCallback<Void>() { + public void onComplete(Void o) { + } + public void onError(Exception e) { + } + }; + } + + protected boolean isOneway() { + return true; + } + + public void start(I iface, pingCuratorProjection_args args, org.apache.thrift.async.AsyncMethodCallback<Void> resultHandler) throws TException { + iface.pingCuratorProjection(args.projection,resultHandler); + } + } + public static class setData<I extends AsyncIface> extends org.apache.thrift.AsyncProcessFunction<I, setData_args, Stat> { public setData() { super("setData"); @@ -14241,6 +14337,365 @@ public class CuratorService { } + public static class pingCuratorProjection_args implements org.apache.thrift.TBase<pingCuratorProjection_args, pingCuratorProjection_args._Fields>, java.io.Serializable, Cloneable, Comparable<pingCuratorProjection_args> { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("pingCuratorProjection_args"); + + private static final org.apache.thrift.protocol.TField PROJECTION_FIELD_DESC = new org.apache.thrift.protocol.TField("projection", org.apache.thrift.protocol.TType.STRUCT, (short)1); + + private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>(); + static { + schemes.put(StandardScheme.class, new pingCuratorProjection_argsStandardSchemeFactory()); + schemes.put(TupleScheme.class, new pingCuratorProjection_argsTupleSchemeFactory()); + } + + public CuratorProjection projection; // 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 { + PROJECTION((short)1, "projection"); + + private static final Map<String, _Fields> byName = new HashMap<String, _Fields>(); + + static { + for (_Fields field : EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // PROJECTION + return PROJECTION; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(String name) { + return byName.get(name); + } + + private final short _thriftId; + private final String _fieldName; + + _Fields(short thriftId, String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.PROJECTION, new org.apache.thrift.meta_data.FieldMetaData("projection", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, CuratorProjection.class))); + metaDataMap = Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(pingCuratorProjection_args.class, metaDataMap); + } + + public pingCuratorProjection_args() { + } + + public pingCuratorProjection_args( + CuratorProjection projection) + { + this(); + this.projection = projection; + } + + /** + * Performs a deep copy on <i>other</i>. + */ + public pingCuratorProjection_args(pingCuratorProjection_args other) { + if (other.isSetProjection()) { + this.projection = new CuratorProjection(other.projection); + } + } + + public pingCuratorProjection_args deepCopy() { + return new pingCuratorProjection_args(this); + } + + @Override + public void clear() { + this.projection = null; + } + + public CuratorProjection getProjection() { + return this.projection; + } + + public pingCuratorProjection_args setProjection(CuratorProjection projection) { + this.projection = projection; + return this; + } + + public void unsetProjection() { + this.projection = null; + } + + /** Returns true if field projection is set (has been assigned a value) and false otherwise */ + public boolean isSetProjection() { + return this.projection != null; + } + + public void setProjectionIsSet(boolean value) { + if (!value) { + this.projection = null; + } + } + + public void setFieldValue(_Fields field, Object value) { + switch (field) { + case PROJECTION: + if (value == null) { + unsetProjection(); + } else { + setProjection((CuratorProjection)value); + } + break; + + } + } + + public Object getFieldValue(_Fields field) { + switch (field) { + case PROJECTION: + return getProjection(); + + } + throw new IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new IllegalArgumentException(); + } + + switch (field) { + case PROJECTION: + return isSetProjection(); + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof pingCuratorProjection_args) + return this.equals((pingCuratorProjection_args)that); + return false; + } + + public boolean equals(pingCuratorProjection_args that) { + if (that == null) + return false; + + boolean this_present_projection = true && this.isSetProjection(); + boolean that_present_projection = true && that.isSetProjection(); + if (this_present_projection || that_present_projection) { + if (!(this_present_projection && that_present_projection)) + return false; + if (!this.projection.equals(that.projection)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + return 0; + } + + @Override + public int compareTo(pingCuratorProjection_args other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = Boolean.valueOf(isSetProjection()).compareTo(other.isSetProjection()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetProjection()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.projection, other.projection); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + schemes.get(iprot.getScheme()).getScheme().read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + schemes.get(oprot.getScheme()).getScheme().write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("pingCuratorProjection_args("); + boolean first = true; + + sb.append("projection:"); + if (this.projection == null) { + sb.append("null"); + } else { + sb.append(this.projection); + } + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + if (projection != null) { + projection.validate(); + } + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { + try { + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class pingCuratorProjection_argsStandardSchemeFactory implements SchemeFactory { + public pingCuratorProjection_argsStandardScheme getScheme() { + return new pingCuratorProjection_argsStandardScheme(); + } + } + + private static class pingCuratorProjection_argsStandardScheme extends StandardScheme<pingCuratorProjection_args> { + + public void read(org.apache.thrift.protocol.TProtocol iprot, pingCuratorProjection_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 1: // PROJECTION + if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) { + struct.projection = new CuratorProjection(); + struct.projection.read(iprot); + struct.setProjectionIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, pingCuratorProjection_args struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.projection != null) { + oprot.writeFieldBegin(PROJECTION_FIELD_DESC); + struct.projection.write(oprot); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class pingCuratorProjection_argsTupleSchemeFactory implements SchemeFactory { + public pingCuratorProjection_argsTupleScheme getScheme() { + return new pingCuratorProjection_argsTupleScheme(); + } + } + + private static class pingCuratorProjection_argsTupleScheme extends TupleScheme<pingCuratorProjection_args> { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, pingCuratorProjection_args struct) throws org.apache.thrift.TException { + TTupleProtocol oprot = (TTupleProtocol) prot; + BitSet optionals = new BitSet(); + if (struct.isSetProjection()) { + optionals.set(0); + } + oprot.writeBitSet(optionals, 1); + if (struct.isSetProjection()) { + struct.projection.write(oprot); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, pingCuratorProjection_args struct) throws org.apache.thrift.TException { + TTupleProtocol iprot = (TTupleProtocol) prot; + BitSet incoming = iprot.readBitSet(1); + if (incoming.get(0)) { + struct.projection = new CuratorProjection(); + struct.projection.read(iprot); + struct.setProjectionIsSet(true); + } + } + } + + } + public static class setData_args implements org.apache.thrift.TBase<setData_args, setData_args._Fields>, java.io.Serializable, Cloneable, Comparable<setData_args> { private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("setData_args");