当前位置: 首页>>代码示例>>Java>>正文


Java TFramedTransport.Factory方法代码示例

本文整理汇总了Java中org.apache.thrift.transport.TFramedTransport.Factory方法的典型用法代码示例。如果您正苦于以下问题:Java TFramedTransport.Factory方法的具体用法?Java TFramedTransport.Factory怎么用?Java TFramedTransport.Factory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.thrift.transport.TFramedTransport的用法示例。


在下文中一共展示了TFramedTransport.Factory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: start

import org.apache.thrift.transport.TFramedTransport; //导入方法依赖的package包/类
public void start(CountDownLatch latch, int port) {
    try {
        TNonblockingServerSocket serverTransport = new TNonblockingServerSocket(port);
        //异步IO,需要使用TFramedTransport,它将分块缓存读取。
        TTransportFactory transportFactory = new TFramedTransport.Factory();
        //使用高密度二进制协议
        TProtocolFactory proFactory = new TBinaryProtocol.Factory();
        //发布多个服务
        TMultiplexedProcessor processor = new TMultiplexedProcessor();
        processor.registerProcessor(ClassNameUtils.getClassName(Hello.class), new Hello.Processor<>(new HelloServer()));

        TServer server = new TThreadedSelectorServer(new
                TThreadedSelectorServer.Args(serverTransport)
                .transportFactory(transportFactory)
                .protocolFactory(proFactory)
                .processor(processor)
        );
        System.out.println("Starting the hello server...");
        latch.countDown();
        server.serve();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:sofn,项目名称:trpc,代码行数:25,代码来源:DemoServer.java

示例2: createThreadedSelectorServer

import org.apache.thrift.transport.TFramedTransport; //导入方法依赖的package包/类
public static TServer createThreadedSelectorServer(TProcessorFactory processorFactory,
        int port, int clientTimeoutMillisecs, int maxFrameSize, long maxReadBufferSize)
        throws TTransportException {
    int numThreads = Math.max(2, Runtime.getRuntime().availableProcessors());
    int selectorThreads = Math.max(2, Runtime.getRuntime().availableProcessors() / 2);
    TNonblockingServerTransport transport = new TNonblockingServerSocket(port,
            clientTimeoutMillisecs);
    TProtocolFactory protocolFactory = new TBinaryProtocol.Factory();
    TTransportFactory transportFactory = new TFramedTransport.Factory(maxFrameSize);
    TThreadedSelectorServer.Args args = new TThreadedSelectorServer.Args(transport)
            .processorFactory(processorFactory).protocolFactory(protocolFactory)
            .transportFactory(transportFactory).workerThreads(numThreads)
            .acceptPolicy(AcceptPolicy.FAIR_ACCEPT).acceptQueueSizePerThread(10000)
            .selectorThreads(selectorThreads);
    args.maxReadBufferBytes = maxReadBufferSize;
    TThreadedSelectorServer server = new TThreadedSelectorServer(args);
    return server;
}
 
开发者ID:DDTH,项目名称:osgi-bundle-frontapi,代码行数:19,代码来源:ThriftUtils.java

示例3: ThriftServerThread

import org.apache.thrift.transport.TFramedTransport; //导入方法依赖的package包/类
public ThriftServerThread(InetAddress listenAddr, int listenPort)
{
    // now we start listening for clients
    logger.info(String.format("Binding thrift service to %s:%s", listenAddr, listenPort));

    TServerFactory.Args args = new TServerFactory.Args();
    args.tProtocolFactory = new TBinaryProtocol.Factory(true, true);
    args.addr = new InetSocketAddress(listenAddr, listenPort);
    args.cassandraServer = new CassandraServer();
    args.processor = new Cassandra.Processor(args.cassandraServer);
    args.keepAlive = DatabaseDescriptor.getRpcKeepAlive();
    args.sendBufferSize = DatabaseDescriptor.getRpcSendBufferSize();
    args.recvBufferSize = DatabaseDescriptor.getRpcRecvBufferSize();
    int tFramedTransportSize = DatabaseDescriptor.getThriftFramedTransportSize();

    logger.info("Using TFramedTransport with a max frame size of {} bytes.", tFramedTransportSize);
    args.inTransportFactory = new TFramedTransport.Factory(tFramedTransportSize);
    args.outTransportFactory = new TFramedTransport.Factory(tFramedTransportSize);
    serverEngine = new TServerCustomFactory(DatabaseDescriptor.getRpcServerType()).buildTServer(args);
}
 
开发者ID:dprguiuc,项目名称:Cassandra-Wasef,代码行数:21,代码来源:ThriftServer.java

示例4: ConcreteServer

import org.apache.thrift.transport.TFramedTransport; //导入方法依赖的package包/类
/**
 *
 */
public ConcreteServer(AnnotateCommunicationService.Iface impl, int port) throws ServerException {
  try {
    this.serverXport = new TNonblockingServerSocket(port);
    // TODO: eval HaHs server?
    final TNonblockingServer.Args args = new TNonblockingServer.Args(this.serverXport);
    args.protocolFactory(new TCompactProtocol.Factory());
    // TODO: eval FastFramedTransport?
    final TFramedTransport.Factory transFactory = new TFramedTransport.Factory(Integer.MAX_VALUE);
    args.transportFactory(transFactory);
    // legitimately do not know type bound here - guessing Iface
    AnnotateCommunicationService.Processor<Iface> proc = new AnnotateCommunicationService.Processor<>(impl);
    args.processorFactory(new TProcessorFactory(proc));
    args.maxReadBufferBytes = Long.MAX_VALUE;

    this.args = args;
    // final TNonblockingServer server = new TNonblockingServer(args);
    this.server = new TNonblockingServer(this.args);
  } catch (TTransportException e) {
    throw new ServerException(e);
  }
}
 
开发者ID:hltcoe,项目名称:concrete-java,代码行数:25,代码来源:ConcreteServer.java

示例5: testProcessor

import org.apache.thrift.transport.TFramedTransport; //导入方法依赖的package包/类
private static int testProcessor(TProcessor processor, List<ToIntFunction<HostAndPort>> clients)
        throws Exception
{
    try (TServerSocket serverTransport = new TServerSocket(0)) {
        TProtocolFactory protocolFactory = new Factory();
        TTransportFactory transportFactory = new TFramedTransport.Factory();
        TServer server = new TSimpleServer(new Args(serverTransport)
                .protocolFactory(protocolFactory)
                .transportFactory(transportFactory)
                .processor(processor));

        Thread serverThread = new Thread(server::serve);
        try {
            serverThread.start();

            int localPort = serverTransport.getServerSocket().getLocalPort();
            HostAndPort address = HostAndPort.fromParts("localhost", localPort);

            int sum = 0;
            for (ToIntFunction<HostAndPort> client : clients) {
                sum += client.applyAsInt(address);
            }
            return sum;
        }
        finally {
            server.stop();
            serverThread.interrupt();
        }
    }
}
 
开发者ID:airlift,项目名称:drift,代码行数:31,代码来源:TestApacheThriftMethodInvoker.java

示例6: testProcessor

import org.apache.thrift.transport.TFramedTransport; //导入方法依赖的package包/类
private static int testProcessor(TProcessor processor, List<ToIntFunction<HostAndPort>> clients)
        throws Exception
{
    try (TServerSocket serverTransport = new TServerSocket(0)) {
        TProtocolFactory protocolFactory = new TBinaryProtocol.Factory();
        TTransportFactory transportFactory = new TFramedTransport.Factory();
        TServer server = new TSimpleServer(new Args(serverTransport)
                .protocolFactory(protocolFactory)
                .transportFactory(transportFactory)
                .processor(processor));

        Thread serverThread = new Thread(server::serve);
        try {
            serverThread.start();

            int localPort = serverTransport.getServerSocket().getLocalPort();
            HostAndPort address = HostAndPort.fromParts("localhost", localPort);

            int sum = 0;
            for (ToIntFunction<HostAndPort> client : clients) {
                sum += client.applyAsInt(address);
            }
            return sum;
        }
        finally {
            server.stop();
            serverThread.interrupt();
        }
    }
}
 
开发者ID:airlift,项目名称:drift,代码行数:31,代码来源:TestDriftNettyMethodInvoker.java

示例7: init

import org.apache.thrift.transport.TFramedTransport; //导入方法依赖的package包/类
public void init() {
    try {
        TMultiplexedProcessor processor = new TMultiplexedProcessor();
        for (ServiceArgs service : serverArgs.getServices()) {
            String className = service.getService();
            if (className.endsWith("$Processor")) {
                className = className.substring(0, className.indexOf("$Processor"));
            }
            processor.registerProcessor(className, service.getProcessor());
        }
        if (serverArgs.getNettyServerArgs() != null) {
            this.server = new TNettyServer(serverArgs.getNettyServerArgs().ip(serverArgs.getHost()).port(serverArgs.getPort()));
        } else {
            TNonblockingServerSocket serverTransport = new TNonblockingServerSocket(new InetSocketAddress(serverArgs.getHost(), serverArgs.getPort()));
            //异步IO,需要使用TFramedTransport,它将分块缓存读取。
            TTransportFactory transportFactory = new TFramedTransport.Factory();
            //使用高密度二进制协议
            TProtocolFactory proFactory = new TBinaryProtocol.Factory();
            // Use this for a multithreaded key
            this.server = new TThreadedSelectorServer(new
                    TThreadedSelectorServer.Args(serverTransport)
                    .transportFactory(transportFactory)
                    .protocolFactory(proFactory)
                    .processor(processor)
            );
        }
        log.info("Starting the Thrift key...");
        this.server.setServerEventHandler(new TrpcRegistryEventHandler(serverArgs));
        this.server.serve();
        if (this.serverArgs.getNettyServerArgs() != null) {
            ((TNettyServer) this.server).waitForClose();
        }
    } catch (Exception e) {
        log.error("publish thrift key error", e);
    }
}
 
开发者ID:sofn,项目名称:trpc,代码行数:37,代码来源:ThriftServerPublisher.java

示例8: getTTransportFactory

import org.apache.thrift.transport.TFramedTransport; //导入方法依赖的package包/类
private static TTransportFactory getTTransportFactory(boolean framed) {
  if (framed) {
    log.debug("Using framed transport");
    return new TFramedTransport.Factory();
  } else {
    return new TTransportFactory();
  }
}
 
开发者ID:fengchen8086,项目名称:LCIndex-HBase-0.94.16,代码行数:9,代码来源:ThriftServer.java

示例9: createThreadedServer

import org.apache.thrift.transport.TFramedTransport; //导入方法依赖的package包/类
public static TServer createThreadedServer(TProcessorFactory processorFactory, int port,
        int clientTimeoutMillisecs, int maxFrameSize) throws TTransportException {
    int maxWorkerThreads = Math.max(2, Runtime.getRuntime().availableProcessors());
    TServerTransport transport = new TServerSocket(port, clientTimeoutMillisecs);
    TProtocolFactory protocolFactory = new TBinaryProtocol.Factory();
    TTransportFactory transportFactory = new TFramedTransport.Factory(maxFrameSize);
    TThreadPoolServer.Args args = new TThreadPoolServer.Args(transport)
            .processorFactory(processorFactory).protocolFactory(protocolFactory)
            .transportFactory(transportFactory).minWorkerThreads(1)
            .maxWorkerThreads(maxWorkerThreads);
    TThreadPoolServer server = new TThreadPoolServer(args);
    return server;
}
 
开发者ID:DDTH,项目名称:osgi-bundle-frontapi,代码行数:14,代码来源:ThriftUtils.java

示例10: createNonBlockingServer

import org.apache.thrift.transport.TFramedTransport; //导入方法依赖的package包/类
public static TServer createNonBlockingServer(TProcessorFactory processorFactory, int port,
        int clientTimeoutMillisecs, int maxFrameSize, long maxReadBufferSize)
        throws TTransportException {
    TNonblockingServerTransport transport = new TNonblockingServerSocket(port,
            clientTimeoutMillisecs);
    TProtocolFactory protocolFactory = new TBinaryProtocol.Factory();
    TTransportFactory transportFactory = new TFramedTransport.Factory(maxFrameSize);
    TNonblockingServer.Args args = new TNonblockingServer.Args(transport)
            .processorFactory(processorFactory).protocolFactory(protocolFactory)
            .transportFactory(transportFactory);
    args.maxReadBufferBytes = maxReadBufferSize;
    TNonblockingServer server = new TNonblockingServer(args);
    return server;
}
 
开发者ID:DDTH,项目名称:osgi-bundle-frontapi,代码行数:15,代码来源:ThriftUtils.java

示例11: createHaHsServer

import org.apache.thrift.transport.TFramedTransport; //导入方法依赖的package包/类
public static TServer createHaHsServer(TProcessorFactory processorFactory, int port,
        int clientTimeoutMillisecs, int maxFrameSize, long maxReadBufferSize)
        throws TTransportException {
    int numThreads = Math.max(2, Runtime.getRuntime().availableProcessors());
    TNonblockingServerTransport transport = new TNonblockingServerSocket(port,
            clientTimeoutMillisecs);
    TProtocolFactory protocolFactory = new TBinaryProtocol.Factory();
    TTransportFactory transportFactory = new TFramedTransport.Factory(maxFrameSize);
    THsHaServer.Args args = new THsHaServer.Args(transport).processorFactory(processorFactory)
            .protocolFactory(protocolFactory).transportFactory(transportFactory)
            .workerThreads(numThreads).stopTimeoutVal(60).stopTimeoutUnit(TimeUnit.SECONDS);
    args.maxReadBufferBytes = maxReadBufferSize;
    THsHaServer server = new THsHaServer(args);
    return server;
}
 
开发者ID:DDTH,项目名称:osgi-bundle-frontapi,代码行数:16,代码来源:ThriftUtils.java

示例12: SearchServiceWrapper

import org.apache.thrift.transport.TFramedTransport; //导入方法依赖的package包/类
/**
 * @param impl
 * @param port
 * @throws TException
 */
public SearchServiceWrapper(SearchService.Iface impl, int port) throws TException {
  this.serverXport = new TNonblockingServerSocket(port);
  final TNonblockingServer.Args args = new TNonblockingServer.Args(this.serverXport);
  args.protocolFactory(new TCompactProtocol.Factory());
  final TFramedTransport.Factory transFactory = new TFramedTransport.Factory(Integer.MAX_VALUE);
  args.transportFactory(transFactory);
  SearchService.Processor<Iface> proc = new SearchService.Processor<>(impl);
  args.processorFactory(new TProcessorFactory(proc));
  args.maxReadBufferBytes = Long.MAX_VALUE;

  this.servArgs = args;
  this.server = new TNonblockingServer(this.servArgs);
}
 
开发者ID:hltcoe,项目名称:concrete-java,代码行数:19,代码来源:SearchServiceWrapper.java

示例13: FetchServiceWrapper

import org.apache.thrift.transport.TFramedTransport; //导入方法依赖的package包/类
public FetchServiceWrapper(FetchCommunicationService.Iface impl, int port) throws TException {
  this.serverXport = new TNonblockingServerSocket(port);
  final TNonblockingServer.Args args = new TNonblockingServer.Args(this.serverXport);
  args.protocolFactory(new TCompactProtocol.Factory());
  final TFramedTransport.Factory transFactory = new TFramedTransport.Factory(Integer.MAX_VALUE);
  args.transportFactory(transFactory);
  FetchCommunicationService.Processor<Iface> proc = new FetchCommunicationService.Processor<>(impl);
  args.processorFactory(new TProcessorFactory(proc));
  args.maxReadBufferBytes = Long.MAX_VALUE;

  this.servArgs = args;
  this.server = new TNonblockingServer(this.servArgs);
}
 
开发者ID:hltcoe,项目名称:concrete-java,代码行数:14,代码来源:FetchServiceWrapper.java

示例14: SummarizationServiceWrapper

import org.apache.thrift.transport.TFramedTransport; //导入方法依赖的package包/类
public SummarizationServiceWrapper(SummarizationService.Iface impl, int port) throws TException {
  this.serverXport = new TNonblockingServerSocket(port);
  final TNonblockingServer.Args args = new TNonblockingServer.Args(this.serverXport);
  args.protocolFactory(new TCompactProtocol.Factory());
  final TFramedTransport.Factory transFactory = new TFramedTransport.Factory(Integer.MAX_VALUE);
  args.transportFactory(transFactory);
  SummarizationService.Processor<SummarizationService.Iface> proc = new SummarizationService.Processor<>(impl);
  args.processorFactory(new TProcessorFactory(proc));
  args.maxReadBufferBytes = Long.MAX_VALUE;

  this.servArgs = args;
  this.server = new TNonblockingServer(this.servArgs);
}
 
开发者ID:hltcoe,项目名称:concrete-java,代码行数:14,代码来源:SummarizationServiceWrapper.java

示例15: StoreServiceWrapper

import org.apache.thrift.transport.TFramedTransport; //导入方法依赖的package包/类
public StoreServiceWrapper(StoreCommunicationService.Iface impl, int port) throws TException {
  this.serverXport = new TNonblockingServerSocket(port);
  final TNonblockingServer.Args args = new TNonblockingServer.Args(this.serverXport);
  args.protocolFactory(new TCompactProtocol.Factory());
  final TFramedTransport.Factory transFactory = new TFramedTransport.Factory(Integer.MAX_VALUE);
  args.transportFactory(transFactory);
  StoreCommunicationService.Processor<Iface> proc = new StoreCommunicationService.Processor<>(impl);
  args.processorFactory(new TProcessorFactory(proc));
  args.maxReadBufferBytes = Long.MAX_VALUE;

  this.servArgs = args;
  this.server = new TNonblockingServer(this.servArgs);
}
 
开发者ID:hltcoe,项目名称:concrete-java,代码行数:14,代码来源:StoreServiceWrapper.java


注:本文中的org.apache.thrift.transport.TFramedTransport.Factory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。