Efficiency of Using Data Proxies
This section illustrates the efficiency of using data proxies in JWAVE applications.
Inefficient System: The Data Makes Two Round Trips
In one typical JWAVE scenario, the client asks the server (a JWAVE wrapper function) to load or generate some data and then asks another JWAVE wrapper to process the data and return a Viewable object back to the client.
Figure 6-2: Inefficient Use of JWAVE illustrates an inefficient version of this scenario, where data makes two complete round trips between the client and the server. This scenario can be summarized as follows:
A
JWaveExecute object executes a JWAVE wrapper function called
DATAGEN on the PV‑WAVE server.
The generated data is then returned by the JWAVE wrapper to the client.
The client passes the data to another
JWaveExecute object, which sends it back to the server as input to another JWAVE wrapper called
FILTER. (The data has made one round trip.)
The filtered data is returned by the JWAVE wrapper to the client.
The client passes the data to a
JWaveView object, which sends it back to the server as input to another PV‑WAVE routine called
GRAPHICS. (The data has now made two round trips.)
Finally, a plot is passed back to the client and displayed.
Efficient System: No Round Trips
Figure 6-3: Efficient Use of JWAVE depicts the same type of processing as
Figure 6-2: Inefficient Use of JWAVE; however, this time the client uses data proxies to refer to the data on the server. The actual dataset is never physically returned to the client. Only after processing is completed is an image object returned to the client and displayed.
In this case, note that the object returned to the client each time is a data proxy, rather than actual data. The client uses the proxy object in subsequent JWaveExecute methods (where, in the previous (inefficient) model, the actual data was passed).
Setting the Return Parameter Mode
By default, a JWAVE wrapper function returns physical data to the client. The client has to specify that it wants the JWAVE wrapper to return a proxy object. To do this, the client uses the JWaveExecute.setReturnParamMode method.
In the next section, we present an example illustrating the use of data proxies.
Example: Using Data Proxies
As previously noted, sending large datasets back and forth between client and server can be expensive in terms of network and client resources. In many cases, it is often more efficient to leave data on the server for at least part of the processing cycle.
This example discusses a JWAVE application that:
creates an array of data on the client
sends the data to the server where it is “processed” by a JWAVE wrapper function
tells the server to return a proxy object rather than the actual data
requests the server to execute a
different JWAVE wrapper function to process the data further
returns the actual processed data to the client and prints it
Figure 6-4: JWAVE with Data Proxies illustrates the flow of this JWAVE application.
note | This client application calls two different JWAVE wrapper functions on the server. From the first wrapper, the client asks for a proxy to be returned. From the second wrapper, the client asks for the actual data values, which it then prints. |
Java Client Program
proxyarry.java: Sends data to the server; retrieves a data proxy; uses the proxy in a subsequent JWaveExecute object
import com.visualnumerics.jwave.*;
public class ProxyArray {
public static void main(String[] args) {
try {
// Create a simple array as data
float[] arr = new float[10];
for (int i=0; i<arr.length; ++i)
arr[i] = i;
// Connect to JWave server
JWaveExecute command = new JWaveExecute(”PROX1”);
// Set the data as ARRAY1 parameter
command.setParam(”ARRAY1”, arr);
// Ask that result data (named DATA) be stored on server,
// and only return a Proxy
ServerDataID saveData = new ServerDataID(”SAVE_NAME”);
command.setReturnParamMode(”DATA”,
JWaveExecute.RETURN_NO_VALUES, saveData);
// Execute PROX1
command.execute();
// Switch to new wrapper function
command.setFunction(”PROX2”);
// Clear previous parameters and return modes
command.clearParams();
command.clearReturnParamModes();
// Set input to PROX2 to use data stored by PROX1. Could
// also use getReturnProxy(”DATA”) rather than saveData
command.setParam(”ARRAY2”, saveData);
// Execute PROX2 and get result
command.execute();
float[] answer = (float[]) command.getReturnData(”DATA”);
// Print result
for (int i=0; i<answer.length; ++i)
System.out.println(answer[i]);
} catch (Exception e) {
System.out.println(e.toString());
}
}
}
First JWAVE Wrapper
prox1.pro: Receives an array from the client and multiplies the elements by 1.5. The client asks the server to return a data proxy rather than the actual data.
FUNCTION PROX1, client_data
; Unpack data and parameters sent from the client.
arr = GETPARAM(client_data, 'ARRAY1', /Value, Default=11)
; Change the array and return.
mydata = arr * 1.5
RETURN, mydata
END
Second JWAVE Wrapper
prox2.pro: The client asks this server program to process the array it stored previously. The client refers to the data on the server with a proxy. Finally, the client asks the server to send back the actual data so that it can be printed. (This wrapper multiplies the previously stored array by 100.5.)
FUNCTION PROX2, client_data
; Unpack data and parameters sent from the client.
arr = GETPARAM(client_data, 'ARRAY2', /Value, Default=11)
; Change the array and return.
mydata = arr * 100.5
RETURN, mydata
END
Java Client Output
When the Java program in
Figure 6-4: JWAVE with Data Proxies is executed, the following output is printed on the client. (The numbers result from multiplying the first array by 1.5 and multiplying the resulting array by 100.5.)
% java proxyarr
0.0
150.75
301.5
452.25
603.0
753.75
904.5
1055.25
1206.0
1356.75
Data Proxies Are Controlled by the Client
Note that in this example no special code in the JWAVE wrapper functions enables storing of data as proxies. The use of proxy data is totally under client control, and you do not need to do anything special in the wrapper functions to control this. This client-side control of proxies allows you to build JWAVE wrappers as modules, without planning all of the possible uses for them. As you build the client Java application, these JWAVE wrapper modules can then be “hooked together” in the best possible ways.
How Long is Proxy Data Stored on the Server
Data that is referred to by a proxy object persists for the duration of the PV‑WAVE session in which it is stored. When the session ends, the data is lost.
note | You can use the Data Manager routines DMSave and DMRestore to store data between sessions. These JWAVE wrapper procedures are described in Appendix A: JWAVE Wrapper API. |