net.larsan.urd.impl
Class Servicebox

java.lang.Object
  |
  +--net.larsan.urd.jndi.ContextBase
        |
        +--net.larsan.urd.jndi.ContextImpl
              |
              +--net.larsan.urd.impl.Servicebox
All Implemented Interfaces:
java.lang.Cloneable, javax.naming.Context, Destroyable, javax.naming.event.EventContext, ShutdownListener

public class Servicebox
extends ContextImpl
implements Destroyable, ShutdownListener

The service box 'boxes' an given service from it's archive or folder location. The box is responsible for the service class loader and also acts as the context node for the service.

Version:
Alpha-0.1 / 2002-10-06 21:37
Author:
Lars J. Nilsson

Field Summary
 
Fields inherited from class net.larsan.urd.jndi.ContextBase
ACCESS_PERMISSION, env, handler, localName, nameParser, parent, port, root, ROOT_ADDRESS, ROOT_PORT
 
Fields inherited from interface javax.naming.event.EventContext
OBJECT_SCOPE, ONELEVEL_SCOPE, SUBTREE_SCOPE
 
Fields inherited from interface javax.naming.Context
APPLET, AUTHORITATIVE, BATCHSIZE, DNS_URL, INITIAL_CONTEXT_FACTORY, LANGUAGE, OBJECT_FACTORIES, PROVIDER_URL, REFERRAL, SECURITY_AUTHENTICATION, SECURITY_CREDENTIALS, SECURITY_PRINCIPAL, SECURITY_PROTOCOL, STATE_FACTORIES, URL_PKG_PREFIXES
 
Constructor Summary
Servicebox(javax.naming.Context parentContext, java.lang.String localName, ServiceArchive archive, Parameters params)
          Create service box with a service archive to read from.
 
Method Summary
 void destroy()
          Destroy servicebox.
 ServiceMetaData getMetaData()
          Get service meta data.
 java.lang.String getNamespaceID()
          Get service namspace ID
 Service getService()
          Get the service instance.
 java.lang.String getSourceName()
          Get the service source name.
 Status getStatus()
          Get the reported status of the boxed service.
 void kill(DefaultErrorHandler errorHandler)
          Stop and unload/destroy service.
 void shutdownWarning(long ttl)
          Thsi method might be called by the framework before module shutdown.
 void start(DefaultErrorHandler errorHandler)
          Start service.
 void stop(DefaultErrorHandler errorHandler)
          Stop service.
 
Methods inherited from class net.larsan.urd.jndi.ContextImpl
bind, clone, close, composeName, createSubcontext, destroySubcontext, getNameParser, hashCode, list, listBindings, lookup, lookupLink, rebind, rename, toString, unbind
 
Methods inherited from class net.larsan.urd.jndi.ContextBase
addNamingListener, addNamingListener, addToEnvironment, bind, checkAccess, composeName, createSubcontext, destroySubcontext, findRootContext, getEnvironment, getEventHandler, getNameInNamespace, getNameParser, getParent, list, listBindings, lookup, lookupLink, objectAdded, objectRemoved, objectRenamed, rebind, removeFromEnvironment, removeNamingListener, rename, setHandler, targetMustExist, unbind
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Servicebox

public Servicebox(javax.naming.Context parentContext,
                  java.lang.String localName,
                  ServiceArchive archive,
                  Parameters params)
           throws javax.naming.NamingException,
                  java.lang.ClassNotFoundException,
                  java.lang.InstantiationException,
                  java.io.IOException
Create service box with a service archive to read from. The service archive must exist a contain a 'Norna-Service' attribute for the service box to succed.

Parameters:
parentContext - Service parent JNDI context, must be a ContextBase
localName - Local context name
archive - Norna archive to read the service from, must not be null
params - Service parameters, must not be null
Throws:
javax.naming.NamingException - On context errors
java.lang.InstantiationException - If the service class cannot be created
java.lang.ClassNotFoundException - If the service class is not found in the archive
java.io.IOException - On IO errors
Method Detail

getNamespaceID

public java.lang.String getNamespaceID()
Get service namspace ID


shutdownWarning

public void shutdownWarning(long ttl)
Description copied from interface: ShutdownListener
Thsi method might be called by the framework before module shutdown. The millisecond argument is the minimum time the module have to do it's cleanup and the framework should not violate this given time unless forced by a runtime error.

Specified by:
shutdownWarning in interface ShutdownListener
Parameters:
ttl - Time to live, minimum time in milliseconds until the stop event may occur

getMetaData

public ServiceMetaData getMetaData()
Get service meta data.

Returns:
Meta data about the boxed service

getService

public Service getService()
Get the service instance.

Returns:
A service instance

start

public void start(DefaultErrorHandler errorHandler)
Start service. This will take place on a new thread.

Parameters:
errorHandler - Error handler to report errors to

stop

public void stop(DefaultErrorHandler errorHandler)
Stop service.

Parameters:
errorHandler - Error handler to report errors to

kill

public void kill(DefaultErrorHandler errorHandler)
Stop and unload/destroy service.

Parameters:
errorHandler - Error handler to report errors to

getSourceName

public java.lang.String getSourceName()
Get the service source name. For file sources this should return the archive name with the extension stripped away.

Returns:
The service source name

destroy

public void destroy()
Destroy servicebox. This immediately disposes of eny references this service box is still holding but does not stop or unload the service itself.

Any attempt to call a method on a destroyed servicebox will relst in a illegal state exception.

Specified by:
destroy in interface Destroyable

getStatus

public Status getStatus()
Get the reported status of the boxed service.

Returns:
The service status