@Test public void getService() throws Exception { OOOMessageHandlerProvider provider = new OOOMessageHandlerProvider(); OOOMessageHandlerConfiguration<EntityMessage, EntityResponse> config = new OOOMessageHandlerConfiguration<>("foo", null); OOOMessageHandler<EntityMessage, EntityResponse> messageHandler = provider.getService(1L, config); assertThat(provider.getService(2L, config), sameInstance(messageHandler)); config = new OOOMessageHandlerConfiguration<>("bar", null); assertThat(provider.getService(2L, config), not(sameInstance(messageHandler))); }
@Override public <T> T getService(long l, ServiceConfiguration<T> serviceConfiguration) { if (serviceConfiguration instanceof OOOMessageHandlerConfiguration) { @SuppressWarnings("unchecked") OOOMessageHandlerConfiguration<EntityMessage, EntityResponse> cmtServiceConfiguration = (OOOMessageHandlerConfiguration<EntityMessage, EntityResponse>) serviceConfiguration; OOOMessageHandler<EntityMessage, EntityResponse> messageHandler = serviceMap.computeIfAbsent(cmtServiceConfiguration.getEntityIdentifier(), id -> new OOOMessageHandlerImpl<>(cmtServiceConfiguration.getTrackerPolicy(), () -> serviceMap.remove(id))); return serviceConfiguration.getServiceType().cast(messageHandler); } throw new IllegalArgumentException("Unexpected configuration type: " + serviceConfiguration); }
OOOMessageHandlerProvider implements ServiceProvider { @Override public <T> T getService(long l, ServiceConfiguration<T> serviceConfiguration) { if (serviceConfiguration instanceof OOOMessageHandlerConfiguration) { @SuppressWarnings("unchecked") OOOMessageHandlerConfiguration<EntityMessage, EntityResponse> cmtServiceConfiguration = (OOOMessageHandlerConfiguration<EntityMessage, EntityResponse>) serviceConfiguration; OOOMessageHandler<EntityMessage, EntityResponse> messageHandler = serviceMap.computeIfAbsent(cmtServiceConfiguration.getEntityIdentifier(), id -> new OOOMessageHandlerImpl<>(cmtServiceConfiguration.getTrackerPolicy(), () -> serviceMap.remove(id))); return serviceConfiguration.getServiceType().cast(messageHandler); } throw new IllegalArgumentException("Unexpected configuration type: " + serviceConfiguration); } }
OOOMessageHandlerProvider implements ServiceProvider { @Override public <T> T getService(long l, ServiceConfiguration<T> serviceConfiguration) { if (serviceConfiguration instanceof OOOMessageHandlerConfiguration) { @SuppressWarnings("unchecked") OOOMessageHandlerConfiguration<EntityMessage, EntityResponse> cmtServiceConfiguration = (OOOMessageHandlerConfiguration<EntityMessage, EntityResponse>) serviceConfiguration; OOOMessageHandler<EntityMessage, EntityResponse> messageHandler = serviceMap.computeIfAbsent(cmtServiceConfiguration.getEntityIdentifier(), id -> new OOOMessageHandlerImpl<>(cmtServiceConfiguration.getTrackerPolicy(), () -> serviceMap.remove(id))); return serviceConfiguration.getServiceType().cast(messageHandler); } throw new IllegalArgumentException("Unexpected configuration type: " + serviceConfiguration); }  }
OOOMessageHandlerProvider implements ServiceProvider { @Override public <T> T getService(long l, ServiceConfiguration<T> serviceConfiguration) { if (serviceConfiguration instanceof OOOMessageHandlerConfiguration) { @SuppressWarnings("unchecked") OOOMessageHandlerConfiguration<EntityMessage, EntityResponse> cmtServiceConfiguration = (OOOMessageHandlerConfiguration<EntityMessage, EntityResponse>) serviceConfiguration; OOOMessageHandler<EntityMessage, EntityResponse> messageHandler = serviceMap.computeIfAbsent(cmtServiceConfiguration.getEntityIdentifier(), id -> new OOOMessageHandlerImpl<>(cmtServiceConfiguration.getTrackerPolicy(), () -> serviceMap.remove(id))); return serviceConfiguration.getServiceType().cast(messageHandler); } throw new IllegalArgumentException("Unexpected configuration type: " + serviceConfiguration); }  @Override boolean initialize(ServiceProviderConfiguration serviceProviderConfiguration, PlatformConfiguration platformConfiguration); @Override T getService(long l, ServiceConfiguration<T> serviceConfiguration); @Override Collection<Class<?>> getProvidedServiceTypes(); @Override void prepareForSynchronization(); @Override void addStateTo(StateDumpCollector stateDumper); }
OOOMessageHandlerProvider implements ServiceProvider { @Override public <T> T getService(long l, ServiceConfiguration<T> serviceConfiguration) { if (serviceConfiguration instanceof OOOMessageHandlerConfiguration) { @SuppressWarnings("unchecked") OOOMessageHandlerConfiguration<EntityMessage, EntityResponse> cmtServiceConfiguration = (OOOMessageHandlerConfiguration<EntityMessage, EntityResponse>) serviceConfiguration; OOOMessageHandler<EntityMessage, EntityResponse> messageHandler = serviceMap.computeIfAbsent(cmtServiceConfiguration.getEntityIdentifier(), id -> new OOOMessageHandlerImpl<>(cmtServiceConfiguration.getTrackerPolicy(), () -> serviceMap.remove(id))); return serviceConfiguration.getServiceType().cast(messageHandler); } throw new IllegalArgumentException("Unexpected configuration type: " + serviceConfiguration); }  @Override boolean initialize(ServiceProviderConfiguration serviceProviderConfiguration, PlatformConfiguration platformConfiguration); @Override T getService(long l, ServiceConfiguration<T> serviceConfiguration); @Override Collection<Class<?>> getProvidedServiceTypes(); @Override void prepareForSynchronization(); @Override void addStateTo(StateDumpCollector stateDumper);  }