⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 valuelistener.java

📁 globus toolkit Math例子
💻 JAVA
字号:
package org.globus.examples.clients.MathService_instance_notif;import org.apache.axis.message.addressing.Address;import org.apache.axis.message.addressing.EndpointReferenceType;import org.globus.examples.services.core.notifications.impl.MathQNames;import org.oasis.wsn.NotificationProducer;import org.oasis.wsn.Subscribe;import org.oasis.wsn.TopicExpressionType;import org.oasis.wsn.WSBaseNotificationServiceAddressingLocator;import org.oasis.wsrf.properties.ResourcePropertyValueChangeNotificationType;import org.globus.wsrf.NotificationConsumerManager;import org.globus.wsrf.NotifyCallback;import org.globus.wsrf.WSNConstants;import org.globus.wsrf.core.notification.ResourcePropertyValueChangeNotificationElementType;import java.util.List;public class ValueListener implements NotifyCallback {	/* This method is called when a notification is delivered */	public void deliver(List topicPath, EndpointReferenceType producer,			Object message) {		ResourcePropertyValueChangeNotificationElementType notif_elem;		ResourcePropertyValueChangeNotificationType notif;		notif_elem = (ResourcePropertyValueChangeNotificationElementType) message;		notif = notif_elem.getResourcePropertyValueChangeNotification();		if (notif != null) {			System.out.println("A notification has been delivered");			System.out.print("Old value: ");			System.out.println(notif.getOldValue().get_any()[0].getValue());			System.out.print("New value: ");			System.out.println(notif.getNewValue().get_any()[0].getValue());		}	}	public void run(String serviceURI) {		try {			// The NotificationConsumerManager sets up an endpoint where			// notifications will be delivered.			NotificationConsumerManager consumer;			consumer = NotificationConsumerManager.getInstance();			consumer.startListening();			EndpointReferenceType consumerEPR = consumer					.createNotificationConsumer(this);						// Create the request to the remote Subscribe() call			Subscribe request = new Subscribe();			// Must the notification be delivered using the Notify operation?			request.setUseNotify(Boolean.TRUE);			// Indicate what the client's EPR is			request.setConsumerReference(consumerEPR);			// The TopicExpression specifies what topic we want to subscribe to			TopicExpressionType topicExpression = new TopicExpressionType();			topicExpression.setDialect(WSNConstants.SIMPLE_TOPIC_DIALECT);			topicExpression.setValue(MathQNames.RP_VALUE);			request.setTopicExpression(topicExpression);						// Get a reference to the NotificationProducer portType			WSBaseNotificationServiceAddressingLocator notifLocator = 				new WSBaseNotificationServiceAddressingLocator();			EndpointReferenceType endpoint = new EndpointReferenceType();			endpoint.setAddress(new Address(serviceURI));			NotificationProducer producerPort = notifLocator					.getNotificationProducerPort(endpoint);			// Start the ball rolling...			producerPort.subscribe(request);			// Loop forever and print notifications.			System.out.println("Waiting for notification. Ctrl-C to end.");			while (true) {				try {					Thread.sleep(30000);				} catch (Exception e) {					System.out.println("Interrupted while sleeping.");				}			}		} catch (Exception e) {			e.printStackTrace();		}	}	public static void main(String[] args) {		ValueListener client = new ValueListener();		client.run(args[0]);	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -