net.larsan.urd.impl
Class ContainerBase

java.lang.Object
  |
  +--net.larsan.urd.jndi.ContextBase
        |
        +--net.larsan.urd.jndi.ContextImpl
              |
              +--net.larsan.urd.impl.ContainerBase
All Implemented Interfaces:
java.lang.Cloneable, Container, javax.naming.Context, Destroyable, javax.naming.event.EventContext
Direct Known Subclasses:
DirectoryContainer

public abstract class ContainerBase
extends ContextImpl
implements Container, Destroyable

A container is an abstraction for a place from which one or more service is excpected to be loaded. The container is responsible for the lifecycle of it's 'children'.

This class is abstract to allow containers to load classes from different source types.

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

Field Summary
protected  boolean autoStart
          Autostart services.
protected  DefaultErrorHandler errorHandler
          Error handle for the container
protected  java.lang.String name
          Local namespace name.
 
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
ContainerBase(ContextBase parentContext, java.lang.String localName)
          Create container
 
Method Summary
protected  void autoStart(Servicebox box)
          Autostart a service.
 void destroy()
          Destroy component.
 void doAutoStarts()
          Attempt to start all autostart services.
 java.lang.String findServiceID(java.lang.String url)
          Resolve a service URL into an id.
 boolean getAutoStart()
          Determine if the services within this contianer should be auto-started.
protected  Servicebox getByIdImpl(java.lang.String id)
          Get service by id.
protected  Servicebox getByURLImpl(java.lang.String url)
          Get service by url.
protected abstract  java.lang.String getContainerID()
          Get the container id.
 ListInfo info(java.lang.String serviceId)
          Get if no for a particular service.
 void init(DefaultErrorHandler errorHandler)
          Initiate the container.
 ListInfo[] list()
          List all service within this container.
protected  Servicebox removeServiceImpl(java.lang.String url)
          Remove a service by URL.
 void setAutoStart(boolean autoStart)
          Set if the services within this container should be auto-started.
protected  void setServiceImpl(java.lang.String cuid, Servicebox box)
          Add a service to the container collection.
 void start(java.lang.String serviceId)
          Start a single service.
 void stop(java.lang.String serviceId)
          Stop a single 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
 

Field Detail

name

protected java.lang.String name
Local namespace name.


errorHandler

protected DefaultErrorHandler errorHandler
Error handle for the container


autoStart

protected boolean autoStart
Autostart services.

Constructor Detail

ContainerBase

public ContainerBase(ContextBase parentContext,
                     java.lang.String localName)
Create container

Parameters:
parentContext - Container JNDI context
localName - Local context name of the container
Method Detail

getContainerID

protected abstract java.lang.String getContainerID()
Get the container id. This id will be used for thread names and error reporting.

Returns:
A unique name for this container

getAutoStart

public boolean getAutoStart()
Determine if the services within this contianer should be auto-started.


setAutoStart

public void setAutoStart(boolean autoStart)
Set if the services within this container should be auto-started.


init

public void init(DefaultErrorHandler errorHandler)
          throws ContainerException
Initiate the container. This should list all services and check their validity but not initiate or start them.

Parameters:
errorHandler - Error handle for this container
Throws:
ContainerException - Id the container cannot start

start

public void start(java.lang.String serviceId)
           throws NoSuchServiceException
Start a single service. This will be done on a separate threads. Exceptions from individual services will be reported through the error handler.

Specified by:
start in interface Container
Parameters:
serviceId - Service name to start
Throws:
NoSuchServiceException - If the service is not found

stop

public void stop(java.lang.String serviceId)
          throws NoSuchServiceException
Stop a single service. This will be done on a separate threads. Exceptions from individual services will be reported through the error handler.

Specified by:
stop in interface Container
Parameters:
serviceId - Service id to start
Throws:
NoSuchServiceException - If the service is not found

info

public ListInfo info(java.lang.String serviceId)
              throws NoSuchServiceException
Get if no for a particular service. Throws an exception if the service id is not found.

Specified by:
info in interface Container
Returns:
A list info obejct for the service
Throws:
NoSuchServiceException - If the service is not found

doAutoStarts

public void doAutoStarts()
Attempt to start all autostart services. If the container is marked as auto-start all service auto-start by default if not explicitly saying 'false'

Specified by:
doAutoStarts in interface Container

findServiceID

public java.lang.String findServiceID(java.lang.String url)
Resolve a service URL into an id. This method return null if the service is not found.

Specified by:
findServiceID in interface Container
Parameters:
url - Service URL to look for
Returns:
The service id matching the URL

list

public ListInfo[] list()
List all service within this container.

Specified by:
list in interface Container
Returns:
A service info array

destroy

public void destroy()
Destroy component.

Specified by:
destroy in interface Destroyable

autoStart

protected void autoStart(Servicebox box)
Autostart a service. This method check the container auto-start value and the service value.


getByIdImpl

protected Servicebox getByIdImpl(java.lang.String id)
Get service by id. This method returns null if the service is not found

Parameters:
id - Service id
Returns:
The service box for the service, or null if not found

getByURLImpl

protected Servicebox getByURLImpl(java.lang.String url)
Get service by url. This method returns null if the service is not found

Parameters:
url - Service context url
Returns:
The service box for the service, or null if not found

removeServiceImpl

protected Servicebox removeServiceImpl(java.lang.String url)
                                throws javax.naming.NamingException
Remove a service by URL. This method return null if the service does not exist.

Parameters:
url - Service context url
Returns:
The service box for the service, or null if not found
javax.naming.NamingException

setServiceImpl

protected void setServiceImpl(java.lang.String cuid,
                              Servicebox box)
                       throws javax.naming.NamingException,
                              AlreadyRegisteredException
Add a service to the container collection. This will produce a url for the service using the path prefix for this container.

Parameters:
cuid - Service id within the container
box - Service to add, must not be null
javax.naming.NamingException
AlreadyRegisteredException