SmartFrog 3.10.000

org.smartfrog.sfcore.compound
Class CompoundImpl

java.lang.Object
  extended by org.smartfrog.sfcore.reference.RemoteReferenceResolverHelperImpl
      extended by org.smartfrog.sfcore.prim.PrimImpl
          extended by org.smartfrog.sfcore.compound.CompoundImpl
All Implemented Interfaces:
java.rmi.Remote, MessageKeys, Compound, ChildMinder, Diagnostics, Liveness, Prim, RemoteReferenceResolver, RemoteReferenceResolverHelper
Direct Known Subclasses:
ApacheImpl, ArrayCompoundImpl, Autoloader, CopyFileImpl, DetachingCompoundImpl, EventCompoundImpl, FileUsingCompoundImpl, GraphImpl, NetElemImpl, ProcessCompoundImpl, SFSetPropertyImpl, Spawn, Tester, ThresholderImpl, UpdatableCompound

public class CompoundImpl
extends PrimImpl
implements Compound

Implements the compound component behavior. A compound deploys component descriptions, and maintains them as its children. This includes liveness, termination and location behavior


Field Summary
static int childCap
          Initial capacity for child vector.
static int childInc
          Capacity increment for child vector.
protected  java.util.Vector lifecycleChildren
          Maintains a temporal list of the children that have to be driven through their sfDeploy and sfStart lifecycle methods.
protected  java.util.Vector sfChildren
          Maintains children on which life of compound depends (and vice versa).
protected  boolean sfSyncTerminate
          Whether termination should be synchronous.
 
Fields inherited from class org.smartfrog.sfcore.prim.PrimImpl
refLivenessDelay, refLivenessFactor, sfCompleteName, sfContext, sfDeployHooks, sfDeployWithHooks, sfExportRef, sfIsDeployed, sfIsStarted, sfIsTerminated, sfIsTerminating, sfLivenessCount, sfLivenessDelay, sfLivenessFactor, sfLivenessSender, sfParent, sfStartHooks, sfTerminateWithHooks, termLock
 
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
CompoundImpl()
          Creates a compound implementation.
 
Method Summary
 void sfAddChild(Liveness target)
          Liveness interface to compound.
protected  void sfASyncTerminateWith(TerminationRecord status)
          Terminate children asynchronously using a seperate thread for each call.
 java.util.Enumeration sfChildren()
          Returns an enumeration over the children of the compound.
 boolean sfContainsChild(Liveness child)
          Checks whether this compound contains given child.
 Prim sfCreateNewApp(java.lang.String name, ComponentDescription cmp, Context parms)
          A high-level component deployment method - creates an app , running it through its entire lifecycle.
 Prim sfCreateNewChild(java.lang.Object name, ComponentDescription cmp, Context parms)
          A high-level component deployment method - creates a child of this Compound, running it through its entire lifecycle.
 Prim sfCreateNewChild(java.lang.Object name, Prim parent, ComponentDescription cmp, Context parms)
          A high-level component deployment method - creates a child of 'parent' Compound, running it through its entire lifecycle.
 void sfDeploy()
          Deploy the compound.
protected  void sfDeployChildren()
          This is an override point.
 Prim sfDeployComponentDescription(java.lang.Object name, Prim parent, ComponentDescription cmp, Context parms)
          An internal SmartFrog method.
 void sfDeployWith(Prim parent, Context cxt)
          Primitive deploy call.
protected  void sfDeployWithChildren()
          Method that selects the children that compound will drive through their lifecycle The children are stored in 'lifecycleChildren'
 void sfDumpState(Dump target)
          Override to forward call to all liveness targets.
 void sfParentageChanged()
          Parentage changed in component hierachy.
 void sfPing(java.lang.Object source)
          Implements ping for a compound.
protected  void sfPingChild(Liveness child)
          Called for each child by sfPing if liveness is to be passed on.
 java.lang.Object sfRemoveAttribute(java.lang.Object key)
          Override superclass behaviour.
 boolean sfRemoveChild(Liveness target)
          Removes a liveness interface from the heartbeat targets.
 void sfStart()
          Starts the compound.
protected  void sfStartChildren()
          This is an override point.
protected  void sfSyncTerminateWith(TerminationRecord status)
          Iterates over children telling each of them to terminate quietly with given status.
 void sfTerminatedWith(TerminationRecord status, Prim comp)
          Sent by sub-components on termination.
protected  void sfTerminateWith(TerminationRecord status)
          Performs the compound termination behaviour.
 
