private ThriftServer createServer(ServiceInterface handler) throws IllegalAccessException, InstantiationException { ThriftServiceProcessor processor = new ThriftServiceProcessor(codecManager, eventHandlers, handler); return new ThriftServer(processor, serverConfig); }
ScribeCollector(Builder builder) { ScribeSpanConsumer scribe = new ScribeSpanConsumer(builder); ThriftServiceProcessor processor = new ThriftServiceProcessor(new ThriftCodecManager(), emptyList(), scribe); server = new ThriftServer(processor, new ThriftServerConfig().setPort(builder.port)); }
/** * Create and start the Thrift server. * * @param conf Giraph conf to set the host and ports for. * @param services Services to start */ public ClientThriftServer(GiraphConfiguration conf, List<?> services) { checkNotNull(conf, "conf is null"); checkNotNull(services, "services is null"); ThriftServiceProcessor processor = new ThriftServiceProcessor(new ThriftCodecManager(), new ArrayList<ThriftEventHandler>(), services); clientThriftServer = new ThriftServer(processor, new ThriftServerConfig()); clientThriftServer.start(); try { CLIENT_THRIFT_SERVER_HOST.set( conf, conf.getLocalHostname()); } catch (UnknownHostException e) { throw new IllegalStateException("Unable to get host information", e); } CLIENT_THRIFT_SERVER_PORT.set(conf, clientThriftServer.getPort()); }
ScribeCollector(Builder builder, Lazy<AsyncSpanConsumer> consumer) { ScribeSpanConsumer scribe = new ScribeSpanConsumer(builder.category, consumer, builder.metrics); ThriftServiceProcessor processor = new ThriftServiceProcessor(new ThriftCodecManager(), emptyList(), scribe); server = new ThriftServer(processor, new ThriftServerConfig().setPort(builder.port)).start(); }
@Test public void testSwiftService() throws Exception { SwiftScribe scribeService = new SwiftScribe(); NiftyProcessor processor = new ThriftServiceProcessor(new ThriftCodecManager(), ImmutableList.<ThriftEventHandler>of(), scribeService); testProcessor(processor); }
@Test public void testSwiftService() throws Exception { SwiftScribe scribeService = new SwiftScribe(); NiftyProcessor processor = new ThriftServiceProcessor(new ThriftCodecManager(), ImmutableList.<ThriftEventHandler>of(), scribeService); List<LogEntry> messages = testProcessor(processor, false); assertEquals(scribeService.getMessages(), newArrayList(concat(toSwiftLogEntry(messages), toSwiftLogEntry(messages)))); }
@Test public void testSwiftService() throws Exception { SwiftScribe scribeService = new SwiftScribe(); NiftyProcessor processor = new ThriftServiceProcessor(new ThriftCodecManager(), ImmutableList.<ThriftEventHandler>of(), scribeService); List<LogEntry> messages = testProcessor(processor); assertEquals(scribeService.getMessages(), newArrayList(concat(toSwiftLogEntry(messages), toSwiftLogEntry(messages)))); }
@Test public void testSwiftServicePlaintext() throws Exception { SwiftScribe scribeService = new SwiftScribe(); NiftyProcessor processor = new ThriftServiceProcessor(new ThriftCodecManager(), ImmutableList.<ThriftEventHandler>of(), scribeService); List<LogEntry> messages = testProcessor(processor, true); assertEquals(scribeService.getMessages(), newArrayList(concat(toSwiftLogEntry(messages), toSwiftLogEntry(messages)))); }
protected ThriftServer createServerFromHandler(ThriftServerConfig config, Object handler) throws IllegalAccessException, InstantiationException { ThriftServiceProcessor processor = new ThriftServiceProcessor(codecManager, ImmutableList.<ThriftEventHandler>of(), handler); config.setMaxFrameSize(new DataSize(MAX_FRAME_SIZE, DataSize.Unit.BYTE)); return new ThriftServer(processor, config).start(); } }
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "Multiple @ThriftMethod-annotated methods named.*") public void testConflictingServices() throws Exception { new ThriftServiceProcessor(new ThriftCodecManager(), ImmutableList.<ThriftEventHandler>of(), new SwiftScribe(), new ConflictingLogService()); }
public void swiftEventHandlerTester(boolean niftyProcessor) throws Exception { SwiftScribe scribeService = new SwiftScribe(); EventHandler eventHandler = new EventHandler(niftyProcessor); EventHandler secondHandler = new EventHandler(niftyProcessor); List<EventHandler> handlers = ImmutableList.of(eventHandler, secondHandler); final ThriftServiceProcessor processor = new ThriftServiceProcessor(new ThriftCodecManager(), handlers, scribeService); List<LogEntry> messages = niftyProcessor ? testProcessor(processor) : testProcessor(NiftyProcessorAdapters.processorToTProcessor(processor)); assertEquals(scribeService.getMessages(), newArrayList(concat(toSwiftLogEntry(messages), toSwiftLogEntry(messages)))); assertTrue(eventHandler.validate(2)); assertTrue(secondHandler.validate(2)); }
@Override protected <T> Runnable doExport(T impl, Class<T> type, URL url) throws RpcException { TProcessor processor = new ThriftServiceProcessor(new ThriftCodecManager(), impl); final ThriftServer server = new ThriftServer(processor, new ThriftServerConfig().setPort(url.getPort())); server.start(); return new Runnable() { public void run() { try { server.close(); } catch (Throwable e) { logger.warn(e.getMessage(), e); } } }; }
@Test public void testPumaSwiftException() throws Exception { PumaReadServer puma = new PumaReadServer(); ReadSemanticException exception = new ReadSemanticException("my exception"); puma.setException(exception); NiftyProcessor processor = new ThriftServiceProcessor(new ThriftCodecManager(), ImmutableList.<ThriftEventHandler>of(), puma); try ( ThriftServer server = new ThriftServer(processor).start(); ThriftClientManager clientManager = new ThriftClientManager(); PumaReadService pumaClient = clientManager.createClient( new FramedClientConnector(HostAndPort.fromParts("localhost", server.getPort())), PumaReadService.class).get() ) { pumaClient.getResultTimeString(PUMA_REQUEST); fail("Expected ReadSemanticException"); } catch (ReadSemanticException e) { assertEquals(e, exception); } }
@Test public void testPumaSwift() throws Exception { // create server and start PumaReadServer puma = new PumaReadServer(); ThriftServiceProcessor processor = new ThriftServiceProcessor(new ThriftCodecManager(), ImmutableList.<ThriftEventHandler>of(), puma); // create server and client try ( ThriftServer server = new ThriftServer(processor).start(); ThriftClientManager clientManager = new ThriftClientManager(); PumaReadService pumaClient = clientManager.createClient( new FramedClientConnector(fromParts("localhost", server.getPort())), PumaReadService.class).get() ) { // invoke puma List<ReadResultQueryInfoTimeString> results = pumaClient.getResultTimeString(PUMA_REQUEST); verifyPumaResults(results); } }
@Test public void testGenericProcessor() throws ExecutionException, InterruptedException { ThriftCodecManager codecManager = new ThriftCodecManager(); ThriftServiceProcessor processor = new ThriftServiceProcessor(codecManager, ImmutableList.<ThriftEventHandler>of(), new GenericService()); try (ThriftServer server = new ThriftServer(processor, new ThriftServerConfig()).start(); ThriftClientManager clientManager = new ThriftClientManager(codecManager)) { ThriftClient<GenericInterface.Client> clientOpener = new ThriftClient<>(clientManager, GenericInterface.Client.class); try (GenericInterface.Client client = clientOpener.open(new FramedClientConnector(HostAndPort.fromParts("localhost", server.getPort()))).get()) { GenericStruct<String> original = new GenericStruct<>(); original.genericField = "original.genericField"; GenericStruct<String> copy = client.echo(original); assertEquals(original, copy); } } } }
public ServerCreator invoke() { ThriftServiceProcessor processor = new ThriftServiceProcessor( new ThriftCodecManager(), ImmutableList.<ThriftEventHandler>of(), new SimpleService() ); taskWorkerExecutor = newFixedThreadPool(1); ThriftServerDef serverDef = ThriftServerDef.newBuilder() .listen(0) .withProcessor(processor) .using(taskWorkerExecutor) .build(); bossExecutor = newCachedThreadPool(); ioWorkerExecutor = newCachedThreadPool(); NettyServerConfig serverConfig = NettyServerConfig.newBuilder() .setBossThreadExecutor(bossExecutor) .setWorkerThreadExecutor(ioWorkerExecutor) .build(); server = new ThriftServer(serverConfig, serverDef); return this; }
public ScopedServer(TProtocolFactory protocolFactory) throws TTransportException, InterruptedException { ThriftServiceProcessor processor = new ThriftServiceProcessor(new ThriftCodecManager(), ImmutableList.<ThriftEventHandler>of(), new ScribeHandler()); ThriftServerDef def = ThriftServerDef.newBuilder() .listen(0) .withProcessor(processor) .protocol(protocolFactory).build(); server = new NettyServerTransport(def, NettyServerConfig.newBuilder().build(), new DefaultChannelGroup()); server.start(); }