public class ClassLoadingBus extends AbstractNurseryService implements Bus
Bus
that makes it possible to load and unload classes and components at run time. AbstractNurseryService.doStartService()
will create a new Bus
with a new ClassLoader
. AbstractNurseryService.doStopService()
will destroy the Bus
and also dispose the ClassLoader
created in AbstractNurseryService.doStartService()
.
As the .class
and .jar
are loaded from disk each time the service started, this will make
it possible to reconfigure the Bus
just by restarting the service.
Configuration options:
displayName
- The name of the Bus
jarFolders
- An array of folders where we will look for jar
files
classFolders
- An array of folders where we will look for class
files
fileConfigurationPath
- A file path to where we can expect to find a nursery configuration directory
resourceConfigurationPath
- A place in classpath where we can expect to find a nursery configuration
GenericService.StartCommand, GenericService.StopCommand
Bus.Property
CLASS_VERSION
mLogger, state
instanceClassNamePropertyName, instanceDescriptionObjectName, instanceDescriptionObjectPath, instanceNamePropertyName
Constructor and Description |
---|
ClassLoadingBus() |
Modifier and Type | Method and Description |
---|---|
Collection<Bus> |
getChildren()
Returns a list of all known children at this time.
|
String[] |
getClassFolders() |
String |
getComponentNameFor(Object component) |
Iterator |
getComponentNames()
Returns all given names of components registered with the bus.
|
String |
getDisplayName()
A terse description of this Bus instance to user interfaces.
|
String |
getFileConfigurationPath() |
UUID |
getIdentifier()
Returns a unique identifier for this Bus instance.
|
String[] |
getJarFolders() |
Bus |
getParent()
Returns the parent
Bus or null if no parent is set |
List<Bus.Property> |
getProperties(String pComponentName)
Returns a list of all available properties for the component with the given name
|
String |
getResourceConfigurationPath() |
boolean |
isAvailable(String name)
Returns wether or not the specified component has been loaded.
|
<O> O |
lookup(String name)
returns the object defined by the given name.
|
<O> O |
lookupSafe(String name)
returns the object defined by the given name.
|
void |
setClassFolders(String[] pClassFolders) |
void |
setDisplayName(String pDisplayName) |
void |
setFileConfigurationPath(String pFileConfigurationPath) |
void |
setJarFolders(String[] pJarFolders) |
void |
setProperty(String pComponentName,
String pPropertyName,
String pPropertyValue) |
void |
setResourceConfigurationPath(String pResourceConfigurationPath) |
protected void |
startService()
Is called by
AbstractNurseryService.doStartService() when the NurseryService is being started. |
protected void |
stopService()
Is called by
AbstractNurseryService.doStopService() when the service is being shut down. |
void |
writeConfiguration(Writer pWriter)
Write the configuration parameters of the Bus to the given stream as a well formed, valid XHTML unordered list.
|
void |
writeConfigurationFor(String pComponentName,
Writer pWriter)
Write the configuration parameters to the given stream as a well formed, valid XHTML unordered list.
|
doStartService, doStopService, stopIdleService
assertServiceRunning, getServiceDescription, getServiceMessage, getServiceState, isServiceEnabled, isServiceFailed, isServiceIdle, isServiceRunning, isServiceShutdownFailed, isServiceStopped, setServiceDescription, setServiceEnabled, start, stop, validateIsTrue, validateNotNull
public String getFileConfigurationPath()
public void setFileConfigurationPath(String pFileConfigurationPath)
public String getResourceConfigurationPath()
public void setResourceConfigurationPath(String pResourceConfigurationPath)
public String getDisplayName()
Bus
getDisplayName
in interface Bus
public void setDisplayName(String pDisplayName)
public String[] getJarFolders()
public void setJarFolders(String[] pJarFolders)
public String[] getClassFolders()
public void setClassFolders(String[] pClassFolders)
protected void startService() throws Exception
AbstractNurseryService
Is called by AbstractNurseryService.doStartService()
when the NurseryService
is being started. Exceptions thrown by this
method are logged by AbstractNurseryService.doStartService()
.
Subclasses must implement this method to bootstrap the service.
startService
in class AbstractNurseryService
Exception
- when something goes wrong during startup. GenericService.isServiceRunning()
will return false
and GenericService.isServiceFailed()
will return true
.IllegalArgumentException
- when the configuration of the service
is invalid. GenericService.isServiceRunning()
will return false
and GenericService.isServiceFailed()
will return true
.IllegalStateException
- when this service is in the wrong state for startup. Used to signal to AbstractNurseryService.doStartService()
that it is OK to try to starting
this service
later. GenericService.isServiceRunning()
returns false
and GenericService.isServiceIdle()
returns true
.AbstractNurseryService.doStartService()
protected void stopService() throws Exception
AbstractNurseryService
Is called by AbstractNurseryService.doStopService()
when the service
is being shut down. Exceptions thrown by this
method are logged by AbstractNurseryService.doStopService()
.
Subclasses must implement this method to shut down the service.
stopService
in class AbstractNurseryService
IllegalStateException
- when this service is in the wrong state for shutdown. Used to signal to AbstractNurseryService.doStopService()
that
it is OK to try stopping this service
later. GenericService.isServiceRunning()
returns true
.Exception
- when something goes during shutdown. GenericService.isServiceRunning()
returns false
and
GenericService.isServiceShutdownFailed()
returns true
.AbstractNurseryService.doStopService()
public <O> O lookup(String name) throws BusException
Bus
If the object has been instantiated before, and that object has not yet been garbage collected, then the same instance is returned. If the object has been garbage collected, then the method acts as if the object never existed.
The method is defined to be thread-safe. It will safely allow two threads to request the same object. In any case, the two requests will return the same object even if they are running in parallel.
lookup
in interface Bus
name
- the name of the object to be retrievedBusException
- if the object does not exist or if the name is nullpublic <O> O lookupSafe(String name)
Bus
If the object has been instantiated before, and that object has not yet been garbage collected, then the same instance is returned. If the object has been garbage collected, then the method acts as if the object never existed.
The method is defined to be thread-safe. It will safely allow two threads to request the same object. In any case, the two requests will return the same object even if they are running in parallel.
lookupSafe
in interface Bus
name
- the name of the object to be retrievedpublic String getComponentNameFor(Object component)
getComponentNameFor
in interface Bus
public boolean isAvailable(String name)
Bus
isAvailable
in interface Bus
public Iterator getComponentNames()
Bus
getComponentNames
in interface Bus
public void writeConfigurationFor(String pComponentName, Writer pWriter) throws IOException
Bus
div
and span
and pre
elements with class attributes to assist machine
parsing.writeConfigurationFor
in interface Bus
pComponentName
- The name of the component to show information aboutpWriter
- The output to write the XML fragmentIOException
public UUID getIdentifier()
Bus
getIdentifier
in interface Bus
public Collection<Bus> getChildren()
Bus
getChildren
in interface Bus
public void setProperty(String pComponentName, String pPropertyName, String pPropertyValue) throws BusException
setProperty
in interface Bus
BusException
public List<Bus.Property> getProperties(String pComponentName) throws BusException
Bus
getProperties
in interface Bus
pComponentName
- the name of the componentBusException
- if fetching the component or properties failspublic void writeConfiguration(Writer pWriter) throws IOException
Bus
div
and span
and pre
elements with class attributes to assist machine
parsing.writeConfiguration
in interface Bus
pWriter
- The output to write the XML fragmentIOException
© 1998- 2018 Stibo DX