本文整理汇总了Java中org.apache.thrift.TProcessor.process方法的典型用法代码示例。如果您正苦于以下问题:Java TProcessor.process方法的具体用法?Java TProcessor.process怎么用?Java TProcessor.process使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.thrift.TProcessor
的用法示例。
在下文中一共展示了TProcessor.process方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: thriftRequest
import org.apache.thrift.TProcessor; //导入方法依赖的package包/类
private String thriftRequest(byte[] input){
try{
//Input
TMemoryBuffer inbuffer = new TMemoryBuffer(input.length);
inbuffer.write(input);
TProtocol inprotocol = new TJSONProtocol(inbuffer);
//Output
TMemoryBuffer outbuffer = new TMemoryBuffer(100);
TProtocol outprotocol = new TJSONProtocol(outbuffer);
TProcessor processor = new Calculator.Processor(new CalculatorHandler());
processor.process(inprotocol, outprotocol);
byte[] output = new byte[outbuffer.length()];
outbuffer.readAll(output, 0, output.length);
return new String(output,"UTF-8");
}catch(Throwable t){
return "Error:"+t.getMessage();
}
}
示例2: thriftRequest
import org.apache.thrift.TProcessor; //导入方法依赖的package包/类
private String thriftRequest(byte[] input){
try{
//Input
TMemoryBuffer inbuffer = new TMemoryBuffer(input.length);
inbuffer.write(input);
TProtocol inprotocol = new TJSONProtocol(inbuffer);
//Output
TMemoryBuffer outbuffer = new TMemoryBuffer(100);
TProtocol outprotocol = new TJSONProtocol(outbuffer);
TProcessor processor = new ThriftTest.Processor(new TestHandler());
processor.process(inprotocol, outprotocol);
byte[] output = new byte[outbuffer.length()];
outbuffer.readAll(output, 0, output.length);
return new String(output,"UTF-8");
}catch(Throwable t){
return "Error:"+t.getMessage();
}
}
示例3: handleRequest
import org.apache.thrift.TProcessor; //导入方法依赖的package包/类
@Override
public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if (!"POST".equals(request.getMethod())) {
throw new HttpRequestMethodNotSupportedException(request.getMethod(), new String[]{"POST"}, "ThriftServiceExporter only supports POST requests");
}
InputStream in = request.getInputStream();
OutputStream out = response.getOutputStream();
try {
ThriftContextHolder.init();
response.setContentType("application/x-thrift");
TTransport transport = new TIOStreamTransport(in, out);
TProtocol protocol = getProtocolFactory().getProtocol(transport);
TProcessor processor = ThriftUtil.buildProcessor(getServiceInterface(), getProxyForService());
processor.process(protocol, protocol);
} catch (Throwable e) {
response.setContentType("text/plain; charset=UTF-8");
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
e.printStackTrace(new PrintWriter(out, true));
if (LOGGER.isErrorEnabled()) {
LOGGER.error("Thrift server direct error", e);
}
} finally {
ThriftContextHolder.reset();
}
}
示例4: run
import org.apache.thrift.TProcessor; //导入方法依赖的package包/类
/**
* Loops on processing a client forever
*/
public void run() {
TProcessor processor = null;
TTransport inputTransport = null;
TTransport outputTransport = null;
TProtocol inputProtocol = null;
TProtocol outputProtocol = null;
try {
processor = processorFactory_.getProcessor(client);
inputTransport = inputTransportFactory_.getTransport(client);
outputTransport = outputTransportFactory_.getTransport(client);
inputProtocol = inputProtocolFactory_.getProtocol(inputTransport);
outputProtocol = outputProtocolFactory_.getProtocol(outputTransport);
// we check stopped_ first to make sure we're not supposed to be shutting
// down. this is necessary for graceful shutdown.
while (!stopped && processor.process(inputProtocol, outputProtocol)) {}
} catch (TTransportException ttx) {
// Assume the client died and continue silently
} catch (TException tx) {
LOG.error("Thrift error occurred during processing of message.", tx);
} catch (Exception x) {
LOG.error("Error occurred during processing of message.", x);
}
if (inputTransport != null) {
inputTransport.close();
}
if (outputTransport != null) {
outputTransport.close();
}
}
示例5: run
import org.apache.thrift.TProcessor; //导入方法依赖的package包/类
/**
* Loops on processing a client forever
*/
public void run() {
TProcessor processor = null;
TTransport inputTransport = null;
TTransport outputTransport = null;
TProtocol inputProtocol = null;
TProtocol outputProtocol = null;
try {
processor = processorFactory_.getProcessor(client_);
inputTransport = inputTransportFactory_.getTransport(client_);
outputTransport = outputTransportFactory_.getTransport(client_);
inputProtocol = inputProtocolFactory_.getProtocol(inputTransport);
outputProtocol = outputProtocolFactory_.getProtocol(outputTransport);
// we check stopped_ first to make sure we're not supposed to be shutting
// down. this is necessary for graceful shutdown.
while (!stopped_ && processor.process(inputProtocol, outputProtocol)) {}
} catch (TTransportException ttx) {
// Assume the client died and continue silently
} catch (TException tx) {
LOG.error("Thrift error occurred during processing of message.", tx);
} catch (Exception x) {
LOG.error("Error occurred during processing of message.", x);
}
if (inputTransport != null) {
inputTransport.close();
}
if (outputTransport != null) {
outputTransport.close();
}
}
示例6: handleRequest
import org.apache.thrift.TProcessor; //导入方法依赖的package包/类
@Override
public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if (!"POST".equals(request.getMethod())) {
throw new HttpRequestMethodNotSupportedException(request.getMethod(),
new String[]{"POST"}, "ThriftServiceExporter only supports POST requests");
}
InputStream in = request.getInputStream();
OutputStream out = response.getOutputStream();
try {
ThriftContextHolder.init();
response.setContentType("application/x-thrift");
TTransport transport = new TIOStreamTransport(in, out);
TProtocol protocol = getProtocolFactory().getProtocol(transport);
TProcessor processor = ThriftUtil.buildProcessor(getServiceInterface(), getProxyForService());
processor.process(protocol, protocol);
} catch (Throwable e) {
response.setContentType("text/plain; charset=UTF-8");
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
e.printStackTrace(new PrintWriter(out, true));
if (LOGGER.isErrorEnabled()) {
LOGGER.error("Thrift server direct error", e);
}
} finally {
ThriftContextHolder.reset();
}
}
示例7: doPost
import org.apache.thrift.TProcessor; //导入方法依赖的package包/类
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
TTransport inTransport = null;
TTransport outTransport = null;
try {
response.setContentType("application/x-thrift");
if (null != this.customHeaders) {
for (Map.Entry<String, String> header : this.customHeaders) {
response.addHeader(header.getKey(), header.getValue());
}
}
InputStream in = request.getInputStream();
OutputStream out = response.getOutputStream();
TTransport transport = new TIOStreamTransport(in, out);
inTransport = transport;
outTransport = transport;
TProtocol inProtocol = inProtocolFactory.getProtocol(inTransport);
TProtocol outProtocol = outProtocolFactory.getProtocol(outTransport);
final TProcessor processor = processorFactory.create(request);
processor.process(inProtocol, outProtocol);
out.flush();
} catch (TException te) {
throw new ServletException(te);
}
}
示例8: run
import org.apache.thrift.TProcessor; //导入方法依赖的package包/类
/**
* Loops on processing a client forever
*/
@Override
public void run() {
TProcessor processor = null;
TTransport inputTransport = null;
TTransport outputTransport = null;
TProtocol inputProtocol = null;
TProtocol outputProtocol = null;
try {
processor = processorFactory_.getProcessor(client);
inputTransport = inputTransportFactory_.getTransport(client);
outputTransport = outputTransportFactory_.getTransport(client);
inputProtocol = inputProtocolFactory_.getProtocol(inputTransport);
outputProtocol = outputProtocolFactory_.getProtocol(outputTransport);
// we check stopped_ first to make sure we're not supposed to be shutting
// down. this is necessary for graceful shutdown.
while (!stopped && processor.process(inputProtocol, outputProtocol)) {}
} catch (TTransportException ttx) {
// Assume the client died and continue silently
} catch (TException tx) {
LOG.error("Thrift error occurred during processing of message.", tx);
} catch (Exception x) {
LOG.error("Error occurred during processing of message.", x);
}
if (inputTransport != null) {
inputTransport.close();
}
if (outputTransport != null) {
outputTransport.close();
}
}
示例9: run
import org.apache.thrift.TProcessor; //导入方法依赖的package包/类
/**
* Loops on processing a client forever
*/
public void run() {
TProcessor processor = null;
TTransport inputTransport = null;
TTransport outputTransport = null;
TProtocol inputProtocol = null;
TProtocol outputProtocol = null;
try {
processor = processorFactory_.getProcessor(client_);
inputTransport = inputTransportFactory_.getTransport(client_);
outputTransport = outputTransportFactory_.getTransport(client_);
inputProtocol = inputProtocolFactory_.getProtocol(inputTransport);
outputProtocol = outputProtocolFactory_.getProtocol(outputTransport);
// we check stopped_ first to make sure we're not supposed to be shutting
// down. this is necessary for graceful shutdown.
while (!stopped_ && processor.process(inputProtocol, outputProtocol)) {}
} catch (TTransportException ttx) {
// Assume the client died and continue silently
} catch (TException tx) {
LOGGER.error("Thrift error occurred during processing of message.", tx);
} catch (Exception x) {
LOGGER.error("Error occurred during processing of message.", x);
}
if (inputTransport != null) {
inputTransport.close();
}
if (outputTransport != null) {
outputTransport.close();
}
}
示例10: process
import org.apache.thrift.TProcessor; //导入方法依赖的package包/类
public boolean process( TProtocol in, TProtocol out ) throws TException {
short magic = in.readI16();
if ( magic != ThriftCodec.MAGIC ) {
logger.error(
new StringBuilder( 24 )
.append( "Unsupported magic " )
.append( magic ).toString() );
return false;
}
in.readI32();
in.readI16();
byte version = in.readByte();
String serviceName = in.readString();
long id = in.readI64();
ByteArrayOutputStream bos = new ByteArrayOutputStream( 1024 );
TIOStreamTransport transport = new TIOStreamTransport( bos );
TProtocol protocol = protocolFactory.getProtocol( transport );
TProcessor processor = processorMap.get( serviceName );
if ( processor == null ) {
logger.error(
new StringBuilder( 32 )
.append( "Could not find processor for service " )
.append( serviceName )
.toString() );
return false;
}
// todo if exception
boolean result = processor.process( in, protocol );
ByteArrayOutputStream header = new ByteArrayOutputStream( 512 );
TIOStreamTransport headerTransport = new TIOStreamTransport( header );
TProtocol headerProtocol = protocolFactory.getProtocol( headerTransport );
headerProtocol.writeI16( magic );
headerProtocol.writeI32( Integer.MAX_VALUE );
headerProtocol.writeI16( Short.MAX_VALUE );
headerProtocol.writeByte( version );
headerProtocol.writeString( serviceName );
headerProtocol.writeI64( id );
headerProtocol.getTransport().flush();
out.writeI16( magic );
out.writeI32( bos.size() + header.size() );
out.writeI16( ( short ) ( 0xffff & header.size() ) );
out.writeByte( version );
out.writeString( serviceName );
out.writeI64( id );
out.getTransport().write( bos.toByteArray() );
out.getTransport().flush();
return result;
}
示例11: run
import org.apache.thrift.TProcessor; //导入方法依赖的package包/类
/**
* Loops on processing a client forever
*/
@Override
public void run() {
TProcessor processor = null;
TTransport inputTransport = null;
TTransport outputTransport = null;
TProtocol inputProtocol = null;
TProtocol outputProtocol = null;
final TServerEventHandler eventHandler = getEventHandler();
ServerContext connectionContext = null;
final ConnectionListener listener = connListener;
final TTransport client = this.client;
Socket clientSocket = null;
try {
processor = processorFactory_.getProcessor(client);
inputTransport = inputTransportFactory_.getTransport(client);
outputTransport = outputTransportFactory_.getTransport(client);
inputProtocol = inputProtocolFactory_.getProtocol(inputTransport);
outputProtocol = outputProtocolFactory_.getProtocol(outputTransport);
if (eventHandler != null) {
connectionContext = eventHandler.createContext(inputProtocol,
outputProtocol);
}
// register with ConnectionListener
if (listener != null) {
if (client instanceof GfxdTSocket) {
clientSocket = ((GfxdTSocket)client).getSocket();
}
else if (client instanceof TSocket) {
clientSocket = ((TSocket)client).getSocket();
}
listener.connectionOpened(clientSocket, this.connectionNumber);
}
// we check stopped_ first to make sure we're not supposed to be
// shutting down. this is necessary for graceful shutdown.
while (true) {
if (eventHandler != null) {
eventHandler.processContext(connectionContext, inputTransport,
outputTransport);
}
if (stopped || !processor.process(inputProtocol, outputProtocol)) {
break;
}
}
} catch (TTransportException tte) {
// Assume the client died and continue silently
} catch (TException te) {
LOGGER.error("Thrift error occurred during processing of message.", te);
} catch (Exception e) {
LOGGER.error("Error occurred during processing of message.", e);
}
if (eventHandler != null) {
eventHandler.deleteContext(connectionContext, inputProtocol,
outputProtocol);
}
if (inputTransport != null) {
inputTransport.close();
}
if (outputTransport != null) {
outputTransport.close();
}
// deregister with ConnectionListener
if (listener != null) {
listener.connectionClosed(clientSocket, this.connectionNumber);
}
}
示例12: run
import org.apache.thrift.TProcessor; //导入方法依赖的package包/类
/**
* Loops on processing a client forever
*/
public void run()
{
TProcessor processor = null;
TTransport inputTransport = null;
TTransport outputTransport = null;
TProtocol inputProtocol = null;
TProtocol outputProtocol = null;
SocketAddress socket = null;
try
{
socket = ((TCustomSocket) client_).getSocket().getRemoteSocketAddress();
ThriftSessionManager.instance.setCurrentSocket(socket);
processor = processorFactory_.getProcessor(client_);
inputTransport = inputTransportFactory_.getTransport(client_);
outputTransport = outputTransportFactory_.getTransport(client_);
inputProtocol = inputProtocolFactory_.getProtocol(inputTransport);
outputProtocol = outputProtocolFactory_.getProtocol(outputTransport);
// we check stopped first to make sure we're not supposed to be shutting
// down. this is necessary for graceful shutdown. (but not sufficient,
// since process() can take arbitrarily long waiting for client input.
// See comments at the end of serve().)
while (!stopped && processor.process(inputProtocol, outputProtocol))
{
inputProtocol = inputProtocolFactory_.getProtocol(inputTransport);
outputProtocol = outputProtocolFactory_.getProtocol(outputTransport);
}
}
catch (TTransportException ttx)
{
// Assume the client died and continue silently
// Log at debug to allow debugging of "frame too large" errors (see CASSANDRA-3142).
logger.debug("Thrift transport error occurred during processing of message.", ttx);
}
catch (TException tx)
{
logger.error("Thrift error occurred during processing of message.", tx);
}
catch (Exception e)
{
JVMStabilityInspector.inspectThrowable(e);
logger.error("Error occurred during processing of message.", e);
}
finally
{
if (socket != null)
ThriftSessionManager.instance.connectionComplete(socket);
if (inputTransport != null)
inputTransport.close();
if (outputTransport != null)
outputTransport.close();
activeClients.decrementAndGet();
}
}
示例13: run
import org.apache.thrift.TProcessor; //导入方法依赖的package包/类
/**
* Loops on processing a client forever
*/
public void run()
{
TProcessor processor = null;
TTransport inputTransport = null;
TTransport outputTransport = null;
TProtocol inputProtocol = null;
TProtocol outputProtocol = null;
SocketAddress socket = null;
try
{
socket = ((TCustomSocket) client_).getSocket().getRemoteSocketAddress();
ThriftSessionManager.instance.setCurrentSocket(socket);
processor = processorFactory_.getProcessor(client_);
inputTransport = inputTransportFactory_.getTransport(client_);
outputTransport = outputTransportFactory_.getTransport(client_);
inputProtocol = inputProtocolFactory_.getProtocol(inputTransport);
outputProtocol = outputProtocolFactory_.getProtocol(outputTransport);
// we check stopped first to make sure we're not supposed to be shutting
// down. this is necessary for graceful shutdown. (but not sufficient,
// since process() can take arbitrarily long waiting for client input.
// See comments at the end of serve().)
while (!stopped && processor.process(inputProtocol, outputProtocol))
{
inputProtocol = inputProtocolFactory_.getProtocol(inputTransport);
outputProtocol = outputProtocolFactory_.getProtocol(outputTransport);
}
}
catch (TTransportException ttx)
{
// Assume the client died and continue silently
// Log at debug to allow debugging of "frame too large" errors (see CASSANDRA-3142).
logger.debug("Thrift transport error occurred during processing of message.", ttx);
}
catch (TException tx)
{
logger.error("Thrift error occurred during processing of message.", tx);
}
catch (Exception x)
{
logger.error("Error occurred during processing of message.", x);
}
finally
{
activeClients.decrementAndGet();
if (socket != null)
ThriftSessionManager.instance.connectionComplete(socket);
}
if (inputTransport != null)
{
inputTransport.close();
}
if (outputTransport != null)
{
outputTransport.close();
}
}
示例14: run
import org.apache.thrift.TProcessor; //导入方法依赖的package包/类
/**
* Loops on processing a client forever
*/
public void run()
{
TProcessor processor = null;
TProtocol inputProtocol = null;
TProtocol outputProtocol = null;
SocketAddress socket = null;
try (TTransport inputTransport = inputTransportFactory_.getTransport(client_);
TTransport outputTransport = outputTransportFactory_.getTransport(client_))
{
socket = ((TCustomSocket) client_).getSocket().getRemoteSocketAddress();
ThriftSessionManager.instance.setCurrentSocket(socket);
processor = processorFactory_.getProcessor(client_);
inputProtocol = inputProtocolFactory_.getProtocol(inputTransport);
outputProtocol = outputProtocolFactory_.getProtocol(outputTransport);
// we check stopped first to make sure we're not supposed to be shutting
// down. this is necessary for graceful shutdown. (but not sufficient,
// since process() can take arbitrarily long waiting for client input.
// See comments at the end of serve().)
while (!stopped && processor.process(inputProtocol, outputProtocol))
{
inputProtocol = inputProtocolFactory_.getProtocol(inputTransport);
outputProtocol = outputProtocolFactory_.getProtocol(outputTransport);
}
}
catch (TTransportException ttx)
{
// Assume the client died and continue silently
// Log at debug to allow debugging of "frame too large" errors (see CASSANDRA-3142).
logger.trace("Thrift transport error occurred during processing of message.", ttx);
}
catch (TException tx)
{
logger.error("Thrift error occurred during processing of message.", tx);
}
catch (Exception e)
{
JVMStabilityInspector.inspectThrowable(e);
logger.error("Error occurred during processing of message.", e);
}
finally
{
if (socket != null)
ThriftSessionManager.instance.connectionComplete(socket);
activeClients.decrementAndGet();
}
}
示例15: run
import org.apache.thrift.TProcessor; //导入方法依赖的package包/类
/**
* Loops on processing a client forever
*/
public void run()
{
TProcessor processor = null;
TTransport inputTransport = null;
TTransport outputTransport = null;
TProtocol inputProtocol = null;
TProtocol outputProtocol = null;
SocketAddress socket = null;
try
{
socket = ((TCustomSocket) client_).getSocket().getRemoteSocketAddress();
ThriftSessionManager.instance.setCurrentSocket(socket);
processor = processorFactory_.getProcessor(client_);
inputTransport = inputTransportFactory_.getTransport(client_);
outputTransport = outputTransportFactory_.getTransport(client_);
inputProtocol = inputProtocolFactory_.getProtocol(inputTransport);
outputProtocol = outputProtocolFactory_.getProtocol(outputTransport);
// we check stopped first to make sure we're not supposed to be shutting
// down. this is necessary for graceful shutdown. (but not sufficient,
// since process() can take arbitrarily long waiting for client input.
// See comments at the end of serve().)
while (!stopped && processor.process(inputProtocol, outputProtocol))
{
inputProtocol = inputProtocolFactory_.getProtocol(inputTransport);
outputProtocol = outputProtocolFactory_.getProtocol(outputTransport);
}
}
catch (TTransportException ttx)
{
// Assume the client died and continue silently
// Log at debug to allow debugging of "frame too large" errors (see CASSANDRA-3142).
logger.debug("Thrift transport error occurred during processing of message.", ttx);
}
catch (TException tx)
{
logger.error("Thrift error occurred during processing of message.", tx);
}
catch (Exception x)
{
logger.error("Error occurred during processing of message.", x);
}
finally
{
if (socket != null)
ThriftSessionManager.instance.connectionComplete(socket);
if (inputTransport != null)
inputTransport.close();
if (outputTransport != null)
outputTransport.close();
activeClients.decrementAndGet();
}
}