|
Page Created :
CXF20DOC :
Multiplexed EndpointReferences
Multiplexed EndpointReferences has been created by Gary Tully (Apr 20, 2007). Content:Support for Multiplexed EndpointReferences in CXF allows a single stateless service instance to represent/impersonate multiple service instances. The single service does not maintain any state itself, but instead uses attributes of the current target EndpointReference to identify instance data. The piggybacking of state in an EndpointReference is a form of applicaion level multiplexing. To illustrate, consider a simple web service called Number that represents an integer and suports a single operation isEven that returns true iff the Number is even. Consider also a NumberFactory service that returns Endpoint References(EPRs) to Numbers through an operation create(int). A typical implementation of NumberFactory.create() would instanciate and publish an endpoint for each requested integer value, returning the corresponding EPR to the caller. Given the infinite set of possible Number values, this implementation would scale poorly as the number of calls to create different values increase. Enter multiplexed endpoint references. The implementation of NumberFactory.create() instanciates and publishes a single template service. Then for each unique value of Number, the implementation generates (using a CXF API) a multiplexed EPR for that particular value. This EPR is returned to the caller. The implementation of the single template Number service needs a mechanism to determine its current state or value. It gets this from CXF based on the target EndpointReference. It then proceeds to determine if the current value is even and returns the result to the caller. In this way, a single service instance can represent all possible Numbers, the only state is embedded in the multiplexed endpoint references that are maintained by the callers. Here is skeleton implementation of NumberFactory.create(): EndpointReferenceType create(int val) {
synchronized (this) {
if (!servicePublished) {
publishSingleInstanceServant(SERVICE_QNAME);
servicePublished = true;
}
}
String state = String.valueOf(val);
String portName = null; // unless there are multiple ports in the service
return EndpointReferenceUtils.getEndpointReferenceWithId(SERVICE_QNAME,
portName, state, BusFactory.getDefaultBus());
}
|
Unsubscribe or edit your notifications preferences
