SmartFrog 3.10.000

org.smartfrog
Class SFSystem

java.lang.Object
  extended by org.smartfrog.SFSystem
All Implemented Interfaces:
MessageKeys

public class SFSystem
extends java.lang.Object
implements MessageKeys

SFSystem offers utility methods to deploy from a stream and a deployer. It attempts to deploy and start the component found in the sfConfig attribute. Any failure will cause a termination of the component under deployment or starting. The main function looks for a property and configuration option on the argument line and deploys locally based on these.

You can create your own main loop, using the utility methods in this class. The main loop of SFSystem reads an optionset, checks if -c or /? missing to pring usage string (and exit). It then reads the system properties, and does a deployFromURLs given the URLs on the command line. Any exception or error causes the main loop to do an exit. If the /e option is present on the command line, the main loop exits after deployment. This is good for one shot deployment, with deployment occurring into other processes.

This class can be subclassed, but one must be very, very careful about doing so.


Field Summary
 
Fields inherited from interface org.smartfrog.sfcore.common.MessageKeys
CANNOT_LINK_TO_PREDICATE, COMPONENT_TERMINATED, COPY_FAILED, COPY_SERIALIZE_FAILED, ERROR_NO_SECURITY_BUT_REQUIRED, ILLEGAL_BOOLEAN_PARAMETER, ILLEGAL_NUMERIC_PARAMETER, ILLEGAL_STRING_PARAMETER, ILLEGAL_VECTOR_PARAMETER, LIVENESS_SEND_FAILURE, LIVENESS_SEND_FAILURE_IN, MISSING_PARAMETER, MSG_CLASS_NOT_FOUND, MSG_CONNECT_ERR, MSG_CONT_OTHER_DEPLOY, MSG_DEPLOY_COMP_TERMINATED, MSG_DEPLOY_SUCCESS, MSG_DEPLOYWITH_PHASE_FAILED, MSG_DETACH_SUCCESS, MSG_DETACH_TERMINATE_SUCCESS, MSG_ERR_DEPLOY_FROM_URL, MSG_ERR_PARSE, MSG_ERR_RESOLVE_PHASE, MSG_ERR_SF_RUNNING, MSG_ERR_TERM, MSG_FAILED_INET_ADDRESS_LOOKUP, MSG_FAILED_TO_CONTACT_PARENT, MSG_FILE_NOT_FOUND, MSG_HOOK_ACTION_FAILED, MSG_ILLEGAL_ACCESS, MSG_ILLEGAL_CLASS_TYPE, MSG_ILLEGAL_CLASS_TYPE_EXPECTING_GOT, MSG_ILLEGAL_REFERENCE, MSG_INPUTSTREAM_NULL, MSG_INSTANTIATION_ERROR, MSG_INVALID_OBJECT_TYPE, MSG_INVOCATION_TARGET, MSG_LANG_NOT_FOUND, MSG_LIVENESS_START_FAILED, MSG_LOADING_URL, MSG_METHOD_NOT_FOUND, MSG_NON_REP_ATTRIB, MSG_NOT_COMPONENT_REFERENCE, MSG_NOT_FOUND_ATTRIBUTE, MSG_NOT_FOUND_REFERENCE, MSG_NOT_VALUE_REFERENCE, MSG_NULL_DEF_METHOD, MSG_NULL_URL, MSG_OBJECT_REGISTRATION_FAILED, MSG_PARENT_LOCATION_FAILED, MSG_PING_SUCCESS, MSG_RANDM_ERR, MSG_REMOTE_CONNECT_ERR, MSG_REPEATED_ATTRIBUTE, MSG_SF_DEAD, MSG_SF_READY, MSG_SF_TERMINATED, MSG_STACKTRACE_FOLLOWS, MSG_START_COMP_TERMINATED, MSG_TERMINATE_SUCCESS, MSG_UNHANDLED_EXCEPTION, MSG_UNKNOWN_HOST, MSG_UNRESOLVED_REFERENCE, MSG_UNRESOLVED_REFERENCE_IN, MSG_UPDATE_SUCCESS, MSG_URL_NOT_FOUND, MSG_URL_TO_PARSE_NOT_FOUND, MSG_WARNING_LIVENESS_ENABLED, MSG_WARNING_STACKTRACE_DISABLED, MSG_WARNING_STACKTRACE_ENABLED, ROOT_MUST_BE_COMPONENT, WARN_NO_SECURITY
 
