Example usage for javax.management Notification Notification

List of usage examples for javax.management Notification Notification

Introduction

In this page you can find the example usage for javax.management Notification Notification.

Prototype

public Notification(String type, Object source, long sequenceNumber, long timeStamp, String message) 

Source Link

Document

Creates a Notification object.

Usage

From source file:com.heliosapm.script.AbstractDeployedScript.java

/**
 * Adds a new notification type for this deployment
 * @param infos The notification infos to add
 *///from ww  w .j av a  2 s .c o  m
protected void registerNotifications(final MBeanNotificationInfo... infos) {
    if (infos == null || infos.length == 0)
        return;
    if (instanceNotificationInfos.isEmpty()) {
        Collections.addAll(instanceNotificationInfos, notificationInfos);
    }
    int added = 0;
    for (MBeanNotificationInfo info : infos) {
        if (info == null)
            continue;
        if (instanceNotificationInfos.add(info)) {
            added++;
        }
    }
    if (added > 0) {
        final Notification notif = new Notification(JMXHelper.MBEAN_INFO_CHANGED, objectName,
                sequence.incrementAndGet(), System.currentTimeMillis(), "Updated MBeanInfo");
        notif.setUserData(JMXHelper.getMBeanInfo(objectName));
        sendNotification(notif);
    }
}

From source file:org.apache.geode.management.internal.beans.ManagementAdapter.java

/**
 * Handles LockService Creation/*from w  w w. j  a v a2  s .  com*/
 * 
 * @param lockService
 */
public void handleLockServiceCreation(DLockService lockService) throws ManagementException {
    if (!isServiceInitialised("handleLockServiceCreation")) {
        return;
    }
    // Internal Locks Should not be exposed to client for monitoring
    if (internalLocks.contains(lockService.getName())) {
        return;
    }
    LockServiceMBeanBridge bridge = new LockServiceMBeanBridge(lockService);
    LockServiceMXBean lockServiceMBean = new LockServiceMBean(bridge);

    ObjectName lockServiceMBeanName = MBeanJMXAdapter.getLockServiceMBeanName(
            internalCache.getDistributedSystem().getDistributedMember(), lockService.getName());

    ObjectName changedMBeanName = service.registerInternalMBean(lockServiceMBean, lockServiceMBeanName);

    service.federate(changedMBeanName, LockServiceMXBean.class, true);

    Notification notification = new Notification(JMXNotificationType.LOCK_SERVICE_CREATED, memberSource,
            SequenceNumber.next(), System.currentTimeMillis(),
            ManagementConstants.LOCK_SERVICE_CREATED_PREFIX + lockService.getName());
    memberLevelNotifEmitter.sendNotification(notification);

    memberMBeanBridge.addLockServiceStats(lockService);
}

From source file:org.helios.jzab.agent.net.active.ActiveHost.java

/**
 * Upserts the active checks for this host
 * @param activeChecks An array of json formatted active checks
 * @return An array of ints representing the counts of: <ol>
 *    <li>The number of checks added<li>
 *  <li>The number of checks updated<li>
 *  <li>The number of checks with no change<li>
 *  <li>The number of checks deleted<li>
 * </ol>//from  w  w  w  .  ja v  a 2s.co m
 * 
 */
