|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.systinet.wasp.webservice.ServiceInstance
ServiceInstance class represents handle for implementation of ServiceEndpoint. Typical usages are as following:
ServiceInstance instance = ServiceInstance.create(HelloService.class); instance.setInstantiationMethod(ServiceInstance.INSTANTIATION_METHOD_PER_CLIENT); instance.set...; ... ServiceEndpoint endpoint = ServiceEndpoint.create("/HelloWorld", instance); Registry.publish(endpoint);Another usage:
ServiceEndpoint endpoint = Registry.getServiceEndpoint("/HelloWorld"); ServiceInstance instance = endpoint.getServiceInstance(); instance.disable();
Field Summary | |
static int |
INSTANTIATION_METHOD_PER_CLIENT
New instance is created for each client. |
static int |
INSTANTIATION_METHOD_SHARED
Clients share common instance. |
Constructor Summary | |
protected |
ServiceInstance()
|
Method Summary | |
static ServiceInstance |
create(java.lang.Class implementationClass)
Creates new service instance. |
static ServiceInstance |
create(java.lang.Object implementationObject)
Creates new service instance. |
static ServiceInstance |
create(java.lang.String implementationClass)
Creates new service instance. |
abstract void |
disable()
Performs transition to the ServiceInstance.Disabled
service state. |
abstract void |
enable()
Performs transition from the Disabled or Offline
states to Enabled state, thus allowing
the service to process requests. |
abstract Attributes |
getAttributes()
Retrieves attributes store bound to this service instance. |
abstract Configurable |
getConfigurable()
Returns the custom configuration of the service instance. |
abstract ServiceInstanceContext |
getContext()
Gets the ServiceInstanceContext object asociated to this
service instance. |
abstract java.lang.Class |
getImplementationClass()
Returns the class implementing this service instance. |
abstract java.lang.String |
getImplementationClassName()
Returns the name of implememntation class. |
abstract java.lang.Object |
getImplementationObject()
Returns the object implementing this service instance creating it, if it does not exist. |
abstract int |
getInstantiationMethod()
Returns the instantiation method. |
abstract int |
getMaxInstances()
Returns maximum count of instances allowed to exist simultaneously for this service. |
abstract java.lang.String |
getResource(java.lang.String path)
Returns the resource with the given name or null if the resource could not be found. |
abstract java.io.InputStream |
getResourceAsStream(java.lang.String path)
Returns an input stream for reading the specified resource. |
abstract int |
getState()
Returns service state of this service instance. |
abstract long |
getTTL()
This setting is valid only for per-client instantiated service. |
abstract void |
kill()
Forces service instance in Active and Enabled states to go to Disabled
without waiting for the active request to complete. |
abstract void |
log(java.lang.String msg)
Logs a message. |
abstract void |
log(java.lang.String message,
java.lang.Throwable throwable)
Logs a message and exception. |
abstract void |
setConfigurable(Configurable serviceConfig)
Sets the custom configuration of the service instance. |
abstract void |
setImplementationClass(java.lang.Class implementationClass)
Sets implementation class. |
abstract void |
setImplementationObject(java.lang.Object implementationObject)
Sets implementation object. |
abstract void |
setInstantiationMethod(int instantiationMethod)
Sets the instantiation method. |
abstract void |
setMaxInstances(int maxInstances)
This setting is valid only for per-client instantiated service. |
abstract void |
setTTL(long seconds)
This setting is valid only for per-client instantiated service. |
abstract void |
waitForState(int states)
Waits for the service instance to enter one of given state. |
abstract boolean |
waitForState(int states,
long timeout)
Waits for the service instance to enter one of s given states. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int INSTANTIATION_METHOD_SHARED
setInstantiationMethod(int)
and getInstantiationMethod()
.
public static final int INSTANTIATION_METHOD_PER_CLIENT
setInstantiationMethod(int)
and getInstantiationMethod()
.
Constructor Detail |
protected ServiceInstance()
Method Detail |
public static ServiceInstance create(java.lang.Object implementationObject)
implementationObject
- the object implementing the servicepublic static ServiceInstance create(java.lang.Class implementationClass)
implementationClass
- the class implementing the servicepublic static ServiceInstance create(java.lang.String implementationClass)
implementationClass
- the class implementing the service. Can be in various formats such
a fully qualified java class name, JNDI name etc. depending on existing instantiation listeners.public abstract Configurable getConfigurable()
public abstract void setConfigurable(Configurable serviceConfig)
serviceConfig
- the configuration of the servicepublic abstract ServiceInstanceContext getContext()
ServiceInstanceContext
object asociated to this
service instance.
ServiceInstanceContext
object or
null
if it does not existpublic abstract java.lang.Object getImplementationObject() throws java.lang.ClassNotFoundException, java.lang.InstantiationException, java.lang.IllegalAccessException
java.lang.ClassNotFoundException
- if implementationClassName
was specified (i.e. for deployed services) and the class was
not found
java.lang.InstantiationException
- if implementationClassName
was specified (i.e. for deployed services) or
implementationClass
was specified and there was
a problem with instantiation
java.lang.IllegalAccessException
- if implementationClassName
was specified (i.e. for deployed services) and the class was not
publicgetImplementationClass()
public abstract java.lang.Class getImplementationClass() throws java.lang.ClassNotFoundException
java.lang.ClassNotFoundException
getImplementationObject()
public abstract java.lang.String getImplementationClassName()
public abstract int getInstantiationMethod()
INSTANTIATION_METHOD_PER_CLIENT
or
INSTANTIATION_METHOD_SHARED
public abstract void setInstantiationMethod(int instantiationMethod) throws java.lang.IllegalStateException
instantiationMethod
- set to
INSTANTIATION_METHOD_PER_CLIENT
or
INSTANTIATION_METHOD_SHARED
java.lang.IllegalStateException
- when service instance is already initialized(service endpoint was published)public abstract long getTTL()
setTTL(long)
.
After last request,if no further request comes in speciefed amount of time, created instance is disposed.
For setting instantiation method see setInstantiationMethod(int)
.
public abstract void setTTL(long seconds)
setInstantiationMethod(int)
.
seconds
- the default time-to-live in seconds, negative value = live
foreverpublic abstract int getMaxInstances()
for further details.
public abstract void setMaxInstances(int maxInstances)
maxInstances
- maximum count of instances allowed, 0 = no
limitpublic abstract int getState()
ServiceState
public abstract void disable() throws java.lang.IllegalStateException, InvalidStateTransitionException
ServiceInstance.Disabled
service state. For more information see documentation about service
states and their transition diagram.
This method is non-blocking.
Use waitForState(ServiceState.DISABLED)
to wait for
the disabled state.
java.lang.IllegalStateException
- when this service instance is not registrated( is not referenced by already
published service endpoint)
InvalidStateTransitionException
- when this service instance transition is not possiblepublic abstract void enable() throws java.lang.IllegalStateException, InvalidStateTransitionException
Disabled
or Offline
states to Enabled
state, thus allowing
the service to process requests.
This method is non-blocking.
Use waitForState(ServiceState.ENABLED | ServiceState.ACTIVE)
to wait for
the enabled state.
java.lang.IllegalStateException
- when this service instance is not registrated( is not referenced by already
published service endpoint)
InvalidStateTransitionException
- when this service instance transition is not possiblepublic abstract void kill() throws java.lang.IllegalStateException, InvalidStateTransitionException
Active
and Enabled
states to go to Disabled
without waiting for the active request to complete. The active connections are abandoned.
Furthermore, if service instance implements Initializable
,
destroy
is NOT processed.
If service instance is already in Initializing or Destroying states and either init() or destroy() is taking place, this method causes interrupting of these methods and transition to Disabled state.
Note: use with care - this method is unsafe and does not terminate active connections properly. It can thus lead to unpredictable behavior. This method is blocking.
java.lang.IllegalStateException
- when this service instance is not registrated( is not referenced by already
published service endpoint)
InvalidStateTransitionException
- when this service instance transition is not possiblepublic abstract void waitForState(int states) throws java.lang.InterruptedException
states
- bitwise mask of service states to wait for. See ServiceState
java.lang.InterruptedException
public abstract boolean waitForState(int states, long timeout) throws java.lang.InterruptedException
states
- bitwise mask of service states to wait fortimeout
- upper bound of time in milliseconds to wait for
service instance to enter required state
false
when timeout interval expires without the
service instance entering given state, true
otherwise
java.lang.InterruptedException
public abstract java.lang.String getResource(java.lang.String path)
null
if the resource could not be found.
The name of a resource is a "/"-separated path name that
identifies the resource.
For the path name "/" returns absolute path of the root directory
of the web service context represented by this instance.
Note, that The "/" path returns valid data only for persistently deployed
services.
path
- path of the resource
public abstract java.io.InputStream getResourceAsStream(java.lang.String path) throws java.io.IOException
null
if the resource could not be found.
path
- path of the resource
java.io.IOException
- if something goes wrongpublic abstract void log(java.lang.String msg)
msg
- message to be loggedpublic abstract void log(java.lang.String message, java.lang.Throwable throwable)
message
- the message to be loggedthrowable
- the exception to be loggedpublic abstract void setImplementationClass(java.lang.Class implementationClass) throws java.lang.IllegalStateException
implementationClass
- implementation class
java.lang.IllegalStateException
- when this service instance is already registrated( is referenced by already
published service endpoint)public abstract void setImplementationObject(java.lang.Object implementationObject) throws java.lang.IllegalStateException
implementationObject
- implementation object
java.lang.IllegalStateException
- when this service instance is already registrated( is referenced by already
published service endpoint)public abstract Attributes getAttributes()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |