SmartFrog 3.10.000

org.smartfrog.sfcore.prim
Class PrimImpl

java.lang.Object
  extended by org.smartfrog.sfcore.reference.RemoteReferenceResolverHelperImpl
      extended by org.smartfrog.sfcore.prim.PrimImpl
All Implemented Interfaces:
java.rmi.Remote, MessageKeys, Diagnostics, Liveness, Prim, RemoteReferenceResolver, RemoteReferenceResolverHelper
Direct Known Subclasses:
AbstractClasspathImpl, AbstractPolicy, AssertComponent, BalancerImpl, CompoundImpl, CounterImpl, CPUMonitorImpl, EventPrimImpl, ExampleTemplateImpl, FileUsingComponentImpl, GeneratorImpl, InputImpl, JavaPackageImpl, LibraryClasspathImpl, LoadClassImpl, LoggerImpl, OutputImpl, PrinterImpl, RunShellImpl, SFConcatImpl, SFDisplay, SFLogRegistrationImpl, SFLogStdStreamImpl, SFLogToFile, SFMCastClientImpl, SFMCastServerImpl, SFPersist, SFPrimLogImpl, SFProcessExecutionImpl, SFReplaceFileVar, SFScriptExecutionImpl, SFScriptImpl, SFTrace, StressControlGuiImpl, StressTesterImpl, SystemPropertiesImpl, UpdatablePrim

public class PrimImpl
extends RemoteReferenceResolverHelperImpl
implements Prim, MessageKeys

Defines the base class for all deployed components. A deployed component knows how to react to termination, deployment requests and heart beats. This implementation allows subclasses to define how a deployed component is communicated with. The sfExport attribute is examined. If set to "true" the sfExportRef method is called, which by default uses RMI to export the component. Subclasses may choose to export a component another way.

A liveness thread is started for a primitive if it has no parent, but is expected to have children (like Compound), or if the parent is remote. Liveness attribute sfLivenessDelay dictates how often (in seconds) sfPing is supposed to be called. sfLivenessFactor is the multiplier for sfLivenessDelay to wait until the primitive declares that there is a liveness failure. Both attributes are looked up using ATTRIB in order to find out whether a parent has set liveness on.


Field Summary
protected static Reference refLivenessDelay
          Reference used to look up sfLivenessDelay attributes.
protected static Reference refLivenessFactor
          Reference used to look up sfLivenessFactor attributes.
protected  Reference sfCompleteName
          Reference that caches cannonical name.
protected  Context sfContext
          Attribute context.
static PrimHookSet sfDeployHooks
          Static attribute that hold the lifecycle hooks for sfDeploy.
static PrimHookSet sfDeployWithHooks
          Static attribute that hold the lifecycle hooks for sfDeployWith.
protected  java.lang.Object sfExportRef
          Reference to export form of self if sfExport is true.
protected  boolean sfIsDeployed
          Flag indicating that this component has been deployed.
protected  boolean sfIsStarted
          Flag indicating that this component has been started.
protected  boolean sfIsTerminated
          Flag indicating that this component has been terminated.
protected  boolean sfIsTerminating
          Flag indicating that this component termination is initiated.
protected  int sfLivenessCount
          Current count for liveness, updated through sfPing.
protected  long sfLivenessDelay
          How often to send liveness in seconds.
protected  int sfLivenessFactor
          Livneess factor.
protected  LivenessSender sfLivenessSender
          Timer for initiating heartbeats.
protected  Prim sfParent
          Parent.
static PrimHookSet sfStartHooks
          Static attribute that hold the lifecycle hooks for sfStart.
static PrimHookSet sfTerminateWithHooks
          Static attribute that hold the lifecycle hooks for sfTerminateWith.
protected  java.lang.Object 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
PrimImpl()
          Used in conjunction with sfDeployWith to set parent and context after creation.
 
Method Summary
 boolean equals(java.lang.Object o)
          Implemented to provide for remote equality checking.
 int hashCode()
          Returns the hashcode for the exported object if it was exported, the object itself if not.
protected  void registerWithProcessCompound()
          Registers component with local ProcessCompound only if it is root component, its parent is remote or the attribute sfProcessComponentName is defined.
 java.lang.Object sfAddAttribute(java.lang.Object name, java.lang.Object value)
          Adds an attribute to this component under given name.
 java.lang.Object sfAttributeKeyFor(java.lang.Object value)
          Returns the attribute key given a value.
 java.util.Iterator sfAttributes()
          Returns an ordered iterator over the attribute names in this component.
 Reference sfCompleteName()
          Returns the complete name for this component from the root of the application.
 Reference sfCompleteNameSafe()
          Returns the complete name for this component from the root of the application and does not throw any exception.
 boolean sfContainsAttribute(java.lang.Object attribute)
          Returns true if the context contains attribute.
 boolean sfContainsValue(java.lang.Object value)
          Returns true if the context contains value.
 Context sfContext()
          Returns the context of this component.
 void sfDeploy()
          Called after instantiation for deployment purposes.
 java.net.InetAddress sfDeployedHost()
          Request the host on which this component is deployed.
 java.lang.String sfDeployedProcessName()
          Request the process in which this component is deployed, the name being that defined in the sfProcessName attribute or the string ROOT if in the root process compound.
 void sfDeployWith(Prim parent, Context cxt)
          Private method to set up newly created component.
 void sfDetach()
          Get this object to detach from its parent.
 void sfDetachAndTerminate(TerminationRecord status)
          Get this object to terminate, after detaching itself from its parent.
 ComponentDescription sfDiagnosticsReport()
          Creates diagnostics report
 void sfDumpState(Dump target)
          Default dump state behavior is to send the context to the target.
protected  java.lang.Object sfExport(java.lang.Object portObj)
          Exports this component using portObj.
 java.lang.Object sfExportRef()
          Export this primitive to accept remote method calls using an anonymous port.
 java.lang.Object sfExportRef(int port)
          Export this primitive to accept remote method calls using port.
 LogSF sfGetApplicationLog()
          To get application logger using ROOT name.
 LogSF sfGetCoreLog()
          To get the sfCore logger
 LogSF sfGetLog(java.lang.String name)
          To get a logger with a particular name.
 boolean sfIsDeployed()
          Returns value of flag indicating if this component has been deployed.
protected  boolean sfIsRemote(java.lang.Object o)
          Checks whether given object is a non-local object.
 boolean sfIsStarted()
          Returns value of flag indicating if this component has been started.
 boolean sfIsTerminated()
          Returns value of flag indicating if this component has been terminated.
 boolean sfIsTerminating()
          Returns value of flag indicating if this component is terminating.
protected  void sfLivenessFailure(java.lang.Object source, java.lang.Object target, java.lang.Throwable failure)
          Handle ping failures.
 LogSF sfLog()
          To log into sfCore logger.
 Prim sfParent()
          Returns the parent of this component.
 void sfParentageChanged()
          Parentage changed in component hierachy.
 void sfPing(java.lang.Object source)
          Liveness call in to check if this component is still alive.
 java.lang.Object sfRemoveAttribute(java.lang.Object name)
          Removes an attribute from this component.
 java.lang.Object sfReplaceAttribute(java.lang.Object name, java.lang.Object value)
          Replace named attribute in component context.
 java.lang.Object sfResolve(Reference r)
          Resolves a given reference.
 java.lang.Object sfResolve(Reference r, int index)
          Resolves given reference starting at given index.
 java.lang.Object sfResolveHere(java.lang.Object name)
          Find an attribute in this component context.
 java.lang.Object sfResolveHere(java.lang.Object name, boolean mandatory)
          Find an attribute in this context.
 java.lang.Object sfResolveParent()
          Returns the parent for this component.
 LogSF sfSetLog(LogSF newlog)
          Method to replace logger used by components.
 void sfStart()
          Can be called to start components.
protected  void sfStartLivenessSender()
          initializes and starts the liveness sender for this primitive.
protected  void sfStopLivenessSender()
          Stops the liveness sender if this component has one.
 void sfTerminate(TerminationRecord status)
          Request this component to terminate.
 void sfTerminatedWith(TerminationRecord status, Prim comp)
          Called from sub-component (normally) to indicate termination.
 void sfTerminateQuietlyWith(TerminationRecord status)
          Called from up the containment tree to terminate.
protected  void sfTerminateWith(TerminationRecord status)
          Provides hook for subclasses to implement useful termination behavior.
 java.util.Iterator sfValues()
          Returns an ordered iterator over the attibute values in this component.
protected  void terminateComponent(Prim targetComponent, java.lang.Throwable excp, Reference componentId)
          Terminates the component in a seperate thread.
protected  void terminateNotifying(TerminationRecord status, Prim comp)
          Notifies a component that this component has terminated through sfTerminatedWith and calls the local hook (sfTerminateWith).
 java.lang.String toString()
          Returns the string of the remote reference if this primitive was exported, the superclass toString if not.
 
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.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
 

Field Detail

sfDeployHooks

public static final PrimHookSet sfDeployHooks
Static attribute that hold the lifecycle hooks for sfDeploy.


sfStartHooks

public static final PrimHookSet sfStartHooks
Static attribute that hold the lifecycle hooks for sfStart.


sfDeployWithHooks

public static final PrimHookSet sfDeployWithHooks
Static attribute that hold the lifecycle hooks for sfDeployWith.


sfTerminateWithHooks

public static final PrimHookSet sfTerminateWithHooks
Static attribute that hold the lifecycle hooks for sfTerminateWith.


refLivenessDelay

protected static final Reference refLivenessDelay
Reference used to look up sfLivenessDelay attributes.


refLivenessFactor

protected static final Reference refLivenessFactor
Reference used to look up sfLivenessFactor attributes.


sfIsTerminated

protected boolean sfIsTerminated
Flag indicating that this component has been terminated.


sfIsTerminating

protected boolean sfIsTerminating
Flag indicating that this component termination is initiated.


sfIsDeployed

protected boolean sfIsDeployed
Flag indicating that this component has been deployed.


sfIsStarted

protected boolean sfIsStarted
Flag indicating that this component has been started.


sfParent

protected Prim sfParent
Parent.


sfContext

protected Context sfContext
Attribute context.


sfLivenessSender

protected LivenessSender sfLivenessSender
Timer for initiating heartbeats.


sfLivenessCount

protected int sfLivenessCount
Current count for liveness, updated through sfPing.


sfLivenessFactor

protected int sfLivenessFactor
Livneess factor. Initializer for liveness count. How many multiples of livenss delay to wait till a liveness failure of the parent is declared, Defaults to 2.


sfLivenessDelay

protected long sfLivenessDelay
How often to send liveness in seconds. Defaults to 0 (off, ie. no liveness).


sfExportRef

protected java.lang.Object sfExportRef
Reference to export form of self if sfExport is true.


sfCompleteName

protected Reference sfCompleteName
Reference that caches cannonical name.


termLock

protected final java.lang.Object termLock
Constructor Detail

PrimImpl

public PrimImpl()
         throws java.rmi.RemoteException
Used in conjunction with sfDeployWith to set parent and context after creation.

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

sfResolveHere

public java.lang.Object sfResolveHere(java.lang.Object name)
                               throws SmartFrogResolutionException
Find an attribute in this component context.

Specified by:
sfResolveHere in interface RemoteReferenceResolver
Parameters:
name - attribute key to resolve
Returns:
Object Reference
Throws:
SmartFrogResolutionException - failed to find attribute

sfResolveHere

public java.lang.Object sfResolveHere(java.lang.Object name,
                                      boolean mandatory)
                               throws SmartFrogResolutionException
Find an attribute in this context.

Specified by:
sfResolveHere in interface RemoteReferenceResolver
Parameters:
name - attribute key to resolve
mandatory - boolean that indicates if this attribute must be present in the description. If it is mandatory and not found it throws a SmartFrogResolutionException
Returns:
Object value for attribute
Throws:
SmartFrogResolutionException - failed to find attribute

sfResolveParent

public java.lang.Object sfResolveParent()
Returns the parent for this component.

Specified by:
sfResolveParent in interface RemoteReferenceResolver
Returns:
parent for this component or null if none

sfResolve

public java.lang.Object sfResolve(Reference r)
                           throws SmartFrogResolutionException,
                                  java.rmi.RemoteException
Resolves a given reference. Forwards to indexed resolve with index 0 and return resulting attribute value.

Specified by:
sfResolve in interface RemoteReferenceResolver
Specified by:
sfResolve in class RemoteReferenceResolverHelperImpl
Parameters:
r - reference to resolve
Returns:
resolved reference
Throws:
SmartFrogResolutionException - occurred while resolving
java.rmi.RemoteException - In case of network/rmi error

sfResolve

