org.objectweb.fractal.julia.control.lifecycle
Class BasicLifeCycleControllerMixin

java.lang.Object
  extended by org.objectweb.fractal.julia.control.lifecycle.BasicLifeCycleControllerMixin
All Implemented Interfaces:
LifeCycleController, LifeCycleCoordinator, Controller

public abstract class BasicLifeCycleControllerMixin
extends Object
implements Controller, LifeCycleCoordinator

Provides a basic implementation of the LifeCycleController interface. This implementation is based on a counter managed by interceptors. This controller needs associated interceptor objects, such as those generated by the InterceptorClassGenerator with a LifeCycleCodeGenerator, in order to work properly (these interceptors are only needed on external server interfaces).

Requirements


Field Summary
 Component _this_weaveableC
          The weaveableC field required by this mixin.
 LifeCycleCoordinator fcCoordinator
          The coordinator used to stop this component with other components simultaneously.
 int fcInvocationCounter
          The number of currently executing method calls in this component.
 int fcState
          The life cycle state of this component.
 
Fields inherited from interface org.objectweb.fractal.api.control.LifeCycleController
STARTED, STOPPED
 
Method Summary
abstract  void _super_initFcController(InitializationContext ic)
          The initFcController method overriden by this mixin.
abstract  void _this_setFcState(boolean started)
          The setFcState method required by this mixin.
abstract  void _this_stopFc(LifeCycleCoordinator[] components)
          The stopFc method required by this mixin.
 void decrementFcInvocationCounter()
          Decrements the number of currently executing method calls in this component.
 LifeCycleCoordinator getFcCoordinator()
          Returns the LifeCycleCoordinator interface of this component.
 String getFcState()
           
 void incrementFcInvocationCounter()
          Increments the number of currently executing method calls in this component.
 void initFcController(InitializationContext ic)
          Initializes the fields of this mixin and then calls the overriden method.
 boolean setFcStarted()
          Sets the state of this component, but not of its sub components, to STARTED.
 boolean setFcStopped()
          Sets the state of this component, but not of its sub components, to STOPPED.
 void setFcStopping(LifeCycleCoordinator coordinator)
          Sets the state of this component, but not of its sub components, to "STOPPING".
 void startFc()
           
 void stopFc()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.objectweb.fractal.julia.control.lifecycle.LifeCycleCoordinator
fcActivated, fcInactivated
 

Field Detail

fcState

public int fcState
The life cycle state of this component. Zero means stopped, one means stopping and two means started.


fcInvocationCounter

public int fcInvocationCounter
The number of currently executing method calls in this component.


fcCoordinator

public LifeCycleCoordinator fcCoordinator
The coordinator used to stop this component with other components simultaneously.


_this_weaveableC

public Component _this_weaveableC
The weaveableC field required by this mixin. This field is supposed to reference the Component interface of the component to which this controller object belongs.

Method Detail

initFcController

public void initFcController(InitializationContext ic)
                      throws InstantiationException
Initializes the fields of this mixin and then calls the overriden method.

Specified by:
initFcController in interface Controller
Parameters:
ic - information about the component to which this controller object belongs.
Throws:
InstantiationException - if the initialization fails.

getFcState

public String getFcState()
Specified by:
getFcState in interface LifeCycleController

startFc

public void startFc()
             throws IllegalLifeCycleException
Specified by:
startFc in interface LifeCycleController
Throws:
IllegalLifeCycleException

stopFc

public void stopFc()
            throws IllegalLifeCycleException
Specified by:
stopFc in interface LifeCycleController
Throws:
IllegalLifeCycleException

setFcStarted

public boolean setFcStarted()
                     throws IllegalLifeCycleException
Description copied from interface: LifeCycleCoordinator
Sets the state of this component, but not of its sub components, to STARTED. Because of component sharing, the startFc method cannot be implemented by just calling itself recursively on the sub components of this componets (otherwise some sub components may be started several times). Hence this method.

Specified by:
setFcStarted in interface LifeCycleCoordinator
Returns:
true if the execution state has changed, or false if it had already the STARTED value.
Throws:
IllegalLifeCycleException - if a problem occurs.

setFcStopping

public void setFcStopping(LifeCycleCoordinator coordinator)
                   throws IllegalLifeCycleException
Description copied from interface: LifeCycleCoordinator
Sets the state of this component, but not of its sub components, to "STOPPING". After this method has been called, and while the setFcStopped has not been called, this component must notify the given coordinator when it becomes inactive, and when it is about to become active, with the fcInactivated and fcActivated methods.
Note: the "STOPPING" state is an internal state that is not visible from the outside. Indeed, in this state, the getFcState method should return STARTED, as the component is not yet stopped.

Specified by:
setFcStopping in interface LifeCycleCoordinator
Parameters:
coordinator - the coordinator that must be notified when this component becomes inactive, and when it is about to become active.
Throws:
IllegalLifeCycleException - if a problem occurs.

setFcStopped

public boolean setFcStopped()
                     throws IllegalLifeCycleException
Description copied from interface: LifeCycleCoordinator
Sets the state of this component, but not of its sub components, to STOPPED. Because of component sharing, the stopFc method cannot be implemented by just calling itself recursively on the sub components of this componets (otherwise some sub components may be stopped several times). Hence this method.

Specified by:
setFcStopped in interface LifeCycleCoordinator
Returns:
true if the execution state has changed, or false if it had already the STOPPED value.
Throws:
IllegalLifeCycleException - if a problem occurs.

incrementFcInvocationCounter

public void incrementFcInvocationCounter()
Increments the number of currently executing method calls in this component. If the component is started this method just increments this counter. If the component is stopped, it waits until the component is restarted, and then increments the counter. Finally, if the component is stopping, there are two cases. If the counter is not null, it is just incremented. If it is null, this method asks the coordinator if the method call can be executed, or if it should be delayed until the component is restarted. The method then blocks or not, depending on the coordinator's response, before incrementing the counter.


decrementFcInvocationCounter

public void decrementFcInvocationCounter()
Decrements the number of currently executing method calls in this component. If the component is stopping, and if the counter of currently executing method calls becomes null after being decremented, this method notifies the coordinator that the component has become inactive.


getFcCoordinator

public LifeCycleCoordinator getFcCoordinator()
Returns the LifeCycleCoordinator interface of this component.

Returns:
the LifeCycleCoordinator interface of the component to which this controller object belongs.

_this_setFcState

public abstract void _this_setFcState(boolean started)
                               throws IllegalLifeCycleException
The setFcState method required by this mixin. This method is supposed to work as this setFcState method.

Parameters:
started - true to set the lifecycle state of the components to STARTED, or false to set this state to STOPPED.
Throws:
IllegalLifeCycleException - if a problem occurs.

_this_stopFc

public abstract void _this_stopFc(LifeCycleCoordinator[] components)
                           throws IllegalLifeCycleException
The stopFc method required by this mixin. This method is supposed to work as this stopFc method.

Parameters:
components - the LifeCycleCoordinator interface of the components to be stopped.
Throws:
IllegalLifeCycleException - if a problem occurs.

_super_initFcController

public abstract void _super_initFcController(InitializationContext ic)
                                      throws InstantiationException
The initFcController method overriden by this mixin.

Parameters:
ic - information about the component to which this controller object belongs.
Throws:
InstantiationException - if the initialization fails.