/** * Create a guarded communication with a send communication. This constructor allows actors which * are not CSPActors access to CSP functionality by providing their own * ConditionalBranchController. * * @param guard The guard for the guarded communication statement represented by this object. * @param port The IOPort containing the channel (and thus receiver) that this branch will try to * rendezvous with. * @param channel The channel in the IOPort that this branch is trying to rendezvous with. * @param branchID The identification number assigned to this branch upon creation by the * CSPActor. * @param token The token this branch is trying to send. * @param controller The controller that this branch uses. * @exception IllegalActionException If the channel has more than one receiver or if the receiver * is not of type CSPReceiver. */ public ConditionalSend( boolean guard, IOPort port, int channel, int branchID, Token token, ConditionalBranchController controller) throws IllegalActionException { super(guard, port, branchID, controller); _port = port; _channel = channel; try { port.workspace().getReadAccess(); if (!port.isOutput()) { throw new IllegalActionException( port, "ConditionalSend: " + "tokens only sent from an output port."); } if (channel >= port.getWidth() || channel < 0) { throw new IllegalActionException(port, "ConditionalSend: " + "channel index out of range."); } Receiver[][] receivers = port.getRemoteReceivers(); if (receivers == null || receivers[channel] == null) { throw new IllegalActionException( port, "ConditionalSend: " + "Trying to rendezvous with null receiver"); } if (!(receivers[channel][0] instanceof CSPReceiver)) { throw new IllegalActionException( port, "ConditionalSend: " + "channel " + channel + " does not have a receiver " + "of type CSPReceiver."); } _setReceivers(receivers[channel]); } finally { port.workspace().doneReading(); } _setToken(token); }
/** * Return true if the receiver containing this boundary detector is connected to the outside of an * output boundary port; return false otherwise. A boundary port is an opaque port that is * contained by a composite actor. If the receiver containing this boundary detector is contained * on the inside of a boundary port, then return false. This method is not synchronized so the * caller should be. * * @return True if the containing receiver is connected to the outside of a boundary port; return * false otherwise. * @exception IllegalActionException */ public boolean isConnectedToBoundaryOutside() throws IllegalActionException { if (_connectedOutsideOfBoundaryCacheIsOn) { return _isConnectedOutsideOfBoundaryValue; } else { IOPort contPort = _receiver.getContainer(); if (contPort == null) { _connectedOutsideOfBoundaryCacheIsOn = false; _isConnectedOutsideOfBoundaryValue = false; return _isConnectedOutsideOfBoundaryValue; } Iterator ports = contPort.connectedPortList().iterator(); while (ports.hasNext()) { IOPort connectedPort = (IOPort) ports.next(); ComponentEntity connectedEntity = (ComponentEntity) connectedPort.getContainer(); if (connectedPort.isOpaque() && !connectedEntity.isAtomic() && connectedPort.isOutput()) { // The port container of this receiver is // connected to the outside of a boundary port. // Now determine if this receiver's channel is // connected to the boundary port. Receiver[][] receivers = connectedPort.getRemoteReceivers(); for (int i = 0; i < receivers.length; i++) { for (int j = 0; j < receivers[i].length; j++) { if (_receiver == receivers[i][j]) { _connectedOutsideOfBoundaryCacheIsOn = true; _isConnectedOutsideOfBoundaryValue = true; return true; } } } } } _connectedOutsideOfBoundaryCacheIsOn = true; _isConnectedOutsideOfBoundaryValue = false; return _isConnectedOutsideOfBoundaryValue; } }
/** * Interconnect all the remote actors in the same manner as the model's topology. In other words, * the connections defined by the model's topology are created virtually over the distributed * platform. For each actor, a portReceiverMap is created. A portReceiverMap is a data structure * representing for a given port the receivers it contains. In case the port is and input port it * consists of a set of receivers ID's i.e. (inputport, (ID1, ..., IDn). In case of an outputport, * it contains a map of services to receiver's IDs, i.e. (outputport, ((service1, (ID1, ..., IDi), * ..., (servicen, (IDj, ..., IDr))). This structure is sent over the network to the corresponding * service. The types of the port are also set on the remote actor. * * @exception IllegalActionException If the remote receivers can't be created. */ private void connectActors() throws IllegalActionException { if (VERBOSE) { System.out.println("Connecting Actors"); System.out.println(">> Creating Ports Receivers Map: "); } for (Iterator keysIterator = actorsThreadsMap.keySet().iterator(); keysIterator.hasNext(); ) { ComponentEntity actor = (ComponentEntity) keysIterator.next(); HashMap portsReceiversMap = new HashMap(); HashMap portTypes = new HashMap(); Iterator allPorts = actor.portList().iterator(); while (allPorts.hasNext()) { IOPort currentPort = (IOPort) allPorts.next(); Receiver[][] receivers = new Receiver[0][0]; if (currentPort.isOutput()) { receivers = currentPort.getRemoteReceivers(); } if (currentPort.isInput()) { receivers = currentPort.getReceivers(); } if (!currentPort.connectedPortList().isEmpty()) { portTypes.put(currentPort.getName(), ((TypedIOPort) currentPort).getType()); } if (receivers.length > 0) { if (VERBOSE) { System.out.print( "Port: " + currentPort.getFullName() + "\n" + DistributedUtilities.receiversArrayToString(receivers)); } if (currentPort.isOutput()) { portsReceiversMap.put(currentPort.getName(), createServicesReceiversMap(receivers)); } if (currentPort.isInput()) { portsReceiversMap.put( currentPort.getName(), DistributedUtilities.convertReceiversToIntegers(receivers)); } } } ServiceItem server = ((ClientThread) actorsThreadsMap.get(actor)).getService(); DistributedActor distributedActor = (DistributedActor) server.service; try { if (VERBOSE) { System.out.println( "Setting connections to: " + actor.getFullName() + " in: " + server.serviceID.toString()); System.out.println( "Setting port Types: " + actor.getFullName() + " in: " + server.serviceID.toString()); } distributedActor.setConnections(portsReceiversMap); distributedActor.setPortTypes(portTypes); } catch (RemoteException e) { KernelException.stackTraceToString(e); } } }