public java.lang.Object sfResolve(Reference r,
                                  int index)
                           throws SmartFrogResolutionException,
                                  java.rmi.RemoteException
Resolves given reference starting at given index. This is forwarded to the reference (and on to each reference part).

Specified by:
sfResolve in interface RemoteReferenceResolver
Specified by:
sfResolve in class RemoteReferenceResolverHelperImpl
Parameters:
r - reference to resolve
index - index in reference to start resolving
Returns:
resolved reference
Throws:
SmartFrogResolutionException - error occurred while resolving
java.rmi.RemoteException - In case of network/rmi error

sfDeployedHost

public java.net.InetAddress sfDeployedHost()
                                    throws java.rmi.RemoteException
Request the host on which this component is deployed.

Specified by:
sfDeployedHost in interface Prim
Returns:
the host InetAddress
Throws:
java.rmi.RemoteException - In case of network/rmi error

sfDeployedProcessName

public java.lang.String sfDeployedProcessName()
                                       throws java.rmi.RemoteException
Request the process in which this component is deployed, the name being that defined in the sfProcessName attribute or the string ROOT if in the root process compound.

Specified by:
sfDeployedProcessName in interface Prim
Returns:
the name of the process
Throws:
java.rmi.RemoteException - In case of Remote/network error

sfAddAttribute

public java.lang.Object sfAddAttribute(java.lang.Object name,
                                       java.lang.Object value)
                                throws SmartFrogRuntimeException,
                                       java.rmi.RemoteException
Adds an attribute to this component under given name. If the attribute value is a ComponentDescription then this component is set as its parent

Specified by:
sfAddAttribute in interface Prim
Parameters:
name - name of attribute
value - value of attribute
Returns:
added attribute if non-existent or null otherwise
Throws:
SmartFrogRuntimeException - when name or value are null
java.rmi.RemoteException - In case of Remote/nework error

sfRemoveAttribute

public java.lang.Object sfRemoveAttribute(java.lang.Object name)
                                   throws SmartFrogRuntimeException,
                                          java.rmi.RemoteException
Removes an attribute from this component. If the attribute value removed is a component description, then its prim parent is removed as well.

Specified by:
sfRemoveAttribute in interface Prim
Parameters:
name - of attribute to be removed
Returns:
removed attribute value if successfull or null if not
Throws:
SmartFrogRuntimeException - when name is null
java.rmi.RemoteException - In case of Remote/nework error

sfReplaceAttribute

public java.lang.Object sfReplaceAttribute(java.lang.Object name,
                                           java.lang.Object value)
                                    throws SmartFrogRuntimeException,
                                           java.rmi.RemoteException
Replace named attribute in component context. If attribute is not present it is added to the context. If the attribute value added is a component description, then its parent is set to this and/or if the one removed is a component description then its parent is reset.

Specified by:
sfReplaceAttribute in interface Prim
Parameters:
name - of attribute to replace
value - value to add or replace
Returns:
the old value if present, null otherwise. It old value was a component description, then its prim parent is reset.
Throws:
SmartFrogRuntimeException - when name or value are null
java.rmi.RemoteException - In case of Remote/nework error

sfAttributeKeyFor

public java.lang.Object sfAttributeKeyFor(java.lang.Object value)
Returns the attribute key given a value.

Specified by:
sfAttributeKeyFor in interface Prim
Parameters:
value - value to look up key for
Returns:
key for attribute value or null if none

sfContainsValue

public boolean sfContainsValue(java.lang.Object value)
                        throws java.rmi.RemoteException
Returns true if the context contains value.

Specified by:
sfContainsValue in interface Prim
Parameters:
value - object to check
Returns:
true if context contains value, false otherwise
Throws:
java.rmi.RemoteException - In case of Remote/nework error

sfContainsAttribute

public boolean sfContainsAttribute(java.lang.Object attribute)
                            throws java.rmi.RemoteException
Returns true if the context contains attribute.

Specified by:
sfContainsAttribute in interface Prim
Parameters:
attribute - to check
Returns:
true if context contains attribute, false otherwise
Throws:
java.rmi.RemoteException - In case of Remote/nework error

sfAttributes

public java.util.Iterator sfAttributes()
                                throws java.rmi.RemoteException
Returns an ordered iterator over the attribute names in this component. The remove operation of this Iterator won't affect the contents of this component

