List of usage examples for org.apache.thrift.server TThreadPoolServer TThreadPoolServer
public TThreadPoolServer(Args args)
From source file:jessy.shipgirlcombatsystem.net.Server.java
public Server(int port) throws IOException, TTransportException { this.socket = new ServerSocket(port); panel = new MapPanel(); Ship redShip = new Ship(gameState.getNewUniqueID(), new Player("A", Color.pink)); redShip.addEquipment(new ShipWeaponSystem("Big Gun", redShip)); redShip.addEquipment(new ShipWeaponSystem("Small Gun", redShip)); gameState.add(redShip, new Hex(4, 4)); Ship blueShip = new Ship(gameState.getNewUniqueID(), new Player("D", new Color(50, 50, 255))); blueShip.addEquipment(new ShipWeaponSystem("Big Gun", blueShip)); blueShip.addEquipment(new ShipWeaponSystem("Small Gun", blueShip)); blueShip.setFacing(Direction.SOUTH); gameState.add(blueShip, new Hex(-4, -4)); //gameState.add(new Ship(gameState.getNewUniqueID(), new Player("B", new Color(50,255,50))), new Hex(2,-2)); //gameState.add(new Ship(gameState.getNewUniqueID(), new Player("C", Color.YELLOW)), new Hex(-2,2)); panel.applyNewTurn(gameState, currentPhase); TServerSocket tsock = new TServerSocket(socket); TThreadPoolServer.Args args = new TThreadPoolServer.Args(tsock); args.requestTimeout(2);//from w ww .j a va 2 s . co m args.requestTimeoutUnit(TimeUnit.HOURS); args.processor(new ShipGirlCombatSystemServer.Processor<>(processor)); server = new TThreadPoolServer(args); server.serve(); }
From source file:joshelser.Server.java
License:Apache License
public static void main(String[] args) throws Exception { Opts opts = new Opts(); opts.parseArgs(Server.class, args); Configuration conf = new Configuration(); FileSystem fs = FileSystem.get(conf); // Parse out the primary/instance@DOMAIN from the principal String principal = SecurityUtil.getServerPrincipal(opts.principal, InetAddress.getLocalHost().getCanonicalHostName()); HadoopKerberosName name = new HadoopKerberosName(principal); String primary = name.getServiceName(); String instance = name.getHostName(); // Log in using the keytab UserGroupInformation.loginUserFromKeytab(principal, opts.keytab); log.info("principal: {}", principal); log.info("name: {}", name); log.info("instance: {}", instance); log.info("primary: {}", primary); log.info("instance: {}", instance); // Get the info from our login UserGroupInformation serverUser = UserGroupInformation.getLoginUser(); log.info("Current user: {}", serverUser); // Open the server using the provide dport TServerSocket serverTransport = new TServerSocket(opts.port); // Wrap our implementation with the interface's processor HdfsService.Processor<Iface> processor = new HdfsService.Processor<Iface>(new HdfsServiceImpl(fs)); // Use authorization and confidentiality Map<String, String> saslProperties = new HashMap<String, String>(); saslProperties.put(Sasl.QOP, "auth-conf"); // Creating the server definition TSaslServerTransport.Factory saslTransportFactory = new TSaslServerTransport.Factory(); saslTransportFactory.addServerDefinition("GSSAPI", // tell SASL to use GSSAPI, which supports Kerberos primary, // kerberos primary for server - "myprincipal" in myprincipal/my.server.com@MY.REALM instance, // kerberos instance for server - "my.server.com" in myprincipal/my.server.com@MY.REALM saslProperties, // Properties set, above new SaslRpcServer.SaslGssCallbackHandler()); // Ensures that authenticated user is the same as the authorized user // Make sure the TTransportFactory is performing a UGI.doAs TTransportFactory ugiTransportFactory = new TUGIAssumingTransportFactory(saslTransportFactory, serverUser); // Processor which takes the UGI for the RPC call, proxy that user on the server login, and then run as the proxied user TUGIAssumingProcessor ugiProcessor = new TUGIAssumingProcessor(processor); // Make a simple TTheadPoolServer with the processor and transport factory TServer server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport) .transportFactory(ugiTransportFactory).processor(ugiProcessor)); // Start the thrift server server.serve();//from w w w . ja v a 2 s . c o m }
From source file:learnj.rpc.ThriftServer.java
License:Apache License
public void startServer() { System.out.println("---startServer---"); try {// w ww. j a v a 2s . c om TServerSocket serverTransport = new TServerSocket(1234); Processor process = new Processor(new SomethingImpl()); Factory portFactory = new TBinaryProtocol.Factory(true, true); Args args = new Args(serverTransport); args.processor(process); args.protocolFactory(portFactory); TServer server = new TThreadPoolServer(args); server.serve(); } catch (TTransportException e) { e.printStackTrace(); } }
From source file:lizard.index.TServerIndex.java
License:Apache License
@Override public void start() { FmtLog.info(log, "Start index server: port = %d", getPort()); // Semapahores to sync. //Semaphore sema = new Semaphore(0) ; new Thread(() -> { try {//from w w w .j a v a2s . c o m getTxnSystem().getTxnMgr().start(); TLZ_Index.Iface handler = new THandlerTupleIndex(getTxnSystem(), getLabel(), index); TLZ_Index.Processor<TLZ_Index.Iface> processor = new TLZ_Index.Processor<TLZ_Index.Iface>(handler); 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 index server: port = %d", getPort()); //sema.release(1); server.serve(); FmtLog.info(log, "Finished index server: port = %d", getPort()); getTxnSystem().getTxnMgr().shutdown(); } catch (Exception e) { e.printStackTrace(); } }).start(); //sema.acquireUninterruptibly(); super.start(); }
From source file:lizard.node.TServerNode.java
License:Apache License
@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);//from w w w . ja v a2 s. c om // 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(); }
From source file:mini_mirc_server.Mini_mirc_server.java
public static void simple(miniIRC.Processor processor) { try {/*from w w w.j a v a 2 s.co m*/ TServerTransport serverTransport = new TServerSocket(2121); TServer server = new TThreadPoolServer(new Args(serverTransport).processor(processor)); System.out.println("Starting simple server..."); server.serve(); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.apache.accumulo.cloudtrace.instrument.TracerTest.java
License:Apache License
@Test public void testThrift() throws Exception { TestReceiver tracer = new TestReceiver(); Tracer.getInstance().addReceiver(tracer); ServerSocket socket = new ServerSocket(0); TServerSocket transport = new TServerSocket(socket); transport.listen();// w w w. j a va 2 s. c om TThreadPoolServer.Args args = new TThreadPoolServer.Args(transport); args.processor(new TestService.Processor(TraceWrap.service(new Service()))); final TServer tserver = new TThreadPoolServer(args); Thread t = new Thread() { public void run() { tserver.serve(); } }; t.start(); TTransport clientTransport = new TSocket(new Socket("localhost", socket.getLocalPort())); TestService.Iface client = new TestService.Client(new TBinaryProtocol(clientTransport), new TBinaryProtocol(clientTransport)); client = TraceWrap.client(client); assertFalse(client.checkTrace(null, "test")); Span start = Trace.on("start"); assertTrue(client.checkTrace(null, "my test")); start.stop(); assertNotNull(tracer.traces.get(start.traceId())); String traces[] = { "my test", "checkTrace", "client:checkTrace", "start" }; assertTrue(tracer.traces.get(start.traceId()).size() == traces.length); for (int i = 0; i < traces.length; i++) assertEquals(traces[i], tracer.traces.get(start.traceId()).get(i).description); tserver.stop(); t.join(100); }
From source file:org.apache.accumulo.core.client.TestThrift1474.java
License:Apache License
@Test public void test() throws IOException, TException, InterruptedException { TServerSocket serverTransport = new TServerSocket(0); serverTransport.listen();/*from w ww .ja v a 2 s . c om*/ int port = serverTransport.getServerSocket().getLocalPort(); TestServer handler = new TestServer(); ThriftTest.Processor<ThriftTest.Iface> processor = new ThriftTest.Processor<ThriftTest.Iface>(handler); TThreadPoolServer.Args args = new TThreadPoolServer.Args(serverTransport); args.stopTimeoutVal = 10; args.stopTimeoutUnit = TimeUnit.MILLISECONDS; final TServer server = new TThreadPoolServer(args.processor(processor)); Thread thread = new Thread() { @Override public void run() { server.serve(); } }; thread.start(); while (!server.isServing()) { UtilWaitThread.sleep(10); } TTransport transport = new TSocket("localhost", port); transport.open(); TProtocol protocol = new TBinaryProtocol(transport); ThriftTest.Client client = new ThriftTest.Client(protocol); assertTrue(client.success()); assertFalse(client.fails()); try { client.throwsError(); fail("no exception thrown"); } catch (ThriftSecurityException ex) { // expected } server.stop(); thread.join(); }
From source file:org.apache.accumulo.server.rpc.TServerUtils.java
License:Apache License
/** * Create a {@link TThreadPoolServer} with the provided server transport, processor and transport factory. * * @param transport/*from www. j a va 2 s .c o m*/ * TServerTransport for the server * @param processor * TProcessor for the server * @param transportFactory * TTransportFactory for the server */ public static TThreadPoolServer createTThreadPoolServer(TServerTransport transport, TProcessor processor, TTransportFactory transportFactory, TProtocolFactory protocolFactory, ExecutorService service) { TThreadPoolServer.Args options = new TThreadPoolServer.Args(transport); options.protocolFactory(protocolFactory); options.transportFactory(transportFactory); options.processorFactory(new ClientInfoProcessorFactory(clientAddress, processor)); if (null != service) { options.executorService(service); } return new TThreadPoolServer(options); }
From source file:org.apache.accumulo.server.trace.TraceServer.java
License:Apache License
public TraceServer(ServerConfiguration serverConfiguration, String hostname) throws Exception { this.serverConfiguration = serverConfiguration; AccumuloConfiguration conf = serverConfiguration.getConfiguration(); table = conf.get(Property.TRACE_TABLE); while (true) { try {/*from w w w .j av a2s. com*/ String principal = conf.get(Property.TRACE_USER); AuthenticationToken at; Map<String, String> loginMap = conf .getAllPropertiesWithPrefix(Property.TRACE_TOKEN_PROPERTY_PREFIX); if (loginMap.isEmpty()) { Property p = Property.TRACE_PASSWORD; at = new PasswordToken(conf.get(p).getBytes()); } else { Properties props = new Properties(); AuthenticationToken token = AccumuloClassLoader.getClassLoader() .loadClass(conf.get(Property.TRACE_TOKEN_TYPE)).asSubclass(AuthenticationToken.class) .newInstance(); int prefixLength = Property.TRACE_TOKEN_PROPERTY_PREFIX.getKey().length() + 1; for (Entry<String, String> entry : loginMap.entrySet()) { props.put(entry.getKey().substring(prefixLength), entry.getValue()); } token.init(props); at = token; } connector = serverConfiguration.getInstance().getConnector(principal, at); if (!connector.tableOperations().exists(table)) { connector.tableOperations().create(table); IteratorSetting setting = new IteratorSetting(10, "ageoff", AgeOffFilter.class.getName()); AgeOffFilter.setTTL(setting, 7 * 24 * 60 * 60 * 1000l); connector.tableOperations().attachIterator(table, setting); } connector.tableOperations().setProperty(table, Property.TABLE_FORMATTER_CLASS.getKey(), TraceFormatter.class.getName()); break; } catch (Exception ex) { log.info("Waiting to checking/create the trace table.", ex); UtilWaitThread.sleep(1000); } } int port = conf.getPort(Property.TRACE_PORT); final ServerSocket sock = ServerSocketChannel.open().socket(); sock.setReuseAddress(true); sock.bind(new InetSocketAddress(hostname, port)); final TServerTransport transport = new TServerSocket(sock); TThreadPoolServer.Args options = new TThreadPoolServer.Args(transport); options.processor(new Processor<Iface>(new Receiver())); server = new TThreadPoolServer(options); registerInZooKeeper(sock.getInetAddress().getHostAddress() + ":" + sock.getLocalPort()); writer = connector.createBatchWriter(table, new BatchWriterConfig().setMaxLatency(5, TimeUnit.SECONDS)); }