Example usage for javax.management Notification getMessage

List of usage examples for javax.management Notification getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Get the notification message.

Usage

From source file:org.webcurator.core.harvester.agent.HarvesterListener.java

/** @see javax.management.NotificationListener#handleNotification(javax.management.Notification, java.lang.Object) */
public void handleNotification(Notification notification, Object handback) {
    String message = notification.getMessage();
    log.info("Notification {} recieved from {}", message, handback);

    ApplicationContext context = ApplicationContextFactory.getWebApplicationContext();
    HarvestAgent agent = (HarvestAgent) context.getBean(Constants.BEAN_HARVEST_AGENT);
    // When the agent moves into the running state grab the settings we need at
    // Job completion as some of these may no longer be available when the job is finished.
    if (message.equals(CrawlJob.STATUS_RUNNING)) {
        agent.loadSettings((String) handback);
    }//from w w w  .  java  2  s . co  m

    // Send a heartbeat with the current status to the core.
    try {
        HarvestCoordinatorNotifier notifier = (HarvestCoordinatorNotifier) context
                .getBean(Constants.BEAN_NOTIFIER);
        notifier.heartbeat(agent.getStatus());
    } catch (Exception e) {
        log.warn("Failed to send heartbeat on notification " + e.getMessage(), e);
    }

    // Schedule the job completion process to be run.
    if (message.equals(CrawlJob.STATUS_FINISHED_ABNORMAL) || message.equals(CrawlJob.STATUS_MISCONFIGURED)
            || message.startsWith(CrawlJob.STATUS_FINISHED)) {

        try {
            SchedulerUtil.scheduleHarvestCompleteJob((String) handback);
        } catch (Exception e) {
            throw new HarvestAgentException("Failed to start harvest complete job : " + e.getMessage(), e);
        }

        log.info("Running Harvest Complete Job {}", handback);
    }
}

From source file:de.iew.spring.integration.SpringIntegrationJmxTest.java

@Test
public void testJmxSpringIntegration() throws Exception {
    // Testfix erstellen

    // Test durchfhren
    Map<String, Object> headers = new Hashtable<String, Object>();
    GenericMessage<String> message = new GenericMessage<String>("Foo Bar", headers);
    this.messageChannel.send(message);

    // Test auswerten
    /// Etwas warten, bis die Notifications verschickt wurden
    Thread.sleep(3000);/*from  w  ww . ja  va2s .  c  om*/

    Assert.assertEquals(1, this.springIntegrationTestNotificationListener.getNotifications().size());

    Notification notification = this.springIntegrationTestNotificationListener.getNotifications().get(0);

    Assert.assertEquals(String.class.getName(), notification.getType());
    Assert.assertEquals("Foo Bar", notification.getMessage());
}

From source file:de.iew.spring.integration.SpringIntegrationJmxTest.java

@Test
public void testJmxSpringIntegrationWithAuditEventMessage() throws Exception {
    // Testfix erstellen
    long timestamp = System.currentTimeMillis();

    Authentication authentication = newAnonymousAuthentication();

    AuditEventMessage auditEventMessage = new AuditEventMessage();
    auditEventMessage.setTimestamp(new Date(timestamp));
    auditEventMessage.setPrincipal(authentication.getName());
    auditEventMessage.setSeverity(Severity.INFO);
    auditEventMessage.setMessage("Foo Bar");

    // Test durchfhren
    Map<String, Object> headers = new Hashtable<String, Object>();
    GenericMessage<AuditEventMessage> message = new GenericMessage<AuditEventMessage>(auditEventMessage,
            headers);//from ww  w  .  j  av  a 2  s .c o  m
    this.messageChannel.send(message);

    // Test auswerten
    /// Etwas warten, bis die Notifications verschickt wurden
    Thread.sleep(3000);

    Assert.assertEquals(1, this.springIntegrationTestNotificationListener.getNotifications().size());

    Notification notification = this.springIntegrationTestNotificationListener.getNotifications().get(0);

    Assert.assertEquals(AuditEventMessage.class.getName(), notification.getType());
    Assert.assertNull(notification.getMessage());

    AuditEventMessage userData = (AuditEventMessage) notification.getUserData();
    Assert.assertEquals("Foo Bar", userData.getMessage());
    Assert.assertEquals(Severity.INFO, userData.getSeverity());
    Assert.assertEquals(new Date(timestamp), userData.getTimestamp());
}

