@PreDestroy public void shutdown() { serverTransport.shutdown(); } }
@PostConstruct public void start() { serverTransport.start(); }
public synchronized ListenableFuture<Object> invoke(String methodName, Map<String, String> headers, Map<Short, Object> parameters) { long startTime = System.nanoTime(); Optional<MethodMetadata> methodMetadata = serverMethodInvoker.getMethodMetadata(methodName); checkArgument(methodMetadata.isPresent(), "Method %s not found", methodName); ListenableFuture<Object> result = serverMethodInvoker.invoke(new ServerInvokeRequest(methodMetadata.get(), headers, parameters)); serverMethodInvoker.recordResult(methodName, startTime, result); return result; }
@Override public void assertInvocation(String expectedMethodName, int expectedId, String expectedName) { assertEquals(request.getMethod().getName(), expectedMethodName); assertEquals(request.getParameters().get((short) 1), expectedId); assertEquals(request.getParameters().get((short) 2), expectedName); } }
private static int testMethodInvoker(ServerMethodInvoker methodInvoker, List<ToIntFunction<HostAndPort>> clients) { TestingPooledByteBufAllocator testingAllocator = new TestingPooledByteBufAllocator(); ServerTransport serverTransport = new DriftNettyServerTransportFactory(new DriftNettyServerConfig(), testingAllocator).createServerTransport(methodInvoker); try { serverTransport.start(); HostAndPort address = HostAndPort.fromParts("localhost", ((DriftNettyServerTransport) serverTransport).getPort()); int sum = 0; for (ToIntFunction<HostAndPort> client : clients) { sum += client.applyAsInt(address); } return sum; } finally { serverTransport.shutdown(); testingAllocator.close(); } }
@Override public ListenableFuture<Object> invoke(ServerInvokeRequest request) { ServiceMethod method = methods.get(request.getMethod().getName()); if (method == null) { return Futures.immediateFailedFuture(new TApplicationException(Type.UNKNOWN_METHOD, "Invalid method name: '" + request.getMethod().getName() + "'")); } return method.invokeMethod(request); }
@Test public void testExplicitPropertyMappings() { Map<String, String> properties = new ImmutableMap.Builder<String, String>() .put("thrift.server.stats.enabled", "false") .build(); DriftServerConfig expected = new DriftServerConfig() .setStatsEnabled(false); assertFullMapping(properties, expected); } }
@Inject public DriftServer( ServerTransportFactory serverTransportFactory, ThriftCodecManager codecManager, MethodInvocationStatsFactory methodInvocationStatsFactory, Set<DriftService> services, Set<MethodInvocationFilter> filters) { requireNonNull(serverTransportFactory, "serverTransportFactory is null"); requireNonNull(codecManager, "codecManager is null"); requireNonNull(services, "services is null"); DriftServerMethodInvoker methodInvoker = new DriftServerMethodInvoker(codecManager, services, ImmutableList.copyOf(filters), methodInvocationStatsFactory); serverTransport = serverTransportFactory.createServerTransport(methodInvoker); }
@Override public final DriftService get() { checkState(injector != null, "injector was not set"); T service = injector.getInstance(Key.get(serverInterface, annotation)); DriftServerConfig config = injector.getInstance(Key.get(DriftServerConfig.class, annotation)); Optional<String> qualifier; if (annotation == DefaultService.class) { qualifier = Optional.empty(); } else { qualifier = Optional.of(annotation.getSimpleName()); } return new DriftService(service, qualifier, config.isStatsEnabled()); } }
@Test public void testDefaults() { assertRecordedDefaults(recordDefaults(DriftServerConfig.class) .setStatsEnabled(true)); }
@Override public void assertInvocation(String expectedMethodName, int expectedId, String expectedName) { assertEquals(request.getMethod().getName(), expectedMethodName); assertEquals(request.getParameters().get((short) 1), expectedId); assertEquals(request.getParameters().get((short) 2), expectedName); } }
public synchronized ListenableFuture<Object> invoke(String methodName, Map<String, String> headers, Map<Short, Object> parameters) { long startTime = System.nanoTime(); Optional<MethodMetadata> methodMetadata = serverMethodInvoker.getMethodMetadata(methodName); checkArgument(methodMetadata.isPresent(), "Method %s not found", methodName); ListenableFuture<Object> result = serverMethodInvoker.invoke(new ServerInvokeRequest(methodMetadata.get(), headers, parameters)); serverMethodInvoker.recordResult(methodName, startTime, result); return result; }
private static int testMethodInvoker(ServerMethodInvoker methodInvoker, List<ToIntFunction<HostAndPort>> clients) { TestingPooledByteBufAllocator testingAllocator = new TestingPooledByteBufAllocator(); ServerTransport serverTransport = new DriftNettyServerTransportFactory(new DriftNettyServerConfig(), testingAllocator).createServerTransport(methodInvoker); try { serverTransport.start(); HostAndPort address = HostAndPort.fromParts("localhost", ((DriftNettyServerTransport) serverTransport).getPort()); int sum = 0; for (ToIntFunction<HostAndPort> client : clients) { sum += client.applyAsInt(address); } return sum; } finally { serverTransport.shutdown(); testingAllocator.close(); } }
@Override public ListenableFuture<Object> invoke(ServerInvokeRequest request) { ServiceMethod method = methods.get(request.getMethod().getName()); if (method == null) { return Futures.immediateFailedFuture(new TApplicationException(Type.UNKNOWN_METHOD, "Invalid method name: '" + request.getMethod().getName() + "'")); } return method.invokeMethod(request); }
@PreDestroy public void shutdown() { serverTransport.shutdown(); } }
@PostConstruct public void start() { serverTransport.start(); }
@Inject public DriftServer( ServerTransportFactory serverTransportFactory, ThriftCodecManager codecManager, MethodInvocationStatsFactory methodInvocationStatsFactory, Set<DriftService> services, Set<MethodInvocationFilter> filters) { requireNonNull(serverTransportFactory, "serverTransportFactory is null"); requireNonNull(codecManager, "codecManager is null"); requireNonNull(services, "services is null"); DriftServerMethodInvoker methodInvoker = new DriftServerMethodInvoker(codecManager, services, ImmutableList.copyOf(filters), methodInvocationStatsFactory); serverTransport = serverTransportFactory.createServerTransport(methodInvoker); }
@Override public final DriftService get() { checkState(injector != null, "injector was not set"); T service = injector.getInstance(Key.get(serverInterface, annotation)); DriftServerConfig config = injector.getInstance(Key.get(DriftServerConfig.class, annotation)); Optional<String> qualifier; if (annotation == DefaultService.class) { qualifier = Optional.empty(); } else { qualifier = Optional.of(annotation.getSimpleName()); } return new DriftService(service, qualifier, config.isStatsEnabled()); } }
@Override public void assertInvocation(String expectedMethodName, int expectedId, String expectedName) { assertEquals(request.getMethod().getName(), expectedMethodName); assertEquals(request.getParameters().get((short) 1), expectedId); assertEquals(request.getParameters().get((short) 2), expectedName); } }
@Override public void assertInvocation(String expectedMethodName, int expectedId, String expectedName) { assertEquals(request.getMethod().getName(), expectedMethodName); assertEquals(request.getParameters().get((short) 1), expectedId); assertEquals(request.getParameters().get((short) 2), expectedName); } }