jrunx.kernel
Class ServiceAdapter

jrunx.kernel.ServiceAdapter
All Implemented Interfaces:
javax.naming.Referenceable, java.io.Serializable, Service, ServiceMBean
Direct Known Subclasses:
AbstractInterceptor, ClusterTransactionCoordinator, CustomInstrumentor, DeploymentService, EntityInstanceCache, EntityPersistenceManager, HtmlAgentService, J2EEModuleFactory, JMSSecurityManager, JMSServiceAdapter, JMSServiceWrapper, JRunAdminService, JRunSecurityManagerService, JRunUserManagerService, MailService, MethodInstrumentor, MetricsService, NamingService, ObjectPoolService, ReplicationIdService, ResourceDeployer, ServerSessionPoolService, ServicePartition, SessionIdGeneratorService, SimpleInstancePool, StatefulSessionInstanceCache, StatefulSessionPersistenceManager, ThreadPoolService, TXDomainService, Watcher, XDocletService

public abstract class ServiceAdapter
implements ServiceMBean, javax.naming.Referenceable

Default JRun Service, designed to provide convenience implementations of registration methods, JRun Service methods, and default JMX Notification support.

ServiceAdapter should be extended in order to plug a new Service into JRun. If the new Service is intended to hold other Services, then ServicePartition should be extended instead.

Author:
PS Neville, Karl Moss

See Also:
ServiceMBean, ServicePartition, Serialized Form

Field Summary
static boolean DEFAULT_DEACTIVATED
           
static java.lang.String DEFAULT_DOMAIN
           
static java.lang.String DOMAIN_NAME_SEPARATOR
           
static java.lang.String DOMAIN_NAME_SUFFIX
           
protected  java.lang.String domainName
          The domain name of the Service
protected  boolean jndiBindable
          By default, do not bind to JNDI
static int LOGGER_CACHE_TIME
           
static java.lang.String SCHEDULER_SERVICE
           
static java.lang.String SECURITY_MANAGER
           
protected  javax.management.MBeanServer server
          Every Service knows its Server upon registration.
 int status
          Every Service knows it current status.
static java.lang.String TRANSACTION_MANAGER
           
 
Fields inherited from interface jrunx.kernel.Service
INITIALIZED, STARTED, STARTING, STOPPED, STOPPING, UNINITIALIZED
 
Constructor Summary
ServiceAdapter()
           
 
Method Summary
 void bind()
          Bind the Service to JNDI.
 void destroy()
          Every service is eventually destroyed.
 javax.management.ObjectInstance findObjectInstance(java.lang.String name)
          Finds the named service within the JMX framework.
 javax.management.ObjectInstance findObjectInstance(java.lang.String name, boolean required)
          Finds a required service.
 javax.management.ObjectInstance findObjectInstance(java.lang.String name, java.lang.String domain)
           
 boolean getBindToJNDI()
           
 boolean getDeactivated()
          Check if the service is deactivated and should not be started
 java.lang.String getDomainName()
          Retrieve the domain name of this service.
protected  java.lang.String getDomainSearchPath()
          Gets the name of the domain that we need to search in.
 java.lang.Object getJRunService()
           
 Logger getLogger()
          Returns an instance of the current logger for this context
 java.lang.String getName()
          Retrieve the String version of the Service's JMX ObjectName.
 ServiceMBean getParentService()
          Gets the parent service of this service, or null if not part of a ConfigurableServicePartition
 javax.naming.Reference getReference()
           
 ResourceManager getResourceManager(java.lang.String path)
          Convenience method for getting a ResourceManager
 java.lang.String getServerName()
          Gets the current server name
protected  java.util.Properties getServerProperties()
          Returns a list of server properties use for dynamic variable substitution.
 int getStatus()
           
 void init()
          Not every service needs to init, implement it out of convenience.
 java.lang.Object invokeMethod(javax.management.ObjectName objName, java.lang.String method, java.lang.Object[] params, java.lang.String[] types)
          Invoke a method on a Service using its ObjectName.
 boolean isInPartition()
          Determines if this service is in a partition
 boolean isPartition()
          Determines if this service is a partition
 java.lang.Object lookup(java.lang.String name)
          Convenience method for looking up a named service in the JNDI context.
 void postDeregister()
          Override for additional functionality after being removed from the server.
 void postRegister(java.lang.Boolean b)
          Override for additional functionality after registration time.
 void preDeregister()
          Override for additional functionality before removal time.
 javax.management.ObjectName preRegister(javax.management.MBeanServer server, javax.management.ObjectName name)
          Override for additional functionality at registration time.
 javax.management.MBeanServer requestServer()
          Every service may report its server by reference.
 void scheduleRunnable(java.lang.Runnable runnable, long msFromNow)
          Schedule a runnable to execute using the standard SchedulerService
 void setBindToJNDI(boolean b)
           
 void setDeactivated(boolean deactivated)
          Deactivate the service to prevent it from being started
 void setDomainName(java.lang.String name)
          Set the domain name of the partition's internal MBeanServer.
 void setName(java.lang.String n)
          Set the JMX ObjectName of this Service using a String.
 void setParentService(ServiceMBean parent)
          Sets the parent service of this service.
 void start()
          Every service other than mere data collections should start
 void stop()
          Every service other than mere data collections should stop
 java.lang.String toString()
           
 void unbind()
          Unbind the service form the JNDI tree.
 void unscheduleRunnable(java.lang.Runnable runnable)
          Unschedule a runnable to execute using the standard SchedulerService
 void updateStatus(int n)
          This is not a 'set' method in order to avoid exposing it as an automatically writable attribute.
 

