.codec(ThriftServerFramedCodec.get()) .reportTo(statsReceiver) .keepAlive(true)
public void start() { Stopwatch sw = new Stopwatch(); sw.start(); ServerCodecConfig codeConfig = new ServerCodecConfig(name, addr); ThriftServerFramedCodec codec = new ThriftServerFramedCodec(codeConfig, new TCompactProtocol.Factory()); server = ServerBuilder.safeBuild(svc, ServerBuilder.get() .codec(codec) .name(name).maxConcurrentRequests(maxConcurrentRequests) .bindTo(addr)); sw.stop(); logger.info(String.format("building finagle server took %s ms", sw.elapsedMillis())); }
public static void main(String[] args) { Haver.ServiceIface server = new HaverServer(); ServerBuilder.safeBuild( new Haver.Service(server, new TBinaryProtocol.Factory()), ServerBuilder.get() .name("HaverServer") .codec(ThriftServerFramedCodec.get()) // IntelliJ shows this as a type error, but compiles .bindTo(new InetSocketAddress(8080)) ); System.out.println("HaverServer's up!"); } }
public static void main(String[] args) { // In this example; use some random port between 2000-9999. // In a real world; probably deploy with the same port on different servers int port = new Random().nextInt(8000)+2000; // Pass port number into our handler for this example (for debugging) FooServiceHandler handler = new FooServiceHandler("port="+port); Server server = ServerBuilder.safeBuild( new FooService.FinagledService(handler, new TBinaryProtocol.Factory()), ServerBuilder.get() .name("FooService") .codec(ThriftServerFramedCodec.get()) .maxConcurrentRequests(50) // .logger(Logger.getLogger("ROOT")) .bindTo(new InetSocketAddress(port)) ); ClusterFactory.reportServerUpAndRunning(server, "FooService"); System.out.println("The server, running from port "+port+" joined the FooService cluster."); int ostrichPort = port + 1; RuntimeEnvironment runtime = new RuntimeEnvironment(""); AdminHttpService admin = new AdminHttpService(ostrichPort, 0, runtime); admin.start(); System.out.println("Ostrich reporting started on port "+ostrichPort); } }
public static void main(String[] args) { try { String serverHostName = InetAddress.getLocalHost().getHostName(); PinLaterQueueConfig queueConfig = new PinLaterQueueConfig(CONFIGURATION); queueConfig.initialize(); String backend = CONFIGURATION.getString("PINLATER_BACKEND"); PinLaterBackendIface backendIFace = getBackendIface(backend, serverHostName); PinLaterServiceImpl serviceImpl = new PinLaterServiceImpl(backendIFace, queueConfig); PinLater.Service service = new PinLater.Service(serviceImpl, new TBinaryProtocol.Factory()); ServiceShutdownHook.register(ServerBuilder.safeBuild( service, ServerBuilder.get() .name("PinLaterService") .codec(ThriftServerFramedCodec.get()) .hostConnectionMaxIdleTime(Duration.fromTimeUnit( CONFIGURATION.getInt("SERVER_CONN_MAX_IDLE_TIME_MINUTES"), TimeUnit.MINUTES)) .maxConcurrentRequests(CONFIGURATION.getInt("MAX_CONCURRENT_REQUESTS")) .reportTo(new OstrichStatsReceiver(Stats.get(""))) .bindTo(new InetSocketAddress(CONFIGURATION.getInt("THRIFT_PORT"))))); new OstrichAdminService(CONFIGURATION.getInt("OSTRICH_PORT")).start(); LOG.info("\n#######################################" + "\n# Ready To Serve Requests. #" + "\n#######################################"); } catch (Exception e) { LOG.error("Failed to start the pinlater server", e); System.exit(1); } } }
.codec(ThriftServerFramedCodec.get()) .reportTo(statsReceiver) .keepAlive(true)