From source file:org.wso2.carbon.registry.subscription.test.util.JMXClient.java

public void handleNotification(Notification ntfyObj, Object handback) {
    log.info("***************************************************");
    log.info("* Notification received at " + new Date().toString());
    log.info("* type      = " + ntfyObj.getType());
    log.info("* message   = " + ntfyObj.getMessage());

    if (ntfyObj.getMessage().contains(path)) {
        setSuccess(true);// w  w w  .j av a  2 s  .co m
    }

    log.info("* seqNum    = " + ntfyObj.getSequenceNumber());
    log.info("* source    = " + ntfyObj.getSource());
    log.info("* seqNum    = " + Long.toString(ntfyObj.getSequenceNumber()));
    log.info("* timeStamp = " + new Date(ntfyObj.getTimeStamp()));
    log.info("* userData  = " + ntfyObj.getUserData());
    log.info("***************************************************");
}

From source file:com.vmware.springsource.hyperic.plugin.gemfire.AlertsPlugin.java

public void handleNotification(Notification notification, Object handback) {
    if (log.isDebugEnabled()) {
        log.debug("[handleNotification] notification.getType() => " + notification.getType());
    }// ww  w .  ja v a 2  s  .c  o m
    if ("gemfire.distributedsystem.alert".equals(notification.getType())) {
        if (log.isDebugEnabled()) {
            log.debug("[handleNotification] notification.getMessage() => " + notification.getMessage().trim());
        }
        Matcher m = msgPatt.matcher(notification.getMessage().trim());
        if (m.find()) {
            try {
                String level = m.group(1);
                Date date = dateFormat.parse(m.group(2));
                String menberID = m.group(4);
                String msg = m.group(5);
                reportEvent(date.getTime(), LOGLEVEL_ERROR, menberID, msg);
            } catch (Exception ex) {
                log.debug("[handleNotification] BAD FORMAT!!!! " + ex.getMessage(), ex);
            }
        } else {
            log.debug("[handleNotification] BAD FORMAT!!!!");
        }
    }
}

From source file:org.red5.server.jmx.JMXAgent.java

public void handleNotification(Notification notification, Object handback) {
    log.debug("handleNotification " + notification.getMessage());
}

From source file:org.hyperic.hq.product.jmx.MxNotificationListener.java

public synchronized void handleNotification(Notification notification, Object handback) {

    String msg;//from  ww w  .j  ava 2 s  .c om
    boolean isAttrChange = notification instanceof AttributeChangeNotification;

    if (log.isDebugEnabled()) {
        log.debug(this.plugin.getName() + " received notification: " + notification);
    }

    if (isAttrChange && this.isConfigTrackEnabled) {
        AttributeChangeNotification change = (AttributeChangeNotification) notification;

        msg = "Attribute: " + change.getAttributeName() + " changed from " + change.getOldValue() + " to "
                + change.getNewValue();
    } else if (this.isLogTrackEnabled) {
        msg = notification.getMessage();
    } else {
        return;
    }

    if (msg == null) {
        Object data = notification.getUserData();
        if (data != null) {
            msg = data.toString();
        } else {
            msg = notification.getType();
        }
    }

    long time = notification.getTimeStamp();

    // Default level to INFO
    int level = LogTrackPlugin.LOGLEVEL_INFO;

    // Check notification.getType() for Error, Warn, Info, Debug (case insensitive)
    String typeString = notification.getType();
    if (typeString != null) {
        if (typeString.equalsIgnoreCase(LogTrackPlugin.LOGLEVEL_ERROR_LABEL)) {
            level = LogTrackPlugin.LOGLEVEL_ERROR;
        } else if (typeString.equalsIgnoreCase(LogTrackPlugin.LOGLEVEL_WARN_LABEL)) {
            level = LogTrackPlugin.LOGLEVEL_WARN;
        } else if (typeString.equalsIgnoreCase(LogTrackPlugin.LOGLEVEL_DEBUG_LABEL)) {
            level = LogTrackPlugin.LOGLEVEL_DEBUG;
        }
    }

    String source = notification.getSource().toString();

    if (isAttrChange) {
        TrackEvent event = new TrackEvent(this.plugin.getName(), time, level, source, msg);
        this.plugin.getManager().reportEvent(event);
    } else {
        //apply filters to msg
        this.plugin.reportEvent(time, level, source, msg);
    }
}

