6.2.2 Receiving query result data (RMI connection custom adaptor)

This subsection explains the basic processing flow for using an RMI connection custom adaptor to receive query result data, based on an implementation example.

Implementation example

public class RMI_ReceiveSample {
 public static void main(String[] args) {
   try {
     // 1. Connect to the SDP server.
     SDPConnector con = SDPConnectorFactory.connect();

     // 2. Connect to the output stream.
     StreamOutput o = con.openStreamOutput("GROUP","QUERY1");

     // 3. Receive tuples.
     try {
       while(true) {
       ArrayList tupleList = o.getAll();
       }
     } catch (SDPClientEndOfStreamException e) {
       System.out.println("Data reception completed");
     } catch (SDPClientQueryGroupStateException e) {
       System.out.println("Query group stopped");
     }

     // 4. Disconnect from the output stream.
     o.close();

     // 5. 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.

  1. Connects to the SDP server and acquires the SDPConnector type object (con).

    SDPConnector con = SDPConnectorFactory.connect();

  2. Uses the SDPConnector type object (con) to connect to an output stream that has "GROUP" as its group name and "QUERY1" as its query name, and acquires the StreamOutput type object (o).

    StreamOutput o = con.openStreamOutput("GROUP","QUERY1");

  3. Uses the StreamOutput type object (o) to acquire the query result tuples (tupleList).

    ArrayList tupleList = o.getAll();

  4. When receiving is completed, the StreamOutput type object (o) is used to disconnect from the output stream.

    o.close();

  5. Uses the SDPConnector type object (con) to disconnect from the SDP server.

    con.close();