List of usage examples for javax.management Notification getSource
public Object getSource()
From source file:de.iew.spring.integration.JmxTestServiceNotificationListener.java
private String formatNotification(Notification notification) { StringBuilder sb = new StringBuilder(); sb.append("recieved notification class: ").append(notification.getType()); sb.append(", method: ").append(notification.getSource()); sb.append(", sequence: ").append(notification.getSequenceNumber()); sb.append(", timestamp: ").append(notification.getTimeStamp()); sb.append(", data: "); Object userData = notification.getUserData(); String formattedUserData;// w w w .jav a 2 s . c o m if (userData == null) { formattedUserData = ""; } else if (userData instanceof String) { formattedUserData = StringUtils.arrayToCommaDelimitedString((Object[]) notification.getUserData()); } else { formattedUserData = userData.toString(); } sb.append(formattedUserData); return sb.toString(); }
From source file:io.fabric8.spi.process.AbstractProcessHandler.java
@Override public final Future<ManagedProcess> start() { State state = managedProcess.getState(); assertNotDestroyed(state);//from w w w .j a v a2 s . c o m // Setup a call back notification to get the JMX connection of the started process final CountDownLatch latch = new CountDownLatch(1); String jmxAgentServiceURL = managedProcess .getAttribute(ContainerAttributes.ATTRIBUTE_KEY_AGENT_JMX_SERVER_URL); String jmxAgentUsername = managedProcess.getAttribute(ContainerAttributes.ATTRIBUTE_KEY_AGENT_JMX_USERNAME); String jmxAgentPassword = managedProcess.getAttribute(ContainerAttributes.ATTRIBUTE_KEY_AGENT_JMX_PASSWORD); JMXConnector connector = ManagementUtils.getJMXConnector(jmxAgentServiceURL, jmxAgentUsername, jmxAgentPassword, 200, TimeUnit.MILLISECONDS); try { final MBeanServerConnection server = connector.getMBeanServerConnection(); server.addNotificationListener(Agent.OBJECT_NAME, new NotificationListener() { @Override public void handleNotification(Notification notification, Object handback) { String eventType = notification.getType(); if (NOTIFICATION_TYPE_AGENT_REGISTRATION.equals(eventType)) { AgentRegistration agentReg = (AgentRegistration) notification.getSource(); String agentName = agentReg.getIdentity().getName(); String procName = (String) handback; if (agentName.equals(procName)) { try { server.removeNotificationListener(Agent.OBJECT_NAME, this); } catch (Exception ex) { // ignore } latch.countDown(); } } } }, null, managedProcess.getIdentity().getName()); } catch (RuntimeException rte) { throw rte; } catch (Exception ex) { throw new IllegalStateException(ex); } finally { IOUtils.safeClose(connector); } try { if (state == State.CREATED || state == State.STOPPED) { doStart(managedProcess); IllegalStateAssertion.assertNotNull(process, "No process created"); managedProcess.setState(State.STARTED); } } catch (Exception ex) { throw new LifecycleException("Cannot start container", ex); } return new ProcessFuture(managedProcess); //, latch); }
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);/*from w w w. ja v a 2 s.c o 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.spotify.reaper.cassandra.JmxProxy.java
/** * Handles notifications from the new repair API (repairAsync) *//*from www. jav a 2 s .co m*/ 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); } }
From source file:com.heliosapm.script.AbstractDeployedScript.java
/** * Initializes the configuration// w w w . ja v a2s . c o m */ public void initConfig() { watchedConfig.set(findWatchedConfiguration()); if (watchedConfig.get() != null) { Map<String, String> parentConfig = getParentConfigurationMap(); if (parentConfig != null && !parentConfig.isEmpty()) { this.getConfiguration().load(parentConfig); } if (watchedConfigListenerRegistered.compareAndSet(false, true)) { try { JMXHelper.addNotificationListener(watchedConfig.get(), configChangeListener, new NotificationFilter() { /** */ private static final long serialVersionUID = -2890751194005498532L; @Override public boolean isNotificationEnabled(final Notification notification) { final Object userData = notification.getUserData(); return (notification.getSource().equals(watchedConfig.get()) && NOTIF_CONFIG_MOD.equals(notification.getType()) && userData != null && (userData instanceof Configuration) && !(((Configuration) userData).isEmpty())); } }, null); } catch (Exception ex) { try { JMXHelper.removeNotificationListener(watchedConfig.get(), configChangeListener); } catch (Exception x) { /* No Op */} log.error("Failed to register configuration listener", ex); watchedConfigListenerRegistered.set(false); } } } }
From source file:org.hyperic.hq.product.jmx.MxNotificationListener.java
public synchronized void handleNotification(Notification notification, Object handback) { String msg;/*from w ww . j ava2 s .co m*/ 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:com.pivotal.gemfire.tools.pulse.internal.data.JMXDataUpdater.java
/** * System Notification Listener// w w w. j ava 2 s . c o m */ @Override public void handleNotification(Notification notification, Object handback) { String type = notification.getType(); if (PulseConstants.NOTIFICATION_TYPE_SYSTEM_ALERT.equals(type)) { Cluster.Alert alert = new Cluster.Alert(); Long timeStamp = notification.getTimeStamp(); Date date = new Date(timeStamp); alert.setTimestamp(date); String notificationSource = (String) notification.getUserData(); alert.setMemberName(notificationSource); String alertDescription = notification.getMessage(); if (alertDescription.startsWith("[error")) { alert.setSeverity(Cluster.Alert.ERROR); } else if (alertDescription.startsWith("[warning")) { alert.setSeverity(Cluster.Alert.WARNING); } else if (alertDescription.startsWith("[severe")) { alert.setSeverity(Cluster.Alert.SEVERE); } else { alert.setSeverity(Cluster.Alert.INFO); } alert.setDescription(notification.getMessage()); alert.setAcknowledged(false); alert.setId(Cluster.Alert.nextID()); cluster.addAlert(alert); } else { Cluster.Alert alert = new Cluster.Alert(); Long timeStamp = notification.getTimeStamp(); Date date = new Date(timeStamp); alert.setTimestamp(date); String notificationSource = (String) notification.getSource(); alert.setMemberName(notificationSource); String alertDescription = notification.getMessage(); alert.setDescription(alertDescription); alert.setSeverity(Cluster.Alert.INFO); alert.setAcknowledged(false); alert.setId(Cluster.Alert.nextID()); cluster.addAlert(alert); } }
From source file:edu.nwpu.gemfire.monitor.data.JMXDataUpdater.java
/** * System Notification Listener/*from www . j a va 2 s.co m*/ */ @Override public void handleNotification(Notification notification, Object handback) { String type = notification.getType(); if (PulseConstants.NOTIFICATION_TYPE_SYSTEM_ALERT.equals(type)) { Cluster.Alert alert = new Cluster.Alert(); Long timeStamp = notification.getTimeStamp(); Date date = new Date(timeStamp); alert.setTimestamp(date); String notificationSource = (String) notification.getUserData(); alert.setMemberName(notificationSource); String alertDescription = notification.getMessage(); if (alertDescription.startsWith("[error")) { alert.setSeverity(Cluster.Alert.ERROR); } else if (alertDescription.startsWith("[warning")) { alert.setSeverity(Cluster.Alert.WARNING); } else if (alertDescription.startsWith("[severe")) { alert.setSeverity(Cluster.Alert.SEVERE); } else { alert.setSeverity(Cluster.Alert.INFO); } alert.setDescription(notification.getMessage()); alert.setAcknowledged(false); alert.setId(Cluster.Alert.nextID()); cluster.addAlert(alert); } else { Cluster.Alert alert = new Cluster.Alert(); Long timeStamp = notification.getTimeStamp(); Date date = new Date(timeStamp); alert.setTimestamp(date); String notificationSource = (String) notification.getSource(); alert.setMemberName(notificationSource); String alertDescription = notification.getMessage(); alert.setDescription(alertDescription); alert.setSeverity(Cluster.Alert.INFO); alert.setAcknowledged(false); alert.setId(Cluster.Alert.nextID()); cluster.addAlert(alert); if (PulseConstants.NOTIFICATION_TYPE_REGION_DESTROYED.equals(type)) { // Remove deleted region from member's regions list String msg = notification.getMessage(); String deletedRegion = msg.substring(msg.indexOf("Name ") + "Name ".length()); String memberName = notificationSource; Cluster.Member member = cluster.getMembersHMap().get(memberName); if (member.getMemberRegions().get(deletedRegion) != null) { member.getMemberRegions().remove(deletedRegion); member.setTotalRegionCount(member.getMemberRegions().size()); } } } }