Methods inherited from class org.smartfrog.sfcore.prim.PrimImpl
equals, hashCode, registerWithProcessCompound, sfAddAttribute, sfAttributeKeyFor, sfAttributes, sfCompleteName, sfCompleteNameSafe, sfContainsAttribute, sfContainsValue, sfContext, sfDeployedHost, sfDeployedProcessName, sfDetach, sfDetachAndTerminate, sfDiagnosticsReport, sfExport, sfExportRef, sfExportRef, sfGetApplicationLog, sfGetCoreLog, sfGetLog, sfIsDeployed, sfIsRemote, sfIsStarted, sfIsTerminated, sfIsTerminating, sfLivenessFailure, sfLog, sfParent, sfReplaceAttribute, sfResolve, sfResolve, sfResolveHere, sfResolveHere, sfResolveParent, sfSetLog, sfStartLivenessSender, sfStopLivenessSender, sfTerminate, sfTerminateQuietlyWith, sfValues, terminateComponent, terminateNotifying, toString
 
Methods inherited from class org.smartfrog.sfcore.reference.RemoteReferenceResolverHelperImpl
sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolveWithParser
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.smartfrog.sfcore.prim.Prim
sfAddAttribute, sfAttributeKeyFor, sfAttributes, sfCompleteName, sfContainsAttribute, sfContainsValue, sfContext, sfDeployedHost, sfDeployedProcessName, sfDetach, sfDetachAndTerminate, sfIsDeployed, sfIsStarted, sfIsTerminated, sfIsTerminating, sfParent, sfReplaceAttribute, sfTerminate, sfTerminateQuietlyWith, sfValues
 
Methods inherited from interface org.smartfrog.sfcore.reference.RemoteReferenceResolver
sfResolve, sfResolve, sfResolveHere, sfResolveHere, sfResolveParent
 
Methods inherited from interface org.smartfrog.sfcore.reference.RemoteReferenceResolverHelper
sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolveWithParser
 
Methods inherited from interface org.smartfrog.sfcore.prim.Diagnostics
sfDiagnosticsReport
 

Field Detail

childCap

public static int childCap
Initial capacity for child vector. Looks up Compound.childCap (offset by SmartFrogCoreProperty.propBaseCompound). Defaults to 5 if not there


childInc

public static int childInc
Capacity increment for child vector. Looks up Compound.childInc (offset by SmartFrogCoreProperty.propBaseCompound). Defaults to 2 if not there


sfChildren

protected java.util.Vector sfChildren
Maintains children on which life of compound depends (and vice versa).


lifecycleChildren

protected java.util.Vector lifecycleChildren
Maintains a temporal list of the children that have to be driven through their sfDeploy and sfStart lifecycle methods.


sfSyncTerminate

protected boolean sfSyncTerminate
Whether termination should be synchronous. Determined by the sfSyncTerminate attribute "true" or "false"

Constructor Detail

CompoundImpl

public CompoundImpl()
             throws java.rmi.RemoteException
Creates a compound implementation.

Throws:
java.rmi.RemoteException - In case of Remote/nework error
Method Detail

sfDeployComponentDescription

public Prim sfDeployComponentDescription(java.lang.Object name,
                                         Prim parent,
                                         ComponentDescription cmp,
                                         Context parms)
                                  throws SmartFrogDeploymentException
An internal SmartFrog method. It deploys a compiled component and makes it an attribute of the parent compound. Also start heartbeating the deployed component if the component registers. Note that the remaining lifecycle methods must still be invoked on the created component - namely sfDeploy() and sfStart(). This is primarily an internal method - the prefered method for end users is #sfCreateNewChild. Note that the remaining lifecycle methods must still be invoked on the created component - namely sfDeploy() and sfStart(). This is primarily an internal method - the preferred method for end users is #sfCreateNewChild.

Specified by:
sfDeployComponentDescription in interface Compound
Parameters:
name - name to name deployed component under in context
parent - of deployer component
cmp - compiled component to deploy
parms - parameters for description
Returns:
newly deployed component
Throws:
SmartFrogDeploymentException - failed to deploy compiled component

sfCreateNewChild

public Prim sfCreateNewChild(java.lang.Object name,
                             ComponentDescription cmp,
                             Context parms)
                      throws java.rmi.RemoteException,
                             SmartFrogDeploymentException
A high-level component deployment method - creates a child of this Compound, running it through its entire lifecycle. This is the preferred way of creating new child components of a Compound. The method is safe against multiple calls of lifecycle.

