120 likes | 322 Views
Notifications What are notifications?. Notifications allow clients to be notified of changes that occur in a Grid service [Sotomayor]. Problem with polling approach: the increase in the network traffic and CPU use. Notifications What are notifications?. Scenario.
E N D
NotificationsWhat are notifications? • Notifications allow clients to be notified of changes that occur in a Grid service [Sotomayor]. • Problem with polling approach: the increase in the network traffic and CPU use.
NotificationsWhat are notifications? Scenario Push approach: The observable informs the clients when the change has been occurred but it does not send any related information. Pull approach: The observable sends the related information to all the clients along with the change information.
NotificationsNotifications in GT3 • The observers subscribe to the service data element in the service not to the whole service. • addListener : subscription • notifyChange • deliverNotification • In GT3 terminology: • Observables: Notification sources • Observers: Notification sinks
NotificationsImplementation • Undeploy your previous project: (Directory: $HOME/gt3) ant undeploy -Dgar.id=mathtutorial • Create a new directory called “notification” under $HOME/gt3/samples/. cd $HOME/gt3/samples mkdir notification cd notification • Create the following directory structure:
NotificationsImplementation • Required files: • GWSDL file • WSDD file • Namespace file • Implementation file • SDE file • Client file • Build.properties file
NotificationsImplementation (GWSDL file) • Copy Math.gwsdl file to $TUTORIAL_DIR/mathtutorial/core/factory/schema. • Modify the following line in Math.gwsdl file: <gwsdl:portType name=”MathPortType” extends=”ogsi:GridService”> • Change above line to the following: <gwsdl:portType name="MathPortType" extends="ogsi:GridService ogsi:NotificationSource">
NotificationsImplementation (SDE file and others) • Copy MathSDE.xsd to $TUTORIAL_DIR/mathtutorial/code/factory/schema. • Copy namespace2package.mappings under $TUTORIAL_DIR. • Copy build.xml and build.properties files under $TUTORIAL_DIR.
NotificationsImplementation File • Copy “MathImpl.java” to $TUTORIAL_DIR/mathtutorial/code/factory/impl. • Modify accordingly: public void add(int a) throws RemoteException { mathDataValue.setLastOp("Addition"); incrementOps(); mathDataValue.setValue(mathDataValue.getValue() + a); mathDataSDE.notifyChange(); }
NotificationsImplementation (Client files) • The first file is for subscription and listening (ClientListener.java): Save them under client directory. public class ClientListener extends ServicePropertiesImpl implements NotificationSinkCallback { public static void main(String[] args) { try { // Get command-line arguments HandleType GSH = new HandleType(args[0]); ClientListener clientListener = new ClientListener(GSH); }catch(Exception e) { System.out.println("ERROR!"); e.printStackTrace(); } } public ClientListener(HandleType GSH) throws Exception { // Start listening to the MathService NotificationSinkManager notifManager = NotificationSinkManager.getManager(); notifManager.startListening(NotificationSinkManager.MAIN_THREAD); String sink = notifManager.addListener("MathData", null, GSH, this); System.out.println("Listening..."); // Wait for key press System.in.read(); // Stop listening notifManager.removeListener(sink); notifManager.stopListening(); System.out.println("Not listening anymore!"); }
NotificationsImplementation (Client files) • The first file is for subscription and listening (ClientListener.java): public void deliverNotification(ExtensibilityType any) throws RemoteException { try { // Service Data has changed. Show new data. ServiceDataValuesType serviceData = AnyHelper.getAsServiceDataValues(any); MathDataType mathData = (MathDataType) AnyHelper.getAsSingleObject(serviceData, MathDataType.class); // Write service data System.out.println("Current value: " + mathData.getValue()); System.out.println("Previous operation: " + mathData.getLastOp()); System.out.println("# of operations: " + mathData.getNumOps()); }catch(Exception exc) { System.out.println("ERROR!"); exc.printStackTrace(); } }}
NotificationsImplementation (Client files) • The first file is for subscription and listening (ClientAdder.java): package mathtutorial.core.factory.client; import mathtutorial.core.factory.service.MathServiceGridLocator; import mathtutorial.core.factory.Math.MathPortType; import java.net.URL; public class ClientAdder { public static void main(String[] args) { try { // Get command-line arguments URL GSH = new java.net.URL(args[0]); int a = Integer.parseInt(args[1]); // Get a reference to the Grid Service instance MathServiceGridLocator mathServiceLocator = new MathServiceGridLocator(); MathPortType math = mathServiceLocator.getMathServicePort(GSH); // Call remote method 'add' math.add(a); System.out.println("Added " + a); }catch(Exception e) { System.out.println("ERROR!"); e.printStackTrace(); } } }
NotificationsDeployment • Set the environment path: setenv TUTORIAL_DIR $HOME/gt3/samples/notification • Deploy your service (Directory = $TUTORIAL_DIR) ant -Dgwsdl.interface=true -Dpackage=mathtutorial.core.factory -Dinterface.name=Math -Dpackage.dir=mathtutorial/core/factory -Dsde.schema.file=MathSDE.xsd • Then, deploy your service into Globus container (Directory = $HOME/gt3). ant deploy -Dgar.name=$TUTORIAL_DIR/build/lib/mathtutorial.core.factory.Math.gar • Run your globus container and check whether your service is displayed. globus-start-container –p $MYPORT • Open another terminal. Then, compile and run your client (Directory = $TUTORIAL_DIR). javac -classpath ./build/classes/:$CLASSPATH mathtutorial/core/factory/client/ClientListener.java • Run your client. java -classpath ./build/classes/:$CLASSPATH -Dorg.globus.ogsa.schema.root=http://131.227.74.147:28161/ mathtutorial.core.factory.client.ClientListener http://131.227.74.147:28161/ogsa/services/mathtutorial/core/factory/MathService • Open another terminal. Then, compile and run your other client. javac -classpath ./build/classes/:$CLASSPATH mathtutorial/core/factory/client/ClientAdder.java java -classpath ./build/classes/:$CLASSPATH -Dorg.globus.ogsa.schema.root=http://131.227.74.147:28161/ mathtutorial.core.factory.client.ClientAdder http://131.227.74.147:28161/ogsa/services/mathtutorial/core/factory/MathService 5