/** * Sends the given notification. * * @param notif notification to send * * @throws NullPointerException if resource or ModelMBean for resource is null */ /* default */static void sendNotification(ManagedResource resource, Notification notif) { try { if (MBeanUtil.isRegistered(resource.getObjectName())) { resource.getModelMBean().sendNotification(notif); if (logger.isDebugEnabled()) { logger.debug("Sent '{}' notification", notif.getType()); } } } catch (RuntimeOperationsException e) { logger .info(String.format("Failed to send %s notification for %s", new Object[] {"'" + notif.getType() + "'", "'" + notif.getMessage() + "'"}), e); } catch (MBeanException e) { logger .info(String.format("Failed to send %s notification for %s", new Object[] {"'" + notif.getType() + "'", "'" + notif.getMessage() + "'"}), e); } } }
@Override public void handleNotification(Notification arg0, Object arg1) { this.logger.info("Notification: " + arg0 + "; o: " + arg1 + "; m: " + arg0.getMessage()); this.critical.set(true); }
notification.getMessage());
@Test public void testRepeatOperationsOpenUsed() throws Exception { final List<Notification> list = new ArrayList<>(); publisher.setNotificationPublisher(new NotificationPublisher() { @Override public void sendNotification(Notification notification) throws UnableToSendNotificationException { list.add(notification); } }); publisher.onApplicationEvent(new SimpleMessageApplicationEvent(this, "foo")); assertEquals(1, list.size()); String message = list.get(0).getMessage(); assertTrue("Message does not contain 'foo': ", message.indexOf("foo") > 0); } }
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 testPublish() { publishChannel.send(new GenericMessage<String>("bar")); Message<?> message = publishInChannel.receive(100000); assertNotNull(message); assertTrue(message.getPayload() instanceof Notification); Notification notification = (Notification) message.getPayload(); assertEquals("bar", notification.getMessage()); assertEquals("foo", notification.getType()); }
@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 //INT-2275 public void publishStringMessageWithinChain() throws Exception { assertNotNull( this.beanFactory.getBean( "chainWithJmxNotificationPublishing$child." + "jmx-notification-publishing-channel-adapter-within-chain.handler", MessageHandler.class)); assertNull(listener.lastNotification); Message<?> message = MessageBuilder.withPayload("XYZ") .setHeader(JmxHeaders.NOTIFICATION_TYPE, "test.type").build(); publishingWithinChainChannel.send(message); assertNotNull(listener.lastNotification); Notification notification = listener.lastNotification; assertEquals("XYZ", notification.getMessage()); assertEquals("test.type", notification.getType()); assertNull(notification.getUserData()); Set<ObjectName> names = server .queryNames(new ObjectName("*:type=MessageHandler," + "name=\"chainWithJmxNotificationPublishing$child." + "jmx-notification-publishing-channel-adapter-within-chain\",*"), null); assertEquals(1, names.size()); names = server .queryNames(new ObjectName("*:type=MessageChannel," + "name=org.springframework.integration.test.anon,source=anonymous,*"), null); assertEquals(1, names.size()); }
@Test public void publishUserData() throws Exception { assertNull(listener.lastNotification); TestData data = new TestData(); Message<?> message = MessageBuilder.withPayload(data) .setHeader(JmxHeaders.NOTIFICATION_TYPE, "test.type").build(); channel.send(message); assertNotNull(listener.lastNotification); Notification notification = listener.lastNotification; assertNull(notification.getMessage()); assertEquals(data, notification.getUserData()); assertEquals("test.type", notification.getType()); }
@Test public void publishStringMessage() throws Exception { adviceCalled = 0; assertNull(listener.lastNotification); Message<?> message = MessageBuilder.withPayload("XYZ") .setHeader(JmxHeaders.NOTIFICATION_TYPE, "test.type").build(); channel.send(message); assertNotNull(listener.lastNotification); Notification notification = listener.lastNotification; assertEquals("XYZ", notification.getMessage()); assertEquals("test.type", notification.getType()); assertNull(notification.getUserData()); assertEquals(1, adviceCalled); }
@Test @SuppressWarnings("serial") public void notificationWithFilter() { QueueChannel outputChannel = new QueueChannel(); NotificationListeningMessageProducer adapter = new NotificationListeningMessageProducer(); adapter.setServer(this.server); adapter.setObjectName(this.objectName); adapter.setOutputChannel(outputChannel); adapter.setFilter(notification -> !notification.getMessage().equals("bad")); adapter.setBeanFactory(mock(BeanFactory.class)); adapter.afterPropertiesSet(); adapter.start(); adapter.onApplicationEvent(new ContextRefreshedEvent(Mockito.mock(ApplicationContext.class))); this.numberHolder.publish("bad"); Message<?> message = outputChannel.receive(0); assertNull(message); this.numberHolder.publish("okay"); message = outputChannel.receive(0); assertNotNull(message); assertTrue(message.getPayload() instanceof Notification); Notification notification = (Notification) message.getPayload(); assertEquals("okay", notification.getMessage()); }
@Override public void sendNotif(Notification notif) { super.sendNotif(notif); if (notif.getMessage().startsWith("CurDialog: Rcvd: procUnstrSsReq: ")) { String s1 = notif.getMessage().substring(17); this.lbMessage.setText(s1); } if (notif.getMessage().startsWith("CurDialog: Rcvd: unstrSsResp: ")) { String s1 = notif.getMessage().substring(17); this.lbMessage.setText(s1); } }
@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 void handleNotification(Notification arg0, Object arg1) { this.logger.info("Notification: " + arg0 + "; o: " + arg1 + "; m: " + arg0.getMessage()); this.critical.set(true); }
@Override public void sendNotif(Notification notif) { super.sendNotif(notif); if (notif.getMessage().startsWith("DlgClosed:")) { this.setDialogClosed(); } if (notif.getMessage().startsWith("DlgStarted:") || notif.getMessage().startsWith("DlgAccepted:")) { this.setDialogOpened(); } }
@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()); } }
@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()); } }
public void broadcastLogEvent(final String event, final String[] throwableStringRep) { Notification notif = new Notification(LOGGING_EVENT_TYPE, this, sequenceNumber.incrementAndGet(), System.currentTimeMillis(), event); notif.setUserData(throwableStringRep); sendNotification(notif); notif = new Notification(notif.getType(), getClass().getName(), notif.getSequenceNumber(), notif.getTimeStamp(), notif.getMessage()); notif.setUserData(throwableStringRep); tcLoggingHistoryProvider.push(notif); }
protected void onSerialize(SerializationContext context, Notification notification) throws IOException { context.serialize(CLASS_NAME_QNAME, null, notification.getType()); context.serialize(SOURCE_QNAME, null, notification.getSource()); context.serialize(SEQUENCE_NUMBER_QNAME, null, new Long(notification.getSequenceNumber())); context.serialize(TIMESTAMP_QNAME, null, new Long(notification.getTimeStamp())); context.serialize(MESSAGE_QNAME, null, notification.getMessage()); context.serialize(USER_DATA_QNAME, null, notification.getUserData()); }