From source file:org.apache.qpid.systest.management.jmx.QueueManagementTest.java

/**
 * Tests the ability to receive queue alerts as JMX notifications.
 *
 * @see NotificationCheckTest/*from www.j a va  2s . co  m*/
 * @see SimpleAMQQueueTest#testNotificationFiredAsync()
 * @see SimpleAMQQueueTest#testNotificationFiredOnEnqueue()
 */
public void testQueueNotification() throws Exception {
    final String queueName = getName();
    final long maximumMessageCount = 3;

    Queue queue = _session.createQueue(queueName);
    createQueueOnBroker(queue);

    ManagedQueue managedQueue = _jmxUtils.getManagedQueue(queueName);
    managedQueue.setMaximumMessageCount(maximumMessageCount);

    RecordingNotificationListener listener = new RecordingNotificationListener(1);

    _jmxUtils.addNotificationListener(_jmxUtils.getQueueObjectName(VIRTUAL_HOST, queueName), listener, null,
            null);

    // Send two messages - this should *not* trigger the notification
    sendMessage(_session, queue, 2);

    assertEquals("Premature notification received", 0, listener.getNumberOfNotificationsReceived());

    // A further message should trigger the message count alert
    sendMessage(_session, queue, 1);

    listener.awaitExpectedNotifications(5, TimeUnit.SECONDS);

    assertEquals("Unexpected number of JMX notifications received", 1,
            listener.getNumberOfNotificationsReceived());

    Notification notification = listener.getLastNotification();
    assertEquals("Unexpected notification message",
            "MESSAGE_COUNT_ALERT 3: Maximum count on queue threshold (3) breached.", notification.getMessage());
}

From source file:com.spotify.reaper.cassandra.JmxProxy.java

/**
 * Handles notifications from the old repair API (forceRepairAsync)
 *//*  www.  j  av  a2  s  . co  m*/
private void processOldApiNotification(Notification notification) {
    try {
        int[] data = (int[]) notification.getUserData();
        // get the repair sequence number
        int repairNo = data[0];
        // get the repair status
        ActiveRepairService.Status status = ActiveRepairService.Status.values()[data[1]];
        // this is some text message like "Starting repair...", "Finished repair...", etc.
        String message = notification.getMessage();
        // let the handler process the event
        repairStatusHandler.get().handle(repairNo, Optional.of(status), Optional.absent(), message);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        LOG.error("Error while processing JMX notification", e);
    }
}

From source file:com.spotify.reaper.cassandra.JmxProxy.java

/**
 * Handles notifications from the new repair API (repairAsync)
 */// w ww .j av  a  2 s  .  c om
private void processNewApiNotification(Notification notification) {
    Map<String, Integer> data = (Map<String, Integer>) notification.getUserData();
    try {
        // get the repair sequence number
        int repairNo = Integer.parseInt(((String) notification.getSource()).split(":")[1]);
        // get the progress status
        ProgressEventType progress = ProgressEventType.values()[data.get("type")];
        // this is some text message like "Starting repair...", "Finished repair...", etc.
        String message = notification.getMessage();
        // let the handler process the event
        repairStatusHandler.get().handle(repairNo, Optional.absent(), Optional.of(progress), message);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        LOG.error("Error while processing JMX notification", e);
    }
}