Java 8 Notification - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Notification class.

This code example shows how to use the following methods:getSource, setSource
	 * @throws IllegalArgumentException if the supplied {@code notification} is {@code null} 
	 * @throws UnableToSendNotificationException if the supplied {@code notification} could not be sent 
	 */ 
	@Override 
	public void sendNotification(Notification notification) {
		Assert.notNull(notification, "Notification must not be null");
		replaceNotificationSourceIfNecessary(notification);
		try { 
			if (notification instanceof AttributeChangeNotification) {
				this.modelMBean.sendAttributeChangeNotification((AttributeChangeNotification) notification);
			} 
			else { 
				this.modelMBean.sendNotification(notification);
			} 
		} 
		catch (MBeanException ex) {
			throw new UnableToSendNotificationException("Unable to send notification [" + notification + "]", ex);
		} 
	} 
 

8
CodeRank
This code example shows how to use the following methods:
		publisher.sendNotification(null);
	} 
 
	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());
	} 
 
	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();
7
CodeRank
This code example shows how to use the following methods:getSource, getSequenceNumber, getTimeStamp, getType, getUserData
        } 
    } 
 
    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; 
    } 
} 
7
CodeRank
This code example shows how to use the following methods:getSource, getMessage, getSequenceNumber, getTimeStamp, getType
            jaxb = mObjectFactory.createNotificationEventType();
            wrap = true;
        } 
 
        // add all of the common properties 
        jaxb.withMessage(aNotification.getMessage())
                .withSequence(aNotification.getSequenceNumber())
                .withSource(String.valueOf(aNotification.getSource()))
                .withTimestamp(aNotification.getTimeStamp())
                .withType(aNotification.getType());
        if (aNotification.getUserData() != null) {
            jaxb.withUserData(String.valueOf(aNotification.getUserData()));
        } 
 
        try { 
            DatatypeFactory df = getDatatypeFactory();
            Date date = new Date(aNotification.getTimeStamp());
            GregorianCalendar gc = new GregorianCalendar();
            gc.setTime(date);
            jaxb.withDateTime(df.newXMLGregorianCalendar(gc));

7
CodeRank
This code example shows how to use the following methods:getSource, getMessage, getSequenceNumber, getType, getUserData
    } 
 
    public void handleNotification(Notification notification, java.lang.Object handback) {
        StringBuilder sb = new StringBuilder();
        sb.append("Notification type: '");
        sb.append(notification.getType());
        sb.append("', seq nr: '");
        sb.append(notification.getSequenceNumber());
        sb.append("', message: '");
        sb.append(notification.getMessage());
        sb.append("', user data: '");
        sb.append(notification.getUserData());
        sb.append("'");
 
        String notif = "Notification: '" + notification + "'";
        String source = "Notification: source: '" + notification.getSource() + "'";
 
 
        if (notification.getType().equals("ogaaction")) {
            if (handback instanceof String) {

7
CodeRank
This code example shows how to use the following methods:getMessage, getTimeStamp, getType, getUserData
        } 
    } 
 
    public void handleNotification(Notification notification, Object handback)
    { 
        if ("repair".equals(notification.getType()))
        { 
            int[] status = (int[]) notification.getUserData();
            assert status.length == 2;
            if (cmd == status[0])
            { 
                String message = String.format("[%s] %s", format.format(notification.getTimeStamp()), notification.getMessage());
                out.println(message);
                // repair status is int array with [0] = cmd number, [1] = status 
                if (status[1] == ActiveRepairService.Status.SESSION_FAILED.ordinal())
                { 
                    success = false;
                } 
                else if (status[1] == ActiveRepairService.Status.FINISHED.ordinal())
                { 

6
CodeRank
This code example shows how to use the following methods:getTimeStamp, getType, getDerivedGauge, getObservedAttribute, getObservedObject
        echo(">>> Received notification: " + notification);
        if (notification instanceof MonitorNotification) {
            String type = notification.getType();
            if (type.equals(MonitorNotification.RUNTIME_ERROR)) {
                MonitorNotification mn = (MonitorNotification) notification;
                echo("\tType: " + mn.getType());
                echo("\tTimeStamp: " + mn.getTimeStamp());
                echo("\tObservedObject: " + mn.getObservedObject());
                echo("\tObservedAttribute: " + mn.getObservedAttribute());
                echo("\tDerivedGauge: " + mn.getDerivedGauge());
                echo("\tTrigger: " + mn.getTrigger());
                messageReceived = true;
            } 
        } 
    } 
 
    /** 
     * Update the counter and check for notifications 
     */ 
    public int counterMonitorNotification() throws Exception {
6
CodeRank
This code example shows how to use the following methods:setUserData
		String type = this.resolveNotificationType(message);
		Assert.hasText(type,
				"No notification type header is available, and no default has been provided."); 
		Object payload = (message != null) ? message.getPayload() : null; 
		String notificationMessage = (payload instanceof String) ? (String) payload : null;
		Notification notification = new Notification(type, this.sourceObjectName,
				this.sequence.incrementAndGet(), System.currentTimeMillis(), notificationMessage);
		if (payload != null && !(payload instanceof String)) {
			notification.setUserData(payload);
		} 
		return notification;
	} 
 
	private String resolveNotificationType(Message<?> message) {
		String type = message.getHeaders().get(JmxHeaders.NOTIFICATION_TYPE, String.class);
		return (type != null) ? type : this.defaultNotificationType;
	} 
 
} 
6
CodeRank
This code example shows how to use the following methods:getType, getUserData
	} 
 
	@Override 
	public void handleNotification(Notification not, Object handback) {
		 
		if (not.getType().equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED)) {
			CompositeDataSupport data=(CompositeDataSupport) not.getUserData();
			 
			 
			String poolName = (String) data.get("poolName");
			MemoryType type = types.get(poolName);
			if(type==MemoryType.HEAP){
				// clear heap 
				aprint.e("Clear heap!"); 
			} 
			else if(type==MemoryType.NON_HEAP) {
				// clear none-heap 
				((Config) handback).checkPermGenSpace(false);
			} 
			 
6
CodeRank
This code example shows how to use the following methods:getTimeStamp, getType, getDerivedGauge, getObservedAttribute, getObservedObject
        echo(">>> Received notification: " + notification);
        if (notification instanceof MonitorNotification) {
            String type = notification.getType();
            if (type.equals(MonitorNotification.RUNTIME_ERROR)) {
                MonitorNotification mn = (MonitorNotification) notification;
                echo("\tType: " + mn.getType());
                echo("\tTimeStamp: " + mn.getTimeStamp());
                echo("\tObservedObject: " + mn.getObservedObject());
                echo("\tObservedAttribute: " + mn.getObservedAttribute());
                echo("\tDerivedGauge: " + mn.getDerivedGauge());
                echo("\tTrigger: " + mn.getTrigger());
                messageReceived = true;
            } 
        } 
    } 
 
    /** 
     * Update the counter and check for notifications 
     */ 
    public int counterMonitorNotification() throws Exception {
6
CodeRank
See Code Examples for Java 8 Notification Methods: