Java 类org.apache.thrift.server.TThreadPoolServer 实例源码

项目:jigsaw-payment    文件:HelloServerConfig.java   
@Bean(name = "pool-server")
public TServer poolServer() throws Exception {
    TServerTransport transport = new TServerSocket(this.port());

    TThreadPoolServer.Args args = new TThreadPoolServer.Args(transport);
    args.transportFactory(new TTransportFactory());
    args.protocolFactory(new TBinaryProtocol.Factory());

    args.processor(this.processor());
    args.executorService(new ThreadPoolExecutor(env.getProperty(
            "rpc.server.min.worker.threads", Integer.class, 512), env
            .getProperty("rpc.server.max.worker.threads", Integer.class,
                    65535), env.getProperty(
            "rpc.server.thread.keep.alive.time", Long.class, 600l),
            TimeUnit.SECONDS, new SynchronousQueue<Runnable>()));

    return new TThreadPoolServer(args);
}
项目:flume-release-1.7.0    文件:ThriftLegacySource.java   
@SuppressWarnings("deprecation")
@Override
public void start() {
  try {
    InetSocketAddress bindAddr = new InetSocketAddress(host, port);
    serverTransport = new TServerSocket(bindAddr);
    ThriftFlumeEventServer.Processor processor =
        new ThriftFlumeEventServer.Processor(new ThriftFlumeEventServerImpl());
    server = new TThreadPoolServer(
        new TThreadPoolServer.Args(serverTransport).processor(processor));
  } catch (TTransportException e) {
    throw new FlumeException("Failed starting source", e);
  }
  ThriftHandler thriftHandler = new ThriftHandler(server);
  thriftHandlerThread = new Thread(thriftHandler);
  thriftHandlerThread.start();
  super.start();
}
项目:scheduler    文件:ProgramEntrance.java   
/**
 * @Title: startSchedulerThriftService
 * @Description: 开启scheduler 同步、异步调用服务
 * @return void 返回类型
 */
private static void startSchedulerThriftService() {
    LOG.info("start scheduler thrift service....");
    new Thread() {
        @Override
        public void run(){
            try {
                SchedulerServiceImpl schedulerServiceImpl =  SpringUtil.getBean(SchedulerServiceImpl.class); 
                TProcessor tprocessor = new SchedulerService.Processor<SchedulerService.Iface>(schedulerServiceImpl);
                TServerSocket serverTransport = new TServerSocket(PropertyLoader.THRIFT_SCHEDULER_PORT);
                TThreadPoolServer.Args ttpsArgs = new TThreadPoolServer.Args(serverTransport);
                ttpsArgs.processor(tprocessor);
                ttpsArgs.protocolFactory(new TBinaryProtocol.Factory());
                //线程池服务模型,使用标准的阻塞式IO,预先创建一组线程处理请求。
                TServer server = new TThreadPoolServer(ttpsArgs);
                server.serve();
            } catch (Exception e) {
                LOG.error("start scheduler thrift service error,msg:"+ExceptionUtil.getStackTraceAsString(e));
            }
        }
    }.start();
    LOG.info("start scheduler thrift server success!");
}
项目:albedo-thrift    文件:ThriftServer.java   
ServerThread() throws TTransportException {
   TMultiplexedProcessor processor = new TMultiplexedProcessor();
   for (String beanName : serviceMap.keySet()) {
      IThriftServerService serverService = (IThriftServerService) serviceMap.getService(beanName);
      String processorName = serverService.getName();
      TProcessor tProcessor = serverService.getProcessor(serverService);
      processor.registerProcessor(processorName, tProcessor);
      logger.info("Register a processorName {} processorImpl {}", processorName, tProcessor);
   }

   logger.info("init default TServerTransport in addr {} port {}", applicationProperties.getAddr(), applicationProperties.getPort());
   TServerTransport tServerTransport = new TServerSocket(new InetSocketAddress(applicationProperties.getAddr(),
           applicationProperties.getPort()));
   TThreadPoolServer.Args args = new TThreadPoolServer.Args(tServerTransport);
   args.processor(processor);
   args.protocolFactory(tProtocolFactory);
   server = new TThreadPoolServer(args);
}
项目:ditb    文件:ThriftServer.java   
private static TServer getTThreadPoolServer(TProtocolFactory protocolFactory,
                                            TProcessor processor,
                                            TTransportFactory transportFactory,
                                            int workerThreads,
                                            InetSocketAddress inetSocketAddress,
                                            int backlog,
                                            int clientTimeout)
    throws TTransportException {
  TServerTransport serverTransport = new TServerSocket(
                                         new TServerSocket.ServerSocketTransportArgs().
                                             bindAddr(inetSocketAddress).backlog(backlog).
                                             clientTimeout(clientTimeout));
  log.info("starting HBase ThreadPool Thrift server on " + inetSocketAddress.toString());
  TThreadPoolServer.Args serverArgs = new TThreadPoolServer.Args(serverTransport);
  serverArgs.processor(processor);
  serverArgs.transportFactory(transportFactory);
  serverArgs.protocolFactory(protocolFactory);
  if (workerThreads > 0) {
    serverArgs.maxWorkerThreads(workerThreads);
  }
  return new TThreadPoolServer(serverArgs);
}
项目:carbon-identity-framework    文件:TCPThriftAuthenticationService.java   
public void start() throws TTransportException, UnknownHostException {
    InetAddress inetAddress = InetAddress.getByName(hostName);

    TSSLTransportFactory.TSSLTransportParameters params =
            new TSSLTransportFactory.TSSLTransportParameters();
    params.setKeyStore(keyStore, keyStorePassword);

    TServerSocket serverTransport;

    serverTransport = TSSLTransportFactory.getServerSocket(port, clientTimeout, inetAddress, params);


    AuthenticatorService.Processor<AuthenticatorServiceImpl> processor =
            new AuthenticatorService.Processor<AuthenticatorServiceImpl>(
                    new AuthenticatorServiceImpl(thriftAuthenticatorService));
    authenticationServer = new TThreadPoolServer(
            new TThreadPoolServer.Args(serverTransport).processor(processor));
    Thread thread = new Thread(new ServerRunnable(authenticationServer));
    if (log.isDebugEnabled()) {
        log.debug("Thrift Authentication Service started at ssl://" + hostName + ":" + port);
    }
    thread.start();
}
项目:ikasoa    文件:ServiceTest.java   
@Test
public void testDefaultServiceImpl() {
    int serverPort = 49000;
    ThriftServerConfiguration thriftServerConfiguration = new ThriftServerConfiguration();
    thriftServerConfiguration.setServerArgsAspect(new ServerArgsAspect() {
        @Override
        public TThreadPoolServer.Args TThreadPoolServerArgsAspect(TThreadPoolServer.Args args) {
            args.stopTimeoutVal = 1;
            return args;
        }
    });
    Factory factory = new GeneralFactory(thriftServerConfiguration);
    ThriftServer thriftServer = factory.getThriftServer(serverPort, new TestService());
    thriftServer.run();
    ThriftClient thriftClient = factory.getThriftClient("localhost", serverPort);
    try {
        Thread.sleep(500);
        Service service = factory.getService(thriftClient);
        assertEquals(service.get(testString), testString);
    } catch (Exception e) {
        fail();
    } finally {
        thriftServer.stop();
    }
}
项目:allocateme    文件:UserProfileServer.java   
public static void main(String[] args) {
    try {
        userProfileServerHandler = new UserProfileServerHandler();
        userProfileProcessor = new UserProfileService.Processor(userProfileServerHandler);

        TMultiplexedProcessor airavataServerProcessor = new TMultiplexedProcessor();

        airavataServerProcessor.registerProcessor("UserProfileService", userProfileProcessor);

        TServerTransport serverTransport = new TServerSocket(9190);

        TServer server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(airavataServerProcessor));

        System.out.println("Starting User Profile server...");
        server.serve();

    } catch (Exception x) {
        x.printStackTrace();
    }
}
项目:hadoop-EAR    文件:CoronaTaskTracker.java   
private synchronized void initializeClusterManagerCallbackServer()
    throws IOException {
  // Create thrift RPC to serve ClusterManager
  int soTimeout = fConf.getInt(
      CORONA_TASK_TRACKER_SERVER_CLIENTTIMEOUT_KEY, 30 * 1000);
  ServerSocket serverSocket = new ServerSocket();
  serverSocket.setReuseAddress(true);
  serverSocket.bind(new InetSocketAddress(0));
  TServerSocket tSocket = new TServerSocket(serverSocket, soTimeout);
  CoronaTaskTrackerService.Processor proc =
      new CoronaTaskTrackerService.Processor(this);
  TBinaryProtocol.Factory protocolFactory =
      new TBinaryProtocol.Factory(true, true);
  TThreadPoolServer.Args args = new TThreadPoolServer.Args(tSocket);
  args.processor(proc);
  args.protocolFactory(protocolFactory);
  clusterManagerCallbackServer = new TThreadPoolServer(args);
  clusterManagerCallbackServerThread =
      new TServerThread(clusterManagerCallbackServer);
  clusterManagerCallbackServerThread.start();
  clusterManagerCallbackServerAddr = new InetAddress(
      getLocalHostname(), serverSocket.getLocalPort());
  LOG.info("SessionServer up at " + serverSocket.getLocalSocketAddress());
}
项目:hadoop-EAR    文件:HadoopThriftServer.java   
/**
 * Constrcts a server object
 */
