Java Doc for StatefulWebServiceManager.java in  » 6.0-JDK-Modules » jax-ws-runtime » com » sun » xml » ws » developer » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » jax ws runtime » com.sun.xml.ws.developer 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


com.sun.xml.ws.developer.StatefulWebServiceManager

StatefulWebServiceManager
public interface StatefulWebServiceManager (Code)
Stateful web service support in the JAX-WS RI.

Usage

Application service implementation classes (or providers) who'd like to use the stateful web service support must declare Stateful annotation on a class. It should also have a public static method/field that takes StatefulWebServiceManager .

 @
Stateful  @
WebService class BankAccount {
 protected final int id;
 private int balance;
 BankAccount(int id) { this.id = id; }
 @
WebMethod public synchronized void deposit(int amount) { balance+=amount; }
 // either via a public static field
 
 public static 
StatefulWebServiceManager <BankAccount> manager;
 
 // ... or  via a public static method (the method name could be anything)
 
 public static void setManager(
StatefulWebServiceManager <BankAccount> manager) {
 ...
 }
 
 }
 

After your service is deployed but before you receive a first request, the resource injection occurs on the field or the method.

A stateful web service class does not need to have a default constructor. In fact, most of the time you want to define a constructor that takes some arguments, so that each instance carries certain state (as illustrated in the above example.)

Each instance of a stateful web service class is identified by an unique EndpointReference . Your application creates an instance of a class, then you'll have the JAX-WS RI assign this unique EPR for the instance as follows:

 @
WebService class Bank { // this is ordinary stateless service
 @
WebMethod public synchronized W3CEndpointReference login(int accountId, int pin) {
 if(!checkPin(pin))
 throw new AuthenticationFailedException("invalid pin");
 BankAccount acc = new BankAccount(accountId);
 return BankAccount.manager.
StatefulWebServiceManager.export export (acc);
 }
 }
 

Typically you then pass this EPR to remote systems. When they send messages to this EPR, the JAX-WS RI makes sure that the particular exported instance associated with that EPR will receive a service invocation.

Things To Consider

When you no longer need to tie an instance to the EPR, use StatefulWebServiceManager.unexport(Object) so that the object can be GC-ed (or else you'll leak memory.) You may choose to do so explicitly, or you can rely on the time out by using StatefulWebServiceManager.setTimeout(long,Callback) .

StatefulWebServiceManager is thread-safe. It can be safely invoked from multiple threads concurrently.
author:
   Kohsuke Kawaguchi
See Also:   StatefulFeature
since:
   2.1


Inner Class :interface Callback



Method Summary
 EPRexport(Class<EPR> epr, T o)
     Exports an object.
 EPRexport(Class<EPR> epr, T o, EPRRecipe recipe)
     Exports an object.

This method works like StatefulWebServiceManager.export(Object) except that you can obtain the EPR in your choice of addressing version, by passing in the suitable epr parameter.
Parameters:
  epr - Either W3CEndpointReference or MemberSubmissionEndpointReference.If other types are specified, this method throws an WebServiceException.
Parameters:
  o - The object to be exported, whose identity be referenced by the returned EPR.
Parameters:
  recipe - The additional data to be put into EPR.

 W3CEndpointReferenceexport(T o)
     Exports an object.

JAX-WS RI assigns an unique EPR to the exported object, and from now on, messages that are sent to this EPR will be routed to the given object.

The object will be locked in memory, so be sure to StatefulWebServiceManager.unexport(Object) unexport it when it's no longer needed.

Notice that the obtained EPR contains the address of the service, which depends on the currently processed request.

 EPRexport(Class<EPR> eprType, WebServiceContext context, T o)
     Exports an object (for AsyncProvider asynchronous web services .)

This method works like StatefulWebServiceManager.export(Class,Object) but it takes an extra WebServiceContext that represents the request currently being processed by the caller (the JAX-WS RI remembers this when the service processing is synchronous, and that's why this parameter is only needed for asynchronous web services.)

Why WebServiceContext is needed?

The obtained EPR contains address, such as host name.

 EPRexport(Class<EPR> eprType, Packet currentRequest, T o)
     Exports an object.

This method is not meant for application code. This is for Tube s that wish to use stateful web service support.
Parameters:
  currentRequest - The request that we are currently processing.

 EPRexport(Class<EPR> eprType, Packet currentRequest, T o, EPRRecipe recipe)
     The same as StatefulWebServiceManager.export(Class,Packet,Object) except that it takes EPRRecipe .
 EPRexport(Class<EPR> eprType, String endpointAddress, T o)
     Exports an object.
Parameters:
  endpointAddress - The endpoint address URL.
 Tresolve(EndpointReference epr)
     Checks if the given EPR represents an object that has been exported from this manager.
 voidsetFallbackInstance(T o)
     Sets the "fallback" instance.

When the incoming request does not have the necessary header to distinguish instances of T, or when the header is present but its value does not correspond with any of the active exported instances known to the JAX-WS, then the JAX-WS RI will try to route the request to the fallback instance.

This provides the application an opportunity to perform application specific error recovery.

If no fallback instance is provided, then the JAX-WS RI will send back the fault.

 voidsetTimeout(long milliseconds, Callback<T> callback)
     Configures timeout for exported instances.

When configured, the JAX-WS RI will internally use a timer so that exported objects that have not received any request for the given amount of minutes will be automatically unexported.

At some point after the time out has occurred for an instance, the JAX-WS RI will invoke the Callback to notify the application that the time out has reached.

 voidtouch(T o)
     Resets the time out timer for the given instance.
 voidunexport(T o)
     Unexports the given instance.



Method Detail
export
EPR export(Class<EPR> epr, T o)(Code)
Exports an object.

This method works like StatefulWebServiceManager.export(Object) except that you can obtain the EPR in your choice of addressing version, by passing in the suitable epr parameter.
Parameters:
  epr - Either W3CEndpointReference or MemberSubmissionEndpointReference.If other types are specified, this method throws an WebServiceException.EndpointReference-subclass that identifies this exportedobject.




export
EPR export(Class<EPR> epr, T o, EPRRecipe recipe)(Code)
Exports an object.

This method works like StatefulWebServiceManager.export(Object) except that you can obtain the EPR in your choice of addressing version, by passing in the suitable epr parameter.
Parameters:
  epr - Either W3CEndpointReference or MemberSubmissionEndpointReference.If other types are specified, this method throws an WebServiceException.
Parameters:
  o - The object to be exported, whose identity be referenced by the returned EPR.
Parameters:
  recipe - The additional data to be put into EPR. Can be null.EndpointReference-subclass that identifies this exportedobject.
since:
   2.1.1




export
W3CEndpointReference export(T o)(Code)
Exports an object.

JAX-WS RI assigns an unique EPR to the exported object, and from now on, messages that are sent to this EPR will be routed to the given object.

The object will be locked in memory, so be sure to StatefulWebServiceManager.unexport(Object) unexport it when it's no longer needed.

Notice that the obtained EPR contains the address of the service, which depends on the currently processed request. So invoking this method multiple times with the same object may return different EPRs, if such multiple invocations are done while servicing different requests. (Of course all such EPRs point to the same object, so messages sent to those EPRs will be served by the same instance.) W3CEndpointReference that identifies this exportedobject. Always non-null.




export
EPR export(Class<EPR> eprType, WebServiceContext context, T o)(Code)
Exports an object (for AsyncProvider asynchronous web services .)

This method works like StatefulWebServiceManager.export(Class,Object) but it takes an extra WebServiceContext that represents the request currently being processed by the caller (the JAX-WS RI remembers this when the service processing is synchronous, and that's why this parameter is only needed for asynchronous web services.)

Why WebServiceContext is needed?

The obtained EPR contains address, such as host name. The server does not know what its own host name is (or there are more than one of them), so this value is determined by what the current client thinks the server name is. This is why we need to take WebServiceContext . Pass in the object given to AsyncProvider.invoke(ObjectAsyncProviderCallbackWebServiceContext) .




export
EPR export(Class<EPR> eprType, Packet currentRequest, T o)(Code)
Exports an object.

This method is not meant for application code. This is for Tube s that wish to use stateful web service support.
Parameters:
  currentRequest - The request that we are currently processing. This is used to infer the address in EPR.
See Also:   StatefulWebServiceManager.export(Class,WebServiceContext,Object)




export
EPR export(Class<EPR> eprType, Packet currentRequest, T o, EPRRecipe recipe)(Code)
The same as StatefulWebServiceManager.export(Class,Packet,Object) except that it takes EPRRecipe .
Parameters:
  recipe - See StatefulWebServiceManager.export(Class,Object,EPRRecipe).



export
EPR export(Class<EPR> eprType, String endpointAddress, T o)(Code)
Exports an object.
Parameters:
  endpointAddress - The endpoint address URL. Normally, this information is determined by other inputs,like Packet or WebServiceContext.



resolve
T resolve(EndpointReference epr)(Code)
Checks if the given EPR represents an object that has been exported from this manager.

This method can be used to have two endpoints in the same application communicate locally. null if the EPR is not exported from this manager.




setFallbackInstance
void setFallbackInstance(T o)(Code)
Sets the "fallback" instance.

When the incoming request does not have the necessary header to distinguish instances of T, or when the header is present but its value does not correspond with any of the active exported instances known to the JAX-WS, then the JAX-WS RI will try to route the request to the fallback instance.

This provides the application an opportunity to perform application specific error recovery.

If no fallback instance is provided, then the JAX-WS RI will send back the fault. By default, no fallback instance is set.

This method can be invoked any time, but most often you'd like to use one instance at the get-go. The following code example illustrates how to do this:

 @
WebService class BankAccount {
 ... continuting from the example in class javadoc ...
 @
Resource  static void setManager(
StatefulWebServiceManager  manager) {
 manager.setFallbackInstance(new BankAccount(0) {
 @
Override void deposit(int amount) {
 putToAuditRecord(id);
 if(thisLooksBad())   callPolice();
 throw new 
WebServiceException ("No such bank account exists");
 }
 });
 }
 }
 

Parameters:
  o - Can be null.



setTimeout
void setTimeout(long milliseconds, Callback<T> callback)(Code)
Configures timeout for exported instances.

When configured, the JAX-WS RI will internally use a timer so that exported objects that have not received any request for the given amount of minutes will be automatically unexported.

At some point after the time out has occurred for an instance, the JAX-WS RI will invoke the Callback to notify the application that the time out has reached. Application then has a choice of either let the object go unexported, or StatefulWebServiceManager.touch(Object) touch let the object live for another round of timer interval.

If no callback is set, the expired object will automatically unexported.

When you call this method multiple times, its effect on existing instances are unspecified, although deterministic.
Parameters:
  milliseconds - The time out interval. Specify 0 to cancel the timeout timer.Note that this only guarantees that time out does not occurat least until this amount of time has elapsed. It does notguarantee that the time out will always happen right afterthe timeout is reached.
Parameters:
  callback - application may choose to install a callback to control thetimeout behavior.




touch
void touch(T o)(Code)
Resets the time out timer for the given instance.

If the object is null, not exported, or already unexported, this method will be no-op.




unexport
void unexport(T o)(Code)
Unexports the given instance.

JAX-WS will release a strong reference to unexported objects, and they will never receive further requests (requests targeted for those unexported objects will be served by the fallback object.)
Parameters:
  o - if null, this method will be no-op.




www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.