All Downloads are FREE. Search and download functionalities are using the official Maven repository.

juliac.generated.SCALifeCycleControllerImpl Maven / Gradle / Ivy

There is a newer version: 2.7
Show newest version
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.ow2.frascati.tinfi.control.content.ContentInstantiationException;
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.ow2.frascati.tinfi.control.content.SCAContentController;
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
 * @see org.ow2.frascati.tinfi.control.content.UseSCAContentControllerMixin
 * @see org.ow2.frascati.tinfi.control.content.LifeCycleEagerMixin
 */
public class SCALifeCycleControllerImpl implements LifeCycleController , Controller , LifeCycleCoordinator , Generated {
    /** 
     * @see org.ow2.frascati.tinfi.control.content.LifeCycleEagerMixin#setFcStarted()
     */
    public boolean setFcStarted() throws IllegalLifeCycleException {
        try {
            weaveableSCACC.eagerInit();
        } catch (ContentInstantiationException ie) {
            throw new ChainedIllegalLifeCycleException(ie , null , "");
        }
        return setFcStarted$0();
    }
    
    /** 
     * @see org.ow2.frascati.tinfi.control.content.UseSCAContentControllerMixin#initFcController(org.objectweb.fractal.julia.InitializationContext)
     */
    public void initFcController(final InitializationContext ic) throws InstantiationException {
        weaveableSCACC = ((SCAContentController)(ic.interfaces.get(SCAContentController.NAME)));
        initFcController$0(ic);
    }
    
    /** 
     * @see org.objectweb.fractal.julia.UseComponentMixin#weaveableC
     */
    public Component weaveableC;
    
    /** 
     * @see org.objectweb.fractal.julia.BasicControllerMixin#initFcController(org.objectweb.fractal.julia.InitializationContext)
     */
    private void initFcController$2(final InitializationContext ic) throws InstantiationException {
    }
    
    /** 
     * @see org.objectweb.fractal.julia.control.lifecycle.ContainerLifeCycleMixin#setFcStarted()
     */
    private boolean setFcStarted$0() throws IllegalLifeCycleException {
        synchronized(this) {
            if (setFcStarted$1()) {
                setFcContentState(true);
                return true;
            } 
            return false;
        }
    }
    
    /** 
     * @see org.objectweb.fractal.julia.UseComponentMixin#weaveableOptC
     */
    public Component weaveableOptC;
    
    /** 
     * @see org.objectweb.fractal.julia.control.lifecycle.BasicLifeCycleCoordinatorMixin#fcActive
     */
    public List fcActive;
    
    /** 
     * @see org.ow2.frascati.tinfi.control.content.LifeCycleEagerMixin#setFcStopped()
     */
    public boolean setFcStopped() throws IllegalLifeCycleException {
        try {
            weaveableSCACC.eagerDestroy();
        } catch (ContentInstantiationException ie) {
            throw new ChainedIllegalLifeCycleException(ie , null , "");
        }
        return setFcStopped$0();
    }
    
    /** 
     * @see org.ow2.frascati.tinfi.control.content.UseSCAContentControllerMixin#weaveableSCACC
     */
    @SuppressWarnings(value = "unused")
    private SCAContentController weaveableSCACC;
    
    /** 
     * @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();
    }
    
    /** 
     * @see org.objectweb.fractal.julia.control.lifecycle.BasicLifeCycleControllerMixin#fcState
     */
    public int fcState;
    
    /** 
     * @see org.objectweb.fractal.julia.UseComponentMixin#initFcController(org.objectweb.fractal.julia.InitializationContext)
     */
    private void initFcController$1(final InitializationContext ic) throws InstantiationException {
        weaveableC = ((Component)(ic.getInterface("component")));
        weaveableOptC = weaveableC;
        initFcController$2(ic);
    }
    
    /** 
     * @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();
            }
        }
    }
    
    /** 
     * @see org.objectweb.fractal.julia.control.lifecycle.BasicLifeCycleControllerMixin#fcInvocationCounter
     */
    public int fcInvocationCounter;
    
    /** 
     * @see org.objectweb.fractal.julia.control.lifecycle.ContainerLifeCycleMixin#setFcStopped()
     */
    private boolean setFcStopped$0() throws IllegalLifeCycleException {
        synchronized(this) {
            if (setFcStopped$1()) {
                setFcContentState(false);
                return true;
            } 
            return false;
        }
    }
    
    private void initFcController$3(InitializationContext ic) throws InstantiationException {
    }
    
    /** 
     * @see org.objectweb.fractal.julia.control.lifecycle.BasicLifeCycleControllerMixin#fcCoordinator
     */
    public LifeCycleCoordinator fcCoordinator;
    
    private boolean setFcStarted$2() throws IllegalLifeCycleException {
        return false;
    }
    
    private boolean setFcStopped$2() throws IllegalLifeCycleException {
        return false;
    }
    
    /** 
     * @see org.objectweb.fractal.julia.control.lifecycle.BasicLifeCycleControllerMixin#initFcController(org.objectweb.fractal.julia.InitializationContext)
     */
    private void initFcController$0(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$1(ic);
    }
    
    /** 
     * @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();
            }
        } 
    }
    
    /** 
     * @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$1() throws IllegalLifeCycleException {
        synchronized(this) {
            if ((fcState) == 2) {
                return false;
            } 
            fcState = 2;
            notifyAll();
            return true;
        }
    }
    
    /** 
     * @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());
            } 
        }
    }
    
    private void startFc$1() throws IllegalLifeCycleException {
    }
    
    /** 
     * @see org.objectweb.fractal.julia.control.lifecycle.BasicLifeCycleControllerMixin#setFcStopped()
     */
    private boolean setFcStopped$1() throws IllegalLifeCycleException {
        synchronized(this) {
            if ((fcState) == 0) {
                return false;
            } 
            fcState = 0;
            fcCoordinator = null;
            return true;
        }
    }
    
    /** 
     * @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);
    }
    
    /** 
     * @see org.objectweb.fractal.julia.control.lifecycle.BasicLifeCycleControllerMixin#decrementFcInvocationCounter()
     */
    public void decrementFcInvocationCounter() {
        --(fcInvocationCounter);
        if ((fcInvocationCounter) == 0) {
            fcCoordinator.fcInactivated(getFcCoordinator());
        } 
    }
    
    /** 
     * @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");
            }
        }
    }
    
    public String getFcGeneratorParameters() {
        return "(org.objectweb.fractal.juliac.spoon.MixinClassGenerator juliac.generated.SCALifeCycleControllerImpl 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 org.ow2.frascati.tinfi.control.content.UseSCAContentControllerMixin org.ow2.frascati.tinfi.control.content.LifeCycleEagerMixin)";
    }
    
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy