@Test public void test_add() { assertThat( () -> handler.add(null, new MyService() {}, noop, mbean), is(throwing(instanceOf(NullPointerException.class)))); assertThat( () -> handler.add(MyService.class, null, noop, mbean), is(throwing(instanceOf(NullPointerException.class)))); DiagnosticServiceDescriptor<MyService> descriptor = handler.add(MyService.class, new MyService() {}, noop, mbean); assertThat(descriptor, is(not(nullValue()))); assertThat( () -> handler.add(MyService.class, new MyService() {}, noop, mbean), is(throwing(instanceOf(IllegalArgumentException.class)).andMessage(is(equalTo("Service org.terracotta.diagnostic.server.DiagnosticRequestHandlerTest$MyService is already registered"))))); }
<T> DiagnosticServiceDescriptor<T> add(Class<T> serviceInterface, T serviceImplementation, Runnable onClose, Function<String, Boolean> jmxExpose) { DiagnosticServiceDescriptor<T> service = new DiagnosticServiceDescriptor<>(serviceInterface, serviceImplementation, onClose, jmxExpose); DiagnosticServiceDescriptor<?> previous = services.putIfAbsent(serviceInterface.getName(), service); if (previous == null) { return service; } throw new IllegalArgumentException("Service " + serviceInterface.getName() + " is already registered"); }
DiagnosticRequestHandler extends StandardMBean implements DiagnosticRequestHandlerMBean { <T> DiagnosticServiceDescriptor<T> add(Class<T> serviceInterface, T serviceImplementation, Runnable onClose, Function<String, Boolean> jmxExpose) { DiagnosticServiceDescriptor<T> service = new DiagnosticServiceDescriptor<>(serviceInterface, serviceImplementation, onClose, jmxExpose); DiagnosticServiceDescriptor<?> previous = services.putIfAbsent(serviceInterface.getName(), service); if (previous == null) { return service; } throw new IllegalArgumentException("Service " + serviceInterface.getName() + " is already registered"); } }
DiagnosticRequestHandler extends StandardMBean implements DiagnosticRequestHandlerMBean { <T> DiagnosticServiceDescriptor<T> add(Class<T> serviceInterface, T serviceImplementation, Runnable onClose, Function<String, Boolean> jmxExpose) { DiagnosticServiceDescriptor<T> service = new DiagnosticServiceDescriptor<>(serviceInterface, serviceImplementation, onClose, jmxExpose); DiagnosticServiceDescriptor<?> previous = services.putIfAbsent(serviceInterface.getName(), service); if (previous == null) { return service; } throw new IllegalArgumentException("Service " + serviceInterface.getName() + " is already registered"); } private  DiagnosticRequestHandler(DiagnosticCodec<?> codec); }
DiagnosticRequestHandler extends StandardMBean implements DiagnosticRequestHandlerMBean { <T> DiagnosticServiceDescriptor<T> add(Class<T> serviceInterface, T serviceImplementation, Runnable onClose, Function<String, Boolean> jmxExpose) { DiagnosticServiceDescriptor<T> service = new DiagnosticServiceDescriptor<>(serviceInterface, serviceImplementation, onClose, jmxExpose); DiagnosticServiceDescriptor<?> previous = services.putIfAbsent(serviceInterface.getName(), service); if (previous == null) { return service; } throw new IllegalArgumentException("Service " + serviceInterface.getName() + " is already registered"); } private  DiagnosticRequestHandler(DiagnosticCodec<?> codec); DiagnosticCodec<String> getCodec(); Collection<DiagnosticServiceDescriptor<?>> getServices(); @Override boolean hasServiceInterface(String serviceName); @SuppressWarnings("unchecked") @Override String request(String payload); }
DiagnosticRequestHandler extends StandardMBean implements DiagnosticRequestHandlerMBean { <T> DiagnosticServiceDescriptor<T> add(Class<T> serviceInterface, T serviceImplementation, Runnable onClose, Function<String, Boolean> jmxExpose) { DiagnosticServiceDescriptor<T> service = new DiagnosticServiceDescriptor<>(serviceInterface, serviceImplementation, onClose, jmxExpose); DiagnosticServiceDescriptor<?> previous = services.putIfAbsent(serviceInterface.getName(), service); if (previous == null) { return service; } throw new IllegalArgumentException("Service " + serviceInterface.getName() + " is already registered"); } private  DiagnosticRequestHandler(DiagnosticCodec<?> codec); DiagnosticCodec<String> getCodec(); Collection<DiagnosticServiceDescriptor<?>> getServices(); @Override boolean hasServiceInterface(String serviceName); @SuppressWarnings("unchecked") @Override String request(String payload);  }