public synchronized int[] upsertActiveChecks(JSONArray activeChecks) {
    final long start = SystemClock.currentTimeMillis();
    markAllChecks(true);
    int adds = 0, updates = 0, nochanges = 0;
    try {
        for (int i = 0; i < activeChecks.length(); i++) {
            JSONObject activeCheck = activeChecks.getJSONObject(i);
            String key = activeCheck.getString(CHECK_ITEM_KEY);
            long mtime = activeCheck.getLong(CHECK_MTIME);
            long delay = activeCheck.getLong(CHECK_DELAY);
            ActiveHostCheck ahc = hostChecks.get(key);
            if (ahc == null) {
                // new ActiveHostCheck
                try {
                    ahc = new ActiveHostCheck(hostName, key, delay, mtime);
                    if (ahc.isDiscovery()) {
                        hostDiscoveryChecks.put(key, ahc);
                    } else {
                        hostChecks.put(key, ahc);
                    }

                    log.trace("New ActiveHostCheck [{}]", ahc);
                    sendNotification(new Notification("host.activecheck.added", objectName,
                            notificationSequence.incrementAndGet(), this.stateTimestamp,
                            String.format("Removed Active Check [%s]", ahc.itemKey)));
                    adds++;
                } catch (Exception e) {
                    log.error("Failed to create active host check for host/key [{}]: [{}]",
                            hostName + "/" + key, e.getMessage());
                    //log.debug("Failed to create active host check for host/key [{}]", hostName + "/" + key, e);
                }
            } else {
                if (ahc.update(delay, mtime)) {
                    // updated ActiveHostCheck
                    log.debug("Updated ActiveHostCheck [{}]", ahc);
                    sendNotification(new Notification("host.activecheck.updated", objectName,
                            notificationSequence.incrementAndGet(), this.stateTimestamp,
                            String.format("Removed Active Check [%s]", ahc.itemKey)));
                    updates++;
                } else {
                    // no change ActiveHostCheck
                    nochanges++;
                }
                ahc.marked = false;
            }
        }
        int checksRemoved = clearMarkedChecks();
        log.info("Removed [{}] Active Host Checks", checksRemoved);
        setState(ActiveHostState.ACTIVE);
        long elapsed = SystemClock.currentTimeMillis() - start;
        lastRefreshChange.update(elapsed, checksRemoved, adds, updates, nochanges);
        return new int[] { adds, updates, nochanges, checksRemoved };
    } catch (Exception e) {
        log.error("Failed to upsert Active Host Checks [{}]", e.getMessage());
        log.debug("Failed to upsert Active Host Checks for JSON [{}]", activeChecks, e);
        return null;
    } finally {
        scheduleNextRefresh();
    }
}

From source file:org.apache.geode.management.internal.beans.ManagementAdapter.java

/**
 * Handles GatewaySender creation//from  ww  w.ja va2s  .c  o m
 * 
 * @param sender the specific gateway sender
 * @throws ManagementException
 */
public void handleGatewaySenderCreation(GatewaySender sender) throws ManagementException {
    if (!isServiceInitialised("handleGatewaySenderCreation")) {
        return;
    }
    GatewaySenderMBeanBridge bridge = new GatewaySenderMBeanBridge(sender);

    GatewaySenderMXBean senderMBean = new GatewaySenderMBean(bridge);
    ObjectName senderObjectName = MBeanJMXAdapter.getGatewaySenderMBeanName(
            internalCache.getDistributedSystem().getDistributedMember(), sender.getId());

    ObjectName changedMBeanName = service.registerInternalMBean(senderMBean, senderObjectName);

    service.federate(changedMBeanName, GatewaySenderMXBean.class, true);

    Notification notification = new Notification(JMXNotificationType.GATEWAY_SENDER_CREATED, memberSource,
            SequenceNumber.next(), System.currentTimeMillis(),
            ManagementConstants.GATEWAY_SENDER_CREATED_PREFIX);
    memberLevelNotifEmitter.sendNotification(notification);
}

From source file:org.apache.qpid.server.jmx.mbeans.QueueMBean.java

@Override
public void notifyClients(NotificationCheck notification, Queue queue, String notificationMsg) {
    notificationMsg = notification.name() + " " + notificationMsg;

    Notification note = new Notification(MonitorNotification.THRESHOLD_VALUE_EXCEEDED, this,
            incrementAndGetSequenceNumber(), System.currentTimeMillis(), notificationMsg);

    getBroadcaster().sendNotification(note);
}

From source file:org.apache.geode.management.internal.beans.ManagementAdapter.java

private void createGatewayReceiverMBean(GatewayReceiver recv) {
    GatewayReceiverMBeanBridge bridge = new GatewayReceiverMBeanBridge(recv);

    GatewayReceiverMXBean receiverMBean = new GatewayReceiverMBean(bridge);
    ObjectName recvObjectName = MBeanJMXAdapter
            .getGatewayReceiverMBeanName(internalCache.getDistributedSystem().getDistributedMember());

    ObjectName changedMBeanName = service.registerInternalMBean(receiverMBean, recvObjectName);

    service.federate(changedMBeanName, GatewayReceiverMXBean.class, true);

    Notification notification = new Notification(JMXNotificationType.GATEWAY_RECEIVER_CREATED, memberSource,
            SequenceNumber.next(), System.currentTimeMillis(),
            ManagementConstants.GATEWAY_RECEIVER_CREATED_PREFIX);
    memberLevelNotifEmitter.sendNotification(notification);
}

