NetAcquire Publish/Subscribe Java Example
Remote temperature data acquisition
import com.netacquire.naps.*; public class SubscribeExample1
{
public static void main(String[] args)
{
try {
Connection netacquire1 = new Connection("na1");
Subscription reactor_temperature =
new Subscription(netacquire1, "reactor_temperature");
System.out.println("Reactor temperature: " + reactor_temperature);
} catch(Exception e) {
e.printStackTrace(System.out);
}
System.exit(0);
}
}
This fully functional example illustrates a complete application requiring only three lines of publish/subscribe executable code.
The first line of the main program creates an object that represents a data publisher. The second line creates an object that represents a specific data subscription. Subscriptions can be given convenient names on the NetAcquire server; in this case the subscription represents an analog voltage from a reactor temperature sensor. Once a subscription is created, the current value of the subscription can be displayed at any time, as illustrated by the final System.out line.
When using the subscription object directly in an output stream as done here the implementation displays all the information associated with the subscription (name, type, raw value, etc.). For more application control over the display of the raw data one can retrieve the subscription’s value using an explicit accessor. Integers of width 8, 16, 32, and 64 bits as well as 32 and 64 bit floating point types are supported.
The above example illustrates that NetAcquire Publish/Subscribe automatically keeps the value of the variable reactor_temperature up-to-date without any coding on the application’s part.
In addition to keeping subscriptions automatically up-to-date, NetAcquire Publish/Subscribe can also notify applications when the value of a subscription changes (see the Java notification example).