Field Detail

server

protected transient javax.management.MBeanServer server
Every Service knows its Server upon registration.

status

public int status
Every Service knows it current status.

jndiBindable

protected boolean jndiBindable
By default, do not bind to JNDI

domainName

protected java.lang.String domainName
The domain name of the Service

DEFAULT_DEACTIVATED

public static final boolean DEFAULT_DEACTIVATED

DEFAULT_DOMAIN

public static final java.lang.String DEFAULT_DOMAIN

DOMAIN_NAME_SEPARATOR

public static final java.lang.String DOMAIN_NAME_SEPARATOR

DOMAIN_NAME_SUFFIX

public static final java.lang.String DOMAIN_NAME_SUFFIX

SCHEDULER_SERVICE

public static final java.lang.String SCHEDULER_SERVICE

TRANSACTION_MANAGER

public static final java.lang.String TRANSACTION_MANAGER

SECURITY_MANAGER

public static final java.lang.String SECURITY_MANAGER

LOGGER_CACHE_TIME

public static final int LOGGER_CACHE_TIME
Constructor Detail

ServiceAdapter

public ServiceAdapter()
Method Detail

init

public void init()
          throws java.lang.Exception
Not every service needs to init, implement it out of convenience.
Specified by:
init in interface Service

start

public void start()
           throws java.lang.Exception
Every service other than mere data collections should start
Specified by:
start in interface Service

stop

public void stop()
          throws java.lang.Exception
Every service other than mere data collections should stop
Specified by:
stop in interface Service

destroy

public void destroy()
             throws java.lang.Exception
Every service is eventually destroyed. Convenience implementation.
Specified by:
destroy in interface Service

getStatus

public int getStatus()
Specified by:
getStatus in interface Service

getDeactivated

public boolean getDeactivated()
Description copied from interface: ServiceMBean
Check if the service is deactivated and should not be started
Specified by:
getDeactivated in interface ServiceMBean

setDeactivated

public void setDeactivated(boolean deactivated)
Description copied from interface: ServiceMBean
Deactivate the service to prevent it from being started
Specified by:
setDeactivated in interface ServiceMBean

updateStatus

public void updateStatus(int n)
This is not a 'set' method in order to avoid exposing it as an automatically writable attribute. NOTE: Consider adding a SecurityPermission to this method.
Specified by:
updateStatus in interface Service

getName

public java.lang.String getName()
Retrieve the String version of the Service's JMX ObjectName.
Specified by:
getName in interface ServiceMBean

setName

public void setName(java.lang.String n)
Set the JMX ObjectName of this Service using a String.
Specified by:
setName in interface ServiceMBean

setDomainName

public void setDomainName(java.lang.String name)
Set the domain name of the partition's internal MBeanServer.
Specified by:
setDomainName in interface ServiceMBean

getDomainName

public java.lang.String getDomainName()
Description copied from interface: ServiceMBean
Retrieve the domain name of this service.
Specified by:
getDomainName in interface ServiceMBean
Returns:
String The name of this service's internal JMX Domain.

requestServer

public javax.management.MBeanServer requestServer()
Every service may report its server by reference. It is not a 'get' method in order to avoid automatic exposure of the method as an attribute method instead of as an operation. NOTE: consider adding a SecurityPermission for this method.
Specified by:
requestServer in interface ServiceMBean

preRegister

public javax.management.ObjectName preRegister(javax.management.MBeanServer server,
                                               javax.management.ObjectName name)
                                        throws java.lang.Exception
Override for additional functionality at registration time.

postRegister

public void postRegister(java.lang.Boolean b)
Override for additional functionality after registration time. This method is invoked just after the MBeanServer registers this Service.

preDeregister

public void preDeregister()
                   throws java.lang.Exception
Override for additional functionality before removal time. This method is invoked just before the MBeanServer attempts to remove this Service.

postDeregister

public void postDeregister()
Override for additional functionality after being removed from the server. This is invoked when the MBeanServer removes this Service.

bind

public void bind()
          throws javax.naming.NamingException
