Package ptolemy.codegen.kernel

Examples of ptolemy.codegen.kernel.CodeGeneratorHelper$Channel


    }

    private boolean connectUsingRemoting(CommandContext cmdCtx, RemotingMBeanServerConnection rmtMBeanSvrConn)
            throws IOException, CliInitializationException {
        Connection conn = rmtMBeanSvrConn.getConnection();
        Channel channel;
        final IoFuture<Channel> futureChannel = conn.openChannel("management", OptionMap.EMPTY);
        IoFuture.Status result = futureChannel.await(5, TimeUnit.SECONDS);
        if (result == IoFuture.Status.DONE) {
            channel = futureChannel.get();
        } else {
View Full Code Here


    }

    /** {@inheritDoc} */
    @Override
    public Channel getChannel() throws IOException {
        final Channel channel = this.channel;
        if(channel == null) {
            synchronized (this) {
                if(this.channel == null) {
                    throw ProtocolMessages.MESSAGES.channelClosed();
                }
View Full Code Here

        this.transactionsRepository = transactionsRepository;
        this.clientMappingRegistryCollector = clientMappingRegistryCollector;
    }

    public void startReceiving() {
        final Channel channel = this.channelAssociation.getChannel();
        channel.addCloseHandler(new ChannelCloseHandler());

        channel.receiveMessage(this);
        // listen to module availability/unavailability events
        this.deploymentRepository.addListener(this);
        // listen to new clusters (a.k.a groups) being started/stopped
        this.clientMappingRegistryCollector.addListener(this);
        // Send the cluster topology for existing clusters in the registry
View Full Code Here

        });
    }

    @Override
    public synchronized ProxyController popChannelAndCreateProxy(final String hostName) {
        final Channel channel = unregisteredHostChannels.remove(hostName);
        if (channel == null) {
            throw MESSAGES.noChannelForHost(hostName);
        }
        channel.addCloseHandler(new CloseHandler<Channel>() {
            public void handleClose(final Channel closed, final IOException exception) {
                unregisterRemoteHost(hostName);
            }
        });
        final PathAddress addr = PathAddress.pathAddress(PathElement.pathElement(ModelDescriptionConstants.HOST, hostName));
View Full Code Here

                CONTROLLER_MANAGEMENT_LOGGER.serverRegistered(serverName, channel);
                executorService.execute(new Runnable() {
                    @Override
                    public void run() {
                        final Channel mgmtChannel = channel;
                        ServerToHostOperationHandlerFactoryService.this.callback.getValue().serverRegistered(serverName, mgmtChannel, new ServerInventory.ProxyCreatedCallback() {
                            @Override
                            public void proxyOperationHandlerCreated(final ManagementMessageHandler handler) {
                                channel.addCloseHandler(new CloseHandler<Channel>() {
                                    @Override
                                    public void handleClose(Channel closed, IOException exception) {
                                        handler.shutdownNow();
                                    }
                                });
                                final Channel.Receiver receiver = ManagementChannelReceiver.createDelegating(handler);
                                mgmtChannel.receiveMessage(receiver);
                                // Send the response once the server is fully registered
                                safeWriteResponse(channel, header, null);
                            }
                        });
                    }
View Full Code Here

        void handleRequest(final String hostId, final DataInput input, final ManagementRequestContext<Void> context) throws IOException {
            context.executeAsync(new ManagementRequestContext.AsyncTask<Void>() {
                @Override
                public void execute(final ManagementRequestContext<Void> context) throws Exception {
                    try {
                        final Channel mgmtChannel = context.getChannel();
                        registry.registerChannel(hostId, mgmtChannel, new ProxyCreatedCallback() {
                            @Override
                            public void proxyCreated(final ManagementMessageHandler handler) {
                                proxyHandler = handler;
                                mgmtChannel.addCloseHandler(new CloseHandler<Channel>() {
                                    @Override
                                    public void handleClose(Channel closed, IOException exception) {
                                        handler.shutdownNow();
                                    }
                                });
View Full Code Here

        Iterator refinements = container.deepEntityList().iterator();
        while (refinements.hasNext()) {
            boolean fireRefinement = true;
            refinementCount++;
            CompositeActor refinement = (CompositeActor) refinements.next();
            CodeGeneratorHelper refinementHelper = (CodeGeneratorHelper) _getHelper(refinement);
            String refinementName = refinement.getName();
            if (!refinementName.equals("default")) {
                if (useSwitch) {
                    code.append(_INDENT2 + "case " + refinementName + ":");
                } else {
                    if (refinementCount == 1) {
                        // Add String to the list of _newTypesUsed.
                        refinementHelper.addNewTypeUsed("String");
                        code.append(_INDENT2 + "if (!strcmp(");
                    } else {
                        code.append(_INDENT2 + "} else if (!strcmp(");
                    }
                    code.append(_codeGenerator
                            .generateVariableName(container.control)
                            + ".payload.String, "
                            + "\""
                            + refinementName
                            + "\")) {" + _eol);
                }
            } else {
                if (useSwitch) {
                    code.append(_INDENT2 + "default: ");
                } else {
                    defaultRefinement = refinement;
                    // Skip Firing the default refinement for now,
                    // we'll do it later.
                    fireRefinement = false;
                }
            }

            // Fire the refinement
            if (fireRefinement) {
                if (inline) {
                    code.append(refinementHelper.generateFireCode());
                    code.append(refinementHelper.generateTypeConvertFireCode());
                } else {
                    code.append(CodeGeneratorHelper.generateName(refinement)
                            + "();" + _eol);
                }
            }
            fireRefinement = true;

            if (useSwitch) {
                code.append(_INDENT2 + "break;" + _eol + _eol);
            }
        }

        if (defaultRefinement != null) {
            code.append(_INDENT2 + "} else {" + _eol);
            if (inline) {
                CodeGeneratorHelper defaultHelper = (CodeGeneratorHelper) _getHelper(defaultRefinement);
                code.append(defaultHelper.generateFireCode());
                code.append(defaultHelper.generateTypeConvertFireCode());
            } else {
                code.append(CodeGeneratorHelper.generateName(defaultRefinement)
                        + "();" + _eol);
            }
        }
View Full Code Here

            while (modifiedVariables.hasNext()) {
                // SetVariable needs this to be a Variable, not a Parameter.
                Variable variable = (Variable) modifiedVariables.next();

                NamedObj container = variable.getContainer();
                CodeGeneratorHelper containerHelper = (CodeGeneratorHelper) _getHelper(container);
                code.append(_INDENT1
                        + generateVariableName(variable)
                        + " = "
                        + containerHelper.getParameterValue(variable.getName(),
                                variable.getContainer()) + ";" + _eol);
            }
        }

        return code.toString();
View Full Code Here

        Iterator states = controller.entityList().iterator();
        while (states.hasNext()) {
            State state = (State) states.next();
            TypedActor[] actors = state.getRefinement();
            if (actors != null) {
                CodeGeneratorHelper refinementHelper = (CodeGeneratorHelper) _getHelper((NamedObj) actors[0]);
                int[][] rates = refinementHelper.getRates();
                if (rates != null) {
                    numberOfConfigurationsOfContainer += rates.length;
                } else {
                    numberOfConfigurationsOfContainer += 1;
                }
            }
        }

        int[][] containerRates = new int[numberOfConfigurationsOfContainer][];

        states = controller.entityList().iterator();
        int configurationNumber = 0;
        while (states.hasNext()) {
            State state = (State) states.next();
            TypedActor[] actors = state.getRefinement();
            if (actors != null) {
                CodeGeneratorHelper refinementHelper = (CodeGeneratorHelper) _getHelper((NamedObj) actors[0]);
                int[][] rates = refinementHelper.getRates();
                if (rates != null) {
                    for (int i = 0; i < rates.length; i++) {
                        // Extract the port rates from the current refinement
                        // and set the port rates of the modal model containing
                        // the refinement.
View Full Code Here

                        // we should only send data to the controller and the
                        // refinement corresponding to current state.
                        for (int m = 0; m < 2; m++) {

                            IOPort sinkPort = sinkPorts[m];
                            CodeGeneratorHelper helper = (CodeGeneratorHelper) _getHelper(sinkPort
                                    .getContainer());
                            code.append(CodeGeneratorHelper
                                    .generateName(sinkPort));

                            if (sinkPort.isMultiport()) {
                                code.append("[" + i + "]");
                            }

                            int sinkPortBufferSize = helper
                                    .getBufferSize(sinkPort);

                            if (sinkPortBufferSize > 1) {
                                String temp = "";
                                Object offsetObject = helper.getWriteOffset(
                                        sinkPort, i);
                                if (offsetObject instanceof Integer) {
                                    int offset = ((Integer) offsetObject)
                                            .intValue()
                                            + k;
                                    offset %= helper.getBufferSize(sinkPort, i);
                                    temp = Integer.toString(offset);
                                } else {
                                    int modulo = helper.getBufferSize(sinkPort,
                                            i) - 1;
                                    temp = "("
                                            + (String) helper.getWriteOffset(
                                                    sinkPort, i) + " + " + k
                                            + ")&" + modulo;
                                }
                                code.append("[" + temp + "]");
                            }
                            code.append(" = ");
                        }
                        code.append(containerHelper
                                .getReference(name + "," + k));
                        code.append(";" + _eol);
                    }

                    // Only update the port write offsets of the
                    // controller and the current refinement. The
                    // offset of the input port itself is updated by
                    // outside director.
                    for (int m = 0; m < 2; m++) {
                        IOPort sinkPort = sinkPorts[m];
                        CodeGeneratorHelper helper = (CodeGeneratorHelper) _getHelper(sinkPort
                                .getContainer());
                        Object offsetObject = helper
                                .getWriteOffset(sinkPort, i);
                        if (offsetObject instanceof Integer) {
                            int offset = ((Integer) offsetObject).intValue();
                            offset = (offset + rate)
                                    % helper.getBufferSize(sinkPort, i);
                            helper.setWriteOffset(sinkPort, i, Integer
                                    .valueOf(offset));
                        } else {
                            int modulo = helper.getBufferSize(sinkPort, i) - 1;
                            String offsetVariable = (String) helper
                                    .getWriteOffset(sinkPort, i);
                            code.append(offsetVariable + " = ("
                                    + offsetVariable + " + " + rate + ")&"
                                    + modulo + ";" + _eol);
                        }
View Full Code Here

TOP

Related Classes of ptolemy.codegen.kernel.CodeGeneratorHelper$Channel

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.