Package ptolemy.kernel.util

Examples of ptolemy.kernel.util.Workspace


        // Don't call "Director.super.fire();" here, do the work instead.
        if (_debugging) {
            _debug("Called fire().");
        }

        Workspace workspace = workspace();

        // In case we have an enclosing process director,
        // we identify it so that we can notify it when we are blocked.
        CompositeActor container = (CompositeActor) getContainer();
        Director outsideDirector = container.getExecutiveDirector();

        if (!(outsideDirector instanceof ProcessDirector)) {
            outsideDirector = null;
        }

        synchronized (this) {
            while (!_areThreadsDeadlocked() && !_areAllThreadsStopped()
                    && !_stopRequested) {
                // Added to get thread to stop reliably on pushing stop button.
                // EAL 8/05
                if (_stopRequested) {
                    return;
                }

                if (_debugging) {
                    _debug("Waiting for actors to stop.");
                }

                try {
                    if (outsideDirector != null) {
                        ((ProcessDirector) outsideDirector).threadBlocked(
                                Thread.currentThread(), null);
                    }

                    workspace.wait(this);
                } catch (InterruptedException e) {
                    // stop all threads
                    stop();
                    return;
                } finally {
View Full Code Here


     *  does not contain a manager, then this method creates one for it.
     */
    public void init() {
        super.init();
        _setupOK = true;
        _workspace = new Workspace(getClass().getName());

        try {
            _toplevel = _createModel(_workspace);

            _toplevel.setModelErrorHandler(new BasicModelErrorHandler());
View Full Code Here

     *  method will block until the input branch controller
     *  has stopped due to all of the branches it controls
     *  stopping, or until the calling thread is interrupted.
     */
    public void stopInputBranchController() {
        Workspace workspace = workspace();

        if (_inputBranchController == null) {
            // This happens under DDE Zeno under IE 5 with Java Plug-in 1.3
            return;
        }

        if (!_inputBranchController.hasBranches()) {
            return;
        }

        _inputBranchController.deactivateBranches();

        while (!_inputBranchController.isBlocked()) {
            try {
                workspace.wait(this);
            } catch (InterruptedException e) {
                // Exit the loop.
                // FIXME: Is this the right thing to do?
                break;
            }
View Full Code Here

     *  method will block until the output branch controller
     *  has stopped due to all of the branches it controls
     *  stopping.
     */
    public void stopOutputBranchController() {
        Workspace workspace = workspace();

        if (_outputBranchController == null) {
            return;
        }

        if (!_outputBranchController.hasBranches()) {
            return;
        }

        _outputBranchController.deactivateBranches();

        while (!_outputBranchController.isBlocked()) {
            try {
                workspace.wait(this);
            } catch (InterruptedException e) {
                // Exit the loop.
                // FIXME: Is this the right thing to do?
                break;
            }
View Full Code Here

        if (_debugging) {
            _debug("Resolving Deadlock");
        }

        Director execDir = ((Actor) getContainer()).getExecutiveDirector();
        Workspace workspace = workspace();

        if (_areThreadsDeadlocked()) {
            if (_areActorsExternallyBlocked()) {
                // There are actors that are blocked on a communication
                // (send or receive) to the outside world.
                if (_inputBranchController.isBlocked()) {
                    while (!_outputBranchController.isBlocked()) {
                        try {
                            workspace.wait(this);
                        } catch (InterruptedException e) {
                            // TODO: determine best way to handle the exception
                            throw new IllegalActionException(this,
                                    "Interrupted.");
                        }
                    }

                    stopInputBranchController();
                    stopOutputBranchController();

                    if (execDir == null) {
                        // This is the top level director - problem!!!
                        throw new IllegalActionException(
                                this,
                                "No executive director exists yet this "
                                        + "director's composite actor is externally "
                                        + "deadlocked.");
                    } else if (execDir instanceof CompositeProcessDirector) {
                        // This is contained by a process-oriented MoC
                        ((CompositeProcessDirector) execDir).threadBlocked(
                                Thread.currentThread(), null);
                        return true;
                    } else {
                        // This is contained by a schedule-oriented MoC
                        return true;
                    }
                } else if (_outputBranchController.isBlocked()) {
                    stopInputBranchController();
                    stopOutputBranchController();

                    if (execDir == null) {
                        // This is the top level director - problem!!!
                        throw new IllegalActionException(
                                this,
                                "No executive director exists yet this "
                                        + "director's composite actor is externally "
                                        + "deadlocked.");
                    } else if (execDir instanceof CompositeProcessDirector) {
                        // This is contained by a process-oriented MoC
                        ((CompositeProcessDirector) execDir).threadBlocked(
                                Thread.currentThread(), null);
                        return true;
                    } else {
                        // This is contained by a schedule-oriented MoC
                        return true;
                    }
                }
            } else {
                // There are no actors that are blocked on a communication
                // (send or receive) to the outside world.
                if (_inputBranchController.isBlocked()) {
                    while (!_outputBranchController.isBlocked()) {
                        try {
                            workspace.wait(this);
                        } catch (InterruptedException e) {
                            // TODO: determine best way to handle the exception
                            throw new IllegalActionException(this,
                                    "Interrupted.");
                        }
                    }

                    stopInputBranchController();
                    stopOutputBranchController();
                    return _resolveInternalDeadlock();
                } else if (_outputBranchController.isBlocked()) {
                    stopInputBranchController();
                    stopOutputBranchController();
                    return _resolveInternalDeadlock();
                } else {
                    while (!_outputBranchController.isBlocked()) {
                        try {
                            workspace.wait(this);
                        } catch (InterruptedException e) {
                            //TODO: determine best way to handle the exception
                            throw new IllegalActionException(this,
                                    "Interrupted.");
                        }
View Full Code Here

                NamedObj entity = getEntity("blank");
                Attribute attribute = getAttribute("blank");
                NamedObj newModel;

                if (entity != null) {
                    newModel = (NamedObj) entity.clone(new Workspace());

                    // The cloning process results an object that defers change
                    // requests.  By default, we do not want to defer change
                    // requests, but more importantly, we need to execute
                    // any change requests that may have been queued
                    // during cloning. The following call does that.
                    newModel.setDeferringChangeRequests(false);
                } else if (attribute != null) {
                    newModel = (NamedObj) attribute.clone(new Workspace());

                    // The cloning process results an object that defers change
                    // requests.  By default, we do not want to defer change
                    // requests, but more importantly, we need to execute
                    // any change requests that may have been queued
                    // during cloning. The following call does that.
                    newModel.setDeferringChangeRequests(false);
                } else {
                    newModel = new TypedCompositeActor(new Workspace());
                }

                // The model should have a parser associated with it
                // so that undo works.
                // Checking to see if there already is a _parser attribute
View Full Code Here

public class GTEntityUtils {

    public static void updateAppearance(final GTEntity entity,
            GTIngredientsAttribute attribute) {

        Workspace workspace = ((NamedObj) entity).workspace();
        try {
            workspace.getWriteAccess();

            Set<String> preservedPortNames = new HashSet<String>();
            boolean isIconSet = false;
            int i = 1;
            GTIngredientList list = attribute.getIngredientList();
            for (GTIngredient ingredient : list) {
                if (ingredient instanceof PortCriterion) {
                    PortCriterion criterion = (PortCriterion) ingredient;
                    String portID = criterion.getPortID(list);
                    preservedPortNames.add(portID);

                    TypedIOPort port = (TypedIOPort)
                            ((ComponentEntity) entity).getPort(portID);
                    boolean isInput = criterion.isInput();
                    boolean isOutput = criterion.isOutput();
                    boolean isMultiport = !criterion.isMultiportEnabled()
                            || criterion.isMultiport();
                    if (port != null) {
                        if (port instanceof PortMatcher) {
                            port.setInput(isInput);
                            port.setOutput(isOutput);
                        } else {
                            MoMLChangeRequest request =
                                new MoMLChangeRequest(entity, (NamedObj) entity,
                                        "<deletePort name=\"" + port.getName()
                                        + "\"/>");
                            request.setUndoable(true);
                            request.setMergeWithPreviousUndo(true);
                            request.execute();
                            port = new PortMatcher(criterion,
                                    (ComponentEntity) entity, portID, isInput,
                                    isOutput);
                            port.setPersistent(false);
                        }
                    } else {
                        port = new PortMatcher(criterion,
                                (ComponentEntity) entity, portID, isInput,
                                isOutput);
                        port.setPersistent(false);
                    }
                    port.setMultiport(isMultiport);
                } else if (ingredient instanceof SubclassCriterion
                        && !isIconSet) {
                    SubclassCriterion criterion = (SubclassCriterion) ingredient;
                    final String superclass = criterion.getSuperclass();
                    ((NamedObj) entity).requestChange(new ChangeRequest(entity,
                            "Deferred load actor icon action.") {
                        protected void _execute() throws Exception {
                            _loadActorIcon(entity, superclass);
                        }
                    });
                    isIconSet = true;
                }
                i++;
            }
            if (!isIconSet) {
                ((NamedObj) entity).requestChange(
                        new RestoreAppearanceChangeRequest(entity));
            }

            List<?> portList = new LinkedList<Object>((List<?>)
                    ((ComponentEntity) entity).portList());
            for (i = 0; i < portList.size(); i++) {
                Port port = (Port) portList.get(i);
                if (port instanceof PortMatcher
                        && !preservedPortNames.contains(port.getName())) {
                    ((PortMatcher) port)._setPortCriterion(null);
                    port.setContainer(null);
                }
            }

        } catch (KernelException e) {
            throw new KernelRuntimeException(e, "Cannot update appearance for "
                    + "actor " + entity.getName() + ".");

        } finally {
            workspace.doneWriting();
        }
    }
View Full Code Here

     *
     * @throws Exception
     */
    public void createBatchDirector(Flow flow) throws Exception {
        if (batch.getBatchDirector() == null) {
            Workspace wspace = (flow == null) ? null : flow.workspace();
            Director director = DirectorFactory.createNewDirector(
                    (useNexusStorage) ? DirectorType.RECORDING
                    : DirectorType.SOLEILSTD, wspace);
            batch.setBatchDirector(director);
        }
View Full Code Here

     *
     * @throws Exception
     */
    public void createBatchDirector(Flow flow) throws Exception {
        if (batch.getBatchDirector() == null) {
            Workspace wspace = (flow == null) ? null : flow.workspace();
            Director director = DirectorFactory.createNewDirector(
                    (useNexusStorage) ? DirectorType.RECORDING
                    : DirectorType.SOLEILSTD, wspace);
            batch.setBatchDirector(director);
        }
View Full Code Here

     *
     * @throws Exception
     */
    public void createBatchDirector(Flow flow) throws Exception {
        if (batch.getBatchDirector() == null) {
            Workspace wspace = (flow == null) ? null : flow.workspace();
            Director director = DirectorFactory.createNewDirector(
                    (useNexusStorage) ? DirectorType.RECORDING
                    : DirectorType.SOLEILSTD, wspace);
            batch.setBatchDirector(director);
        }
View Full Code Here

TOP

Related Classes of ptolemy.kernel.util.Workspace

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.