/** * Create an {@code ApplicationService} instance. * @param provider Provider to create topology instances for registered applications. * @param submitter Submitter for registered applications. * @param alias Alias used to register the control MBean. */ public AppService(TopologyProvider provider, DirectSubmitter<Topology, Job> submitter, String alias) { this.provider = provider; this.submitter = submitter; ControlService cs = submitter.getServices().getService(ControlService.class); if (cs != null) cs.registerControl(ApplicationServiceMXBean.TYPE, ALIAS+System.currentTimeMillis(), alias, ApplicationServiceMXBean.class, new AppServiceControl(this)); }
/** * Create an {@code ApplicationService} instance. * @param provider Provider to create topology instances for registered applications. * @param submitter Submitter for registered applications. * @param alias Alias used to register the control MBean. */ public AppService(TopologyProvider provider, DirectSubmitter<Topology, Job> submitter, String alias) { this.provider = provider; this.submitter = submitter; ControlService cs = submitter.getServices().getService(ControlService.class); if (cs != null) cs.registerControl(ApplicationServiceMXBean.TYPE, ALIAS+System.currentTimeMillis(), alias, ApplicationServiceMXBean.class, new AppServiceControl(this)); }
@Override public synchronized void start() { ControlService cs = getOpletContext().getService(ControlService.class); // TODO BUG HERE: the control alias needs to be unique across the // entire provider instance (multiple topologies) because the ControlService // is provider-wide, not topology specific. // Scope it with just the jobId. What's going to unregister this control? if (cs != null) cs.registerControl(TSTREAM_TYPE, getOpletContext().uniquify(getClass().getSimpleName()), getAlias(), PeriodMXBean.class, this); schedule(false); }
@Override public synchronized void start() { ControlService cs = getOpletContext().getService(ControlService.class); // TODO BUG HERE: the control alias needs to be unique across the // entire provider instance (multiple topologies) because the ControlService // is provider-wide, not topology specific. // Scope it with just the jobId. What's going to unregister this control? if (cs != null) cs.registerControl(TSTREAM_TYPE, getOpletContext().uniquify(getClass().getSimpleName()), getAlias(), PeriodMXBean.class, this); schedule(false); }
/** * Register a {@link StreamScopeRegistryMXBean} with the registered * {@link ControlService} (for use by the Edgent Console). */ private void registerRegistryBean(ServiceContainer services) { ControlService cs = services.getService(ControlService.class); if (cs == null || rgy == null) throw new IllegalStateException(); { // more workaround... // // If a rgyBean control is already registered, then don't reregister // (this will/should be the JMXControlService case) so as to avoid // an "already registered" exception from the ControlService. // The rgyBean is gotta be for the matching rgy with this // singleton StreamScopeSetup instance scheme so everything is OK. StreamScopeRegistryMXBean mbean = cs.getControl(StreamScopeRegistryMXBean.TYPE, StreamScopeRegistryMXBean.TYPE, StreamScopeRegistryMXBean.class); if (mbean != null) { return; } } if (rgyBean == null) rgyBean = new StreamScopeRegistryBean(rgy, cs); rgyBeanControlId = cs.registerControl(StreamScopeRegistryMXBean.TYPE, StreamScopeRegistryMXBean.TYPE+"_0", StreamScopeRegistryMXBean.TYPE, StreamScopeRegistryMXBean.class, rgyBean); }
@Override public StreamScopeMXBean lookup(String jobId, String opletId, int oport) { // lazy-register the mbeans String streamId = StreamScopeRegistry.mkStreamId(jobId, opletId, oport); StreamScopeMXBean mbean = cs.getControl(StreamScopeMXBean.TYPE, streamId, StreamScopeMXBean.class); if (mbean == null) { String name = StreamScopeRegistry.nameForStreamId(streamId); StreamScope<?> ss = rgy.lookup(name); if (ss != null) { mbean = new StreamScopeBean(ss); String controlId = cs.registerControl(StreamScopeMXBean.TYPE, StreamScopeMXBean.TYPE+streamId, streamId, StreamScopeMXBean.class, mbean); controlIdMap.put(name, controlId); } } return mbean; }
@Test(expected=RuntimeException.class) public void testDoubleRegister() throws Exception { ControlService cs = new JMXControlService(DOMAIN, new Hashtable<>()); String type = "timer"; String id = "a"; String alias = "ControlA"; String controlId = cs.registerControl(type, id, alias, TimerMBean.class, new Timer()); try { cs.registerControl(type, id, alias, TimerMBean.class, new Timer()); } finally { cs.unregister(controlId); } } @Test(expected=RuntimeException.class)
@Test(expected=RuntimeException.class) public void testDoubleunregister() throws Exception { ControlService cs = new JMXControlService(DOMAIN, new Hashtable<>()); String type = "timer"; String id = "a"; String alias = "ControlA"; String controlId = cs.registerControl(type, id, alias, TimerMBean.class, new Timer()); cs.unregister(controlId); cs.unregister(controlId); } }
private void registerControl(ControlService cs) { if (cs == null) throw new IllegalArgumentException("ControlService must not be null"); logger.trace("Registering control for job id {}, job name {}", job.getId(), job.getName()); this.controlService = cs; JobMXBean oldControl = cs.getControl(JobMXBean.TYPE, job.getName(), JobMXBean.class); if (oldControl != null) { String oldControlId = cs.getControlId(JobMXBean.TYPE, job.getName(), JobMXBean.class); if (oldControlId != null) { if (isJobClosed(oldControl)) { cs.unregister(oldControlId); logger.debug("Old control id {} for CLOSED job name {} was unregistered", oldControlId, job.getName()); } else { throw new IllegalStateException( "Cannot register job control for alias " + job.getName() + " because a job control with id " + oldControlId + " for the same alias already exists and is not CLOSED"); } } } this.controlId = cs.registerControl(JobMXBean.TYPE, job.getId(), job.getName(), JobMXBean.class, this); logger.debug("Control for job id {}, job name {} was registered with id {}", job.getId(), job.getName(), controlId); }
private void registerControl(ControlService cs) { if (cs == null) throw new IllegalArgumentException("ControlService must not be null"); logger.trace("Registering control for job id {}, job name {}", job.getId(), job.getName()); this.controlService = cs; JobMXBean oldControl = cs.getControl(JobMXBean.TYPE, job.getName(), JobMXBean.class); if (oldControl != null) { String oldControlId = cs.getControlId(JobMXBean.TYPE, job.getName(), JobMXBean.class); if (oldControlId != null) { if (isJobClosed(oldControl)) { cs.unregister(oldControlId); logger.debug("Old control id {} for CLOSED job name {} was unregistered", oldControlId, job.getName()); } else { throw new IllegalStateException( "Cannot register job control for alias " + job.getName() + " because a job control with id " + oldControlId + " for the same alias already exists and is not CLOSED"); } } } this.controlId = cs.registerControl(JobMXBean.TYPE, job.getId(), job.getName(), JobMXBean.class, this); logger.debug("Control for job id {}, job name {} was registered with id {}", job.getId(), job.getName(), controlId); }
@Test public void testControlObject() throws Exception { ControlService cs = new JMXControlService(DOMAIN, new Hashtable<>()); String type = "timer"; String id = "a"; String alias = "ControlA"; String controlId = cs.registerControl(type, id, alias, TimerMBean.class, new Timer()); assertNotNull(controlId); ObjectName on = ObjectName.getInstance(controlId); assertEquals(DOMAIN, on.getDomain()); assertEquals(type, ObjectName.unquote(on.getKeyProperty("type"))); assertEquals(id, ObjectName.unquote(on.getKeyProperty("id"))); assertEquals(alias, ObjectName.unquote(on.getKeyProperty("alias"))); assertEquals(TimerMBean.class.getName(), ObjectName.unquote(on.getKeyProperty("interface"))); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); assertTrue(mbs.isRegistered(on)); cs.unregister(controlId); assertFalse(mbs.isRegistered(on)); }
String id = "a"; String alias = "ControlA"; String controlId = cs.registerControl(type, id, alias, TimerMBean.class, new Timer());