Specified by:
sfAttributes in interface Prim
Returns:
iterator
Throws:
java.rmi.RemoteException - In case of Remote/nework error

sfValues

public java.util.Iterator sfValues()
                            throws java.rmi.RemoteException
Returns an ordered iterator over the attibute values in this component. The remove operation of this Iterator won't affect the contents of this component

Specified by:
sfValues in interface Prim
Returns:
iterator
Throws:
java.rmi.RemoteException - In case of Remote/nework error

sfContext

public Context sfContext()
Returns the context of this component.

Specified by:
sfContext in interface Prim
Returns:
component context

sfCompleteName

public Reference sfCompleteName()
                         throws java.rmi.RemoteException
Returns the complete name for this component from the root of the application.

Specified by:
sfCompleteName in interface Prim
Returns:
reference of attribute names to this component
Throws:
java.rmi.RemoteException - In case of network/rmi error

sfCompleteNameSafe

public Reference sfCompleteNameSafe()
Returns the complete name for this component from the root of the application and does not throw any exception. If an exception is thrown it will return a new empty reference.

Specified by:
sfCompleteNameSafe in class RemoteReferenceResolverHelperImpl
Returns:
reference of attribute names to this component or an empty reference

sfParent

public Prim sfParent()
              throws java.rmi.RemoteException
Returns the parent of this component.

Specified by:
sfParent in interface Prim
Returns:
parent component
Throws:
java.rmi.RemoteException - In case of Remote/nework error

sfDeployWith

public void sfDeployWith(Prim parent,
                         Context cxt)
                  throws SmartFrogDeploymentException,
                         java.rmi.RemoteException
Private method to set up newly created component. Primitives should only override sfDeploy since this is the one which does the actual work

Specified by:
sfDeployWith in interface Prim
Parameters:
parent - parent of component
cxt - context for component
Throws:
SmartFrogDeploymentException - In case of any error while deploying the component
java.rmi.RemoteException - In case of network/rmi error

sfExport

protected java.lang.Object sfExport(java.lang.Object portObj)
                             throws java.rmi.RemoteException,
                                    java.rmi.RemoteException,
                                    SmartFrogException
Exports this component using portObj. portObj can be a port or a vector containing a set of valid ports. If a vector is used the component tries to see if the port used by the local ProcessCompound is in the vector set and use that if so. If not tries to use the first one avaible

Parameters:
portObj - Object
Returns:
Object Reference to exported object
Throws:
java.rmi.RemoteException - In case of Remote/nework error
SmartFrogException - if failed to export

registerWithProcessCompound

protected void registerWithProcessCompound()
                                    throws java.rmi.RemoteException,
                                           SmartFrogException
Registers component with local ProcessCompound only if it is root component, its parent is remote or the attribute sfProcessComponentName is defined.

Throws:
java.rmi.RemoteException - In case of Remote/nework error
SmartFrogException - if failed to register

sfExportRef

public java.lang.Object sfExportRef(int port)
                             throws SmartFrogException
Export this primitive to accept remote method calls using port. If port value is 0 it will be using an anonymous port. Default implementation is to use UnicastRemoteObject. Check is done if sfExportRef is already set, in which case this is returned. Note that for remote methods to work equals, hashCode and toString must be implemented. This is done for PrimImpl in which case those requests are forwarded to the sfExportRef.

Parameters:
port - where to export. If 0, it will use any port available.
Returns:
exported primitive
Throws:
SmartFrogException - failed to export primitive

sfExportRef

public java.lang.Object sfExportRef()
                             throws SmartFrogException
Export this primitive to accept remote method calls using an anonymous port. Implementation is to use UnicastRemoteObject. Check is done if sfExportRef is already set, in which case this is returned. Note that for remote methods to work equals, hashCode and toString must be implemented. This is done for PrimImpl in which case those requests are forwarded to the sfExportRef.

Returns:
exported primitive
Throws:
SmartFrogException - failed to export primitive

sfStartLivenessSender

protected void sfStartLivenessSender()
                              throws SmartFrogLivenessException
initializes and starts the liveness sender for this primitive. A component needs a liveness sender if it has no parent, but is has children (ie. is a ChildMinder) or if the parent is remote.

Throws:
SmartFrogLivenessException - failed to initialize or start sender

sfStopLivenessSender

protected void sfStopLivenessSender()
Stops the liveness sender if this component has one.


