Merge pull request #1678 from BELUGABEHR/THRIFT-4725

THRIFT-4725: Change Return Type Signature of Process Methods
This commit is contained in:
James E. King III 2019-01-14 16:54:59 -05:00 committed by GitHub
commit 010ccf0a0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 32 additions and 26 deletions

View File

@ -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)

View File

@ -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

View File

@ -21,8 +21,13 @@ package org.apache.thrift;
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;
}

View File

@ -43,7 +43,7 @@ public class TBaseAsyncProcessor<I> implements TAsyncProcessor, TProcessor {
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 class TBaseAsyncProcessor<I> implements TAsyncProcessor, TProcessor {
out.getTransport().flush();
}
fb.responseReady();
return true;
return;
}
//Get Args
@ -89,7 +89,7 @@ public class TBaseAsyncProcessor<I> implements TAsyncProcessor, TProcessor {
out.getTransport().flush();
}
fb.responseReady();
return true;
return;
}
in.readMessageEnd();
@ -105,11 +105,10 @@ public class TBaseAsyncProcessor<I> implements TAsyncProcessor, TProcessor {
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 {
}
}

View File

@ -23,7 +23,7 @@ public abstract class TBaseProcessor<I> 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();
ProcessFunction fn = processMap.get(msg.name);
if (fn == null) {
@ -34,9 +34,8 @@ public abstract class TBaseProcessor<I> implements TProcessor {
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;
}
}

View File

@ -92,7 +92,7 @@ public class TMultiplexedProcessor implements TProcessor {
* 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 @@ public class TMultiplexedProcessor implements TProcessor {
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 @@ public class TMultiplexedProcessor implements TProcessor {
);
// Dispatch processing to the stored processor
return actualProcessor.process(new StoredMessageProtocol(iprot, standardMessage), oprot);
actualProcessor.process(new StoredMessageProtocol(iprot, standardMessage), oprot);
}
/**

View File

@ -24,9 +24,7 @@ import org.apache.thrift.protocol.TProtocol;
/**
* 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;
}

View File

@ -77,9 +77,7 @@ public class TSimpleServer extends TServer {
if (eventHandler_ != null) {
eventHandler_.processContext(connectionContext, inputTransport, outputTransport);
}
if(!processor.process(inputProtocol, outputProtocol)) {
break;
}
processor.process(inputProtocol, outputProtocol);
}
}
} catch (TTransportException ttx) {

View File

@ -307,9 +307,10 @@ public class TThreadPoolServer extends TServer {
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);

View File

@ -57,13 +57,12 @@ public class TestMultiplexedProcessor {
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;
}
}