Class DatagramWriter
- java.lang.Object
-
- ptolemy.kernel.util.NamedObj
-
- ptolemy.kernel.InstantiableNamedObj
-
- ptolemy.kernel.Entity<T>
-
- ptolemy.kernel.ComponentEntity<T>
-
- ptolemy.actor.AtomicActor<TypedIOPort>
-
- ptolemy.actor.TypedAtomicActor
-
- ptolemy.actor.lib.net.DatagramWriter
-
- All Implemented Interfaces:
java.lang.Cloneable
,Actor
,Executable
,FiringsRecordable
,Initializable
,TypedActor
,Changeable
,Debuggable
,DebugListener
,Derivable
,Instantiable
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
public class DatagramWriter extends TypedAtomicActor
This actor sends its input as a Datagram over the network using the UDP protocol. Before being sent, the data is optionally encoded as a text string representing the value being sent. When this option is selected, any Ptolemy data type may be represented. See the encoding parameter.NOTE: This actor has problems, the tests do not reliably pass. For details, see
https://chess.eecs.berkeley.edu/bugzilla/show_bug.cgi?id=54
.The address and socket number towards which the datagram is sent are given by the optional inputs remoteAddress and remoteSocketNumber. However, unless/until token(s) arrive at these inputs, default values, given by defaultRemoteAddress and defaultRemoteSocketNumber are used. Note that some IP addresses are special broadcast addresses. An address such as "128.32.239.255" broadcasts to any IP addresses on the "128.23.239.X" subnet. This only works on your own subnet.
Each instance of this actor needs to allocate a local socket from which to transmit datagrams. Initially, the local socket number is set to 4003, just to pick a number. The socket is not allocated until the model is run.
- Since:
- Ptolemy II 2.0
- Version:
- $Id$
- Author:
- Winthrop Williams, Joern Janneck, Xiaojun Liu, Edward A. Lee (Based on TiltSensor actor written by Chamberlain Fong, Xiaojun Liu, Edward Lee)
- Pt.AcceptedRating:
- Yellow (winthrop)
- Pt.ProposedRating:
- Yellow (winthrop)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description TypedIOPort
data
Data to be sent.Parameter
defaultRemoteAddress
The default remote address to which to send datagrams.Parameter
defaultRemoteSocketNumber
The default remote UDP socket to which to launch the packet.Parameter
localSocketNumber
The local socket number for this actor's socket.TypedIOPort
remoteAddress
The remote address towards which to launch the packet.TypedIOPort
remoteSocketNumber
The remote socket number towards which to launch the packet.TypedIOPort
triggerOutput
The triggerOutput port.-
Fields inherited from class ptolemy.actor.TypedAtomicActor
_typesValid
-
Fields inherited from class ptolemy.actor.AtomicActor
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
-
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
-
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
-
-
Constructor Summary
Constructors Constructor Description DatagramWriter(CompositeEntity container, java.lang.String name)
Construct a DatagramWriter actor with given name in the given container.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
attributeChanged(Attribute attribute)
Override the base class to reinitialize the state if the localSocketNumber, defaultRemoteAddress or defaultRemoteSocketNumber parameter has changed.void
fire()
Does up to three things, in this order: Set new remote address value, Set new remote socket number, transmit data as a UDP packet over the ethernet.void
initialize()
Initialize allocates the socket and makes use of default parameters for the remote address and socket to which datagrams will be sent.void
setContainer(CompositeEntity container)
Override the setContainer() method to call wrapup() if container is not equal to the result of getContainer().void
wrapup()
Wrap up.-
Methods inherited from class ptolemy.actor.TypedAtomicActor
_containedTypeConstraints, _customTypeConstraints, _defaultTypeConstraints, _fireAt, _fireAt, attributeTypeChanged, clone, clone, isBackwardTypeInferenceEnabled, newPort, typeConstraintList, typeConstraints
-
Methods inherited from class ptolemy.actor.AtomicActor
_actorFiring, _actorFiring, _declareDelayDependency, addActorFiringListener, addInitializable, connectionsChanged, createReceivers, declareDelayDependency, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, postfire, prefire, preinitialize, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, stop, stopFire, terminate
-
Methods inherited from class ptolemy.kernel.ComponentEntity
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
-
Methods inherited from class ptolemy.kernel.Entity
_addPort, _description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName
-
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
-
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _executeChangeRequests, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, addHierarchyListener, attributeDeleted, attributeList, attributeList, decorators, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, notifyOfNameChange, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, validateSettables, workspace
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface ptolemy.actor.Actor
createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
-
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
-
Methods inherited from interface ptolemy.actor.Executable
isFireFunctional, isStrict, iterate, postfire, prefire, stop, stopFire, terminate
-
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, preinitialize, removeInitializable
-
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
-
-
-
-
Field Detail
-
triggerOutput
public TypedIOPort triggerOutput
The triggerOutput port. The type of this port is GENERAL, forcing input ports connected here to also be of type GENERAL, (as trigger inputs typically are). This port always transmits a Token with nothing in it. This gives the designer a way to control the order in which other actors fire with respect to the firing of this actor in the SDF domain.
-
localSocketNumber
public Parameter localSocketNumber
The local socket number for this actor's socket. Integer in the range 0..65535. Default is 4003.
-
data
public TypedIOPort data
Data to be sent. Data can be encoded different ways, depending on the setting of encoding.
-
defaultRemoteAddress
public Parameter defaultRemoteAddress
The default remote address to which to send datagrams. This is a string. It will get looked up to find the IP address. (Legal forms of this string include "128.32.239.10" and "localhost".)
-
remoteAddress
public TypedIOPort remoteAddress
The remote address towards which to launch the packet. This is a multiport. This permits it to be left unconnected in DE. If multiple addresses are delivered simultaneously to this port, the one arriving via the highest numbered channel is used. Type is string.
-
defaultRemoteSocketNumber
public Parameter defaultRemoteSocketNumber
The default remote UDP socket to which to launch the packet. This is an integer in 0..65535. NOTE: TCP sockets get their own distinct, non-interfering, set of 2^16 numbers!
-
remoteSocketNumber
public TypedIOPort remoteSocketNumber
The remote socket number towards which to launch the packet. This is a multiport. This permits it to be left unconnected in DE. If multiple addresses are delivered simultaneously to this port, the one arriving via the highest numbered channel is used. Type is integer.
-
-
Constructor Detail
-
DatagramWriter
public DatagramWriter(CompositeEntity container, java.lang.String name) throws NameDuplicationException, IllegalActionException
Construct a DatagramWriter actor with given name in the given container. Set up ports, parameters and default values. Two of the parameters, defaultRemoteAddress and defaultRemoteSocketNumber, give default values for when the remoteAddress and remoteSocketNumber ports have not yet received tokens. I wonder if the port and parameter concepts could be combined in some way to factor out this functionality. Perhaps every port could have the capability of having a default value and a setting as to whether this default takes effect every time the actor is fired and a token is absent of whether the previous input is repeated once an has been present.- Parameters:
container
- The container.name
- The name for this actor.- Throws:
NameDuplicationException
- If the container already has an actor with this name.IllegalActionException
- If the actor cannot be contained by this container.
-
-
Method Detail
-
attributeChanged
public void attributeChanged(Attribute attribute) throws IllegalActionException
Override the base class to reinitialize the state if the localSocketNumber, defaultRemoteAddress or defaultRemoteSocketNumber parameter has changed.If the parameter changed is localSocketNumber, then if the model is running (as evidenced by socket != null) then close socket and reopen with new socket number (even if it is the same as the old socket number). Do not close the socket until a new one has been successfully opened. If defaultRemoteAddress or defaultRemoteSocketNumber is changed, simply update these parameters, checking, in the case of the address, that it passes lookup anc conversion to an IP address. If the encoding parameter is changed, set the private encoding settings to the new values.
- Overrides:
attributeChanged
in classNamedObj
- Parameters:
attribute
- The attribute that changed.- Throws:
IllegalActionException
- If the socket cannot be created.
-
fire
public void fire() throws IllegalActionException
Does up to three things, in this order: Set new remote address value, Set new remote socket number, transmit data as a UDP packet over the ethernet. The first two can, of course, affect where the datagram goes. Any remote address/socket values supplied are saved and become the defaults for next time.- Specified by:
fire
in interfaceExecutable
- Overrides:
fire
in classAtomicActor<TypedIOPort>
- Throws:
IllegalActionException
- Not thrown in this base class.
-
initialize
public void initialize() throws IllegalActionException
Initialize allocates the socket and makes use of default parameters for the remote address and socket to which datagrams will be sent.- Specified by:
initialize
in interfaceInitializable
- Overrides:
initialize
in classAtomicActor<TypedIOPort>
- Throws:
IllegalActionException
- If the default remote socket number is outside the range 0..65535, the local socket number is outside the range 0..65535, the local socket cannot be created with the given socket number (such as because that number is already in use), or translation of remote address fails to make an IP address from the given address string (i.e. InetAddress.getByName() fails in the address lookup attempt.
-
setContainer
public void setContainer(CompositeEntity container) throws IllegalActionException, NameDuplicationException
Override the setContainer() method to call wrapup() if container is not equal to the result of getContainer(). If this method did not override super.setContainer(), then when the actor is deleted while the model is running, wrapup() would never get called.- Overrides:
setContainer
in classAtomicActor<TypedIOPort>
- Parameters:
container
- The proposed container.- Throws:
IllegalActionException
- If the action would result in a recursive containment structure, or if this entity and container are not in the same workspace.NameDuplicationException
- If the container already has an entity with the name of this entity.- See Also:
ComponentEntity.getContainer()
-
wrapup
public void wrapup() throws IllegalActionException
Wrap up. Free the socket, allowing the socket number to be reused.- Specified by:
wrapup
in interfaceInitializable
- Overrides:
wrapup
in classAtomicActor<TypedIOPort>
- Throws:
IllegalActionException
- If the socket was already null.
-
-