Specified by:
sfCreateNewChild in interface Compound
Parameters:
name - name of attribute which the deployed component should adopt
cmp - compiled component to deploy and start
parms - parameters for description
Returns:
deployed component if successfull
Throws:
SmartFrogDeploymentException - failed to deploy compiled component
java.rmi.RemoteException - In case of Remote/nework error

sfCreateNewApp

public Prim sfCreateNewApp(java.lang.String name,
                           ComponentDescription cmp,
                           Context parms)
                    throws java.rmi.RemoteException,
                           SmartFrogDeploymentException
A high-level component deployment method - creates an app , running it through its entire lifecycle. This is the preferred way of creating new app.

Specified by:
sfCreateNewApp in interface Compound
Parameters:
name - name for the new application
cmp - compiled component to deploy and start
parms - parameters for description
Returns:
deployed component if successful
Throws:
SmartFrogDeploymentException - failed to deploy compiled component
java.rmi.RemoteException - In case of Remote/nework error

sfCreateNewChild

public Prim sfCreateNewChild(java.lang.Object name,
                             Prim parent,
                             ComponentDescription cmp,
                             Context parms)
                      throws java.rmi.RemoteException,
                             SmartFrogDeploymentException
A high-level component deployment method - creates a child of 'parent' Compound, running it through its entire lifecycle. This is the preferred way of creating new child components of a Compound.

Specified by:
sfCreateNewChild in interface Compound
Parameters:
name - name of attribute which the deployed component should adopt
parent - of deployer component
cmp - compiled component to deploy and start
parms - parameters for description
Returns:
deployed component if successfull
Throws:
SmartFrogDeploymentException - failed to deploy compiled component
java.rmi.RemoteException - In case of Remote/nework error

sfAddChild

public void sfAddChild(Liveness target)
                throws java.rmi.RemoteException
Liveness interface to compound. A liveness target must be an attribute off the compound.

Specified by:
sfAddChild in interface ChildMinder
Parameters:
target - target to heartbeat
Throws:
java.rmi.RemoteException - In case of Remote/nework error

sfRemoveChild

public boolean sfRemoveChild(Liveness target)
                      throws SmartFrogRuntimeException,
                             java.rmi.RemoteException
Removes a liveness interface from the heartbeat targets. The target is also removed as an attribute of the compound.

Specified by:
sfRemoveChild in interface ChildMinder
Parameters:
target - object to remove from heartbeat
Returns:
true if child is removed successfully else false
Throws:
SmartFrogRuntimeException - if failed to remove the child
java.rmi.RemoteException - In case of Remote/nework error

sfContainsChild

public boolean sfContainsChild(Liveness child)
Checks whether this compound contains given child.

Specified by:
sfContainsChild in interface ChildMinder
Parameters:
child - child to check
Returns:
true if child in compound, false otherwise

sfChildren

public java.util.Enumeration sfChildren()
Returns an enumeration over the children of the compound.

Specified by:
sfChildren in interface ChildMinder
Returns:
enumeration over children

sfRemoveAttribute

public java.lang.Object sfRemoveAttribute(java.lang.Object key)
                                   throws SmartFrogRuntimeException,
                                          java.rmi.RemoteException
Override superclass behaviour. If in heart beat then remove.

Specified by:
sfRemoveAttribute in interface Prim
Overrides:
sfRemoveAttribute in class PrimImpl
Parameters:
key - attribute key to remove
Returns:
Reference to removed object
Throws:
SmartFrogRuntimeException - when name is null
java.rmi.RemoteException - In case of Remote/nework error

sfDeployWith

public void sfDeployWith(Prim parent,
                         Context cxt)
                  throws SmartFrogDeploymentException,
                         java.rmi.RemoteException
Primitive deploy call. Causes the compound to do initial deployment of its contained eager component descriptions. Deployed results are then placed in the compound context. It is the responsibility of the deployed component to register with the heart beat of the compound. PrimImpl takes care of that as part of the sfDeployWith call.

Specified by:
sfDeployWith in interface Prim
Overrides:
sfDeployWith in class PrimImpl
Parameters:
parent - parent component
cxt - context for compound
Throws:
SmartFrogDeploymentException - failed to deploy sub-components
java.rmi.RemoteException - In case of Remote/nework error

sfDeployWithChildren

protected void sfDeployWithChildren()
                             throws SmartFrogDeploymentException
Method that selects the children that compound will drive through their lifecycle The children are stored in 'lifecycleChildren'

Throws:
SmartFrogDeploymentException

sfDeploy

public void sfDeploy()
              throws SmartFrogException,
                     java.rmi.RemoteException
Deploy the compound. Deployment is defined as iterating over the context and deploying any parsed eager components.

