GT4 WS Core Tutorial Sam Meder {[email protected]} Jarek Gawor {[email protected]} 6/11/04.
Transcript of GT4 WS Core Tutorial Sam Meder {[email protected]} Jarek Gawor {[email protected]} 6/11/04.
![Page 2: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/2.jpg)
Disclaimer
Everything GT4 related is subject to change
Don’t expect to be able to do more than prototype with current code
![Page 3: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/3.jpg)
GT 4 WS Core Architecture
Grid Service vs. Web Service + Resource Operation Providers Service Properties vs. JNDI Directory Service State Management vs. Resource
State Management Client side support Service Data vs. Resource Properties Notifications Security
![Page 4: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/4.jpg)
GT3 Grid Service
Implements the OGSI grid service port type Persistent/Transient lifecycle Provides operations for
Service lifetime management Inspecting and changing Service Data
![Page 5: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/5.jpg)
GT4 Web Service + Resource
The service bit is just a plain web service Resources are managed/discovered via a
Resource Home:
ResourceHome implementations provide: Custom create() methods Methods that operate on a set of resources
+find(in key : ResourceKey) : Resource+remove(in key : ResourceKey)+getKeyTypeName() : QName+getKeyTypeClass() : Class
«interface»ResourceHome
+getValue() : Object+getName() : QName+toSOAPElement() : SOAPElement
«interface»ResourceKey
![Page 6: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/6.jpg)
Resource DiscoveryContainer
Service
Resource
Resource Home
Registry
Obtain State From Resource
Get Resource
Get Resource Home
![Page 7: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/7.jpg)
Resource Discovery in Practice The simple case:
Counter counter = (Counter) ResourceContext.getResource();
The complicated case:
ResourceContext ctx = null; ResourceHome home = null; ResourceKey key = null; Counter counter = null; try { ctx = ResourceContext.getResourceContext(); home = ctx.getResourceHome(); key = ctx.getResourceKey();
counter = (Counter)home.find(key); } catch (Exception e) { throw new RemoteException("", e); }
![Page 8: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/8.jpg)
GT4 Web Service + Resource
Service and resource in the same object One resource per service
Service and resource as separate entity Any number of resources per service
Service
Container
Resource
Service
Container
Resource
![Page 9: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/9.jpg)
Available Resource Homes
SimpleResourceHome Basic hash table based implementation
SoftResourceHome Uses soft references for storing resources
ServiceResourceHome Service/Resource singleton home
PersistentResourceHome For use with resources that can be persisted
We may introduce a more generic home to replace some of these implementations
![Page 10: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/10.jpg)
Operation Provider Model Introduced in GT3
Provides a web service composition framework Enables reusable components
In GT4 Any service can be an operation provider No special interface required Currently implemented:
Destroy Set Termination Time Get Current Message Notification Consumer Pause/Resume Subscription Subscribe Get/Set Resource Property Get Multiple Resource Properties Query Resource Properties
![Page 11: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/11.jpg)
GT3 Service Properties
Allows services to store/checkpoint configuration properties Flat Table (key, value) Values can be persisted to deployment
descriptor Works for simple things
![Page 12: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/12.jpg)
GT4 Directory
Uses JNDI code from Apache Tomcat Hierarchical Object Factories
Resource Homes DataSource Etc.
Entries can be linked For more information see:
http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jndi-resources-howto.html
Note: Configuration file format slightly different
![Page 13: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/13.jpg)
JNDI Examples
Environment entry:<environment
name="subscriptionManagerServiceName”
type="java.lang.String" value="SubscriptionManagerService"/>
Resource Link entry:<resourceLink
name="home" target="java:comp/env/notificationConsumerHome"/>
![Page 14: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/14.jpg)
JNDI Examples Continued Resource entry:
<resource name="subscriptionHome"
type="org.globus.wsrf.impl.notification.SimpleSubscriptionHome"> <resourceParams> <parameter> <name> factory </name> <value> org.globus.wsrf.tools.jndi.BeanFactory </value> </parameter> </resourceParams></resource>
![Page 15: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/15.jpg)
GT3 Service State Management
Persistent vs. Transient Service Persistent service - created through
container configuration entry Transient service – created at runtime
Persistent vs. Transient Lifecycle Persistent – Service can checkpoint and
recover properties Transient – Service Properties are volatile
![Page 16: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/16.jpg)
GT4 Resource State Management
Resource State Management Will provide implementations for common
patterns: Soft references
Good when state is easily recreated Persistent Resources
Design your service with scalability in mind Don’t keep long lived references to your
resources
![Page 17: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/17.jpg)
Persistent Resources in GT4
Must implement PersistentResource interface Must have a default constructor Must define at least one create() operation Up to implementation to call store() when appropriate Currently, can only be used with
PersistentResourceHome
+getID() : Object
«interface»ResourceIdentifier
+load(in key : ResourceKey)+store()
«interface»PersistentResource
+remove()
«interface»RemoveCallback
![Page 18: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/18.jpg)
Client Side Model
No more Grid Service Handle to Grid Service Reference resolution Similar step likely in GT4
Needed for below Discovery of remote security policy and certificates
Can’t really pass WS-A Endpoint References on command line Factory returns human readable string as
well as EPR Discover EPR via Service Group lookup
![Page 19: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/19.jpg)
Security
Model remains unchanged Clients will have to set security properties on stub Service/Resource security policy via deployment
descriptor Security settings will be per resource
New Features in 4.0 Better GSI Secure Message support
Encryption Replay Attack Prevention
Flexible Authorization Support Based on Work in OGSA AuthZ WG
(Rebase on Apache WSS4J code)
![Page 20: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/20.jpg)
GT3 Service Data
Grid Service
Service Data Set Query Engine
Service Data
Service Data
Expression Evaluator
Expression Evaluator
….
….
![Page 21: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/21.jpg)
GT4 Resource Properties
Resource
Resource Property Set Query Engine
Resource Property
Resource Property
Expression Evaluator
Expression Evaluator
….
….
![Page 22: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/22.jpg)
GT4 Resource Properties
Resources implement the Resource Properties interface:
The Resource Property Set manages properties:
+getResourcePropertySet() : ResourcePropertySet
«interface»ResourceProperties
+add(in property : ResourceProperty) : ResourceProperty+remove(in property : ResourceProperty) : ResourceProperty+get(in property : QName) : ResourceProperty+create(in propName : QName) : ResourceProperty+iterator() : Iterator+isOpenContent() : boolean+getQName() : QName
«interface»ResourcePropertySet
![Page 23: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/23.jpg)
GT4 Resource Properties
Every Resource Property implements:
+getName() : QName+add(in value : Object)+remove(in value : Object) : Object+get(in index : int) : Object+set(in index : int, in value : Object) : Object+clear()+size() : int+isNillab le() : boolean+setNillab le(in nillab le : boolean)+getMinOccurs() : int+setMinOccurs(in minOccurs : int)+getMaxOccurs() : int+setMaxOccurs(in maxOccurs : int)+toSOAPElement() : SOAPElement[]+toSOAPElement(in list : List)+toElement() : Element[]
«interface»ResourceProperty
![Page 24: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/24.jpg)
Resource Property Implementations
SimpleResourceProperty Basic resource property implementation Stores the resource property values
ReflectionResourceProperty Relies on reflection to get/set values
![Page 25: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/25.jpg)
GT Query Framework
Supports multiple query dialects New dialects can be added at runtime Evaluation engine is chosen using dialect in
query
![Page 26: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/26.jpg)
Resource Properties Summary
+getResourcePropertySet() : ResourcePropertySet
«interface»ResourceProperties
+add(in property : ResourceProperty) : ResourceProperty+remove(in property : ResourceProperty) : ResourceProperty+get(in property : QName) : ResourceProperty+create(in propName : QName) : ResourceProperty+iterator() : Iterator+isOpenContent() : boolean+getQName() : QName
«interface»ResourcePropertySet
+getName() : QName+add(in value : Object)+remove(in value : Object) : Object+get(in index : int) : Object+set(in index : int, in value : Object) : Object+clear()+size() : int+isNillab le() : boolean+setNillab le(in nillab le : boolean)+getMinOccurs() : int+setMinOccurs(in minOccurs : int)+getMaxOccurs() : int+setMaxOccurs(in maxOccurs : int)+toSOAPElement() : SOAPElement[]+toSOAPElement(in list : List)+toElement() : Element[]
«interface»ResourceProperty
+registerEvaluator(in evaluator : ExpressionEvaluator)+executeQuery(in query : QueryExpressionType, in properties : ResourcePropertySet) : Object+getEvaluator(in dialect : String) : ExpressionEvaluator
«interface»QueryEngine
+evaluate(in query : QueryExpressionType, in properties : ResourcePropertySet)+getDialects()
«interface»ExpressionEvaluator
1
*
1
*1
1
![Page 27: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/27.jpg)
GT3 Notification
Notifications are coupled to Service Data changes Flat namespace
Notification interfaces are added via operation providers
Often required one notification sink per subscription Disambiguation of source
![Page 28: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/28.jpg)
GT4 Notification
Main change: Notifications are no longer coupled to service data Parallel code structure Hierarchy of topics Topic can represent anything you want
Default notification consumer (sink) service per hosting environment Individual sinks are represented by resources
Default subscription manager service per hosting environment Subscriptions are resources
Still uses operation providers model
![Page 29: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/29.jpg)
GT4 Notification Overview
Resource
Topic List Topic Expression Engine
Root Topic
Topic Expression Evaluator
Topic Expression Evaluator
….
Sub Topic Sub Topic….
Root Topic
….
![Page 30: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/30.jpg)
GT4 Notification Interfaces
+addTopic(in topic : Topic)+removeTopic(in topic : Topic)+getTopic(in topicPath : List) : Topic+getTopics(in topicPath : TopicExpressionType) : Collection+setFixedTopicSet(in fixedTopicSet : boolean)+isTopicSetFixed() : boolean+topicIterator() : Iterator
«interface»TopicList
+pause()+resume()+isPaused() : boolean+getConsumerReference() : EndpointReferenceType+getTopicPathExpression() : TopicExpressionType+getPrecondition() : QueryExpressionType+getSelector() : QueryExpressionType+getSubscriptionPolicy() : PolicyExpression+getUseNotify() : boolean+getResource() : Resource+getProducerReference() : EndpointReferenceType+getCreationTime() : Calendar
«interface»Subscription
+getTopicList() : TopicList
«interface»TopicListAccessor
+topicChanged(in topic : Topic)+topicAdded(in topic : Topic)+topicRemoved(in topic : Topic)
«interface»TopicListener
+addTopic(in topic : Topic)+removeTopic(in topic : Topic)+getTopic(in topicName : QName) : Topic+setTopicReference(in topicPath : TopicExpressionType)+getTopicReference() : TopicExpressionType+getName() : QName+setTopicPath(in topicPath : List)+getTopicPath() : List+notify(in obj : Object)+getCurrentMessage() : Object+isReference() : boolean+topicIterator() : Iterator
«interface»Topic
1
*1
*
1
1
1*
+addTopicListener(in listener : TopicListener)+removeTopicListener(in listener : TopicListener)
«interface»TopicListenerList
+getTerminationTime() : Calendar+setTerminationTime(in terminationTime : Calendar)+getCurrentTime() : Calendar
«interface»ResourceLifetime
![Page 31: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/31.jpg)
GT4 Notification Interfaces
Topic List Accessor Allows for different TopicList
implementations Usually implemented by a Resource
Topic List List of root topics
Topic Represents a topic May have child topics
![Page 32: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/32.jpg)
GT4 Notification Interfaces
Topic Listener Interface for propagating Topic changes Used to connect subscriptions to topics\ Used for creating the topics RP
Subscription Interface to subscription state
![Page 33: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/33.jpg)
Current Topic Implementations
SimpleTopic Your basic no-frills implementation
ResourcePropertyTopic Creates a topic from a object that
implements the Resource Property Interface
![Page 34: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/34.jpg)
Topic Expression Framework
Similar to Query Engine You will also need to register dialect with Axis
+registerEvaluator(in evaluator : TopicExpressionEvaluator)+resolveTopicExpression(in topicExpression : TopicExpressionType, in topicList : TopicList) : Collection+getConcretePath(in topicExpression : TopicExpressionType) : List+getEvaluator(in dialect : URI) : TopicExpressionEvaluator+getSupportedDialects() : URI[]
«interface»TopicExpressionEngine
+resolve(in expression : Object, in topicList : TopicList) : Collection+getDialects() : URI[]+getConcreteTopicPath(in expression : TopicExpressionEngine) : List+toTopicExpression(in topicPath : List) : TopicExpressionType
«interface»TopicExpressionEvaluator
1
*
![Page 35: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/35.jpg)
GT4 Threads and Timers
Based on J2EE APIs proposed by IBM & BEA Royalty free More information at http://www-
106.ibm.com/developerworks/java/library/j-commonj-sdowmt/
WorkManager & Timer interfaces Using thread/timer pools Container provides default WorkManager
and Timer objects via JNDI lookup Replaces SweeperPool in GT3
![Page 36: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/36.jpg)
Timer Example Get the TimeManager and schedule:
Context initialContext = new InitialContext();TimerManager timerManager = (TimerManager)
initialContext.lookup(WSRFConstants.DEFAULT_TIMER);timerManager.schedule(new TerminationTimerListener(), period, period);
Each timer task needs to implement TimerListener:protected class TerminationTimerListener implements
TimerListener{ public void timerExpired(Timer timer) {
… }
}
![Page 37: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/37.jpg)
WorkManager Example Get the WorkManager and schedule:
Context initialContext = new InitialContext();WorkManager workManager = (WorkManager)
initialContext.lookup(WSRFConstants.DEFAULT_WORK_MANAGER);WorkItem item1 = workManager.schedule(work1);
Each work task needs to implement Work:private class TestWork implements Work{ public void release() {
… } public void run() {
… }
}
![Page 38: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/38.jpg)
Base Faults
You should define your service faults Helper API (FaultHelper)
Methods for populating and inspecting Base Faults
Currently have a handler that fills in some of the fields (timestamp etc.)
![Page 39: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/39.jpg)
GT3 vs. GT4 Summary
What has fundamentally changed: No long lived address anymore (GSH) doc/literal (GT4) instead of wrapped/literal Decoupled notification framework
Not that much
![Page 40: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/40.jpg)
Counter Service II: The Revenge
What is required to implement a new service? WSDL Service Resource Resource Home Client Configuration
![Page 41: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/41.jpg)
Counter Service Interaction
Client CounterWS-Resource
Create Resource
Create Subscription
Add(3)
Value Change Notify
Get Resource Property
Destroy
NotificationConsumer
Service
Counter Service
CounterResource
![Page 42: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/42.jpg)
The Code: WSDL <types> <xsd:schema targetNamespace="http://counter.com" xmlns:tns="http://counter.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
… <xsd:element name="Value" type="xsd:int"/> <xsd:element name="CounterRP"> <xsd:complexType> <xsd:sequence> <xsd:element ref="tns:Value" minOccurs="1" maxOccurs="1"/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema> </types>
![Page 43: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/43.jpg)
The Code - WSDL
<portType name="CounterPortType" gtwsdl:implements="wsnt:NotificationProducer wsrl:ImmediateResourceTermination" wsrp:ResourceProperties ="tns:CounterRP"> <operation name="createCounter"> <input message="tns:CreateCounterRequest"/> <output message="tns:CreateCounterResponse"/> </operation> <operation name="add"> <input message="tns:AddInputMessage"/> <output message="tns:AddOutputMessage"/> </operation>
</portType>
![Page 44: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/44.jpg)
The Code: Service public _createCounterResponse createCounter(_createCounterRequest request) throws RemoteException { ResourceContext ctx = null; CounterHome home = null; ResourceKey key = null;
try { ctx = ResourceContext.getResourceContext(); home = (CounterHome) ctx.getResourceHome(); key = home.create(); } catch(RemoteException e) { throw e; } catch(Exception e) { throw new RemoteException("", e); }
![Page 45: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/45.jpg)
The Code: Service EndpointReferenceType epr = null; try { epr = AddressingUtils.createEndpointReference(ctx, key); } catch(Exception e) { throw new RemoteException("", e); } _createCounterResponse response = new _createCounterResponse(); response.setEndpointReference(epr); return response; }
![Page 46: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/46.jpg)
The Code: Service public int add(int arg0) throws RemoteException { Object resource = null; try { resource = ResourceContext.getResourceContext().getResource(); } catch(RemoteException e) { throw e; } catch(Exception e) { throw new RemoteException("", e); } Counter counter = (Counter) resource; int result = counter.getValue(); result += arg0; counter.setValue(result); return result; }
![Page 47: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/47.jpg)
The Code: Resourcepublic class PersistentCounter extends Counter implements RemoveCallback, PersistentResource, ResourceLifetime {
public void setValue(int value) { super.setValue(value); try { store(); } catch (Exception e) { throw new RuntimeException(e.getMessage()); } }
public void setTerminationTime(Calendar time) { super.setTerminationTime(time); try { store(); } catch (Exception e) { throw new RuntimeException(e.getMessage()); } }
![Page 48: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/48.jpg)
The Code: Resource
/** * User-defined function. * * @return the resource key */ public Object create() throws Exception { Object key = super.create(); store(); return key; }
![Page 49: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/49.jpg)
/** * Called when activating a Counter resource by PersistentResourceHome */ public void load(ResourceKey key) throws ResourceException { File file = getKeyAsFile(key.getValue()); if (!file.exists()) { throw new NoSuchResourceException(); } FileInputStream fis = null; int value = 0; try { fis = new FileInputStream(file); ObjectInputStream ois = new ObjectInputStream(fis); value = ois.readInt(); this.terminationTime = (Calendar)ois.readObject(); } catch (Exception e) { throw new ResourceException("Failed to load resource", e); } finally { if (fis != null) { try { fis.close(); } catch (Exception ee) {} } } initialize(key.getValue()); this.value.set(0, new Integer(value)); }
![Page 50: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/50.jpg)
The Code: Resource
public void store() throws ResourceException { FileOutputStream fos = null; try { fos = new FileOutputStream(getKeyAsFile(this.key)); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeInt(((Integer) this.value.get(0)).intValue()); oos.writeObject(this.terminationTime); } catch (Exception e) { throw new ResourceException("Failed to store resource", e); } finally { if (fos != null) { try { fos.close(); } catch (Exception ee) {} } } }
![Page 51: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/51.jpg)
The Code: Resource private static File getKeyAsFile(Object key) throws InvalidResourceKeyException { if (key instanceof Integer) { return new File(key.toString()); } else { throw new InvalidResourceKeyException(); } }
public void remove() throws ResourceException { File f = getKeyAsFile(this.key); f.delete(); }
![Page 52: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/52.jpg)
The Code: Resource Home
public class CounterHome extends PersistentResourceHome {
static Log logger = LogFactory.getLog(CounterHome.class.getName());
public ResourceKey create() throws Exception { Counter counter = (Counter)createNewInstance(); counter.create(); ResourceKey key = new SimpleResourceKey(keyTypeName, counter.getID()); this.resources.put(key, counter); return key; }}
![Page 53: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/53.jpg)
The Code: Configuration<?xml version="1.0" encoding="UTF-8"?><jndiConfig xmlns="http://wsrf.globus.org/jndi/config"> <service name="CounterService"> <resource name="home" type="org.globus.wsrf.samples.counter.CounterHome"> <resourceParams> <parameter> <name>factory</name> <value>org.globus.wsrf.tools.jndi.BeanFactory</value> </parameter> <parameter> <name>resourceClass</name> <value>org.globus.wsrf.samples.counter.PersistentCounter</value> </parameter> <parameter> <name>resourceKeyName</name> <value>{http://counter.com}CounterKey</value> </parameter> <parameter> <name>resourceKeyType</name> <value>java.lang.Integer</value> </parameter> </resourceParams> </resource> </service></jndiConfig>
![Page 54: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/54.jpg)
The Code: Configuration<?xml version="1.0" encoding="UTF-8"?><deployment name="defaultServerConfig" xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <service name="CounterService" provider="Handler" use="literal" style="document"> <parameter name="allowedMethodsClass" value="com.counter.CounterPortType"/> <parameter name="handlerClass" value="org.globus.axis.providers.RPCProvider"/> <parameter name="className" value="org.globus.wsrf.samples.counter.CounterService"/> <wsdlFile>share/schema/core/samples/counter/counter_service.wsdl</wsdlFile> <parameter name="scope" value="Application"/> <parameter name="providers" value=" DestroyProvider SetTerminationTimeProvider GetRPProvider SubscribeProvider GetCurrentMessageProvider"/> </service>
</deployment>
![Page 55: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/55.jpg)
The Code: Clientpublic class CounterClient implements NotifyCallback {
public static void main(String [] args) { CounterServiceAddressingLocator locator = new CounterServiceAddressingLocator(); NotificationConsumerManager consumer = null; try { EndpointReferenceType endpoint = new EndpointReferenceType(); endpoint.setAddress( new Address( "http://localhost:8080/wsrf/services/CounterService")); CounterPortType port = locator.getCounterPortTypePort(endpoint); // Create counter resource _createCounterResponse createResponse = port.createCounter(new _createCounter()); endpoint = createResponse.getEndpointReference(); port = locator.getCounterPortTypePort(endpoint); _Subscribe request = new _Subscribe(); request.setUseNotify(Boolean.TRUE);
![Page 56: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/56.jpg)
The Code: Client // Create client side notification consumer consumer = NotificationConsumerManager.getInstance(); consumer.startListening(); EndpointReferenceType consumerEPR = consumer.createNotificationConsumer(new CounterClient());
request.setConsumerReference(consumerEPR); TopicExpressionType topicExpression = new TopicExpressionType(); topicExpression.setDialect(WSRFConstants.SIMPLE_TOPIC_DIALECT); topicExpression.setValue(Counter.VALUE); request.setTopicExpression(topicExpression); // Subscribe to value port.subscribe(request);
![Page 57: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/57.jpg)
The Code: Client // Add 3 port.add(3); // Sleep so we actually get the notification Thread.sleep(5000); // Get the value RP _GetResourcePropertyResponse getRPResponse = port.getResourceProperty(Counter.VALUE); System.out.println("Counter has value: " + getRPResponse.get_any()[0].getValue()); // Destroy the counter resource port.destroy(new _Destroy()); } catch(Exception e) { e.printStackTrace(); } finally { if (consumer != null) { try { consumer.stopListening(); } catch (Exception ee) {} } }
![Page 58: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/58.jpg)
The Code: Client
// Notification callback public void deliver( List topicPath, EndpointReferenceType producer, Object message) { ResourcePropertyValueChangeNotificationType changeMessage = ((ResourcePropertyValueChangeNotificationElementType) message). getResourcePropertyValueChangeNotification();
if(changeMessage != null) { System.out.println("Got notification with value: " + changeMessage.getNewValue().get_any()[0].getValue()); } }
![Page 59: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/59.jpg)
What is still missing?
GT3 Compatibility Layer More Helper APIs Performance Work Lots of examples Lots of polish Service Group
![Page 60: GT4 WS Core Tutorial Sam Meder {meder@mcs.anl.gov} Jarek Gawor {gawor@mcs.anl.gov} 6/11/04.](https://reader033.fdocuments.us/reader033/viewer/2022051110/5514ba9f550346b0338b459e/html5/thumbnails/60.jpg)
Take A Look
Anonymous CVS: cvs \
-d:pserver:[email protected]:/home/globdev/CVS/globus-packages \login
When asked for a password, please enter your email. cvs \
-d:pserver:[email protected]:/home/globdev/CVS/globus-packages \checkout \wsrf
unset GLOBUS_LOCATION ; cd wsrf ; ant all Installation will end up in wsrf/install Take a look at test services in wsrf/java/core/test/interop