/** * Initializes the timer for sending refresh notifications. */ static void createRefreshTimer() { try { refreshTimer = new javax.management.timer.Timer(); mbeanServer.registerMBean(refreshTimer, refreshTimerObjectName); refreshTimer.start(); } catch (JMException e) { logStackTrace(Level.WARN, e, "Failed to create/register/start refresh timer."); } catch (JMRuntimeException e) { logStackTrace(Level.WARN, e, "Failed to create/register/start refresh timer."); } catch (Exception e) { logStackTrace(Level.WARN, e, "Failed to create/register/start refresh timer."); } }
private synchronized void manageTimer() { if (!timer.isActive()) { if ((perfTimerStarted && perfTimerListeners > 0) || (structuralTimerStarted && structuralTimerListeners > 0)) timer.start(); } else { if ((!perfTimerStarted || perfTimerListeners == 0) && (!structuralTimerStarted || structuralTimerListeners == 0)) timer.stop(); } }
private void registerTargetCheckTimer() { try { mTargetCheckTimer = new Timer(); mTargetCheckTimerObjectName = new ObjectName(EventManagementConstants.EVENT_MANAGEMENT_TARGET_CHECK_TIMER_MBEAN_NAME); ((MBeanServer) mMBeanServer).registerMBean(mTargetCheckTimer, mTargetCheckTimerObjectName); hookUpToTimerService(mTargetCheckInterval); mTargetCheckTimer.start(); } catch (Exception e) { String bundleKey = "caps.management.server.alert.instance.check.timer.setup.error.log.msg"; String message = AlertUtil.constructLogMessage(bundleKey); mLogger.log(Level.WARNING, message, e); } }
public synchronized void startUpdates() { if (!timerStarted) { timer.addNotification("tickTimer", null, null, new Date(System.currentTimeMillis()), timerPeriod); this.timerStarted = true; timer.start(); } }
public synchronized void stopUpdates() { if (timerStarted) { try { timer.removeNotifications("tickTimer"); this.timerStarted = false; } catch (InstanceNotFoundException ex) { } timer.stop(); } }
public void unregisterMBean() { try { if (registered) { LOG.info("Unregistering MBean {}", name); ManagementFactory.getPlatformMBeanServer().unregisterMBean(new ObjectName(name)); timer.stop(); } this.registered = false; } catch (Exception e) { LOG.warn("Exception:", e); } }
private void killTimerOnExit() { timer.addNotification("isLastThreadTest", null, null, new Date(System.currentTimeMillis()), 1500); timer.addNotificationListener(new NotificationListener() { @Override public void handleNotification(Notification notification, Object handback) {
public synchronized void addPerfNotificationListener(NotificationListener listener, Object handback) { timer.addNotificationListener(listener, new NotificationFilter() { @Override public boolean isNotificationEnabled(Notification notification) { return "perfTimer".equals(notification.getType()); } }, handback); perfTimerListeners++; manageTimer(); }
/** * @see javax.management.timer.Timer#start() */ public void start() { this.reset(); super.start(); }
@Override public synchronized void startPerformanceUpdates() { if (!perfTimerStarted) { timer.addNotification("perfTimer", null, null, new Date(System.currentTimeMillis()), perfTimerPeriod); this.perfTimerStarted = true; } manageTimer(); }
@Override public synchronized void stopStructuralUpdates() { if (structuralTimerStarted) { try { timer.removeNotifications("structTimer"); this.structuralTimerStarted = false; } catch (InstanceNotFoundException ex) { } } manageTimer(); }
public synchronized void removePerfNotificationListener(NotificationListener listener) { try { timer.removeNotificationListener(listener); perfTimerListeners--; manageTimer(); } catch (ListenerNotFoundException ex) { ex.printStackTrace(); } }
private void registerPolicyExecutionTimer() { try { mTimer = new Timer(); mTimerObjectName = new ObjectName(EventManagementConstants.EVENT_MANAGEMENT_REMOVAL_POLICY_TIMER_MBEAN_NAME); if(mPlatformContext.isAdminServer() && ((MBeanServer) mMBeanServer).isRegistered(mTimerObjectName)) { return; // registered by the controller mbean } ((MBeanServer) mMBeanServer).registerMBean(mTimer, mTimerObjectName); hookUpToTimerService(mAlertPersistenceConfiguration.getPersistenceAlertPolicyExecInterval()); if(mAlertPersistenceConfiguration.getPersistedAlertRemovalPolicyExecEnabled()) { // add notification interval prior to starting isTimerRunning = true; mTimer.start(); } } catch (Exception e) { String bundleKey = "caps.management.server.alert.persistence.removal.policy.setup.error.log.msg"; String message = AlertUtil.constructLogMessage(bundleKey); mLogger.log(Level.WARNING, message, e); } }
@Override public void handleNotification(Notification notification, Object handback) { final ThreadMXBean mbean = ManagementFactory.getThreadMXBean(); int tCount = mbean.getThreadCount(); int dCount = mbean.getDaemonThreadCount(); if (tCount - dCount <= 2) { boolean stop = true; Thread[] ts; for (;;) { ts = new Thread[mbean.getThreadCount() + 3]; if (Thread.enumerate(ts) < ts.length) break; } for (Thread t : ts) { if(t == null) break; if (t.isDaemon() || t == Thread.currentThread()) continue; if (!t.getName().equals("DestroyJavaVM")) stop = false; } if (stop) timer.stop(); } } }, new NotificationFilter() {
public synchronized void addStructuralNotificationListener(NotificationListener listener, Object handback) { timer.addNotificationListener(listener, new NotificationFilter() { @Override public boolean isNotificationEnabled(Notification notification) { return "structTimer".equals(notification.getType()); } }, handback); structuralTimerListeners++; manageTimer(); }
@Override public synchronized void startStructuralUpdates() { if (!structuralTimerStarted) { timer.addNotification("structTimer", null, null, new Date(System.currentTimeMillis()), structuralTimerPeriod); this.structuralTimerStarted = true; } manageTimer(); }
@Override public synchronized void stopPerformanceUpdates() { if (perfTimerStarted) { try { timer.removeNotifications("perfTimer"); this.perfTimerStarted = false; } catch (InstanceNotFoundException ex) { } } manageTimer(); }
public synchronized void removeStructuralNotificationListener(NotificationListener listener) { try { timer.removeNotificationListener(listener); structuralTimerListeners--; manageTimer(); } catch (ListenerNotFoundException ex) { ex.printStackTrace(); } } }