sfIsRemote

protected boolean sfIsRemote(java.lang.Object o)
Checks whether given object is a non-local object. This implementation is RMI oriented, so checks whether the given object is a RemoteStub, which would indicate that this object is remote. Subclasses can override this (and associated sfExport method) if the underlying remote infrastructure is not RMI.

Parameters:
o - object to check remoteness on
Returns:
true if object a remote reference, false if local

sfDeploy

public void sfDeploy()
              throws SmartFrogException,
                     java.rmi.RemoteException
Called after instantiation for deployment purposes. Heart monitor is started and if there is a parent the deployed component is added to the heartbeat. Subclasses can override to provide additional deployment behavior.

Specified by:
sfDeploy in interface Prim
Throws:
SmartFrogException - error while deploying
java.rmi.RemoteException - In case of network/rmi error

sfStart

public void sfStart()
             throws SmartFrogException,
                    java.rmi.RemoteException
Can be called to start components. Subclasses should override to provide functionality Do not block in this call, but spawn off any main loops!

Specified by:
sfStart in interface Prim
Throws:
SmartFrogException - failure while starting
java.rmi.RemoteException - In case of network/rmi error

sfDumpState

public void sfDumpState(Dump target)
Default dump state behavior is to send the context to the target.

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

sfTerminate

public void sfTerminate(TerminationRecord status)
Request this component to terminate. Termination causes the object to set the sfIsTerminated flag (so a component can not be terminated twice). Need some way of stopping this server object, so that remote stubs will fail, but does not solve the local reference problem (local objects can still call this object)

Specified by:
sfTerminate in interface Prim
Parameters:
status - termination status record

sfTerminateWith

protected void sfTerminateWith(TerminationRecord status)
Provides hook for subclasses to implement useful termination behavior. Deregisters component from local process compound (if ever registered)

Parameters:
status - termination status

terminateNotifying

protected void terminateNotifying(TerminationRecord status,
                                  Prim comp)
Notifies a component that this component has terminated through sfTerminatedWith and calls the local hook (sfTerminateWith).

Parameters:
status - termination status
comp - component to notify of termination

sfDetach

public void sfDetach()
              throws SmartFrogException,
                     java.rmi.RemoteException
Get this object to detach from its parent. Calls sfStartLivenessSender since this component might now be eligible for a liveness sender. Every detached component will be re-parented with its local ProcessCompound.The detached component will be registed using "sfProcessComponentName" value or a random name if it does not exist. It sends sfParantageChanged() notification.

Specified by:
sfDetach in interface Prim
Throws:
SmartFrogException - detachment failed
java.rmi.RemoteException - In case of network/rmi error

sfDetachAndTerminate

public void sfDetachAndTerminate(TerminationRecord status)
Get this object to terminate, after detaching itself from its parent.

Specified by:
sfDetachAndTerminate in interface Prim
Parameters:
status - termination status

sfTerminatedWith

public void sfTerminatedWith(TerminationRecord status,
                             Prim comp)
Called from sub-component (normally) to indicate termination. Subclasses should implement useful behavior.

Specified by:
sfTerminatedWith in interface Prim
Parameters:
status - termination status
comp - component that has terminated

sfTerminateQuietlyWith

public void sfTerminateQuietlyWith(TerminationRecord status)
Called from up the containment tree to terminate. This is to avoid the upcall to the parent which sfTerminate causes. Will only cause termination if the sender component is the parent of this component.

Specified by:
sfTerminateQuietlyWith in interface Prim
Parameters:
status - termination status

sfPing

public void sfPing(java.lang.Object source)
            throws SmartFrogLivenessException,
                   java.rmi.RemoteException
Liveness call in to check if this component is still alive. This method can be overriden to check other state of a component. An example is Compound where all children of the compound are checked. This basic check updates the liveness count if the ping came from its parent. Otherwise (if source non-null) the liveness count is decreased by the sfLivenessFactor attribute. If the count ever reaches 0 liveness failure on tha parent has occurred and sfLivenessFailure is called with source this, and target parent. Note: the sfLivenessCount must be decreased AFTER doing the test to correctly count the number of ping opportunities that remain before invoking sfLivenessFailure. If done before then the number of missing pings is reduced by one. E.g. if sfLivenessFactor is 1 then a sfPing from the parent sets sfLivenessCount to 1. The sfPing from a non-parent would reduce the count to 0 and immediately fail.

