private static void runOrEnqueueCommand(ManagementCommand command) { if (commandQueue == null) command.run(); else { // Try to enqueue the command unless the queue is full. // Recover from a full queue by running already queued commands first to protect the async. implementation // from being vulnerable to DOS attacks. while (!commandQueue.offer(command)) normalizeAndRunQueuedCommands(); } }
private static void runOrEnqueueCommand(ManagementCommand command) { if (commandQueue == null) command.run(); else { // Try to enqueue the command unless the queue is full. // Recover from a full queue by running already queued commands first to protect the async. implementation // from being vulnerable to DOS attacks. while (!commandQueue.offer(command)) normalizeAndRunQueuedCommands(); } }
@Override public void run() { while (!isInterrupted()) { try { normalizeAndRunQueuedCommands(); sleep(250); // sampling interval } catch (InterruptedException ex) { return; } catch (Exception ex) { log.error("an unexpected error occurred in JMX asynchronous registration code", ex); } } } }.start();
@Override public void run() { while (!isInterrupted()) { try { normalizeAndRunQueuedCommands(); sleep(250); // sampling interval } catch (InterruptedException ex) { return; } catch (Exception ex) { log.error("an unexpected error occurred in JMX asynchronous registration code", ex); } } } }.start();
@After public void tearDown() throws Exception { ManagementRegistrar.unregister(objectName); ManagementRegistrar.normalizeAndRunQueuedCommands(); }
@After public void tearDown() throws Exception { ManagementRegistrar.unregister(objectName); ManagementRegistrar.normalizeAndRunQueuedCommands(); }
@Test public void testCanRegister() throws Exception { final int iterations = 100000; final List<TestBean> beans = new ArrayList<TestBean>(iterations); for (int i = 0; i < iterations; i++) { if (i > 0) ManagementRegistrar.unregister(objectName); TestBean testBean = new TestBean("#" + i); beans.add(testBean); // holding a hard reference to ensure the instances are not GCed. ManagementRegistrar.register(objectName, testBean); } ManagementRegistrar.normalizeAndRunQueuedCommands(); assertEquals(beans.get(beans.size() - 1).getName(), mBeanServer.getAttribute(new ObjectName(objectName), "Name")); }
@Test(expected = InstanceNotFoundException.class) public void testCanUnregister() throws Exception { TestBean testBean = new TestBean("1"); ManagementRegistrar.register(objectName, testBean); ManagementRegistrar.unregister(objectName); ManagementRegistrar.normalizeAndRunQueuedCommands(); mBeanServer.getAttribute(new ObjectName(objectName), "Name"); } }
@Test public void testCanRegister() throws Exception { final int iterations = 100000; final List<TestBean> beans = new ArrayList<TestBean>(iterations); for (int i = 0; i < iterations; i++) { if (i > 0) ManagementRegistrar.unregister(objectName); TestBean testBean = new TestBean("#" + i); beans.add(testBean); // holding a hard reference to ensure the instances are not GCed. ManagementRegistrar.register(objectName, testBean); } ManagementRegistrar.normalizeAndRunQueuedCommands(); assertEquals(beans.get(beans.size() - 1).getName(), mBeanServer.getAttribute(new ObjectName(objectName), "Name")); }
@Test(expected = InstanceNotFoundException.class) public void testCanUnregister() throws Exception { TestBean testBean = new TestBean("1"); ManagementRegistrar.register(objectName, testBean); ManagementRegistrar.unregister(objectName); ManagementRegistrar.normalizeAndRunQueuedCommands(); mBeanServer.getAttribute(new ObjectName(objectName), "Name"); } }