From source file:org.apache.geode.management.internal.beans.ManagementAdapter.java

/**
 * Handles Gateway receiver creation/*from  w w  w  . ja v a  2s.c o m*/
 * 
 * @param recv specific gateway receiver
 * @throws ManagementException
 */
public void handleGatewayReceiverStart(GatewayReceiver recv) throws ManagementException {
    if (!isServiceInitialised("handleGatewayReceiverStart")) {
        return;
    }

    if (!recv.isManualStart()) {
        createGatewayReceiverMBean(recv);
    }

    GatewayReceiverMBean mbean = (GatewayReceiverMBean) service.getLocalGatewayReceiverMXBean();
    GatewayReceiverMBeanBridge bridge = mbean.getBridge();

    bridge.startServer();

    Notification notification = new Notification(JMXNotificationType.GATEWAY_RECEIVER_STARTED, memberSource,
            SequenceNumber.next(), System.currentTimeMillis(),
            ManagementConstants.GATEWAY_RECEIVER_STARTED_PREFIX);
    memberLevelNotifEmitter.sendNotification(notification);
}

From source file:org.helios.jzab.agent.net.active.ActiveHost.java

/**
 * Removes all marked active host checks
 * @return The number of active host checks removed
 *//*from   w ww. j  a  va2  s. c  o m*/
protected int clearMarkedChecks() {
    Set<ActiveHostCheck> checksToRemove = new HashSet<ActiveHostCheck>();
    for (ActiveHostCheck ac : hostChecks.values()) {
        if (ac.marked) {
            checksToRemove.add(ac);
        }
    }
    for (ActiveHostCheck ac : checksToRemove) {
        hostChecks.remove(ac.itemKey);
        scheduleBucket.removeItem(ac.delay, ac);
        if (log.isDebugEnabled())
            removedCheckNames.add(ac.itemKey);
        sendNotification(
                new Notification("host.activecheck.removed", objectName, notificationSequence.incrementAndGet(),
                        this.stateTimestamp, String.format("Removed Active Check [%s]", ac.itemKey)));
    }
    return checksToRemove.size();
}

From source file:org.apache.geode.management.internal.beans.ManagementAdapter.java

/**
 * Handles Gateway receiver creation//ww w  .  j a v a  2s.c o m
 * 
 * @param recv specific gateway receiver
 * @throws ManagementException
 */
public void handleGatewayReceiverStop(GatewayReceiver recv) throws ManagementException {
    if (!isServiceInitialised("handleGatewayReceiverStop")) {
        return;
    }
    GatewayReceiverMBean mbean = (GatewayReceiverMBean) service.getLocalGatewayReceiverMXBean();
    GatewayReceiverMBeanBridge bridge = mbean.getBridge();

    bridge.stopServer();

    Notification notification = new Notification(JMXNotificationType.GATEWAY_RECEIVER_STOPPED, memberSource,
            SequenceNumber.next(), System.currentTimeMillis(),
            ManagementConstants.GATEWAY_RECEIVER_STOPPED_PREFIX);
    memberLevelNotifEmitter.sendNotification(notification);
}

From source file:org.apache.geode.management.internal.beans.ManagementAdapter.java

public void handleAsyncEventQueueCreation(AsyncEventQueue queue) throws ManagementException {
    if (!isServiceInitialised("handleAsyncEventQueueCreation")) {
        return;//from   www  .  j a va 2s  . co m
    }
    AsyncEventQueueMBeanBridge bridge = new AsyncEventQueueMBeanBridge(queue);
    AsyncEventQueueMXBean queueMBean = new AsyncEventQueueMBean(bridge);
    ObjectName senderObjectName = MBeanJMXAdapter.getAsyncEventQueueMBeanName(
            internalCache.getDistributedSystem().getDistributedMember(), queue.getId());

    ObjectName changedMBeanName = service.registerInternalMBean(queueMBean, senderObjectName);

    service.federate(changedMBeanName, AsyncEventQueueMXBean.class, true);

    Notification notification = new Notification(JMXNotificationType.ASYNC_EVENT_QUEUE_CREATED, memberSource,
            SequenceNumber.next(), System.currentTimeMillis(),
            ManagementConstants.ASYNC_EVENT_QUEUE_CREATED_PREFIX);
    memberLevelNotifEmitter.sendNotification(notification);
}