diff --git a/CHANGES.md b/CHANGES.md index 4f84275177..2dd7f0afcf 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -19,6 +19,7 @@ - [THRIFT-4730](https://issues.apache.org/jira/browse/THRIFT-4730) - C++: BoostThreadFactory, PosixThreadFactory, StdThreadFactory removed - [THRIFT-4732](https://issues.apache.org/jira/browse/THRIFT-4732) - C++: CMake build changed to use BUILD_SHARED_LIBS - [THRIFT-4735](https://issues.apache.org/jira/browse/THRIFT-4735) - C++: Removed Qt4 support +- [THRIFT-4725](https://issues.apache.org/jira/browse/THRIFT-4725) - Java change return type signature of 'process' methods ### Known Isues (Blocker or Critical) diff --git a/lib/java/README.md b/lib/java/README.md index 0b5f0d802d..505746508c 100644 --- a/lib/java/README.md +++ b/lib/java/README.md @@ -164,6 +164,11 @@ http://gradle.org/ # Breaking Changes +## 1.0 + +The signature of the 'process' method in TAsyncProcessor and TProcessor has +changed to remove a boolean return type and to instead rely on Exceptions. + ## 0.12.0 The access modifier of the AutoExpandingBuffer class has been changed from diff --git a/lib/java/src/org/apache/thrift/TAsyncProcessor.java b/lib/java/src/org/apache/thrift/TAsyncProcessor.java index 533e74d86c..66f7688962 100644 --- a/lib/java/src/org/apache/thrift/TAsyncProcessor.java +++ b/lib/java/src/org/apache/thrift/TAsyncProcessor.java @@ -21,8 +21,13 @@ import org.apache.thrift.server.AbstractNonblockingServer.AsyncFrameBuffer; public interface TAsyncProcessor { - /** - * Implementations must call fb.responseReady() once processing is complete - */ - public boolean process(final AsyncFrameBuffer fb) throws TException; + /** + * Process a single frame. + + * <b>Note:</b> Implementations must call fb.responseReady() once processing + * is complete + * + * @throws TException if the frame cannot be processed + */ + public void process(final AsyncFrameBuffer fb) throws TException; } diff --git a/lib/java/src/org/apache/thrift/TBaseAsyncProcessor.java b/lib/java/src/org/apache/thrift/TBaseAsyncProcessor.java index 0ab1827dc2..f13f068ef4 100644 --- a/lib/java/src/org/apache/thrift/TBaseAsyncProcessor.java +++ b/lib/java/src/org/apache/thrift/TBaseAsyncProcessor.java @@ -43,7 +43,7 @@ public TBaseAsyncProcessor(I iface, Map<String, AsyncProcessFunction<I, ? extend return Collections.unmodifiableMap(processMap); } - public boolean process(final AsyncFrameBuffer fb) throws TException { + public void process(final AsyncFrameBuffer fb) throws TException { final TProtocol in = fb.getInputProtocol(); final TProtocol out = fb.getOutputProtocol(); @@ -67,7 +67,7 @@ public boolean process(final AsyncFrameBuffer fb) throws TException { out.getTransport().flush(); } fb.responseReady(); - return true; + return; } //Get Args @@ -89,7 +89,7 @@ public boolean process(final AsyncFrameBuffer fb) throws TException { out.getTransport().flush(); } fb.responseReady(); - return true; + return; } in.readMessageEnd(); @@ -105,11 +105,10 @@ public boolean process(final AsyncFrameBuffer fb) throws TException { LOGGER.debug("Exception handling function", e); resultHandler.onError(e); } - return true; + return; } @Override - public boolean process(TProtocol in, TProtocol out) throws TException { - return false; + public void process(TProtocol in, TProtocol out) throws TException { } } diff --git a/lib/java/src/org/apache/thrift/TBaseProcessor.java b/lib/java/src/org/apache/thrift/TBaseProcessor.java index f9a9a9e371..55a0f15d34 100644 --- a/lib/java/src/org/apache/thrift/TBaseProcessor.java +++ b/lib/java/src/org/apache/thrift/TBaseProcessor.java @@ -23,7 +23,7 @@ protected TBaseProcessor(I iface, Map<String, ProcessFunction<I, ? extends TBase } @Override - public boolean process(TProtocol in, TProtocol out) throws TException { + public void process(TProtocol in, TProtocol out) throws TException { TMessage msg = in.readMessageBegin(); ProcessFunction fn = processMap.get(msg.name); if (fn == null) { @@ -34,9 +34,8 @@ public boolean process(TProtocol in, TProtocol out) throws TException { x.write(out); out.writeMessageEnd(); out.getTransport().flush(); - return true; + } else { + fn.process(msg.seqid, in, out, iface); } - fn.process(msg.seqid, in, out, iface); - return true; } } diff --git a/lib/java/src/org/apache/thrift/TMultiplexedProcessor.java b/lib/java/src/org/apache/thrift/TMultiplexedProcessor.java index d0c5603872..14b541d81c 100644 --- a/lib/java/src/org/apache/thrift/TMultiplexedProcessor.java +++ b/lib/java/src/org/apache/thrift/TMultiplexedProcessor.java @@ -92,7 +92,7 @@ public void registerDefault(TProcessor processor) { * name was not found in the service map. You called {@link #registerProcessor(String, TProcessor) registerProcessor} * during initialization, right? :) */ - public boolean process(TProtocol iprot, TProtocol oprot) throws TException { + public void process(TProtocol iprot, TProtocol oprot) throws TException { /* Use the actual underlying protocol (e.g. TBinaryProtocol) to read the message header. This pulls the message "off the wire", which we'll @@ -109,7 +109,8 @@ Use the actual underlying protocol (e.g. TBinaryProtocol) to read the if (index < 0) { if (defaultProcessor != null) { // Dispatch processing to the stored processor - return defaultProcessor.process(new StoredMessageProtocol(iprot, message), oprot); + defaultProcessor.process(new StoredMessageProtocol(iprot, message), oprot); + return; } throw new TException("Service name not found in message name: " + message.name + ". Did you " + "forget to use a TMultiplexProtocol in your client?"); @@ -131,7 +132,7 @@ Use the actual underlying protocol (e.g. TBinaryProtocol) to read the ); // Dispatch processing to the stored processor - return actualProcessor.process(new StoredMessageProtocol(iprot, standardMessage), oprot); + actualProcessor.process(new StoredMessageProtocol(iprot, standardMessage), oprot); } /** diff --git a/lib/java/src/org/apache/thrift/TProcessor.java b/lib/java/src/org/apache/thrift/TProcessor.java index d79522c3e5..15ba9c0fe7 100644 --- a/lib/java/src/org/apache/thrift/TProcessor.java +++ b/lib/java/src/org/apache/thrift/TProcessor.java @@ -24,9 +24,7 @@ /** * A processor is a generic object which operates upon an input stream and * writes to some output stream. - * */ public interface TProcessor { - public boolean process(TProtocol in, TProtocol out) - throws TException; + public void process(TProtocol in, TProtocol out) throws TException; } diff --git a/lib/java/src/org/apache/thrift/server/TSimpleServer.java b/lib/java/src/org/apache/thrift/server/TSimpleServer.java index e815b2cf16..13501efc6c 100644 --- a/lib/java/src/org/apache/thrift/server/TSimpleServer.java +++ b/lib/java/src/org/apache/thrift/server/TSimpleServer.java @@ -77,9 +77,7 @@ public void serve() { if (eventHandler_ != null) { eventHandler_.processContext(connectionContext, inputTransport, outputTransport); } - if(!processor.process(inputProtocol, outputProtocol)) { - break; - } + processor.process(inputProtocol, outputProtocol); } } } catch (TTransportException ttx) { diff --git a/lib/java/src/org/apache/thrift/server/TThreadPoolServer.java b/lib/java/src/org/apache/thrift/server/TThreadPoolServer.java index 1697ad6ae4..db1ecb9dab 100644 --- a/lib/java/src/org/apache/thrift/server/TThreadPoolServer.java +++ b/lib/java/src/org/apache/thrift/server/TThreadPoolServer.java @@ -307,9 +307,10 @@ public void run() { eventHandler.processContext(connectionContext, inputTransport, outputTransport); } - if(stopped_ || !processor.process(inputProtocol, outputProtocol)) { + if (stopped_) { break; } + processor.process(inputProtocol, outputProtocol); } } catch (TException tx) { LOGGER.error("Thrift error occurred during processing of message.", tx); diff --git a/lib/java/test/org/apache/thrift/TestMultiplexedProcessor.java b/lib/java/test/org/apache/thrift/TestMultiplexedProcessor.java index 01776ca395..85e7966bf2 100644 --- a/lib/java/test/org/apache/thrift/TestMultiplexedProcessor.java +++ b/lib/java/test/org/apache/thrift/TestMultiplexedProcessor.java @@ -57,13 +57,12 @@ public void testNoSuchService() throws TException { static class StubProcessor implements TProcessor { @Override - public boolean process(TProtocol in, TProtocol out) throws TException { + public void process(TProtocol in, TProtocol out) throws TException { TMessage msg = in.readMessageBegin(); if (!"func".equals(msg.name) || msg.type!=TMessageType.CALL || msg.seqid!=42) { throw new TException("incorrect parameters"); } out.writeMessageBegin(new TMessage("func", TMessageType.REPLY, 42)); - return true; } }
With regards, Apache Git Services