Bind the Service to JNDI. After the bind, the service is accessible via jrun:service/[servicename] and if the service is inside a partition, the service can be accessed through jrun:service/[domainname]/[servicename].
For example, a service with the the name "SimpleService" deployed will be accessible through jrun:service/SimpleService and that same service if created by a partition named "SimplePartition" would be accessible through jrun:service/SimplePartition/SimpleService.
By default, Services are not bound to JNDI. To have a Service automatically bound, set the bindToJNI element to true and be sure that the Service has an ObjectName.
Specified by:
bind in interface ServiceMBean

isPartition

public boolean isPartition()
Determines if this service is a partition
Returns:
true if we are a partition

isInPartition

public boolean isInPartition()
Determines if this service is in a partition
Returns:
true if we are in a partition

getServerName

public java.lang.String getServerName()
Gets the current server name
Specified by:
getServerName in interface ServiceMBean

getReference

public javax.naming.Reference getReference()
Specified by:
getReference in interface javax.naming.Referenceable

lookup

public java.lang.Object lookup(java.lang.String name)
                        throws java.lang.Exception
Convenience method for looking up a named service in the JNDI context. If this is a partition, we will look for the name in the partition first and, if not found, then in the server name space.
Parameters:
name - The service name to find
Returns:
The service, or null if not found

getDomainSearchPath

protected java.lang.String getDomainSearchPath()
Gets the name of the domain that we need to search in. For partitions this includes the service name; for services that are part of a partition this will be the domain name. If this service is part of the default domain, and empty string will be returned

unbind

public void unbind()
            throws javax.naming.NamingException
Description copied from interface: ServiceMBean
Unbind the service form the JNDI tree.
Specified by:
unbind in interface ServiceMBean

findObjectInstance

public final javax.management.ObjectInstance findObjectInstance(java.lang.String name)
Finds the named service within the JMX framework.
Parameters:
name - The service name
Returns:
The ObjectInstance, or null if not found

findObjectInstance

public final javax.management.ObjectInstance findObjectInstance(java.lang.String name,
                                                                boolean required)
                                                         throws ServiceException
Finds a required service. If the service is not found, a ServiceException will be thrown.
Parameters:
name - The service name
required - true if the service is required
Returns:
The ObjectInstance

findObjectInstance

public javax.management.ObjectInstance findObjectInstance(java.lang.String name,
                                                          java.lang.String domain)

invokeMethod

public java.lang.Object invokeMethod(javax.management.ObjectName objName,
                                     java.lang.String method,
                                     java.lang.Object[] params,
                                     java.lang.String[] types)
                              throws java.lang.Exception
Invoke a method on a Service using its ObjectName. Merely wraps the JMX invocation.

scheduleRunnable

public void scheduleRunnable(java.lang.Runnable runnable,
                             long msFromNow)
                      throws java.lang.Exception
Schedule a runnable to execute using the standard SchedulerService
Parameters:
runnable - The runnable
msFromNow - The number of ms from now to run, or 0 for immediate

unscheduleRunnable

public void unscheduleRunnable(java.lang.Runnable runnable)
                        throws java.lang.Exception
Unschedule a runnable to execute using the standard SchedulerService
Parameters:
runnable - The runnable

getBindToJNDI

public boolean getBindToJNDI()
Specified by:
getBindToJNDI in interface ServiceMBean

setBindToJNDI

public void setBindToJNDI(boolean b)
Specified by:
setBindToJNDI in interface ServiceMBean

getLogger

public Logger getLogger()
Returns an instance of the current logger for this context
Specified by:
getLogger in interface ServiceMBean
Returns:
The logger, or null if not found

getServerProperties

protected java.util.Properties getServerProperties()
Returns a list of server properties use for dynamic variable substitution. The current list includes: jrun.rootdir - The root directory of jrun jrun.server.rootdir - The root directory of the current server jrun.server.name - The server name jrun.name - The product name jrun.version - The product version, such as 4.0 jrun.build - The internal build number jrun.vendor - The product vendor jrun.vendor.url - The url of the product vendor

getResourceManager

public ResourceManager getResourceManager(java.lang.String path)
                                   throws java.lang.Exception
Convenience method for getting a ResourceManager
Parameters:
path - The root path

setParentService

public void setParentService(ServiceMBean parent)
Description copied from interface: ServiceMBean
Sets the parent service of this service. This is automatically set when a service is part of a ConfigurableServicePartition
Specified by:
setParentService in interface ServiceMBean
Following copied from interface: jrunx.kernel.ServiceMBean
Parameters:
parent - The parent service

getParentService

public ServiceMBean getParentService()
Description copied from interface: ServiceMBean
Gets the parent service of this service, or null if not part of a ConfigurableServicePartition
Specified by:
getParentService in interface ServiceMBean
Following copied from interface: jrunx.kernel.ServiceMBean
Returns:
The parent service or null if none

toString

public java.lang.String toString()

getJRunService

public java.lang.Object getJRunService()
Specified by:
getJRunService in interface ServiceMBean


Copyright � 2002 Macromedia Corporation. All Rights Reserved.