Changes between Version 5 and Version 6 of Java API
- Timestamp:
- 09/05/12 16:23:50 (13 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Java API
v5 v6 16 16 === Conduits === 17 17 18 The conduit is the mechanism in the MUSCLE runtime environment to send data. In the API, the ConduitEntrance and ConduitExit are accessible. The ConduitEntrance is used to send data, while the ConduitExit receives data. These entrances and exits, as we call them, can be accessed in two ways. Either they are created in the addPortals() method, or they are called on the fly in the code using the out() and in()methods.19 20 The addPortalsmethod is called before the submodel starts, so the exits and entrances are stored as fields of your class. The conduit exit and entrance uses Java Generics to define what kind of data will be received or sent, both in the field declaration and in the addExit or addEntrance method. This allows for compile-time and run-time checking of data that is sent over the conduit.18 The conduit is the mechanism in the MUSCLE runtime environment to send data. In the API, the {{{ConduitEntrance}}} and {{{ConduitExit}}} are accessible. The {{{ConduitEntrance}}} is used to send data, while the {{{ConduitExit}}} receives data. These entrances and exits, as we call them, can be accessed in two ways. Either they are created in the {{{addPortals()}}} method, or they are called on the fly in the code using the {{{out()}}} and {{{in()}}} methods. 19 20 The {{{addPortals()}}} method is called before the submodel starts, so the exits and entrances are stored as fields of your class. The conduit exit and entrance uses Java Generics to define what kind of data will be received or sent, both in the field declaration and in the addExit or addEntrance method. This allows for compile-time and run-time checking of data that is sent over the conduit. 21 21 {{{ 22 22 ConduitExit<double[]> exitA; … … 29 29 } 30 30 }}} 31 To send or receive, use the fields that were initialized in addPortals().31 To send or receive, use the fields that were initialized in {{{addPortals()}}}. 32 32 {{{ 33 33 double[] dataA = exitA.receive(); … … 35 35 }}} 36 36 37 If addPortals() is not overridden it is possible to use the out() and in() methods to send or receive data. It is then not necessary to store the ConduitExit and ConduitEntranceas a field.37 If {{{addPortals()}}} is not overridden it is possible to use the out() and in() methods to send or receive data. It is then not necessary to store the {{{ConduitExit}}} and {{{ConduitEntrance}}} as a field. 38 38 {{{ 39 39 double[] dataA = (double[]) in("exitName").receive(); 40 40 out("entranceName").send(dataA); 41 41 }}} 42 In this case received data needs to be cast to double[] to use it, and in the send statement, the Java compiler will give a warning that an unchecked conversion is being done. If the cast is not correct, a ClassCastException will be thrown by Java. If the exit or entrance name is not configured, an IllegalArgumentExceptionwill be thrown by MUSCLE.42 In this case received data needs to be cast to {{{double[]}}} to use it, and in the send statement, the Java compiler will give a warning that an unchecked conversion is being done. If the cast is not correct, a {{{ClassCastException}}} will be thrown by Java. If the exit or entrance name is not configured, an {{{IllegalArgumentException}}} will be thrown by MUSCLE. 43 43 44 44 The advantage of the first method is that it is type-safe, so there is no need to cast the data. Also if the code and the configuration file do not match this is detected immediately. The advantage of the second method is that it is less verbose and leads to smaller classes. 45 45 46 A ConduitExit is used for receiving in a blocking mode. There are two receive methods: receive() and receiveObservation(). In the first case only the data is received. In the second, an observation is received, which contains the data but also the timestamp at which the data was sent, and the timestamp at which the next message will arrive. So,46 A {{{ConduitExit}}} is used for receiving in a blocking mode. There are two receive methods: {{{receive()}}} and {{{receiveObservation()}}}. In the first case only the data is received. In the second, an observation is received, which contains the data but also the timestamp at which the data was sent, and the timestamp at which the next message will arrive. So, 47 47 {{{ 48 48 double[] dataA = exitA.receive(); … … 74 74 === Parameters === 75 75 76 Parameters that are defined in the configuration file are accessed through a range of get*Property()methods. The most basic form is76 Parameters that are defined in the configuration file are accessed through a range of {{{get*Property()}}} methods. The most basic form is 77 77 {{{ 78 78 String parameter = getProperty("propName"); 79 79 }}} 80 In this form the property is read as a string. It first tries to find the instance property by searching for "instanceName:propName" and then for a global property named "propName". All get*Property() methods will throw an IllegalArgumentException if the property does not exist, this can be prevented by first calling hasProperty().80 In this form the property is read as a string. It first tries to find the instance property by searching for "instanceName:propName" and then for a global property named "propName". All {{{get*Property()}}} methods will throw an {{{IllegalArgumentException}}} if the property does not exist, this can be prevented by first calling {{{hasProperty()}}}. 81 81 If a instance property is specifically required, this can be checked by first calling 82 82 {{{ … … 91 91 }}} 92 92 93 To get other types of parameters than strings, use getPathProperty for a File, getIntProperty for an int, getDoubleProperty for a double and getBoolProperty for a boolean.93 To get other types of parameters than strings, use {{{getPathProperty()}}} for a {{{File}}}, {{{getIntProperty()}}} for an {{{int}}}, {{{getDoubleProperty()}}} for a {{{double}}} and {{{getBoolProperty()}}} for a {{{boolean}}}. 94 94 95 95 == MUSCLE MML API == … … 262 262 }}} 263 263 264 With MUSCLE a DoubleFileSink, NullFileSink and a DoubleFileSource are provided in the {{{muscle.core.conduit.terminal}}} package. Also the abstract classes FileSource and FileSinkare available to override. See the API documentation for more information.264 With MUSCLE a {{{DoubleFileSink}}}, {{{NullFileSink}}} and a {{{DoubleFileSource}}} are provided in the {{{muscle.core.conduit.terminal}}} package. Also the abstract classes {{{FileSource}}} and {{{FileSink}}} are available to override. See the API documentation for more information. 265 265 266 266 == MUSCLE free-form API ==