Package com.facebook.thrift.transport

Examples of com.facebook.thrift.transport.TTransport


   */
  @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);
View Full Code Here


      LOGGER.error("Error occurred during listening.", ttx);
      return;
    }

    while (!stopped_) {
      TTransport client = null;
      TProcessor processor = null;
      TTransport inputTransport = null;
      TTransport outputTransport = null;
      TProtocol inputProtocol = null;
      TProtocol outputProtocol = null;
      try {
        client = serverTransport_.accept();
        if (client != null) {
          processor = processorFactory_.getProcessor(client);
          inputTransport = inputTransportFactory_.getTransport(client);
          inputProtocol = inputProtocolFactory_.getProtocol(inputTransport);
          // THeaderProtocol must be the same instance for both input and output
          if (inputProtocol instanceof THeaderProtocol) {
            outputProtocol = inputProtocol;
          } else {
            outputTransport = outputTransportFactory_.getTransport(client);
            outputProtocol = outputProtocolFactory_.getProtocol(outputTransport);
          }
          TRpcConnectionContext server_ctx = new TRpcConnectionContext(client,
                                                                       inputProtocol,
                                                                       outputProtocol);
          while (processor.process(inputProtocol, outputProtocol, server_ctx)) {}
        }
      } catch (TTransportException ttx) {
        // Client died, just move on
      } catch (TException tx) {
        if (!stopped_) {
          LOGGER.error("Thrift error occurred during processing of message.", tx);
        }
      } catch (Exception x) {
        if (!stopped_) {
          LOGGER.error("Error occurred during processing of message.", x);
        }
      }

      if (inputTransport != null) {
        inputTransport.close();
      }

      if (outputTransport != null) {
        outputTransport.close();
      }

    }
  }
View Full Code Here

    if (args.length != 2) {
      System.out.println("usage: java -cp build/classes com.facebook.thrift.test.ReadStruct filename proto_factory_class");
      System.out.println("Read in an instance of CompactProtocolTestStruct from 'file', making sure that it is equivalent to Fixtures.compactProtoTestStruct. Use a protocol from 'proto_factory_class'.");
    }

    TTransport trans = new TIOStreamTransport(new BufferedInputStream(new FileInputStream(args[0])));

    TProtocolFactory factory = (TProtocolFactory)Class.forName(args[1]).newInstance();

    TProtocol proto = factory.getProtocol(trans);
View Full Code Here

    }

    stopped_ = false;
    while (!stopped_) {
      try {
        TTransport client = serverTransport_.accept();
        WorkerProcess wp = new WorkerProcess(client);
        try {
          executorService_.execute(wp);
        } catch (RejectedExecutionException ree) {
          LOGGER.warn("Client request was rejected by executor", ree);
          // close the connection, we don't need it anymore
          // if clause should always be true, but just to be on the safe side
          if (client != null && client.isOpen()) {
            client.close();
          }
        }
      } catch (TTransportException ttx) {
        if (!stopped_) {
          LOGGER.warn("Transport error occurred during acceptance of message.", ttx);
View Full Code Here

    /**
     * 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_);
        inputProtocol = inputProtocolFactory_.getProtocol(inputTransport);
        // THeaderProtocol must be the same instance for both input and output
        if (inputProtocol instanceof THeaderProtocol) {
          outputProtocol = inputProtocol;
        } else {
          outputTransport = outputTransportFactory_.getTransport(client_);
          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.
        TRpcConnectionContext server_ctx = new TRpcConnectionContext(client_,
                                                                     inputProtocol,
                                                                     outputProtocol);
        while (!stopped_ && processor.process(inputProtocol, outputProtocol, server_ctx)) {}
      } 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();
      }
    }
View Full Code Here

public class JavaClient {
  public static void main(String [] args) {
    try {

      TTransport transport = new TSocket("localhost", 9090);
      TProtocol protocol = new TBinaryProtocol(transport);
      Calculator.Client client = new Calculator.Client(protocol);

      transport.open();

      client.ping();
      System.out.println("ping()");

      int sum = client.add(1,1);
      System.out.println("1+1=" + sum);

      Work work = new Work();

      work.op = Operation.DIVIDE;
      work.num1 = 1;
      work.num2 = 0;
      try {
        int quotient = client.calculate(1, work);
        System.out.println("Whoa we can divide by 0");
      } catch (InvalidOperation io) {
        System.out.println("Invalid operation: " + io.why);
      }

      work.op = Operation.SUBTRACT;
      work.num1 = 15;
      work.num2 = 10;
      try {
        int diff = client.calculate(1, work);
        System.out.println("15-10=" + diff);
      } catch (InvalidOperation io) {
        System.out.println("Invalid operation: " + io.why);
      }

      SharedStruct log = client.getStruct(1);
      System.out.println("Check log: " + log.value);

      transport.close();

    } catch (TException x) {
      x.printStackTrace();
    }
View Full Code Here

    /**
     * Actually invoke the method signified by this FrameBuffer.
     */
    public synchronized void invoke() {
      TTransport inTrans;
      TProtocol inProt;
      TProtocol outProt;
      // For THeader inProt and outProt must be the same object
      if (inputProtocolFactory_ instanceof THeaderProtocol.Factory) {
        inTrans = getInputOutputTransport();
View Full Code Here

TOP

Related Classes of com.facebook.thrift.transport.TTransport

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.