
juliac.generated.LifeCycleControllerImpl Maven / Gradle / Ivy
package juliac.generated;
import java.util.ArrayList;
import org.objectweb.fractal.api.control.BindingController;
import org.objectweb.fractal.julia.control.binding.ChainedIllegalBindingException;
import org.objectweb.fractal.julia.control.lifecycle.ChainedIllegalLifeCycleException;
import org.objectweb.fractal.julia.factory.ChainedInstantiationException;
import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.api.type.ComponentType;
import org.objectweb.fractal.julia.control.lifecycle.ContentLifeCycleController;
import org.objectweb.fractal.julia.Controller;
import org.objectweb.fractal.julia.loader.Generated;
import org.objectweb.fractal.api.control.IllegalBindingException;
import org.objectweb.fractal.api.control.IllegalLifeCycleException;
import org.objectweb.fractal.julia.InitializationContext;
import org.objectweb.fractal.api.factory.InstantiationException;
import org.objectweb.fractal.api.type.InterfaceType;
import org.objectweb.fractal.api.control.LifeCycleController;
import org.objectweb.fractal.julia.control.lifecycle.LifeCycleCoordinator;
import java.util.List;
import org.objectweb.fractal.api.NoSuchInterfaceException;
import org.objectweb.fractal.api.Type;
/**
* @see org.objectweb.fractal.julia.BasicControllerMixin
* @see org.objectweb.fractal.julia.UseComponentMixin
* @see org.objectweb.fractal.julia.control.lifecycle.BasicLifeCycleCoordinatorMixin
* @see org.objectweb.fractal.julia.control.lifecycle.BasicLifeCycleControllerMixin
* @see org.objectweb.fractal.julia.control.lifecycle.TypeLifeCycleMixin
* @see org.objectweb.fractal.julia.control.lifecycle.ContainerLifeCycleMixin
*/
public class LifeCycleControllerImpl implements LifeCycleController , Controller , LifeCycleCoordinator , Generated {
/**
* The {@link Component} interface of the component to which this controller
* object belongs.
* @see org.objectweb.fractal.julia.UseComponentMixin#weaveableC
*/
public Component weaveableC;
/**
* Does nothing.
*
* @param ic information about the component to which this controller object
* belongs.
* @throws InstantiationException if the initialization fails.
* @see org.objectweb.fractal.julia.BasicControllerMixin#initFcController(org.objectweb.fractal.julia.InitializationContext)
*/
private void initFcController$1(final InitializationContext ic) throws InstantiationException {
}
/**
* Calls the overriden method and then calls the {@link #setFcContentState
* setFcContentState} method.
*
* @return true if the execution state has changed, or false
* if it had already the {@link #STARTED STARTED} value.
* @throws IllegalLifeCycleException if a problem occurs.
* @see org.objectweb.fractal.julia.control.lifecycle.ContainerLifeCycleMixin#setFcStarted()
*/
public boolean setFcStarted() throws IllegalLifeCycleException {
synchronized(this) {
if (setFcStarted$0()) {
setFcContentState(true);
return true;
}
return false;
}
}
/**
* The {@link Component} interface of the component to which this controller
* object belongs.
* @see org.objectweb.fractal.julia.UseComponentMixin#weaveableOptC
*/
public Component weaveableOptC;
/**
* The components that are currently active.
* @see org.objectweb.fractal.julia.control.lifecycle.BasicLifeCycleCoordinatorMixin#fcActive
*/
public List fcActive;
/**
* Checks the mandatory client interfaces of the component (and of all its sub
* components) and then calls the overriden method.
*
* @throws IllegalLifeCycleException if a problem occurs.
* @see org.objectweb.fractal.julia.control.lifecycle.TypeLifeCycleMixin#startFc()
*/
public void startFc() throws IllegalLifeCycleException {
Component thisComponent;
try {
thisComponent = ((Component)(weaveableC.getFcInterface("component")));
} catch (NoSuchInterfaceException e) {
throw new ChainedIllegalLifeCycleException(e , weaveableC , "Cannot start the component");
}
List allSubComponents = org.objectweb.fractal.julia.control.content.Util.getAllSubComponents(thisComponent);
for (int i = 0 ; i < (allSubComponents.size()) ; ++i) {
Component subComponent = ((Component)(allSubComponents.get(i)));
try {
checkFcMandatoryInterfaces(subComponent);
} catch (IllegalBindingException e) {
throw new ChainedIllegalLifeCycleException(e , weaveableC , "Cannot start the component");
}
}
startFc$0();
}
/**
* The life cycle state of this component. Zero means stopped, one means
* stopping and two means started.
* @see org.objectweb.fractal.julia.control.lifecycle.BasicLifeCycleControllerMixin#fcState
*/
public int fcState;
/**
* Initializes the fields of this mixin and then calls the overriden method.
*
* @param ic information about the component to which this controller object
* belongs.
* @throws InstantiationException if the initialization fails.
* @see org.objectweb.fractal.julia.UseComponentMixin#initFcController(org.objectweb.fractal.julia.InitializationContext)
*/
private void initFcController$0(final InitializationContext ic) throws InstantiationException {
weaveableC = ((Component)(ic.getInterface("component")));
weaveableOptC = weaveableC;
initFcController$1(ic);
}
/**
* Sets the lifecycle state of this component and of all its direct and
* indirect sub components that have a {@link LifeCycleCoordinator} interface.
*
* @param started true to set the lifecycle state of the components
* to {@link #STARTED STARTED}, or false to set this state to
* {@link #STOPPED STOPPED}.
* @throws IllegalLifeCycleException if a problem occurs.
* @see org.objectweb.fractal.julia.control.lifecycle.BasicLifeCycleCoordinatorMixin#setFcState(boolean)
*/
public void setFcState(final boolean started) throws IllegalLifeCycleException {
Component thisComponent;
try {
thisComponent = ((Component)(weaveableC.getFcInterface("component")));
} catch (NoSuchInterfaceException e) {
throw new ChainedIllegalLifeCycleException(e , weaveableC , "Cannot set the lifecycle state");
}
List allSubComponents = org.objectweb.fractal.julia.control.content.Util.getAllSubComponents(thisComponent);
for (int i = 0 ; i < (allSubComponents.size()) ; ++i) {
Component c = ((Component)(allSubComponents.get(i)));
LifeCycleCoordinator lc;
try {
lc = ((LifeCycleCoordinator)(c.getFcInterface("lifecycle-controller")));
} catch (Exception e) {
try {
lc = ((LifeCycleCoordinator)(c.getFcInterface("/lifecycle-coordinator")));
} catch (NoSuchInterfaceException f) {
continue;
}
}
if (started) {
lc.setFcStarted();
} else {
lc.setFcStopped();
}
}
}
/**
* The number of currently executing method calls in this component.
* @see org.objectweb.fractal.julia.control.lifecycle.BasicLifeCycleControllerMixin#fcInvocationCounter
*/
public int fcInvocationCounter;
/**
* Calls the overriden method and then calls the {@link #setFcContentState
* setFcContentState} method.
*
* @return true if the execution state has changed, or false
* if it had already the {@link #STOPPED STOPPED} value.
* @throws IllegalLifeCycleException if a problem occurs.
* @see org.objectweb.fractal.julia.control.lifecycle.ContainerLifeCycleMixin#setFcStopped()
*/
public boolean setFcStopped() throws IllegalLifeCycleException {
synchronized(this) {
if (setFcStopped$0()) {
setFcContentState(false);
return true;
}
return false;
}
}
/**
* The coordinator used to stop this component with other components
* simultaneously.
* @see org.objectweb.fractal.julia.control.lifecycle.BasicLifeCycleControllerMixin#fcCoordinator
*/
public LifeCycleCoordinator fcCoordinator;
/**
* Initializes the fields of this mixin and then calls the overriden method.
*
* @param ic information about the component to which this controller object
* belongs.
* @throws InstantiationException if the initialization fails.
* @see org.objectweb.fractal.julia.control.lifecycle.BasicLifeCycleControllerMixin#initFcController(org.objectweb.fractal.julia.InitializationContext)
*/
public void initFcController(final InitializationContext ic) throws InstantiationException {
try {
if (!((ic.getInterface("lifecycle-controller")) instanceof LifeCycleCoordinator)) {
throw new Exception();
}
} catch (Exception e) {
try {
ic.getInterface("/lifecycle-coordinator");
} catch (Exception f) {
throw new ChainedInstantiationException(f , null , "The component must provide a LifeCycleCoordinator interface");
}
}
initFcController$0(ic);
}
/**
* Calls the {@link LifeCycleController#startFc startFc} or {@link
* LifeCycleController#stopFc stopFc} method on the encapsulated component.
* This method does nothing if there is no encapsulated component, or if it
* does not implement the {@link LifeCycleController} interface.
*
* @param started true to call the {@link LifeCycleController#startFc
* startFc}, or false to call the {@link
* LifeCycleController#stopFc stopFc} method.
* @throws IllegalLifeCycleException if a problem occurs.
* @see org.objectweb.fractal.julia.control.lifecycle.ContainerLifeCycleMixin#setFcContentState(boolean)
*/
public void setFcContentState(final boolean started) throws IllegalLifeCycleException {
Object content;
try {
content = weaveableOptC.getFcInterface("/content");
} catch (NullPointerException e) {
return ;
} catch (NoSuchInterfaceException e) {
return ;
}
if (content == (this)) {
if ((this) instanceof ContentLifeCycleController) {
if (started) {
((ContentLifeCycleController)(this)).startFcContent();
} else {
((ContentLifeCycleController)(this)).stopFcContent();
}
}
} else if (content instanceof LifeCycleController) {
if (started) {
((LifeCycleController)(content)).startFc();
} else {
((LifeCycleController)(content)).stopFc();
}
}
}
/**
* Checks that all the mandatory client interface of the given component are
* bound.
*
* @param c a component.
* @throws IllegalBindingException if a mandatory client interface of the
* given component is not bound.
* @see org.objectweb.fractal.julia.control.lifecycle.TypeLifeCycleMixin#checkFcMandatoryInterfaces(org.objectweb.fractal.api.Component)
*/
public void checkFcMandatoryInterfaces(final Component c) throws IllegalBindingException {
BindingController bc;
try {
bc = ((BindingController)(c.getFcInterface("binding-controller")));
} catch (NoSuchInterfaceException e) {
return ;
}
ComponentType compType = ((ComponentType)(c.getFcType()));
String[] names = bc.listFc();
for (int i = 0 ; i < (names.length) ; ++i) {
InterfaceType itfType;
try {
itfType = compType.getFcInterfaceType(names[i]);
} catch (NoSuchInterfaceException e) {
continue;
}
if ((itfType.isFcClientItf()) && (!(itfType.isFcOptionalItf()))) {
Object sItf;
try {
sItf = bc.lookupFc(names[i]);
} catch (NoSuchInterfaceException e) {
continue;
}
if (sItf == null) {
throw new ChainedIllegalBindingException(null , c , null , names[i] , null , "Mandatory client interface unbound");
}
}
}
}
/**
* @see org.objectweb.fractal.julia.control.lifecycle.BasicLifeCycleCoordinatorMixin#fcActivated(org.objectweb.fractal.julia.control.lifecycle.LifeCycleCoordinator)
*/
public boolean fcActivated(final LifeCycleCoordinator component) {
synchronized(fcActive) {
if ((fcActive.size()) > 0) {
if (!(fcActive.contains(component))) {
fcActive.add(component);
}
return true;
}
return false;
}
}
/**
* @see org.objectweb.fractal.julia.control.lifecycle.BasicLifeCycleControllerMixin#getFcState()
*/
public String getFcState() {
return (fcState) == 0 ? LifeCycleController.STOPPED : LifeCycleController.STARTED;
}
/**
* @see org.objectweb.fractal.julia.control.lifecycle.BasicLifeCycleControllerMixin#startFc()
*/
private void startFc$0() throws IllegalLifeCycleException {
if ((fcState) != 2) {
setFcState(true);
}
}
/**
* @see org.objectweb.fractal.julia.control.lifecycle.BasicLifeCycleCoordinatorMixin#fcInactivated(org.objectweb.fractal.julia.control.lifecycle.LifeCycleCoordinator)
*/
public void fcInactivated(final LifeCycleCoordinator component) {
synchronized(fcActive) {
fcActive.remove(component);
fcActive.notifyAll();
}
}
/**
* @see org.objectweb.fractal.julia.control.lifecycle.BasicLifeCycleControllerMixin#stopFc()
*/
public void stopFc() throws IllegalLifeCycleException {
if ((fcState) == 2) {
stopFc(new LifeCycleCoordinator[]{ getFcCoordinator() });
setFcState(false);
}
}
/**
* @see org.objectweb.fractal.julia.control.lifecycle.BasicLifeCycleControllerMixin#setFcStarted()
*/
private boolean setFcStarted$0() throws IllegalLifeCycleException {
synchronized(this) {
if ((fcState) == 2) {
return false;
}
fcState = 2;
notifyAll();
return true;
}
}
/**
* Stops the given components simultaneously. This method sets the state of
* the components to "STOPPING", waits until all the components
* are simultaneoulsy inactive (their state is known thanks to the {@link
* #fcActivated fcActivated} and {@link #fcInactivated fcInactivated} callback
* methods), and then sets the state of the components to {@link #STOPPED
* STOPPED}.
*
* @param components the {@link LifeCycleCoordinator} interface of the
* components to be stopped.
* @throws IllegalLifeCycleException if a problem occurs.
* @see org.objectweb.fractal.julia.control.lifecycle.BasicLifeCycleCoordinatorMixin#stopFc(org.objectweb.fractal.julia.control.lifecycle.LifeCycleCoordinator[])
*/
public void stopFc(final LifeCycleCoordinator[] components) throws IllegalLifeCycleException {
fcActive = new ArrayList();
for (int i = 0 ; i < (components.length) ; ++i) {
if (components[i].getFcState().equals(LifeCycleController.STARTED)) {
fcActive.add(components[i]);
}
}
LifeCycleCoordinator c;
try {
c = ((LifeCycleCoordinator)(weaveableC.getFcInterface("lifecycle-controller")));
} catch (Exception e) {
try {
c = ((LifeCycleCoordinator)(weaveableC.getFcInterface("/lifecycle-coordinator")));
} catch (NoSuchInterfaceException f) {
throw new ChainedIllegalLifeCycleException(f , weaveableC , "Cannot stop components");
}
}
for (int i = 0 ; i < (components.length) ; ++i) {
if (components[i].getFcState().equals(LifeCycleController.STARTED)) {
components[i].setFcStopping(c);
}
}
synchronized(fcActive) {
while ((fcActive.size()) > 0) {
try {
fcActive.wait();
} catch (InterruptedException e) {
}
}
}
for (int i = 0 ; i < (components.length) ; ++i) {
if (components[i].getFcState().equals(LifeCycleController.STARTED)) {
components[i].setFcStopped();
}
}
fcActive = null;
}
/**
* @see org.objectweb.fractal.julia.control.lifecycle.BasicLifeCycleControllerMixin#setFcStopping(org.objectweb.fractal.julia.control.lifecycle.LifeCycleCoordinator)
*/
public void setFcStopping(final LifeCycleCoordinator coordinator) throws IllegalLifeCycleException {
synchronized(this) {
fcState = 1;
fcCoordinator = coordinator;
if ((fcInvocationCounter) == 0) {
fcCoordinator.fcInactivated(getFcCoordinator());
}
}
}
/**
* The {@link LifeCycleCoordinator#setFcStarted setFcStarted} method overriden
* by this mixin.
*
* @return true if the execution state has changed, or false
* if it had already the {@link #STARTED STARTED} value.
* @throws IllegalLifeCycleException if a problem occurs.
*/
private boolean setFcStarted$1() throws IllegalLifeCycleException {
return false;
}
/**
* The {@link LifeCycleController#startFc startFc} method overriden by this
* mixin.
*
* @throws IllegalLifeCycleException if a problem occurs.
*/
private void startFc$1() throws IllegalLifeCycleException {
}
/**
* @see org.objectweb.fractal.julia.control.lifecycle.BasicLifeCycleControllerMixin#setFcStopped()
*/
private boolean setFcStopped$0() throws IllegalLifeCycleException {
synchronized(this) {
if ((fcState) == 0) {
return false;
}
fcState = 0;
fcCoordinator = null;
return true;
}
}
/**
* The {@link LifeCycleCoordinator#setFcStopped setFcStopped} method overriden
* by this mixin.
*
* @return true if the execution state has changed, or false
* if it had already the {@link #STOPPED STOPPED} value.
* @throws IllegalLifeCycleException if a problem occurs.
*/
private boolean setFcStopped$1() throws IllegalLifeCycleException {
return false;
}
/**
* 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.
* @see org.objectweb.fractal.julia.control.lifecycle.BasicLifeCycleControllerMixin#incrementFcInvocationCounter()
*/
public void incrementFcInvocationCounter() {
boolean ok;
do {
if ((fcState) == 0) {
ok = false;
} else if ((fcState) == 1) {
if ((fcInvocationCounter) == 0) {
ok = fcCoordinator.fcActivated(getFcCoordinator());
} else {
ok = true;
}
} else {
ok = true;
}
if (!ok) {
try {
wait();
} catch (final InterruptedException e) {
}
}
} while (!ok );
++(fcInvocationCounter);
}
/**
* 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.
* @see org.objectweb.fractal.julia.control.lifecycle.BasicLifeCycleControllerMixin#decrementFcInvocationCounter()
*/
public void decrementFcInvocationCounter() {
--(fcInvocationCounter);
if ((fcInvocationCounter) == 0) {
fcCoordinator.fcInactivated(getFcCoordinator());
}
}
/**
* Returns the {@link LifeCycleCoordinator} interface of this component.
*
* @return the {@link LifeCycleCoordinator} interface of the component to
* which this controller object belongs.
* @see org.objectweb.fractal.julia.control.lifecycle.BasicLifeCycleControllerMixin#getFcCoordinator()
*/
public LifeCycleCoordinator getFcCoordinator() {
try {
return ((LifeCycleCoordinator)(weaveableC.getFcInterface("lifecycle-controller")));
} catch (Exception e) {
try {
return ((LifeCycleCoordinator)(weaveableC.getFcInterface("/lifecycle-coordinator")));
} catch (NoSuchInterfaceException f) {
throw new Error("Internal error");
}
}
}
/**
* The {@link Controller#initFcController initFcController} method overriden
* by this mixin.
*
* @param ic information about the component to which this controller object
* belongs.
* @throws InstantiationException if the initialization fails.
*/
private void initFcController$2(InitializationContext ic) throws InstantiationException {
}
public String getFcGeneratorParameters() {
return "(org.objectweb.fractal.juliac.spoon.MixinClassGenerator juliac.generated.LifeCycleControllerImpl org.objectweb.fractal.julia.BasicControllerMixin org.objectweb.fractal.julia.UseComponentMixin org.objectweb.fractal.julia.control.lifecycle.BasicLifeCycleCoordinatorMixin org.objectweb.fractal.julia.control.lifecycle.BasicLifeCycleControllerMixin org.objectweb.fractal.julia.control.lifecycle.TypeLifeCycleMixin org.objectweb.fractal.julia.control.lifecycle.ContainerLifeCycleMixin)";
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy