/** * {@inheritDoc} * <P> * All control service MBeans must be valid according * to {@link Controls#isControlServiceMBean(Class)}. * </P> * * @see Controls#isControlServiceMBean(Class) */ @Override public synchronized <T> String registerControl(String type, String id, String alias, Class<T> controlInterface, T control) { if (!Controls.isControlServiceMBean(controlInterface)) throw new IllegalArgumentException(); final String controlId = getControlId(type, id, alias); if (mbeans.containsKey(controlId)) { logger.error("Control id: {} already exists", controlId); throw new IllegalStateException(); } logger.trace("Register control id: {}", controlId); mbeans.put(controlId, new ControlMBean<T>(controlInterface, control)); return controlId; }
/** * {@inheritDoc} * <P> * All control service MBeans must be valid according * to {@link Controls#isControlServiceMBean(Class)}. * </P> * * @see Controls#isControlServiceMBean(Class) */ @Override public synchronized <T> String registerControl(String type, String id, String alias, Class<T> controlInterface, T control) { if (!Controls.isControlServiceMBean(controlInterface)) throw new IllegalArgumentException(); final String controlId = getControlId(type, id, alias); if (mbeans.containsKey(controlId)) { logger.error("Control id: {} already exists", controlId); throw new IllegalStateException(); } logger.trace("Register control id: {}", controlId); mbeans.put(controlId, new ControlMBean<T>(controlInterface, control)); return controlId; }
@Test public void testNotValid() { // Not an interface assertFalse(isControlServiceMBean(Object.class)); // List extends anther assertFalse(isControlServiceMBean(List.class)); // Is parameterized assertFalse(isControlServiceMBean(Callable.class)); // Methods with unsupported signatures. assertFalse(isControlServiceMBean(DataInput.class)); } @Test
@Test public void testValid() { assertTrue(isControlServiceMBean(Runnable.class)); assertTrue(isControlServiceMBean(JobMXBean.class)); } }
@Test public void testMyBean() { assertTrue(Controls.isControlServiceMBean(MyBean.class)); assertFalse(Controls.isControlServiceMBean(MyBeanImpl.class)); }