if (serviceRegistry.getExecutorService() == null) { ThreadFactory tFactory = AccessController.doPrivileged(new PrivilegedAction<ThreadFactory>() { @Override threadPool = serviceRegistry.getExecutorService(); this.threadPoolSupplied = true; if (serviceRegistry.getIOExecutorService() != null) { this.ioExecutorFactory = new OrderedExecutorFactory(serviceRegistry.getIOExecutorService()); } else { ThreadFactory tFactory = AccessController.doPrivileged(new PrivilegedAction<ThreadFactory>() { if (serviceRegistry.getScheduledExecutorService() == null) { ThreadFactory tFactory = AccessController.doPrivileged(new PrivilegedAction<ThreadFactory>() { @Override } else { this.scheduledPoolSupplied = true; this.scheduledPool = serviceRegistry.getScheduledExecutorService();
private void setInterceptors(Configuration configuration) { incomingInterceptors.addAll(serviceRegistry.getIncomingInterceptors(configuration.getIncomingInterceptorClassNames())); outgoingInterceptors.addAll(serviceRegistry.getOutgoingInterceptors(configuration.getOutgoingInterceptorClassNames())); }
/** * Tests ensures that setInterceptors methods adds both interceptors from the service registry and also interceptors * defined in the configuration. */ @Test public void testSetInterceptorsAddsBothInterceptorsFromConfigAndServiceRegistry() throws Exception { Method method = RemotingServiceImpl.class.getDeclaredMethod("setInterceptors", Configuration.class); Field incomingInterceptors = RemotingServiceImpl.class.getDeclaredField("incomingInterceptors"); Field outgoingInterceptors = RemotingServiceImpl.class.getDeclaredField("outgoingInterceptors"); method.setAccessible(true); incomingInterceptors.setAccessible(true); outgoingInterceptors.setAccessible(true); serviceRegistry.addIncomingInterceptor(new FakeInterceptor()); serviceRegistry.addOutgoingInterceptor(new FakeInterceptor()); List<String> interceptorClassNames = new ArrayList<>(); interceptorClassNames.add(FakeInterceptor.class.getCanonicalName()); configuration.setIncomingInterceptorClassNames(interceptorClassNames); configuration.setOutgoingInterceptorClassNames(interceptorClassNames); method.invoke(remotingService, configuration); assertTrue(((List) incomingInterceptors.get(remotingService)).size() == 2); assertTrue(((List) outgoingInterceptors.get(remotingService)).size() == 2); assertTrue(((List) incomingInterceptors.get(remotingService)).contains(serviceRegistry.getIncomingInterceptors(null).get(0))); assertTrue(((List) outgoingInterceptors.get(remotingService)).contains(serviceRegistry.getOutgoingInterceptors(null).get(0))); }
server.getServiceRegistry().addIncomingInterceptor(incomingInterceptor); server.getServiceRegistry().addOutgoingInterceptor(outgoingInterceptor);
@Test public void testSuppliedThreadPoolsAreCorrectlySet() throws Exception { assertEquals(serviceRegistry.getScheduledExecutorService(), server.getScheduledPool()); // To check the Executor is what we expect we must reflectively inspect the OrderedExecutorFactory. Field field = server.getExecutorFactory().getClass().getDeclaredField("parent"); field.setAccessible(true); assertEquals(serviceRegistry.getExecutorService(), field.get(server.getExecutorFactory())); }
/** * Tests that the service registry gets propaged into remotingService. */ @Test public void testPropagatingInterceptors() throws Exception { for (int i = 0; i < 5; i++) { serviceRegistry.addIncomingInterceptor(new FakeInterceptor()); } remotingService = new RemotingServiceImpl(null, configuration, null, null, null, null, null, serviceRegistry); assertTrue(remotingService.getIncomingInterceptors().size() == 5); assertTrue(remotingService.getIncomingInterceptors().get(0) instanceof FakeInterceptor); assertTrue(remotingService.getIncomingInterceptors().get(0) != remotingService.getIncomingInterceptors().get(1)); }
AcceptorFactory factory = server.getServiceRegistry().getAcceptorFactory(info.getName(), info.getFactoryClassName());
/** * Test that the connectors added via the service registry are added to the connectorsService, * * @throws Exception */ @Test public void testConnectorsServiceUsesInjectedConnectorServiceFactory() throws Exception { ConnectorServiceConfiguration connectorServiceConfiguration = new ConnectorServiceConfiguration().setFactoryClassName(null).setParams(new HashMap<String, Object>()).setName("myfact"); // Creates a fake connector service factory that returns the fake connector service object ConnectorService connectorService = new FakeConnectorService(); FakeConnectorServiceFactory connectorServiceFactory = new FakeConnectorServiceFactory(); serviceRegistry.addConnectorService(connectorServiceFactory, connectorServiceConfiguration); ConnectorsService connectorsService = new ConnectorsService(configuration, null, null, null, serviceRegistry); connectorsService.start(); assertTrue(connectorsService.getConnectors().size() == 1); assertTrue(connectorsService.getConnectors().values().contains(connectorServiceFactory.getConnectorService())); }
/** * Tests ensures that both interceptors from the service registry and also interceptors defined in the configuration * are added to the RemotingServiceImpl on creation */ @Test public void testInterceptorsAreAddedOnCreationOfServiceRegistry() throws Exception { Field incomingInterceptors = RemotingServiceImpl.class.getDeclaredField("incomingInterceptors"); Field outgoingInterceptors = RemotingServiceImpl.class.getDeclaredField("outgoingInterceptors"); incomingInterceptors.setAccessible(true); outgoingInterceptors.setAccessible(true); serviceRegistry.addIncomingInterceptor(new FakeInterceptor()); serviceRegistry.addOutgoingInterceptor(new FakeInterceptor()); List<String> interceptorClassNames = new ArrayList<>(); interceptorClassNames.add(FakeInterceptor.class.getCanonicalName()); configuration.setIncomingInterceptorClassNames(interceptorClassNames); configuration.setOutgoingInterceptorClassNames(interceptorClassNames); remotingService = new RemotingServiceImpl(null, configuration, null, null, null, null, null, serviceRegistry); assertTrue(((List) incomingInterceptors.get(remotingService)).size() == 2); assertTrue(((List) outgoingInterceptors.get(remotingService)).size() == 2); assertTrue(((List) incomingInterceptors.get(remotingService)).contains(serviceRegistry.getIncomingInterceptors(null).get(0))); assertTrue(((List) outgoingInterceptors.get(remotingService)).contains(serviceRegistry.getOutgoingInterceptors(null).get(0))); } }
server.getServiceRegistry().addIncomingInterceptor(incomingInterceptor); server.getServiceRegistry().addOutgoingInterceptor(outgoingInterceptor);
@Override @After public void tearDown() throws Exception { if (server.isActive()) { server.stop(); } serviceRegistry.getExecutorService().shutdown(); serviceRegistry.getScheduledExecutorService().shutdown(); serviceRegistry.getIOExecutorService().shutdown(); super.tearDown(); }