/** * Replaces the notification source if necessary to do so. * From the {@link Notification javadoc}: * <i>"It is strongly recommended that notification senders use the object name * rather than a reference to the MBean object as the source."</i> * @param notification the {@link Notification} whose * {@link javax.management.Notification#getSource()} might need massaging */ private void replaceNotificationSourceIfNecessary(Notification notification) { if (notification.getSource() == null || notification.getSource().equals(this.managedResource)) { notification.setSource(this.objectName); } }
/** * Replaces the notification source if necessary to do so. * From the {@link Notification javadoc}: * <i>"It is strongly recommended that notification senders use the object name * rather than a reference to the MBean object as the source."</i> * @param notification the {@link Notification} whose * {@link javax.management.Notification#getSource()} might need massaging */ private void replaceNotificationSourceIfNecessary(Notification notification) { if (notification.getSource() == null || notification.getSource().equals(this.managedResource)) { notification.setSource(this.objectName); } }
private static Map buildOperationNotificationPacket(Notification note) { Map<String, Object> result = new HashMap<String, Object>(); result.put("event", note.getType()); result.put("source", note.getSource()); result.put("sequenceNumber", note.getSequenceNumber()); result.put("timeStamp", note.getTimeStamp()); result.put("data", note.getUserData()); return result; } }
Object notifSource = notification.getSource(); if (AdminDistributedSystemJmxImpl.NOTIF_MEMBER_JOINED.equals(notification.getType())) { ObjectName source = (ObjectName) notifSource;
public void testSendAttributeChangeNotificationWhereSourceIsNotTheManagedResource() throws Exception { StubSpringModelMBean mbean = new StubSpringModelMBean(); Notification notification = new AttributeChangeNotification(this, 1872, System.currentTimeMillis(), "Shall we break for some tea?", "agree", "java.lang.Boolean", Boolean.FALSE, Boolean.TRUE); ObjectName objectName = createObjectName(); NotificationPublisher publisher = new ModelMBeanNotificationPublisher(mbean, objectName, mbean); publisher.sendNotification(notification); assertNotNull(mbean.getActualNotification()); assertTrue(mbean.getActualNotification() instanceof AttributeChangeNotification); assertSame("The exact same Notification is not being passed through from the publisher to the mbean.", notification, mbean.getActualNotification()); assertSame("The 'source' property of the Notification is *wrongly* being set to the ObjectName of the associated MBean.", this, mbean.getActualNotification().getSource()); }
public void testSendAttributeChangeNotification() throws Exception { StubSpringModelMBean mbean = new StubSpringModelMBean(); Notification notification = new AttributeChangeNotification(mbean, 1872, System.currentTimeMillis(), "Shall we break for some tea?", "agree", "java.lang.Boolean", Boolean.FALSE, Boolean.TRUE); ObjectName objectName = createObjectName(); NotificationPublisher publisher = new ModelMBeanNotificationPublisher(mbean, objectName, mbean); publisher.sendNotification(notification); assertNotNull(mbean.getActualNotification()); assertTrue(mbean.getActualNotification() instanceof AttributeChangeNotification); assertSame("The exact same Notification is not being passed through from the publisher to the mbean.", notification, mbean.getActualNotification()); assertSame("The 'source' property of the Notification is not being set to the ObjectName of the associated MBean.", objectName, mbean.getActualNotification().getSource()); }
public void testSendVanillaNotification() throws Exception { StubSpringModelMBean mbean = new StubSpringModelMBean(); Notification notification = new Notification("network.alarm.router", mbean, 1872); ObjectName objectName = createObjectName(); NotificationPublisher publisher = new ModelMBeanNotificationPublisher(mbean, objectName, mbean); publisher.sendNotification(notification); assertNotNull(mbean.getActualNotification()); assertSame("The exact same Notification is not being passed through from the publisher to the mbean.", notification, mbean.getActualNotification()); assertSame("The 'source' property of the Notification is not being set to the ObjectName of the associated MBean.", objectName, mbean.getActualNotification().getSource()); }
private void verifyReceipt(PollableChannel channel, String beanName) { Message<?> message = channel.receive(1000); assertNotNull(message); assertEquals(Notification.class, message.getPayload().getClass()); assertEquals("ABC", ((Notification) message.getPayload()).getMessage()); assertTrue(((String) ((Notification) message.getPayload()).getSource()).endsWith(beanName)); }
@Test public void simplePublish() { MessageHandler handler = context.getBean("testPublisher", MessageHandler.class); assertEquals(0, this.listener.notifications.size()); handler.handleMessage(new GenericMessage<String>("foo")); assertEquals(1, this.listener.notifications.size()); Notification notification = this.listener.notifications.get(0); assertEquals(this.publisherObjectName, notification.getSource()); assertEquals("foo", notification.getMessage()); assertEquals("test.type", notification.getType()); }
@Test public void simpleNotification() { QueueChannel outputChannel = new QueueChannel(); NotificationListeningMessageProducer adapter = new NotificationListeningMessageProducer(); adapter.setServer(this.server); adapter.setObjectName(this.objectName); adapter.setOutputChannel(outputChannel); adapter.setBeanFactory(mock(BeanFactory.class)); adapter.afterPropertiesSet(); adapter.start(); adapter.onApplicationEvent(new ContextRefreshedEvent(Mockito.mock(ApplicationContext.class))); this.numberHolder.publish("foo"); Message<?> message = outputChannel.receive(0); assertNotNull(message); assertTrue(message.getPayload() instanceof Notification); Notification notification = (Notification) message.getPayload(); assertEquals("foo", notification.getMessage()); assertEquals(objectName, notification.getSource()); assertNull(message.getHeaders().get(JmxHeaders.NOTIFICATION_HANDBACK)); }
@Test public void notificationWithHandback() { QueueChannel outputChannel = new QueueChannel(); NotificationListeningMessageProducer adapter = new NotificationListeningMessageProducer(); adapter.setServer(this.server); adapter.setObjectName(this.objectName); adapter.setOutputChannel(outputChannel); Integer handback = 123; adapter.setHandback(handback); adapter.setBeanFactory(mock(BeanFactory.class)); adapter.afterPropertiesSet(); adapter.start(); adapter.onApplicationEvent(new ContextRefreshedEvent(Mockito.mock(ApplicationContext.class))); this.numberHolder.publish("foo"); Message<?> message = outputChannel.receive(0); assertNotNull(message); assertTrue(message.getPayload() instanceof Notification); Notification notification = (Notification) message.getPayload(); assertEquals("foo", notification.getMessage()); assertEquals(objectName, notification.getSource()); assertEquals(handback, message.getHeaders().get(JmxHeaders.NOTIFICATION_HANDBACK)); }
public boolean isNotificationEnabled(Notification n) { return RARDeployment.MCF_ATTRIBUTE_CHANGED_NOTIFICATION.equals(n.getType()) && managedConnectionFactoryName.equals(n.getSource()); } },
public String toString(){ StringBuilder sb = new StringBuilder(); sb.append("Recorded Notif [ Type ").append(jmxNotificaiton.getType()) .append(" source : ").append(jmxNotificaiton.getSource()) .append(" message : ").append(jmxNotificaiton.getMessage()) .append(" userData : ").append(jmxNotificaiton.getUserData()) .append(" timestamp : ").append(jmxNotificaiton.getTimeStamp()) .append(" ]"); return sb.toString(); }
@Override public void handleNotification(Notification notification, Object handback) { Session session = getSession(); StringBuilder sb = new StringBuilder("notification received: "); sb.append("timestamp=").append(notification.getTimeStamp()); sb.append(",class=").append(notification.getClass().getName()); sb.append(",source=").append(notification.getSource()); sb.append(",type=").append(notification.getType()); sb.append(",message=").append(notification.getMessage()); session.output.println(sb.toString()); } }
private static Map buildOperationNotificationPacket(Notification note) { Map<String, Object> result = new HashMap<String, Object>(); result.put("event", note.getType()); result.put("source", note.getSource()); result.put("sequenceNumber", note.getSequenceNumber()); result.put("timeStamp", note.getTimeStamp()); result.put("data", note.getUserData()); return result; } }
private static Map buildOperationNotificationPacket(Notification note) { Map<String, Object> result = new HashMap<String, Object>(); result.put("event", note.getType()); result.put("source", note.getSource()); result.put("sequenceNumber", note.getSequenceNumber()); result.put("timeStamp", note.getTimeStamp()); result.put("data", note.getUserData()); return result; } }
private static Map buildOperationNotificationPacket(Notification note) { Map<String, Object> result = new HashMap<String, Object>(); result.put("event", note.getType()); result.put("source", note.getSource()); result.put("sequenceNumber", note.getSequenceNumber()); result.put("timeStamp", note.getTimeStamp()); result.put("data", note.getUserData()); return result; } }
private static Map buildOperationNotificationPacket(Notification note) { Map<String, Object> result = new HashMap<String, Object>(); result.put("event", note.getType()); result.put("source", note.getSource()); result.put("sequenceNumber", note.getSequenceNumber()); result.put("timeStamp", note.getTimeStamp()); result.put("data", note.getUserData()); return result; } }
private void printJMXNotification(Notification notification, Object handback) { StringBuilder sb = new StringBuilder(); sb.append("JMXNotificationListener(" + prefix + ") : Notification [ type=").append(notification.getType()).append(", message=") .append(notification.getMessage()) .append(", source=").append(notification.getSource()) .append(", seqNo=").append(notification.getSequenceNumber()) .append(", timestamp=").append(notification.getTimeStamp()) .append(", data=").append(ObjectToString(notification.getUserData())) .append(", handbackObject=").append(ObjectToString(handback)).append(" ]"); logInfo(sb.toString()); }
/** * Handle the Event Notification * @param the notification * @param the handback object * * @see javax.management.NotificationListener#handleNotification(javax.management.Notification, java.lang.Object) */ public void handleNotification(Notification notification, Object handback) { EventNotificationImpl event = new EventNotificationImpl(notification.getSource()); event.setNotification(notification); executorService.execute(new NotificationSender(this.listeners, event)); }