Constructor Summary
SFSystem()
           
 
Method Summary
protected static ProcessCompound createRootProcess()
           
 void execute(java.lang.String[] args)
          This is the implementation of the main function.
 void exitWith(java.lang.String str, int exitCode)
          Prints given error string and exits system.
static void exitWithStatus(boolean somethingFailed, int exitCode)
          exit with an error code that depends on the status of the execution
static byte[] getByteArrayForResource(java.lang.String resourceSFURL)
          Gets ByteArray for the given resource.
static java.io.InputStream getInputStreamForResource(java.lang.String resourceSFURL)
          Gets input stream for the given resource.
static java.lang.String getProperty(java.lang.String key)
          Common entry point to get system properties.
static java.lang.String getProperty(java.lang.String key, java.lang.String def)
          Entry point to get system properties.
 ProcessCompound getRootProcess()
          get the root process
static void initSystem()
          initialise the system.
static boolean isSmartfrogInit()
          test for the system being initialised already
static void main(java.lang.String[] args)
          Method invoked to start the SmartFrog system.
 void printStackTrace(java.lang.Throwable thr)
          Prints StackTrace
static void readPropertiesFrom(java.io.InputStream is)
          Reads and sets system properties given in input stream.
static void readPropertiesFromIniFile()
          Reads properties given a system property "org.smartfrog.iniFile".
static java.lang.Object runConfigurationDescriptor(ConfigurationDescriptor cfgDesc)
          Runs a configuration descripor trapping any possible exception
static java.lang.Object runConfigurationDescriptor(ConfigurationDescriptor configuration, boolean throwException)
          run whatever action is configured
static void runConfigurationDescriptors(java.util.Vector cfgDescs)
          Runs a set (vector) of configuration descriptors
static ProcessCompound runSmartFrog()
          Run SmartFrog as configured.
static ProcessCompound runSmartFrog(java.util.Vector cfgDescriptors)
          Run SmartFrog as configured.
static void setOutputStreams()
          Sets stdout and stderr streams to different streams if class names specified in system properties.
 void setRootProcess(ProcessCompound rootProcess)
          set the root process; this is called after it is started.
static LogSF sfLog()
           
 void terminateSystem(java.lang.String message)
          terminate the system.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SFSystem

public SFSystem()
Method Detail

getProperty

public static java.lang.String getProperty(java.lang.String key,
                                           java.lang.String def)
Entry point to get system properties. Works around a bug in some JVM's (ie. Solaris) to return the default correctly.

Parameters:
key - property key to look up
def - default to return if key not present
Returns:
property value under key or default if not present

getProperty

public static java.lang.String getProperty(java.lang.String key)
Common entry point to get system properties.

Parameters:
key - key to look up
Returns:
property value under key

readPropertiesFromIniFile

public static void readPropertiesFromIniFile()
                                      throws SmartFrogException
Reads properties given a system property "org.smartfrog.iniFile".

Throws:
SmartFrogException - if failed to read properties from the ini file

readPropertiesFrom

public static void readPropertiesFrom(java.io.InputStream is)
                               throws java.io.IOException
Reads and sets system properties given in input stream.

Parameters:
is - input stream
Throws:
java.io.IOException - failed to read properties

setOutputStreams

public static void setOutputStreams()
                             throws SmartFrogException
Sets stdout and stderr streams to different streams if class names specified in system properties. Uses System.setErr and setOut to set the PrintStreams which form stderr and stdout

Throws:
SmartFrogException - failed to create or set output/error streams

exitWith

public void exitWith(java.lang.String str,
                     int exitCode)
Prints given error string and exits system.

Parameters:
str - string to print on out

exitWithStatus

public static void exitWithStatus(boolean somethingFailed,
                                  int exitCode)
exit with an error code that depends on the status of the execution

Parameters:
somethingFailed - flag to indicate trouble

runConfigurationDescriptors

public static void runConfigurationDescriptors(java.util.Vector cfgDescs)
Runs a set (vector) of configuration descriptors

Parameters:
cfgDescs - Vector of ConfigurationDescriptors
See Also:
ConfigurationDescriptor

runConfigurationDescriptor

public static java.lang.Object runConfigurationDescriptor(ConfigurationDescriptor cfgDesc)
Runs a configuration descripor trapping any possible exception

Parameters:
cfgDesc - ConfigurationDescriptor
See Also:
ConfigurationDescriptor

runConfigurationDescriptor

