org.norther.tammi.core.startup
Class DefaultStartup

java.lang.Object
  extended by org.norther.tammi.core.base.Adaptee
      extended by org.norther.tammi.core.startup.DefaultStartup
All Implemented Interfaces:
Serializable, NotificationBroadcaster, NotificationEmitter, Manageable, MBeanDelegate, Startable, Configurable, Startup

public class DefaultStartup
extends Adaptee
implements Startup

A default implementation of StartupMBean.

Version:
$Id: DefaultStartup.java,v 1.26 2009/09/28 15:08:45 cvsimp Exp $
Author:
Ilkka Priha
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.norther.tammi.core.base.Adaptee
ADAPTEE_NOTIF_DESCRIPTION, ADAPTEE_NOTIFICATIONS
 
Fields inherited from interface org.norther.tammi.core.startup.Startup
GROUP_ID_PROPERTY, SCRIPT_ENGINE_PROPERTY, SCRIPT_LANGUAGE_PROPERTY, USER_ID_PROPERTY
 
Constructor Summary
DefaultStartup()
          Constructs a new startup.
DefaultStartup(MBeanServer server)
          Constructs a new startup with arguments in the specified server.
 
Method Summary
 void addProperty(int index, String key, String value)
          Inserts a multivalued property at the specified index.
 void addProperty(String key, String value)
          Adds a multivalued property.
 void addPropertyFilePath(String path)
          Adds a property file path.
 void addPropertyFilePath(String path, String encoding)
          Adds a property file path with an encoding.
 void clearProperties()
          Clears all properties.
 boolean containsProperty(String key)
          Checks whether a property is defined.
 String getConfigKey()
          Gets the path finder key for resolving configuration paths.
 String[] getProperties(String key)
          Gets a multivalued property.
 String getProperty(String key)
          Gets a property.
 String getPropertyFilePath()
          Gets the property file path.
 String[] getPropertyFilePaths()
          Gets the property file paths.
 int getRestartDelay()
          Gets the restart delay.
 long getShutdownDelay()
          Gets the shutdown delay.
 int indexOfProperty(String key, String value)
          Returns the index of a multivalued property value.
 boolean isStarted()
          Checks whether the startable has been started.
 OrderedMap<String,Object> propertyMap()
          Returns a map of properties.
 OrderedMap<String,Object> propertyMap(String prefix)
          Returns a map of prefixed properties.
 void register(String[] args)
          Registers the startup without starting.
 Object removeProperty(String key)
          Removes a property.
 boolean removeProperty(String key, String value)
          Removes a multivalued property.
 void removePropertyFilePath(String path)
          Removes a property file path.
 void restart(int delay)
          Restarts after a delay.
 void setConfigKey(String key)
          Sets the path finder key for resolving configuration paths.
 Object setProperties(String key, String[] values)
          Sets a multivalued property.
 Object setProperty(String key, String value)
          Sets a property.
 void setPropertyFilePath(String path)
          Sets the property file path.
 void setPropertyFilePath(String path, String encoding)
          Sets the property file path with an encoding.
 void setPropertyFilePaths(String[] paths)
          Sets the property file paths.
 void setPropertyFilePaths(String[] paths, String... encoding)
          Sets the property file paths with encodings.
 void setShutdownDelay(long delay)
          Sets the shutdown delay forcing a shutdown after running all shutdown scripts.
 void start()
          Starts up if registered.
 void stop()
          Shuts down.
 void storeProperties()
          Stores properties to the property file.
 void unmanaged()
          This method is called when the implementing adaptee is unmanaged either during pre-deregistration of the corresponding adapter MBean or just before it is explicitly removed from the adapter MBean during run-time.
 
Methods inherited from class org.norther.tammi.core.base.Adaptee
addAdaptee, addNotificationListener, getAttributeSupport, getBroker, getCanonicalName, getDomain, getFactory, getLoader, getLog, getLog, getMBean, getMBeanServer, getNotificationInfo, getObjectName, getRegistrationTime, getSequenceNumber, hasListeners, isRegistered, postmanaged, premanaged, removeNotificationListener, removeNotificationListener, sendNotification, sendNotification, sendNotification, sendNotification, unregister
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.norther.tammi.core.startup.Startup
unregister
 

Constructor Detail

DefaultStartup