Specified by:
sfPing in interface Liveness
Parameters:
source - source of call
Throws:
SmartFrogLivenessException - component is terminated
java.rmi.RemoteException - for consistency with the Liveness interface

sfLivenessFailure

protected void sfLivenessFailure(java.lang.Object source,
                                 java.lang.Object target,
                                 java.lang.Throwable failure)
Handle ping failures. Default behavior is to terminate with a liveness send failure record storing the name of the target of the ping (which generally is one of the children or the parent of this component).

Parameters:
source - source of update
target - target that update was trying to reach
failure - error that occurred

equals

public boolean equals(java.lang.Object o)
Implemented to provide for remote equality checking. If the primitive was export the sfExportRef is used to compare objects, otherwise the super class (Object) is requested to check equality.

Overrides:
equals in class java.lang.Object
Parameters:
o - object to compare with
Returns:
true if equal, false if not

hashCode

public int hashCode()
Returns the hashcode for the exported object if it was exported, the object itself if not.

Overrides:
hashCode in class java.lang.Object
Returns:
hashcode for this object or its remote reference

toString

public java.lang.String toString()
Returns the string of the remote reference if this primitive was exported, the superclass toString if not.

Overrides:
toString in class java.lang.Object
Returns:
string form for this component

terminateComponent

protected void terminateComponent(Prim targetComponent,
                                  java.lang.Throwable excp,
                                  Reference componentId)
Terminates the component in a seperate thread. A component should call this method when it encounters any fatal exception that requires termination of the component.

Parameters:
targetComponent - The component that encountered the error
excp - The error that caused the termination
componentId - Component Identifier

sfLog

public LogSF sfLog()
To log into sfCore logger. This method should be used to log Core messages Types of possible logs in SF: - Core log - Application log - Component log - Using sfSetLog() - Specific log - Using sfLog attribute in component When initialized, sflog uses CoreLog, once the component enters in the sfDeploy lifecycle phase, it is changed to use the specific log if sfLog attribute is defined or if it is not defined it defaults to the core log.

Returns:
Logger implementing LogSF and Log

sfSetLog

public LogSF sfSetLog(LogSF newlog)
Method to replace logger used by components.

Parameters:
newlog - replacement for Prim core log
Returns:
oldlog

sfGetLog

public LogSF sfGetLog(java.lang.String name)
To get a logger with a particular name.

Parameters:
name - logger name
Returns:
Logger implementing LogSF and Log

sfGetCoreLog

public LogSF sfGetCoreLog()
To get the sfCore logger

Returns:
Logger implementing LogSF and Log

sfGetApplicationLog

public LogSF sfGetApplicationLog()
                          throws SmartFrogException,
                                 java.rmi.RemoteException
To get application logger using ROOT name. The name used is cached in attritube SmartFrogCoreKeys.SF_APP_LOG_NAME If this attribute has been pre-set then it is used to get the application logger, otherwise ROOT cannonical name is used.

Returns:
Logger implementing LogSF and Log
Throws:
SmartFrogException - if failed
java.rmi.RemoteException - In case of Remote/nework error

sfParentageChanged

public void sfParentageChanged()
                        throws java.rmi.RemoteException
Parentage changed in component hierachy. Actions: sfCompleteName cache is cleaned

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

sfIsTerminated

public boolean sfIsTerminated()
Returns value of flag indicating if this component has been terminated.

Specified by:
sfIsTerminated in interface Prim
Returns:
boolean

sfIsTerminating

public boolean sfIsTerminating()
Returns value of flag indicating if this component is terminating.

Specified by:
sfIsTerminating in interface Prim
Returns:
boolean

sfIsDeployed

public boolean sfIsDeployed()
Returns value of flag indicating if this component has been deployed.

Specified by:
sfIsDeployed in interface Prim
Returns:
boolean

sfIsStarted

public boolean sfIsStarted()
Returns value of flag indicating if this component has been started.

Specified by:
sfIsStarted in interface Prim
Returns:
boolean

sfDiagnosticsReport

public ComponentDescription sfDiagnosticsReport()
Creates diagnostics report

Specified by:
sfDiagnosticsReport in interface Diagnostics
Returns:
Component description

SmartFrog CORE 3.10.000

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