public static java.lang.Object runConfigurationDescriptor(ConfigurationDescriptor configuration,
                                                          boolean throwException)
                                                   throws SmartFrogException
run whatever action is configured

Parameters:
configuration -
throwException -
Returns:
whatever came back from calling ConfigurationDescriptor.execute(ProcessCompound)
Throws:
SmartFrogException

main

public static void main(java.lang.String[] args)
Method invoked to start the SmartFrog system.

Parameters:
args - command line arguments. Please see the usage to get more details

execute

public void execute(java.lang.String[] args)
This is the implementation of the main function.

Parameters:
args -

printStackTrace

public void printStackTrace(java.lang.Throwable thr)
Prints StackTrace

Parameters:
thr - Throwable

runSmartFrog

public static ProcessCompound runSmartFrog(java.util.Vector cfgDescriptors)
                                    throws java.lang.Exception
Run SmartFrog as configured. This call does not exit SmartFrog, even if the OptionSet requests it. This entry point exists so that alternate entry points (e.g. Ant Tasks) can start the system. Important: things like the output streams can be redirected inside this call

Parameters:
cfgDescriptors - Vector of Configuration opts with list of ConfigurationDescriptors
Returns:
the root process
Throws:
SmartFrogException - for a specific SmartFrog problem
java.net.UnknownHostException - if the target host is unknown
java.rmi.ConnectException - if the remote system's SmartFrog daemon is unreachable
java.rmi.RemoteException - if something goes wrong during the communication
java.lang.Exception - if anything else went wrong
See Also:
ConfigurationDescriptor

runSmartFrog

public static ProcessCompound runSmartFrog()
                                    throws SmartFrogException,
                                           java.net.UnknownHostException,
                                           java.rmi.ConnectException,
                                           java.rmi.RemoteException,
                                           SFGeneralSecurityException
Run SmartFrog as configured. This call does not exit smartfrog, even if the OptionSet requests it. This entry point exists so that alternate entry points (e.g. Ant Tasks) can start the system. Important: things like the output streams can be redirected.

Returns:
the root process
Throws:
SmartFrogException - for a specific SmartFrog problem
java.net.UnknownHostException - if the target host is unknown
java.rmi.ConnectException - if the remote system's SmartFrog daemon is unreachable
java.rmi.RemoteException - if something goes wrong during the communication
SFGeneralSecurityException - for security trouble

createRootProcess

protected static ProcessCompound createRootProcess()
                                            throws SmartFrogException,
                                                   java.rmi.RemoteException
Throws:
SmartFrogException
java.rmi.RemoteException

initSystem

public static void initSystem()
                       throws SmartFrogException,
                              SFGeneralSecurityException
initialise the system. Turn security on, read properties from an ini file and then look at stack tracing. This method is idempotent and synchronised; you can only init the system once.

Throws:
SmartFrogException
SFGeneralSecurityException

sfLog

public static LogSF sfLog()
Returns:
LogSF

isSmartfrogInit

public static boolean isSmartfrogInit()
test for the system being initialised already

Returns:
true if we have already initialised the system

getInputStreamForResource

public static java.io.InputStream getInputStreamForResource(java.lang.String resourceSFURL)
                                                     throws SmartFrogException
Gets input stream for the given resource. Throws exception if stream is null.

Parameters:
resourceSFURL - Name of the resource. SF url valid.
Returns:
Input stream for the resource
Throws:
SmartFrogException - if input stream could not be created for the resource
See Also:
SFClassLoader

getByteArrayForResource

public static byte[] getByteArrayForResource(java.lang.String resourceSFURL)
                                      throws SmartFrogException
Gets ByteArray for the given resource. Throws exception if stream is null.

Parameters:
resourceSFURL - Name of the resource. SF url valid.
Returns:
ByteArray (byte []) with the resource data
Throws:
SmartFrogException - if input stream could not be created for the resource
See Also:
SFClassLoader

getRootProcess

public ProcessCompound getRootProcess()
get the root process

Returns:
the root process, null for none.

setRootProcess

public void setRootProcess(ProcessCompound rootProcess)
set the root process; this is called after it is started.

Parameters:
rootProcess - process compoond; may be

terminateSystem

public void terminateSystem(java.lang.String message)
terminate the system. the rootProcess field is set to null afterwards. Any error is dealt with by printing a stack trace to system.err.

Parameters:
message - message to send

SmartFrog CORE 3.10.000

(C) Copyright 1998-2006 Hewlett-Packard Development Company, LP