/** * Return true if the receiver containing this boundary detector is connected to the inside of an * input boundary port; return false otherwise. A boundary port is an opaque port that is * contained by a composite actor. This method is not synchronized so the caller should be. * * @return True if the containing receiver is connected to the inside of a boundary port; return * false otherwise. * @exception IllegalActionException * @exception InvalidStateException */ public boolean isConnectedToBoundaryInside() throws InvalidStateException, IllegalActionException { if (_connectedInsideOfBoundaryCacheIsOn) { return _isConnectedInsideOfBoundaryValue; } else { IOPort contPort = _receiver.getContainer(); if (contPort == null) { _connectedInsideOfBoundaryCacheIsOn = false; _isConnectedInsideOfBoundaryValue = false; return _isConnectedInsideOfBoundaryValue; } ComponentEntity contEntity = (ComponentEntity) contPort.getContainer(); IOPort connectedPort = null; ComponentEntity connectedEntity = null; Iterator ports = contPort.connectedPortList().iterator(); while (ports.hasNext()) { connectedPort = (IOPort) ports.next(); connectedEntity = (ComponentEntity) connectedPort.getContainer(); if ((connectedEntity == contEntity.getContainer()) && connectedPort.isInput() && connectedPort.isOpaque()) { // The port container of this receiver is // connected to the inside of a boundary port. // Now determine if this receiver's channel is // connected to the boundary port. Receiver[][] receivers = connectedPort.deepGetReceivers(); for (int i = 0; i < receivers.length; i++) { for (int j = 0; j < receivers[i].length; j++) { if (_receiver == receivers[i][j]) { _connectedInsideOfBoundaryCacheIsOn = true; _isConnectedInsideOfBoundaryValue = true; return true; } } } } } _connectedInsideOfBoundaryCacheIsOn = true; _isConnectedInsideOfBoundaryValue = false; return _isConnectedInsideOfBoundaryValue; } }
/** * Return the list of sending (up-stream) ports that are connected to the specified port. This * treats every port as an opaque port. * * @param port The specified port. * @return The list of sending ports. */ protected static List<IOPort> _getSourcePortList(IOPort port) { List<IOPort> result = new ArrayList<IOPort>(); for (IOPort connectedPort : (List<IOPort>) port.connectedPortList()) { boolean isInput = connectedPort.isInput(); boolean isCompositeInput = connectedPort.getContainer() instanceof CompositeEntity && isInput && port.depthInHierarchy() > connectedPort.depthInHierarchy(); if (!isInput || isCompositeInput) { result.add(connectedPort); } } return result; }
/** * 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); } } }