TINE console client applications play an important role in middle-layer servers, automatic servers, scripts, diagnostic checks, etc. Client applications requiring a user interface are best written as GUI applications.
The example below is a simple java client code module which obtains the sine curve from the simple console server example, and illustrates both synchronous and asynchronous calls.
Create a new java project and make sure that tine.jar is included in the library list on otherwise on the class path. In this example, we'll assume this is a java project in Eclipse called "SINE-console", where a package "tineSineClientExample" has been created with a class called "SineClient".
In the SineClient.java code, make sure you add "import TINE.*;" underneath the package declaration.
Add the String variable 'devSrvName' and int variable 'size' to the class, initializing 'devSrvName' to the device server name of your test sine server and 'size' to 1024. Now add the float arrays sdat and refdat, dimensioned to size; Also add an embedded class 'cdSineClient' which implements the TLinkCallback class. The callback class will simply print out the first 10 values of the sine wave (minus the initial reference). Your SineClient.java code should now look like the following:
Add an initialize() method which obtains a 'reference' curve and starts an asynchronous link to get the sine wave from the sine server. The details are shown below:
Note that after using the 'ref' link to synchronously obtain a 'reference' curve, we have terminated it explicitily by calling 'ref.cancel()'. If an application needs to make intermittent synchronous calls to the same link it would be better NOT to terminate the link reference and instead to issue 'execute()' calls when needed.
The callback (showsine()) is used as an asynchronous callback. Note that this is just an example. In general, displaying 1024 float values on the console at 1 Hz is a bad idea!
In the main method, you can create an instance of the SineClient class, call the initialization routine, and then block the thread from exiting by calling sleep, as shown below.
Here, the thread is blocked for 10 seconds before exiting, as a way of demonstrating this simple client program. There are several alternatives to this coding style. Namely, you could also put the code contained in the initialize() method directly in the main method and forgo the need to create an instance of the SineClient class. You can also block the thread for exiting forever, etc.
When you run the application, make sure the the virtual machine definition -Dtine.home is set (e.g -Dtine.home=L:\database or -Dtine.home=/usr/etc/tine), or that a properties file tine.properties containing this information is located in the same directory where tine.jar is located.