public DefaultStartup()
Constructs a new startup.


DefaultStartup

public DefaultStartup(MBeanServer server)
Constructs a new startup with arguments in the specified server.

Parameters:
server - the MBean server.
Method Detail

unmanaged

public void unmanaged()
               throws Exception
Description copied from interface: Manageable
This method is called when the implementing adaptee is unmanaged either during pre-deregistration of the corresponding adapter MBean or just before it is explicitly removed from the adapter MBean during run-time.

Specified by:
unmanaged in interface Manageable
Overrides:
unmanaged in class Adaptee
Throws:
Exception - if the adaptee refused to be unmanaged.

register

public void register(String[] args)
              throws Exception
Description copied from interface: Startup
Registers the startup without starting.

Specified by:
register in interface Startup
Parameters:
args - the startup arguments.
Throws:
Exception - if registration fails.

isStarted

public boolean isStarted()
Description copied from interface: Startable
Checks whether the startable has been started.

Specified by:
isStarted in interface Startable
Returns:
true if started, otherwise false.

start

public void start()
           throws Exception
Description copied from interface: Startup
Starts up if registered.

Specified by:
start in interface Startable
Specified by:
start in interface Startup
Throws:
Exception - if startup fails.

stop

public void stop()
Description copied from interface: Startup
Shuts down.

Specified by:
stop in interface Startable
Specified by:
stop in interface Startup

restart

public void restart(int delay)
Description copied from interface: Startup
Restarts after a delay.

Specified by:
restart in interface Startup
Parameters:
delay - the restart delay in secs.

getRestartDelay

public int getRestartDelay()
Description copied from interface: Startup
Gets the restart delay.

Specified by:
getRestartDelay in interface Startup
Returns:
the restart delay in secs.

getShutdownDelay

public long getShutdownDelay()
Description copied from interface: Startup
Gets the shutdown delay.

Specified by:
getShutdownDelay in interface Startup
Returns:
the shutdown delay in msecs.

setShutdownDelay

public void setShutdownDelay(long delay)
Description copied from interface: Startup
Sets the shutdown delay forcing a shutdown after running all shutdown scripts.

Specified by:
setShutdownDelay in interface Startup
Parameters:
delay - the shutdown delay in msecs (-1 = never).

getConfigKey

public String getConfigKey()
Description copied from interface: Configurable
Gets the path finder key for resolving configuration paths.

Specified by:
getConfigKey in interface Configurable
Returns:
the path finder key.

setConfigKey

public void setConfigKey(String key)
Description copied from interface: Configurable
Sets the path finder key for resolving configuration paths. The default key is PathFinderMBean.CONFIG.

Specified by:
setConfigKey in interface Configurable
Parameters:
key - the path finder key.

getPropertyFilePath

public String getPropertyFilePath()
Description copied from interface: Configurable
Gets the property file path. The first one is returned if more than one is defined.

Specified by:
getPropertyFilePath in interface Configurable
Returns:
the property file path or null.

setPropertyFilePath

public void setPropertyFilePath(String path)
Description copied from interface: Configurable
Sets the property file path. The path may be an absolute file path, a file path relative to the specified config key folder or a URL. The properties will be loaded before the next get/set property operation.

Note that all previously defined property file paths and properties are cleared.

Specified by:
setPropertyFilePath in interface Configurable
Parameters:
path - a property file path.

setPropertyFilePath

public void setPropertyFilePath(String path,
                                String encoding)
Description copied from interface: Configurable
Sets the property file path with an encoding.

Specified by:
setPropertyFilePath in interface Configurable
Parameters:
path - a property file path.
encoding - an encoding to use.

getPropertyFilePaths

public String[] getPropertyFilePaths()
Description copied from interface: Configurable
Gets the property file paths.

Specified by:
getPropertyFilePaths in interface Configurable
Returns:
the property file paths.

setPropertyFilePaths

public void setPropertyFilePaths(String[] paths)
Description copied from interface: Configurable
Sets the property file paths. The path may be an absolute file path, a file path relative to the specified config key folder or a URL. The properties will be loaded before the next get/set property operation. New paths are added after existing ones.

Specified by:
setPropertyFilePaths in interface Configurable
Parameters:
paths - property file paths.

setPropertyFilePaths

public void setPropertyFilePaths(String[] paths,
                                 String... encoding)
