200 likes | 414 Views
Project Demo- Grid Notification. Presentation by: Ben Zhang. Overview. Project summary Notification Concept Go through steps of implementing a notification grid service Demo. Project Objective. Show how Grid Notification works Idea:
E N D
Project Demo-Grid Notification Presentation by: Ben Zhang
Overview • Project summary • Notification Concept • Go through steps of implementing a notification grid service • Demo
Project Objective • Show how Grid Notification works • Idea: • Implement a Grid Service with a notification SDE. This Grid Service provides clients with stock quote and has a notification SDE storing the recent queried stock info. If there is a change, its subscribed clients should get the notification.
Background • What are notification • When there are some changes of service, the observable notifies all its subscribed observers of the changes. • Notification approach • Push approach:allow data to travel along with the notification • Pull approach: data not travel along with the notification.
Notification in GT3 • Notification in GT3 is closely related to service data. The clients don't subscribe to a whole service, but to a particular Service Data Element (SDE) in that service. • Whenever a change happens the service will ask the SDE to notify its subscribers. • GT3 only supports push notification. But a pull notification can be implemented by subscribing to a 'dummy SDE' with no data.
Notification in GT3 • addListener: This call subscribes the calling client to a particular SDE. • notifyChange: Whenever a change happens, the GridService will ask the SDE to notify its subscribers. • deliverNotification: The SDE notifies the subscribers that a change had happened.
StockQuote Grid Service • StockQuote Grid Service • provides clients real-time stock info based on stock ticker. The info includes stock’s last price, date, time, change, open price,daily high,daily low, volume, etc. • Notification SDE: • stores the last stock info queried by clients • has the follows fields: • Stock symbol • Last price • Date • time
Step1-define interface • Define the service interface: • <gwsdl:portType name="StockPortType" extends="ogsi:GridService ogsi:NotificationSource">, extend from a standard portType called NotificationSource which includes notification-related operations. • Other changes comparing to our MathServiceSD service: <definitions name="StockQuoteService“ targetNamespace=http://www.globus.org/namespaces/bxz01Assignments/StockQuoteService xmlns:tns=http://www.globus.org/namespaces/bxz01Assignments/StockQuoteService xmlns:data=http://www.globus.org/namespaces/bxz01Assignments/StockQuoteService/StockSDE … <import location="StockSDE.xsd“ namespace="http://www.globus.org/namespaces/bxz01Assignments/StockQuoteService/StockSDE"/>
Step 2-service implementation • Get real-time stock info from yahoo base on stock ticker(symbol). • http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1c1ohgv&s=YHOO In the link, f=sl1d1t1c1ohgv defines the format of querying result. (S-symbol, l-lastprice, d-date, t-time, c-change, o-openprice, h-dailyhigh, g-dailylow,v-volume) For example: "YHOO",37.99,"11/29/2004","3:06pm",+0.18,38.07,38.24,37.50,10358000
Step2- (continue) • When there is a change of StockDataSDE, StockDataSDE notify all its subscribers through notifyChange() method. public void setSymbol(String symbol) throws RemoteException { this.symbol = symbol.toUpperCase(); getQuote(); StockDataValue.setSymbol(symbol); StockDataValue.setLastPrice(Double.parseDouble(lastPrice)); StockDataValue.setDate(date1); StockDataValue.setTime(time1); StockDataSDE.notifyChange(); }
Step3- Deployment Descriptor <?xml version="1.0"?> <deployment name="defaultServerConfig" xmlns=http://xml.apache.org/axis/wsdd/ xmlns:java=http://xml.apache.org/axis/wsdd/providers/java <service name="bxz01Assignments/StockQuoteService" provider="Handler" style="wrapped"> <parameter name="name" value="StockQuoteService (with notification)"/> <parameter name="baseClassName" value="bxz01Assignments.services.StockQuoteService.impl.StockQuoteImpl"/> <parameter name="className" value="bxz01Assignments.stubs.StockQuoteService.StockPortType"/> <parameter name="schemaPath" value="schema/bxz01Assignments/StockQuoteService/StockQuote_service.wsdl"/> <parameter name="operationProviders" value="org.globus.ogsa.impl.ogsi.NotificationSourceProvider"/> <!-- Start common parameters --> <parameter name="allowedMethods" value="*"/> <parameter name="persistent" value="true"/> <parameter name="handlerClass" value="org.globus.ogsa.handlers.RPCURIProvider"/> </service>
Step 4- compile and deploy • build the service • ./build.sh bxz01Assignments/services/StockQuoteService schema/bxz01Assignments/StockQuoteService/StockQuote.gwsdl • Deploy • ant deploy -Dgar.name=/home/bxz01/GridServices/build/lib/bxz01Assignments_services_StockQuoteService.gar
Step 5- Client Listener • Class declaration • public class ClientListener extends ServicePropertiesImpl implements NotificationSinkCallback • extends ServicePropertiesImpl: • This class is the base class of GridServiceImpl which is intended for the server-side of our application. Atually, our "client" is both a client and a server, because it is going to make calls to StockQuoteService (to subscribe to the StockDataSDE), but also receive them (deliverNotification). So, our client needs a server infrastructure, which the ServicePropertiesImpl class provides. • implements NotificationSinkCallback: • This interface must be implemented by classes that wish to subscribe to notifications. A deliverNotification method which is called by the Grid Service when a change is produced
Step 5- (continue) • Subscribe to a SDE. • Can be done by NotificationSinkManager. Two simple steps: startListening and addListener NotificationSinkManager notifManager = NotificationSinkManager.getManager(); notifManager.startListening(NotificationSinkManager.MAIN_THREAD); String sink = notifManager.addListener("StockData", null, GSH, this); • addListenermethod specifies which service and SDE the client should subscribe. The parameters are follows • The Service Data Element we want to subscribe to. • A timeout (null--if we don't want to stop listening) • The GSH of the Grid Service that has the Service Data Element we want to subscribe to • The class which will take care of receiving the notifications
Step 5- (continue ) • Implement deliverNotificationmethod public void deliverNotification(ExtensibilityType any) throws RemoteException { try { // Service Data has changed. Show new data. ServiceDataValuesType serviceData = AnyHelper.getAsServiceDataValues(any); StockDataType StockData = (StockDataType) AnyHelper.getAsSingleObject(serviceData, StockDataType.class); // Write service data System.out.println("Current stock info: "); System.out.println("symbol: " + StockData.getSymbol()); System.out.println("lastPrice: " + StockData.getLastPrice()); System.out.println("Date: " + StockData.getDate()); System.out.println("Time: " + StockData.getTime()); }catch(Exception exc) { System.out.println("ERROR!"); exc.printStackTrace(); } }
Step 5- (continue ) • Unsubscribe client // Stop listening notifManager.removeListener(sink); notifManager.stopListening();
Step 6 – run command • Compile client javac -classpath ./build/classes/:$CLASSPATH bxz01Assignments/clients/StockQuoteService/ClientListener.java • Start container globus-start-container -p 30000 • Run client java -classpath ./build/classes/:$CLASSPATH -Dorg.globus.ogsa.schema.root=http://localhost:30000/ bxz01Assignments.clients.StockQuoteService.ClientListener http://talon.csce.uark.edu:30000/ogsa/services/bxz01Assignments/StockQuoteService Notice: we have to define a property called org.globus.ogsa.schema.root.
References • http://www.casa-sotomayor.net/gt3-tutorial/multiplehtml/ch06s01.html • http://www-unix.globus.org/toolkit/docs/3.2/core/