This subsection explains the basic flow for receiving the query result data of an in-process connection custom adaptor, based on an implementation example.
Either the polling method or the callback method can be used by the in-process connection adaptor for receiving query result data. Each of these methods is explained below.
This method dynamically receives stream query result data from the SDP server.
An implementation example of receiving query result data using the polling method is described below.
Implementation example
public class Inpro_ReceiveSample1 implements StreamInprocessUP {
// Implement StreamInprocessUP.
public void execute(SDPConnector con) {
try {
// 1. Connect to the output stream.
StreamOutput o = con.openStreamOutput("GROUP","QUERY1");
// 2. Receive tuples.
try {
while(true) {
ArrayList tupleList = o.getAll();
}
} catch (SDPClientEndOfStreamException e) {
System.out.println("Data reception completed");
}
// 3. Disconnect from the output stream.
o.close();
// 4. Disconnect from the SDP server.
con.close();
} catch (SDPClientException e) {
System.err.println(e.getMessage());
}
}
}
Explanation of the implementation details
The meaning of each process is explained below. The numbers correspond to the comment numbers in the implementation example.
StreamOutput o = con.openStreamOutput("GROUP","QUERY1");
ArrayList tupleList = o.getAll();
o.close();
con.close();
In this method, the actual method for receiving query result data is initiated by the SDP server.
Implementation examples of receiving query result data using the callback method are described below.
To use the callback method for receiving the query result data, you need to implement the following two methods:
An implementation example of each is explained below.
Implementation example (using the execute method)
public class Inpro_ReceiveSample2 implements StreamInprocessUP {
// Implement StreamInprocessUP.
public void execute(SDPConnector con) { // Process that
// is executed when the application starts.
// 1. Connect to the output stream.
StreamOutput o = con.openStreamOutput("GROUP","QUERY2");
// 2. Generate a listener object for callback.
CallBack notifiable = new CallBack();
// 3. Register the listener object for callback.
o.registerForNotification(notifiable);
}
public void stop() { // Process that is executed when
// the application stops.
// 4. Cancel the listener object for callback.
o.unregisterForNotification(notifiable);
// 5. Disconnect from the SDP server.
con.close();
}
}
Implementation example (using the onEvent method)
public class CallBack implements StreamEventListener {
// Implement StreamEventListener.
public void onEvent(StreamTuple tuple) {
// 6. Processing when tuples are received
System.out.println("Tuple received:" + tuple);
}
}
Explanation of the implementation details
The meaning of each process is explained below. The numbers correspond to the comment numbers in the implementation examples.
StreamOutput o = con.openStreamOutput("GROUP","QUERY2");
CallBack notifiable = new CallBack();
o.registerForNotification(notifiable);
o.unregisterForNotification(notifiable);
con.close();
public void onEvent(StreamTuple tuple) {
// 6. Processing when tuples are received
}