Java Code Examples for org.apache.thrift.TProcessor#process()
The following examples show how to use
org.apache.thrift.TProcessor#process() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TBoundedThreadPoolServer.java From hbase with Apache License 2.0 | 5 votes |
/** * 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 (true) { if (stopped) { break; } 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(); } }
Example 2
Source File: TFactoryBasedThreadPoolServer.java From RDFS with Apache License 2.0 | 5 votes |
/** * 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(); } }
Example 3
Source File: MultiServiceProcessor.java From dubbo-2.6.5 with Apache License 2.0 | 4 votes |
@Override public boolean process(TProtocol in, TProtocol out) throws TException { short magic = in.readI16(); if (magic != ThriftCodec.MAGIC) { logger.error("Unsupported magic " + magic); 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("Could not find processor for service " + serviceName); 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; }
Example 4
Source File: MultiServiceProcessor.java From dubbox with Apache License 2.0 | 4 votes |
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; }
Example 5
Source File: MultiServiceProcessor.java From dubbox-hystrix with Apache License 2.0 | 4 votes |
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; }
Example 6
Source File: GfxdThriftServerThreadPool.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * 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); } }
Example 7
Source File: MultiServiceProcessor.java From dubbox with Apache License 2.0 | 4 votes |
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; }
Example 8
Source File: GfxdThriftServerThreadPool.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * 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); } }
Example 9
Source File: MultiServiceProcessor.java From dubbox with Apache License 2.0 | 4 votes |
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; }
Example 10
Source File: CustomTThreadPoolServer.java From stratio-cassandra with Apache License 2.0 | 4 votes |
/** * 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(); } }