本文整理汇总了Java中com.sun.jmx.examples.scandir.ScanManagerMXBean.ScanState.CLOSED属性的典型用法代码示例。如果您正苦于以下问题:Java ScanState.CLOSED属性的具体用法?Java ScanState.CLOSED怎么用?Java ScanState.CLOSED使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.sun.jmx.examples.scandir.ScanManagerMXBean.ScanState
的用法示例。
在下文中一共展示了ScanState.CLOSED属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: waitForClose
/**
* Wait for someone to call 'close()' on the ScanManagerMXBean singleton.
* Every time its state changes, the ScanManagerMXBean emits a notification.
* We don't rely on the notification content (if we were using a remote
* connection, we could miss some notifications) - we simply use the
* state change notifications to react more quickly to state changes.
* We do so simply by polling the {@link BlockingQueue} in which our
* listener is pushing notifications, and checking the ScanManagerMXBean
* state every time that a notification is received.
* <p>
* We can do so because we know that once the ScanManagerMXBean state is
* switched to 'CLOSED', it will remain 'CLOSED' whatsoever. <br>
* Therefore we don't need to concern ourselves with the possibility of
* missing the window in which the ScanManagerMXBean state's will be
* CLOSED, because that particular window stays opened forever.
* <p>
* Had we wanted to wait for 'RUNNING', we would have needed to apply
* a different strategy - e.g. by taking into account the actual content
* of the state changed notifications we received.
* @throws java.io.IOException wait failed - a communication problem occurred.
* @throws javax.management.JMException wait failed - the MBeanServer threw an exception.
*/
public void waitForClose() throws IOException, JMException {
// Wait until state is closed
while(proxy.getState() != ScanState.CLOSED ) {
try {
// Wake up at least every 30 seconds - if we missed a
// notification - we will at least get a chance to
// call getState(). 30 seconds is obviously quite
// arbitrary - if this were a real daemon - id'be tempted
// to wait 30 minutes - knowing that any incoming
// notification will wake me up anyway.
// Note: we simply use the state change notifications to
// react more quickly to state changes: see javadoc above.
//
queue.poll(30,TimeUnit.SECONDS);
} catch (InterruptedException ex) {
// OK
}
}
}