public HadoopThriftServer(String [] args) {

  if (args.length > 0) {
    serverPort = new Integer(args[0]);
  }
  try {
    ServerSocket ssock = createServerSocket(serverPort);
    TServerTransport serverTransport = new TServerSocket(ssock);
    Iface handler = new HadoopThriftHandler("hdfs-thrift-dhruba");
    ThriftHadoopFileSystem.Processor processor = new ThriftHadoopFileSystem.Processor(handler);
    TThreadPoolServer.Args serverArgs = new TThreadPoolServer.Args(serverTransport);
    serverArgs.minWorkerThreads = 10;
    serverArgs.processor(processor);
    serverArgs.transportFactory(new TTransportFactory());
    serverArgs.protocolFactory(new TBinaryProtocol.Factory());
    server = new TThreadPoolServer(serverArgs);
    System.out.println("Starting the hadoop thrift server on port [" + serverPort + "]...");
    HadoopThriftHandler.LOG.info("Starting the hadoop thrift server on port [" +serverPort + "]...");
    System.out.flush();

  } catch (Exception x) {
    x.printStackTrace();
  }
}
项目:ezbake-common-java    文件:ThriftUtils.java   
private static TServer startThreadedPoolServer(final TServerTransport transport, final TProcessor processor,
        Properties properties) throws Exception {

    TThreadPoolServer.Args serverArgs;
    if (properties == null) {
        serverArgs = new TThreadPoolServer.Args(transport).processor(processor);
    } else {
        serverArgs =
                (TThreadPoolServer.Args) ThriftUtils.getServerArgs(transport, properties).processor(
                        processor);
    }

    final TServer server = new TThreadPoolServer(serverArgs);
    new Thread(new Runnable() {
        @Override
        public void run() {
            server.serve();
        }
    }).start();
    return server;
}
项目:ezbake-common-java    文件:ThriftUtils.java   
@SuppressWarnings("null")
public static TServer.AbstractServerArgs<?> getServerArgs(TServerTransport transport, Properties properties) {
    TServer.AbstractServerArgs<?> args = null;
    ThriftConfigurationHelper thriftConfiguration = new ThriftConfigurationHelper(properties);
    switch (thriftConfiguration.getServerMode()) {
        case Simple:
            args = new TServer.Args(transport);
            break;
        case ThreadedPool:
            args = new TThreadPoolServer.Args(transport);
            break;
        case HsHa:
            throw new IllegalArgumentException("Unable to create an HsHa Server Args at this time");
    }

    // Use the EzSecureTransport (exposes peer ssl certs) if using SSL
    if (thriftConfiguration.useSSL()) {
        args.inputTransportFactory(new EzSecureServerTransport.Factory(properties));
    }

    return args;
}
项目:jstrom    文件:SaslTransportPlugin.java   
@Override
public TServer getServer(TProcessor processor) throws IOException, TTransportException {
    int port = type.getPort(storm_conf);
    TTransportFactory serverTransportFactory = getServerTransportFactory();
    TServerSocket serverTransport = new TServerSocket(port);
    int numWorkerThreads = type.getNumThreads(storm_conf);
    Integer queueSize = type.getQueueSize(storm_conf);

    TThreadPoolServer.Args server_args =
            new TThreadPoolServer.Args(serverTransport).processor(new TUGIWrapProcessor(processor)).minWorkerThreads(numWorkerThreads)
                    .maxWorkerThreads(numWorkerThreads).protocolFactory(new TBinaryProtocol.Factory(false, true));

    if (serverTransportFactory != null) {
        server_args.transportFactory(serverTransportFactory);
    }
    BlockingQueue workQueue = new SynchronousQueue();
    if (queueSize != null) {
        workQueue = new ArrayBlockingQueue(queueSize);
    }
    ThreadPoolExecutor executorService = new ExtendedThreadPoolExecutor(numWorkerThreads, numWorkerThreads, 60, TimeUnit.SECONDS, workQueue);
    server_args.executorService(executorService);
    return new TThreadPoolServer(server_args);
}
项目:springside-engine    文件:StandardBIOServer.java   
public static void main(String[] args) {
    try {
        handler = new CalculatorHandler();
        processor = new Calculator.Processor(handler);

        try {
            TServerTransport serverTransport = new TServerSocket(9090);
            TServer server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(processor));

            System.out.println("Starting the  server...");
            server.serve();
        } catch (TTransportException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    } catch (Exception x) {
        x.printStackTrace();
    }
}
项目:carbon-identity    文件:TCPThriftAuthenticationService.java   
public void start() throws TTransportException, UnknownHostException {
    InetAddress inetAddress = InetAddress.getByName(hostName);

    TSSLTransportFactory.TSSLTransportParameters params =
            new TSSLTransportFactory.TSSLTransportParameters();
    params.setKeyStore(keyStore, keyStorePassword);

    TServerSocket serverTransport;

    serverTransport = TSSLTransportFactory.getServerSocket(port, clientTimeout, inetAddress, params);


    AuthenticatorService.Processor<AuthenticatorServiceImpl> processor =
            new AuthenticatorService.Processor<AuthenticatorServiceImpl>(
                    new AuthenticatorServiceImpl(thriftAuthenticatorService));
    authenticationServer = new TThreadPoolServer(
            new TThreadPoolServer.Args(serverTransport).processor(processor));
    Thread thread = new Thread(new ServerRunnable(authenticationServer));
    if (log.isDebugEnabled()) {
        log.debug("Thrift Authentication Service started at ssl://" + hostName + ":" + port);
    }
    thread.start();
}
项目:incubator-storm    文件:SaslTransportPlugin.java   
public TServer getServer(int port, TProcessor processor) throws IOException, TTransportException {
    TTransportFactory serverTransportFactory = getServerTransportFactory();

    //define THsHaServer args 
    //original: THsHaServer + TNonblockingServerSocket
    //option: TThreadPoolServer + TServerSocket
    TServerSocket serverTransport = new TServerSocket(port);
    TThreadPoolServer.Args server_args = new TThreadPoolServer.Args(serverTransport).
            processor(new TUGIWrapProcessor(processor)).
            minWorkerThreads(64).
            maxWorkerThreads(64).
            protocolFactory(new TBinaryProtocol.Factory());            
    if (serverTransportFactory != null) 
        server_args.transportFactory(serverTransportFactory);

    //construct THsHaServer
    return new TThreadPoolServer(server_args);
}
项目:thrift-client-pool-java    文件:TestThriftServiceStarter.java   
public static void main(String[] args) {
    int port = 9090;

    try {
        TServerTransport serverTransport = new TServerSocket(port);

        Args processor = new TThreadPoolServer.Args(serverTransport)
                .inputTransportFactory(new TFramedTransport.Factory())
                .outputTransportFactory(new TFramedTransport.Factory())
                .processor(new Processor<>(new TestThriftServiceHandler()));
        //            processor.maxWorkerThreads = 20;
        TThreadPoolServer server = new TThreadPoolServer(processor);

        System.out.println("Starting the server...");
        server.serve();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:thrift-client-pool-java    文件:TestThriftClientPool.java   
@BeforeClass
public static void setUp() {
    int port = 9090;

    try {
        TServerTransport serverTransport = new TServerSocket(port);

        Args processor = new TThreadPoolServer.Args(serverTransport)
                .inputTransportFactory(new TFramedTransport.Factory())
                .outputTransportFactory(new TFramedTransport.Factory())
                .processor(new Processor<>(new TestThriftServiceHandler()));
        //            processor.maxWorkerThreads = 20;
        TThreadPoolServer server = new TThreadPoolServer(processor);

        logger.info("Starting test server...");
        new Thread(server::serve).start();
        Thread.sleep(1000); // waiting server init
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:lizard    文件:TServerNode.java   
@Override
public void start() {
    //FmtLog.debug(log, "Start node server, port = %d", getPort()) ;
    TLZ_NodeTable.Iface handler = new THandlerNodeTable(getTxnSystem(), getLabel(), nodeTable) ;
    TLZ_NodeTable.Processor<TLZ_NodeTable.Iface> processor = new TLZ_NodeTable.Processor<TLZ_NodeTable.Iface>(handler);

    // Semapahores to sync??
    new Thread(()-> {
        try {
            getTxnSystem().getTxnMgr().start();
            TThreadPoolServer.Args args = new TThreadPoolServer.Args(serverTransport) ;
            args.processor(processor) ;
            args.inputProtocolFactory(new TCompactProtocol.Factory()) ;
            args.outputProtocolFactory(new TCompactProtocol.Factory()) ;
            TServer server = new TThreadPoolServer(args);
            FmtLog.info(log, "Started node server: port = %d", getPort()) ;
            server.serve();
            FmtLog.info(log, "Finished node server: port = %d", getPort()) ;
            getTxnSystem().getTxnMgr().shutdown();
          } catch (Exception e) {
            e.printStackTrace();
          }
    }) .start() ;
    super.start() ;
}
项目:storm-resa    文件:SaslTransportPlugin.java   
public TServer getServer(int port, TProcessor processor) throws IOException, TTransportException {
    TTransportFactory serverTransportFactory = getServerTransportFactory();

    //define THsHaServer args 
    //original: THsHaServer + TNonblockingServerSocket
    //option: TThreadPoolServer + TServerSocket
    TServerSocket serverTransport = new TServerSocket(port);
    TThreadPoolServer.Args server_args = new TThreadPoolServer.Args(serverTransport).
            processor(new TUGIWrapProcessor(processor)).
            minWorkerThreads(64).
            maxWorkerThreads(64).
            protocolFactory(new TBinaryProtocol.Factory());            
    if (serverTransportFactory != null) 
        server_args.transportFactory(serverTransportFactory);

    //construct THsHaServer
    return new TThreadPoolServer(server_args);
}
项目:kaa    文件:KaaNodeInitializationServiceTest.java   
/**
 * Test kaa node initialization service start.
 *
 * @throws Exception the exception
 */
@Test
public void testKaaNodeInitializationServiceStart() throws Exception {
  KaaNodeInitializationService kaaNodeInitializationService = kaaNodeInitializationServiceSpy();

  TThreadPoolServer server = Mockito.mock(TThreadPoolServer.class);
  Mockito.doNothing().when(server).serve();

  Mockito.doReturn(server).when(kaaNodeInitializationService).createServer(Mockito.any(TServerTransport.class),
      Mockito.any(TMultiplexedProcessor.class));

  kaaNodeInitializationService.start();

  Mockito.verify(controlInitializationService).start();
  Mockito.verify(bootstrapInitializationService).start();
  Mockito.verify(operationsInitializationService).start();
}
项目:kaa    文件:KaaNodeInitializationServiceTest.java   
/**
 * Test kaa node initialization service start with transport exception.
 *
 * @throws Exception the exception
 */
@Test
public void testKaaNodeInitializationServiceStartTransportException() throws Exception {
  KaaNodeInitializationService kaaNodeInitializationService = kaaNodeInitializationServiceSpy();

  TThreadPoolServer server = Mockito.mock(TThreadPoolServer.class);
  Mockito.doThrow(TTransportException.class).when(server).serve();

  Mockito.doReturn(server).when(kaaNodeInitializationService).createServer(Mockito.any(TServerTransport.class),
      Mockito.any(TMultiplexedProcessor.class));

  kaaNodeInitializationService.start();

  Mockito.verify(controlInitializationService).start();
  Mockito.verify(bootstrapInitializationService).start();
  Mockito.verify(operationsInitializationService).start();
}
项目:kaa    文件:KaaNodeInitializationServiceTest.java   
/**
 * Test kaa node initialization service stop.
 *
 * @throws Exception the exception
 */
@Test
public void testKaaNodeInitializationServiceStop() throws Exception {
  KaaNodeInitializationService kaaNodeInitializationService = kaaNodeInitializationServiceSpy();

  TThreadPoolServer server = Mockito.mock(TThreadPoolServer.class);
  Mockito.doNothing().when(server).serve();

  Mockito.doReturn(server).when(kaaNodeInitializationService).createServer(Mockito.any(TServerTransport.class),
      Mockito.any(TMultiplexedProcessor.class));

  kaaNodeInitializationService.start();
  kaaNodeInitializationService.stop();

  Mockito.verify(controlInitializationService).start();
  Mockito.verify(bootstrapInitializationService).start();
  Mockito.verify(operationsInitializationService).start();

  Mockito.verify(controlInitializationService).stop();
  Mockito.verify(bootstrapInitializationService).stop();
  Mockito.verify(operationsInitializationService).stop();

}
项目:pinpoint    文件:SyncEchoTestServer.java   
public static SyncEchoTestServer<TThreadPoolServer> threadedPoolServer(final TestEnvironment environment)
        throws TTransportException {
    TThreadPoolServer server = new TThreadPoolServer(new TThreadPoolServer.Args(new TServerSocket(
            environment.getPort())).processor(getProcessor())
            .inputProtocolFactory(environment.getProtocolFactory())
            .outputProtocolFactory(environment.getProtocolFactory()));
    return new SyncEchoTestServer<TThreadPoolServer>(server, environment) {
        @Override
        public SyncEchoTestClient getSynchronousClient() throws TTransportException {
            return new SyncEchoTestClient.Client(environment);
        }

        @Override
        public AsyncEchoTestClient getAsynchronousClient() throws IOException {
            return new AsyncEchoTestClient.Client(environment);
        }
    };
}
项目:spring-thrift-service-manager    文件:SecuredThreadPoolWrapper.java   
@Override
protected TServer getServer(TProcessor processor) throws TTransportException {
    LOGGER.debug("Setting Secured Server on port {} and keystore", remotePort, keystoreFile);

    TSSLTransportFactory.TSSLTransportParameters params = new TSSLTransportFactory.TSSLTransportParameters();
    params.setKeyStore(keystoreFile, keystorePass);

    TServerSocket serverTransport;
    try {
        serverTransport = TSSLTransportFactory.getServerSocket(remotePort, 1000, InetAddress.getByName("localhost"), params);
    } catch (UnknownHostException e) {
        throw new TTransportException(e);
    }

    return new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(processor));
}
项目:RDFS    文件:CoronaTaskTracker.java   
private synchronized void initializeClusterManagerCallbackServer()
    throws IOException {
  // Create thrift RPC to serve ClusterManager
  int soTimeout = fConf.getInt(
      CORONA_TASK_TRACKER_SERVER_CLIENTTIMEOUT_KEY, 30 * 1000);
  ServerSocket serverSocket = new ServerSocket();
  serverSocket.setReuseAddress(true);
  serverSocket.bind(new InetSocketAddress(0));
  TServerSocket tSocket = new TServerSocket(serverSocket, soTimeout);
  CoronaTaskTrackerService.Processor proc =
      new CoronaTaskTrackerService.Processor(this);
  TBinaryProtocol.Factory protocolFactory =
      new TBinaryProtocol.Factory(true, true);
  TThreadPoolServer.Args args = new TThreadPoolServer.Args(tSocket);
  args.processor(proc);
  args.protocolFactory(protocolFactory);
  clusterManagerCallbackServer = new TThreadPoolServer(args);
  clusterManagerCallbackServerThread =
      new TServerThread(clusterManagerCallbackServer);
  clusterManagerCallbackServerThread.start();
  clusterManagerCallbackServerAddr = new InetAddress(
      getLocalHostname(), serverSocket.getLocalPort());
  LOG.info("SessionServer up at " + serverSocket.getLocalSocketAddress());
}
项目:jstorm    文件:SaslTransportPlugin.java   
@Override
public TServer getServer(TProcessor processor) throws IOException, TTransportException {
    int port = type.getPort(storm_conf);
    TTransportFactory serverTransportFactory = getServerTransportFactory();
    TServerSocket serverTransport = new TServerSocket(port);
    int numWorkerThreads = type.getNumThreads(storm_conf);
    Integer queueSize = type.getQueueSize(storm_conf);

    TThreadPoolServer.Args server_args =
            new TThreadPoolServer.Args(serverTransport).processor(new TUGIWrapProcessor(processor)).minWorkerThreads(numWorkerThreads)
                    .maxWorkerThreads(numWorkerThreads).protocolFactory(new TBinaryProtocol.Factory(false, true));

    if (serverTransportFactory != null) {
        server_args.transportFactory(serverTransportFactory);
    }
    BlockingQueue workQueue = new SynchronousQueue();
    if (queueSize != null) {
        workQueue = new ArrayBlockingQueue(queueSize);
    }
    ThreadPoolExecutor executorService = new ExtendedThreadPoolExecutor(numWorkerThreads, numWorkerThreads, 60, TimeUnit.SECONDS, workQueue);
    server_args.executorService(executorService);
    return new TThreadPoolServer(server_args);
}
项目:EatDubbo    文件:AbstractTest.java   
protected void init() throws Exception {
    TServerTransport serverTransport = new TServerSocket( PORT );

    TBinaryProtocol.Factory bFactory = new TBinaryProtocol.Factory();

    server = new TThreadPoolServer(
            new TThreadPoolServer.Args( serverTransport )
                    .inputProtocolFactory( bFactory )
                    .outputProtocolFactory( bFactory )
                    .inputTransportFactory( getTransportFactory() )
                    .outputTransportFactory( getTransportFactory() )
                    .processor( getProcessor() ) );

    Thread startTread = new Thread() {

        @Override
        public void run() {
            server.serve();
        }

    };

    startTread.setName( "thrift-server" );

    startTread.start();

    while( !server.isServing() ) {
        Thread.sleep( 100 );
    }

    protocol = ExtensionLoader.getExtensionLoader(Protocol.class)
            .getExtension( ThriftProtocol.NAME );

    invoker = protocol.refer( getInterface(), getUrl() );

}
项目:dubbo2    文件:AbstractTest.java   
protected void init() throws Exception {
    TServerTransport serverTransport = new TServerSocket( PORT );

    TBinaryProtocol.Factory bFactory = new TBinaryProtocol.Factory();

    server = new TThreadPoolServer(
            new TThreadPoolServer.Args( serverTransport )
                    .inputProtocolFactory( bFactory )
                    .outputProtocolFactory( bFactory )
                    .inputTransportFactory( getTransportFactory() )
                    .outputTransportFactory( getTransportFactory() )
                    .processor( getProcessor() ) );

    Thread startTread = new Thread() {

        @Override
        public void run() {
            server.serve();
        }

    };

    startTread.setName( "thrift-server" );

    startTread.start();

    while( !server.isServing() ) {
        Thread.sleep( 100 );
    }

    protocol = ExtensionLoader.getExtensionLoader(Protocol.class)
            .getExtension( ThriftProtocol.NAME );

    invoker = protocol.refer( getInterface(), getUrl() );

}
项目:flume-release-1.7.0    文件:ThriftSource.java   
private TServer getTThreadPoolServer() {
  TServerTransport serverTransport;
  if (enableSsl) {
    serverTransport = getSSLServerTransport();
  } else {
    serverTransport = getTServerTransport();
  }
  TThreadPoolServer.Args serverArgs = new TThreadPoolServer.Args(serverTransport);
  serverArgs.maxWorkerThreads(maxThreads);
  populateServerParams(serverArgs);
  return new TThreadPoolServer(serverArgs);
}
项目:dubbox-hystrix    文件:AbstractTest.java   
protected void init() throws Exception {
    TServerTransport serverTransport = new TServerSocket( PORT );

    TBinaryProtocol.Factory bFactory = new TBinaryProtocol.Factory();

    server = new TThreadPoolServer(
            new TThreadPoolServer.Args( serverTransport )
                    .inputProtocolFactory( bFactory )
                    .outputProtocolFactory( bFactory )
                    .inputTransportFactory( getTransportFactory() )
                    .outputTransportFactory( getTransportFactory() )
                    .processor( getProcessor() ) );

    Thread startTread = new Thread() {

        @Override
        public void run() {
            server.serve();
        }

    };

    startTread.setName( "thrift-server" );

    startTread.start();

    while( !server.isServing() ) {
        Thread.sleep( 100 );
    }

    protocol = ExtensionLoader.getExtensionLoader(Protocol.class)
            .getExtension( ThriftProtocol.NAME );

    invoker = protocol.refer( getInterface(), getUrl() );

}
项目:dubbocloud    文件:AbstractTest.java   
protected void init() throws Exception {
    TServerTransport serverTransport = new TServerSocket( PORT );

    TBinaryProtocol.Factory bFactory = new TBinaryProtocol.Factory();

    server = new TThreadPoolServer(
            new TThreadPoolServer.Args( serverTransport )
                    .inputProtocolFactory( bFactory )
                    .outputProtocolFactory( bFactory )
                    .inputTransportFactory( getTransportFactory() )
                    .outputTransportFactory( getTransportFactory() )
                    .processor( getProcessor() ) );

    Thread startTread = new Thread() {

        @Override
        public void run() {
            server.serve();
        }

    };

    startTread.setName( "thrift-server" );

    startTread.start();

    while( !server.isServing() ) {
        Thread.sleep( 100 );
    }

    protocol = ExtensionLoader.getExtensionLoader(Protocol.class)
            .getExtension( ThriftProtocol.NAME );

    invoker = protocol.refer( getInterface(), getUrl() );

}
项目:metacat    文件:AbstractThriftServer.java   
private void startServing(final ExecutorService executorService, final TServerTransport serverTransport) {
    if (!stopping.get()) {
        final TThreadPoolServer.Args serverArgs = new TThreadPoolServer.Args(serverTransport)
            .processor(getProcessor())
            .executorService(executorService);
        server = new TThreadPoolServer(serverArgs);
        if (hasServerEventHandler()) {
            server.setServerEventHandler(getServerEventHandler());
        }

        final String threadName = getServerName() + "-thread-#" + serverThreadCount.incrementAndGet();
        new Thread(threadName) {
            @Override
            public void run() {
                log.debug("starting serving");
                try {
                    server.serve();
                } catch (Throwable t) {
                    if (!stopping.get()) {
                        log.error("Unexpected exception in {}. This probably "
                            + "means that the worker pool was exhausted. "
                            + "Increase 'metacat.thrift.server_max_worker_threads' "
                            + "from {} or throttle the number of requests. "
                            + "This server thread is not in a bad state so starting a new one.",
                            getServerName(), config.getThriftServerMaxWorkerThreads(), t);
                        startServing(executorService, serverTransport);
                    } else {
                        log.debug("stopping serving");
                    }
                }
                log.debug("started serving");
            }
        }.start();
    }
}
项目:dubbos    文件:AbstractTest.java   
protected void init() throws Exception {
    TServerTransport serverTransport = new TServerSocket( PORT );

    TBinaryProtocol.Factory bFactory = new TBinaryProtocol.Factory();

    server = new TThreadPoolServer(
            new TThreadPoolServer.Args( serverTransport )
                    .inputProtocolFactory( bFactory )
                    .outputProtocolFactory( bFactory )
                    .inputTransportFactory( getTransportFactory() )
                    .outputTransportFactory( getTransportFactory() )
                    .processor( getProcessor() ) );

    Thread startTread = new Thread() {

        @Override
        public void run() {
            server.serve();
        }

    };

    startTread.setName( "thrift-server" );

    startTread.start();

    while( !server.isServing() ) {
        Thread.sleep( 100 );
    }

    protocol = ExtensionLoader.getExtensionLoader(Protocol.class)
            .getExtension( ThriftProtocol.NAME );

    invoker = protocol.refer( getInterface(), getUrl() );

}
项目:dubbo-comments    文件:AbstractTest.java   
protected void init() throws Exception {
    TServerTransport serverTransport = new TServerSocket( PORT );

    TBinaryProtocol.Factory bFactory = new TBinaryProtocol.Factory();

    server = new TThreadPoolServer(
            new TThreadPoolServer.Args( serverTransport )
                    .inputProtocolFactory( bFactory )
                    .outputProtocolFactory( bFactory )
                    .inputTransportFactory( getTransportFactory() )
                    .outputTransportFactory( getTransportFactory() )
                    .processor( getProcessor() ) );

    Thread startTread = new Thread() {

        @Override
        public void run() {
            server.serve();
        }

    };

    startTread.setName( "thrift-server" );

    startTread.start();

    while( !server.isServing() ) {
        Thread.sleep( 100 );
    }

    protocol = ExtensionLoader.getExtensionLoader(Protocol.class)
            .getExtension( ThriftProtocol.NAME );

    invoker = protocol.refer( getInterface(), getUrl() );

}
项目:dubbox    文件:AbstractTest.java   
protected void init() throws Exception {
    TServerTransport serverTransport = new TServerSocket( PORT );

    TBinaryProtocol.Factory bFactory = new TBinaryProtocol.Factory();

    server = new TThreadPoolServer(
            new TThreadPoolServer.Args( serverTransport )
                    .inputProtocolFactory( bFactory )
                    .outputProtocolFactory( bFactory )
                    .inputTransportFactory( getTransportFactory() )
                    .outputTransportFactory( getTransportFactory() )
                    .processor( getProcessor() ) );

    Thread startTread = new Thread() {

        @Override
        public void run() {
            server.serve();
        }

    };

    startTread.setName( "thrift-server" );

    startTread.start();

    while( !server.isServing() ) {
        Thread.sleep( 100 );
    }

    protocol = ExtensionLoader.getExtensionLoader(Protocol.class)
            .getExtension( ThriftProtocol.NAME );

    invoker = protocol.refer( getInterface(), getUrl() );

}
项目:dubbo    文件:AbstractTest.java   
protected void init() throws Exception {
    TServerTransport serverTransport = new TServerSocket( PORT );

    TBinaryProtocol.Factory bFactory = new TBinaryProtocol.Factory();

    server = new TThreadPoolServer(
            new TThreadPoolServer.Args( serverTransport )
                    .inputProtocolFactory( bFactory )
                    .outputProtocolFactory( bFactory )
                    .inputTransportFactory( getTransportFactory() )
                    .outputTransportFactory( getTransportFactory() )
                    .processor( getProcessor() ) );

    Thread startTread = new Thread() {

        @Override
        public void run() {
            server.serve();
        }

    };

    startTread.setName( "thrift-server" );

    startTread.start();

    while( !server.isServing() ) {
        Thread.sleep( 100 );
    }

    protocol = ExtensionLoader.getExtensionLoader(Protocol.class)
            .getExtension( ThriftProtocol.NAME );

    invoker = protocol.refer( getInterface(), getUrl() );

}
项目:ikasoa    文件:TestExampleService.java   
@Before
public void setUp() {
    // configurator.setClientInvocationHandler(new
    // LoggerClientInvocationHandlerImpl());
    thriftServerConfiguration.setServerArgsAspect(new ServerArgsAspect() {
        @Override
        public TThreadPoolServer.Args TThreadPoolServerArgsAspect(TThreadPoolServer.Args args) {
            args.stopTimeoutVal = 1;
            return args;
        }
    });
}
项目:ikasoa    文件:DefaultThriftServerImpl.java   
/**
 * 初始化Thrift服务
 * <p>
 * 启动Thrift服务之前必须要进行初始化.
 * 
 * @param serverTransport
 *            服务传输类型
 */
protected void initServer(TServerTransport serverTransport) {
    ThriftServerConfiguration configuration = getThriftServerConfiguration();
    // 默认使用TThreadPoolServer方式启动Thrift服务器,对每个连接都会单独建立一个线程.
    TThreadPoolServer.Args args = new TThreadPoolServer.Args(serverTransport)
            .transportFactory(configuration.getTransportFactory())
            .protocolFactory(configuration.getProtocolFactory());
    // 如果不设置ExecutorService,则默认使用ThreadPoolExecutor实现.
    if (configuration.getExecutorService() != null)
        args.executorService(configuration.getExecutorService());
    server = new TThreadPoolServer(
            configuration.getServerArgsAspect().TThreadPoolServerArgsAspect(args).processor(getProcessor()));
    if (configuration.getServerEventHandler() != null)
        server.setServerEventHandler(configuration.getServerEventHandler());
}
项目:ikasoa    文件:AysncServiceTest.java   
@Before
public void setUp() {
    thriftServerConfiguration = new ThriftServerConfiguration();
    thriftServerConfiguration.setProtocolFactory(new TCompactProtocol.Factory());
    thriftServerConfiguration.setServerArgsAspect(new ServerArgsAspect() {
        @Override
        public TThreadPoolServer.Args TThreadPoolServerArgsAspect(TThreadPoolServer.Args args) {
            args.stopTimeoutVal = 1;
            return args;
        }
    });
}