6.2.1 Sending stream data (RMI connection custom adaptor)

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

Implementation example

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

     // 2. Connect to the input stream to be sent.
     StreamInput in = con.openStreamInput("GROUP","STREAM1");

     // 3. Send tuples.
     Object[] data=new Object[]{new Integer(1)};
     StreamTuple tuple=new StreamTuple(data);
     try {
       in.put(tuple);

       // 4. Send data transmission completion notification.
       in.putEnd();
     } catch (SDPClientQueryGroupStateException e) {
       System.out.println("Query group stopped");
     }

     // 5. Disconnect from the input stream.
     in.close();

     // 6. 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 input stream that has "GROUP" as its group name and "STREAM1" as its stream name, and acquires the StreamInput type object (in).

    StreamInput in = con.openStreamInput("GROUP","STREAM1");

  3. Uses the StreamInput type object (in) to send tuples (stream data).

    in.put(tuple);

  4. Uses the StreamInput type object (in) to send a data transmission completion notification.

    in.putEnd();

  5. Uses the StreamInput type object (in) to disconnect from the input stream.

    in.close();

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

    con.close();