Specified by:
sfDeploy in interface Prim
Overrides:
sfDeploy in class PrimImpl
Throws:
SmartFrogException - failure deploying compound or sub-component
java.rmi.RemoteException - In case of Remote/nework error

sfDeployChildren

protected void sfDeployChildren()
                         throws SmartFrogResolutionException,
                                java.rmi.RemoteException,
                                SmartFrogLifecycleException
This is an override point. It is called during sfDeploy() after Prim has deployed, and it instantiates all children. It is not synchronized, but is called from a synchronized parent method. If overridden, a subclass must call super.sfDeployChildren() if they want to deploy any children.

Throws:
SmartFrogResolutionException - if stuff cannot get resolved
java.rmi.RemoteException - if the network is playing up
SmartFrogLifecycleException - if any exception (or throwable) is raised by a child component.

sfStart

public void sfStart()
             throws SmartFrogException,
                    java.rmi.RemoteException
Starts the compound. This sends a synchronous sfStart to all managed components in the compound context. Any failure will cause the compound to terminate

Specified by:
sfStart in interface Prim
Overrides:
sfStart in class PrimImpl
Throws:
SmartFrogException - failed to start compound
java.rmi.RemoteException - In case of Remote/nework error

sfStartChildren

protected void sfStartChildren()
                        throws SmartFrogLifecycleException,
                               java.rmi.RemoteException,
                               SmartFrogResolutionException
This is an override point. It is called during sfStart() after Prim has started, and it starts all children. It is not synchronized, but is called from a synchronized parent method. If overridden, a subclass must call super.sfStartChildren() if they want to start any children.

Throws:
SmartFrogResolutionException - if stuff cannot get resolved
java.rmi.RemoteException - if the network is playing up
SmartFrogLifecycleException - if any exception (or throwable) is raised by a child component.

sfTerminateWith

protected void sfTerminateWith(TerminationRecord status)
Performs the compound termination behaviour. Based on sfSyncTerminate flag this gets forwarded to sfSyncTerminate or sfASyncTerminateWith method. Terminates children before self.

Overrides:
sfTerminateWith in class PrimImpl
Parameters:
status - termination status

sfSyncTerminateWith

protected void sfSyncTerminateWith(TerminationRecord status)
Iterates over children telling each of them to terminate quietly with given status. It iterates from the last one created to the first one.

Parameters:
status - status to terminate with

sfASyncTerminateWith

protected void sfASyncTerminateWith(TerminationRecord status)
Terminate children asynchronously using a seperate thread for each call. It iterates from the last one created to the first one.

Parameters:
status - status to terminate with

sfTerminatedWith

public void sfTerminatedWith(TerminationRecord status,
                             Prim comp)
Sent by sub-components on termination. Compound behaviour is to terminate itself if the sending component is one if it's heart beat targets.

Specified by:
sfTerminatedWith in interface Prim
Overrides:
sfTerminatedWith in class PrimImpl
Parameters:
status - termination status of sender
comp - sender of termination

sfDumpState

public void sfDumpState(Dump target)
Override to forward call to all liveness targets.

Specified by:
sfDumpState in interface Prim
Overrides:
sfDumpState in class PrimImpl
Parameters:
target - target to dump to

sfPing

public void sfPing(java.lang.Object source)
            throws SmartFrogLivenessException,
                   java.rmi.RemoteException
Implements ping for a compound. A compound extends prim functionality by pinging each of its children, any failure to do so will call sfLivenessFailure with the compound as source and the errored child as target. The exception that ocurred is also passed in. This check is only done if the source is non-null and if the source is the parent (if parent exists). If there is no parent and the source is non-null the check is still done.

Specified by:
sfPing in interface Liveness
Overrides:
sfPing in class PrimImpl
Parameters:
source - source of ping
Throws:
SmartFrogLivenessException - liveness failed
java.rmi.RemoteException - for consistency with the Liveness interface

sfPingChild

protected void sfPingChild(Liveness child)
                    throws SmartFrogLivenessException,
                           java.rmi.RemoteException
Called for each child by sfPing if liveness is to be passed on.

Parameters:
child - child to send to
Throws:
SmartFrogLivenessException - failed to ping child
java.rmi.RemoteException - In case of Remote/nework error

sfParentageChanged

public void sfParentageChanged()
                        throws java.rmi.RemoteException
Parentage changed in component hierachy. A notification is sent to all children.

Specified by:
sfParentageChanged in interface Prim
Overrides:
sfParentageChanged in class PrimImpl
Throws:
java.rmi.RemoteException - In case of Remote/nework error

SmartFrog CORE 3.10.000

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