Package com.swiftmq.swiftlet
Class SwiftletManager
- java.lang.Object
-
- com.swiftmq.swiftlet.SwiftletManager
-
public class SwiftletManager extends java.lang.Object
The SwiftletManager is the single instance of a SwiftMQ router that is acting as a container for Swiftlets. It is responsible for:
- startup/shutdown of the router (halt/reboot)
- startup/shutdown of Kernel Swiftlets
- startup/shutdown of Extension Swiftlets
- load/save of the configuration file
For each Swiftlet defined in the startorder attribute, the following tasks are performed:
- Instantiating the Swiftlet class from the kernel classloader
- Invoking the
startup
method of the Swiftlet. The Swiftlet configuration is passed as parameter.
startup
methods have been processed without exceptions.
A shutdown of a router is processed in the reverse order and theshutdown
method of each Swiftlet is invoked.
Extension Swiftlets are loaded/unloaded on request through the methodsloadExtensionSwiftlet
andunloadExtensionSwiftlet
.- Author:
- IIT GmbH, Bremen/Germany, Copyright (c) 2000-2002, All Rights Reserved
-
-
Field Summary
Fields Modifier and Type Field Description protected static SwiftletManager
_instance
-
Constructor Summary
Constructors Modifier Constructor Description protected
SwiftletManager()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addKernelStartupListener(KernelStartupListener l)
Adds a KernelStartupListener.void
addSurviveData(java.lang.String key, java.lang.Object data)
Adds data to the survive data store.void
addSwiftletManagerListener(SwiftletManagerListener l)
Adds a SwiftletManagerListener for all Swiftlets.void
addSwiftletManagerListener(java.lang.String swiftletName, SwiftletManagerListener l)
Adds a SwiftletManagerListener for a specific Swiftlet.protected java.util.Map
createBundleTable(java.lang.String kernelPath)
protected void
createRouterCommands()
void
disableShutdownHook()
protected void
fireKernelStartedEvent()
protected void
fireSwiftletManagerEvent(java.lang.String swiftletName, java.lang.String methodName, SwiftletManagerEvent evt)
protected Configuration
getConfiguration(Swiftlet swiftlet)
Configuration
getConfiguration(java.lang.String name)
Returns the configuration of a specific Swiftlet.static SwiftletManager
getInstance()
Returns the singleton instance of the SwiftletManagerjava.lang.String
getLastSwiftlet()
protected org.dom4j.Element[]
getOptionalElements()
java.lang.String
getRouterName()
Returns the name of this routerjava.lang.Object
getSurviveData(java.lang.String key)
Returns the survive data, stored under the given key.Swiftlet
getSwiftlet(java.lang.String swiftletName)
Returns the Swiftlet with the given name.int
getSwiftletState(java.lang.String swiftletName)
Returns the state of a Swiftlet.java.lang.String
getWorkingDirectory()
boolean
isHA()
boolean
isQuietMode()
boolean
isRebooting()
Returns true if the router is within the reboot phase.boolean
isRegisterShutdownHook()
boolean
isStartup()
Returns true if the router is within the startup phase.boolean
isStrippedMode()
boolean
isSwiftletDefined(java.lang.String swiftletName)
Checks if the Swiftlet is defined.boolean
isUseSmartTree()
Returns true if the router is configured to use a smart management tree to avoid overloading management tools like SwiftMQ Explorer or CLI with management messages when connected to a router running a high load.void
loadExtensionSwiftlet(Bundle bundle)
Loads a new Extension Swiftlet.protected Swiftlet
loadSwiftlet(java.lang.String swiftletName)
protected void
parseOptionalConfiguration(org.dom4j.Element root)
void
reboot()
Reboots this router without delay.void
reboot(long delay)
Reboots this router with delay.void
removeKernelStartupListener(KernelStartupListener l)
Removes a KernelStartupListener.void
removeSurviveData(java.lang.String key)
Removes the survive data, stored under the given key.void
removeSwiftletManagerListener(SwiftletManagerListener l)
Removes a SwiftletManagerListener for all Swiftlets.void
removeSwiftletManagerListener(java.lang.String swiftletName, SwiftletManagerListener l)
Removes a SwiftletManagerListener for a specific Swiftlet.void
saveConfigIfDirty()
void
saveConfiguration()
Saves this router's configuration.protected java.lang.String[]
saveConfiguration(RouterConfigInstance entity)
void
setConfigDirty(boolean configDirty)
void
setDoFireKernelStartedEvent(boolean doFireKernelStartedEvent)
void
setQuietMode(boolean quietMode)
void
setRegisterShutdownHook(boolean registerShutdownHook)
void
setStrippedMode(boolean strippedMode)
void
setWorkingDirectory(java.lang.String workingDirectory)
void
shutdown()
Performs a shutdown of the router.void
shutdown(boolean removeShutdownHook)
protected void
shutdownSwiftlet(Swiftlet swiftlet)
protected void
startKernelSwiftlet(java.lang.String actSwiftletName, java.util.Map table)
protected void
startKernelSwiftlets()
void
startRouter(java.lang.String name)
Starts the router.protected void
startSwiftletDeployer()
protected void
stopKernelSwiftlets()
protected void
stopSwiftletDeployer()
protected void
trace(java.lang.String message)
void
unloadExtensionSwiftlet(Bundle bundle)
Unloads an Extension Swiftlet.
-
-
-
Field Detail
-
_instance
protected static SwiftletManager _instance
-
-
Method Detail
-
getInstance
public static SwiftletManager getInstance()
Returns the singleton instance of the SwiftletManager- Returns:
- singleton instance
-
isHA
public boolean isHA()
-
setDoFireKernelStartedEvent
public void setDoFireKernelStartedEvent(boolean doFireKernelStartedEvent)
-
trace
protected void trace(java.lang.String message)
-
startSwiftletDeployer
protected void startSwiftletDeployer()
-
stopSwiftletDeployer
protected void stopSwiftletDeployer()
-
getConfiguration
protected Configuration getConfiguration(Swiftlet swiftlet) throws java.lang.Exception
- Throws:
java.lang.Exception
-
getConfiguration
public Configuration getConfiguration(java.lang.String name)
Returns the configuration of a specific Swiftlet.- Parameters:
name
- Swiftlet name, e.g. "sys$topicmanager".- Returns:
- configuration
-
shutdownSwiftlet
protected void shutdownSwiftlet(Swiftlet swiftlet) throws SwiftletException
- Throws:
SwiftletException
-
startKernelSwiftlets
protected void startKernelSwiftlets()
-
startKernelSwiftlet
protected void startKernelSwiftlet(java.lang.String actSwiftletName, java.util.Map table) throws java.lang.Exception
- Throws:
java.lang.Exception
-
stopKernelSwiftlets
protected void stopKernelSwiftlets()
-
getWorkingDirectory
public java.lang.String getWorkingDirectory()
-
setWorkingDirectory
public void setWorkingDirectory(java.lang.String workingDirectory)
-
isRegisterShutdownHook
public boolean isRegisterShutdownHook()
-
setRegisterShutdownHook
public void setRegisterShutdownHook(boolean registerShutdownHook)
-
disableShutdownHook
public void disableShutdownHook()
-
isQuietMode
public boolean isQuietMode()
-
setQuietMode
public void setQuietMode(boolean quietMode)
-
isStrippedMode
public boolean isStrippedMode()
-
setStrippedMode
public void setStrippedMode(boolean strippedMode)
-
setConfigDirty
public void setConfigDirty(boolean configDirty)
-
saveConfigIfDirty
public void saveConfigIfDirty()
-
getLastSwiftlet
public java.lang.String getLastSwiftlet()
-
loadExtensionSwiftlet
public void loadExtensionSwiftlet(Bundle bundle) throws java.lang.Exception
Loads a new Extension Swiftlet. Will be used from the Deploy Swiftlet only.- Parameters:
bundle
- deployment bundle.- Throws:
java.lang.Exception
- on error during load
-
unloadExtensionSwiftlet
public void unloadExtensionSwiftlet(Bundle bundle)
Unloads an Extension Swiftlet. Will be used from the Deploy Swiftlet only.- Parameters:
bundle
- deployment bundle.
-
isUseSmartTree
public boolean isUseSmartTree()
Returns true if the router is configured to use a smart management tree to avoid overloading management tools like SwiftMQ Explorer or CLI with management messages when connected to a router running a high load. This is only a hint. Each Swiftlet is responsible which content it puts into the management tree, especially the usage part.- Returns:
- true/false.
-
isStartup
public boolean isStartup()
Returns true if the router is within the startup phase.- Returns:
- true/false.
-
isRebooting
public boolean isRebooting()
Returns true if the router is within the reboot phase.- Returns:
- true/false.
-
createBundleTable
protected java.util.Map createBundleTable(java.lang.String kernelPath) throws java.lang.Exception
- Throws:
java.lang.Exception
-
startRouter
public void startRouter(java.lang.String name) throws java.lang.Exception
Starts the router. This method is called from the bootstrap class only.- Parameters:
name
- name of the configuration file.- Throws:
java.lang.Exception
- on error.
-
parseOptionalConfiguration
protected void parseOptionalConfiguration(org.dom4j.Element root)
-
createRouterCommands
protected void createRouterCommands()
-
reboot
public void reboot()
Reboots this router without delay. A separate thread is used. The method returns immediately.
-
reboot
public void reboot(long delay)
Reboots this router with delay. A separate thread is NOT used. The method return after the reboot is done. This method call must be used from a separate thread.- Parameters:
delay
- A reboot delay in ms
-
loadSwiftlet
protected Swiftlet loadSwiftlet(java.lang.String swiftletName) throws java.lang.Exception
- Throws:
java.lang.Exception
-
getSwiftlet
public Swiftlet getSwiftlet(java.lang.String swiftletName)
Returns the Swiftlet with the given name. This method only returns Kernel Swiftlets. It is not possible to get Extension Swiftlets due to different class loaders. If the Swiftlet is undefined or not started, null is returned.- Parameters:
swiftletName
- name of the Swiftlet, e.g. "sys$timer".- Returns:
- Swiftlet.
-
getSwiftletState
public final int getSwiftletState(java.lang.String swiftletName) throws UnknownSwiftletException
Returns the state of a Swiftlet.- Parameters:
swiftletName
- name of the Swiftlet.- Returns:
- state.
- Throws:
UnknownSwiftletException
- if the Swiftlet is undefined.
-
isSwiftletDefined
public final boolean isSwiftletDefined(java.lang.String swiftletName)
Checks if the Swiftlet is defined.- Parameters:
swiftletName
- name of the Swiftlet.- Returns:
- true/false.
-
shutdown
public void shutdown(boolean removeShutdownHook)
-
shutdown
public void shutdown()
Performs a shutdown of the router.
-
getRouterName
public java.lang.String getRouterName()
Returns the name of this router- Returns:
- router name.
-
saveConfiguration
public void saveConfiguration()
Saves this router's configuration.
-
getOptionalElements
protected org.dom4j.Element[] getOptionalElements()
-
saveConfiguration
protected java.lang.String[] saveConfiguration(RouterConfigInstance entity)
-
addSurviveData
public void addSurviveData(java.lang.String key, java.lang.Object data)
Adds data to the survive data store. Due to different class loaders of the Extension Swiftlets, it is not possible to store data in static data structures within the Swiftlet that do survive a reboot (shutdown/restart) of a router. Normally, a Swiftlet shouldn't have any data that must survive, but there are some exceptions, e.g. server sockets which should be reused. This kind of data can be registered within theshutdown
method of a Swiftlet under some key and fetched for reuse during thestartup
method.- Parameters:
key
- some key.data
- the data
-
removeSurviveData
public void removeSurviveData(java.lang.String key)
Removes the survive data, stored under the given key.- Parameters:
key
- key.
-
getSurviveData
public java.lang.Object getSurviveData(java.lang.String key)
Returns the survive data, stored under the given key.- Parameters:
key
- key.- Returns:
- survive data.
-
addSwiftletManagerListener
public final void addSwiftletManagerListener(java.lang.String swiftletName, SwiftletManagerListener l)
Adds a SwiftletManagerListener for a specific Swiftlet.- Parameters:
swiftletName
- Swiftlet Name.l
- Listener.
-
addSwiftletManagerListener
public final void addSwiftletManagerListener(SwiftletManagerListener l)
Adds a SwiftletManagerListener for all Swiftlets.- Parameters:
l
- Listener.
-
removeSwiftletManagerListener
public final void removeSwiftletManagerListener(java.lang.String swiftletName, SwiftletManagerListener l)
Removes a SwiftletManagerListener for a specific Swiftlet.- Parameters:
swiftletName
- Swiftlet Name.l
- Listener.
-
removeSwiftletManagerListener
public final void removeSwiftletManagerListener(SwiftletManagerListener l)
Removes a SwiftletManagerListener for all Swiftlets.- Parameters:
l
- Listener.
-
addKernelStartupListener
public final void addKernelStartupListener(KernelStartupListener l)
Adds a KernelStartupListener.- Parameters:
l
- Listener.
-
removeKernelStartupListener
public final void removeKernelStartupListener(KernelStartupListener l)
Removes a KernelStartupListener.- Parameters:
l
- Listener.
-
fireKernelStartedEvent
protected void fireKernelStartedEvent()
-
fireSwiftletManagerEvent
protected void fireSwiftletManagerEvent(java.lang.String swiftletName, java.lang.String methodName, SwiftletManagerEvent evt)
-
-