Description copied from interface: Configurable
Sets the property file paths with encodings.

Specified by:
setPropertyFilePaths in interface Configurable
Parameters:
paths - property file paths.
encoding - encodings to use.

addPropertyFilePath

public void addPropertyFilePath(String path)
Description copied from interface: Configurable
Adds a property file path.

Specified by:
addPropertyFilePath in interface Configurable
Parameters:
path - a property file path.

addPropertyFilePath

public void addPropertyFilePath(String path,
                                String encoding)
Description copied from interface: Configurable
Adds a property file path with an encoding.

Specified by:
addPropertyFilePath in interface Configurable
Parameters:
path - a property file path.
encoding - an encoding to use.

removePropertyFilePath

public void removePropertyFilePath(String path)
Description copied from interface: Configurable
Removes a property file path.

Specified by:
removePropertyFilePath in interface Configurable
Parameters:
path - the property file path.

containsProperty

public boolean containsProperty(String key)
Description copied from interface: Configurable
Checks whether a property is defined.

Specified by:
containsProperty in interface Configurable
Parameters:
key - the key.
Returns:
true for a defined property, false otherwise.

getProperty

public String getProperty(String key)
Description copied from interface: Configurable
Gets a property.

Specified by:
getProperty in interface Configurable
Parameters:
key - the key.
Returns:
the value or null.

setProperty

public Object setProperty(String key,
                          String value)
Description copied from interface: Configurable
Sets a property.

Specified by:
setProperty in interface Configurable
Parameters:
key - the key.
value - the value.
Returns:
the previous value.

getProperties

public String[] getProperties(String key)
Description copied from interface: Configurable
Gets a multivalued property.

Specified by:
getProperties in interface Configurable
Parameters:
key - the key.
Returns:
the values or null.

setProperties

public Object setProperties(String key,
                            String[] values)
Description copied from interface: Configurable
Sets a multivalued property.

Specified by:
setProperties in interface Configurable
Parameters:
key - the key.
values - the values.
Returns:
the previous value.

removeProperty

public Object removeProperty(String key)
Description copied from interface: Configurable
Removes a property.

Specified by:
removeProperty in interface Configurable
Parameters:
key - the key.
Returns:
the removed value or null.

indexOfProperty

public int indexOfProperty(String key,
                           String value)
Description copied from interface: Configurable
Returns the index of a multivalued property value.

Specified by:
indexOfProperty in interface Configurable
Parameters:
key - the key.
value - the value.
Returns:
the index of the value or -1.

addProperty

public void addProperty(String key,
                        String value)
Description copied from interface: Configurable
Adds a multivalued property.

Specified by:
addProperty in interface Configurable
Parameters:
key - the key.
value - the property.

addProperty

public void addProperty(int index,
                        String key,
                        String value)
Description copied from interface: Configurable
Inserts a multivalued property at the specified index.

Specified by:
addProperty in interface Configurable
Parameters:
index - the index.
key - the key.
value - the value.

removeProperty

public boolean removeProperty(String key,
                              String value)
Description copied from interface: Configurable
Removes a multivalued property.

Specified by:
removeProperty in interface Configurable
Parameters:
key - the key.
value - the value.
Returns:
true if removed, false otherwise.

clearProperties

public void clearProperties()
Description copied from interface: Configurable
Clears all properties.

Specified by:
clearProperties in interface Configurable

propertyMap

public OrderedMap<String,Object> propertyMap()
Description copied from interface: Configurable
Returns a map of properties. Multivalued properties are presented as string arrays.

Specified by:
propertyMap in interface Configurable
Returns:
a map of properties.

propertyMap

public OrderedMap<String,Object> propertyMap(String prefix)
Description copied from interface: Configurable
Returns a map of prefixed properties. The prefix is removed from the keys of the returned map. Multivalued properties are presented as string arrays.

Specified by:
propertyMap in interface Configurable
Parameters:
prefix - the prefix.
Returns:
a map of properties.

storeProperties

public void storeProperties()
                     throws IOException
Description copied from interface: Configurable
Stores properties to the property file. The first defined property file is applied to all properties.

Specified by:
storeProperties in interface Configurable
Throws:
IOException - on I/O errors.


Copyright © 2004 The Norther Organization. All rights reserved.