8.3.3 Content of the in-process connection transmission/reception control application

This subsection explains the content of the in-process connection transmission/reception control application (Inprocess_Main.java) complied in step 4 under 8.3.1 Procedure for executing the sample program for an in-process connection custom adaptor. This program is the main program that controls the application for sending and receiving tuples.

The source code is described below. Comments indicated by //[1], //...[1] and the like correspond to the numbers in the explanation provided below. Note that these comments are not written in the actual sample program. Also, the code explained by these comments may differ in some cases from the code in the actual sample program.

Sample program content

package samples;

import jp.co.Hitachi.soft.sdp.api.SDPConnector;
import jp.co.Hitachi.soft.sdp.api.inprocess.StreamInprocessUP;
import jp.co.Hitachi.soft.sdp.common.exception.SDPClientException;

public class Inprocess_Main implements StreamInprocessUP {

 // Thread object for reception
 Inprocess_Receiver receiver = null;

 // Thread object for transmission
 Inprocess_Sender sender = null;

 //Connector to the SDP server
 SDPConnector connector = null;

 //[1]
 public void execute(SDPConnector sc) {
 //...[1]

   this.connector = sc;

   //[2]
   // Start the reception thread for polling.
   this.receiver = new Inprocess_Receiver(sc);
   receiver.start();

   // Start the transmission thread.
   this.sender = new Inprocess_Sender(sc);
   sender.start();
   //...[2]
 }

 //[1]
 public void stop() {
 //...[1]

   try {
     //[3]
     // Stop the transmission thread.
     if(sender != null) {
       sender.terminate();
       sender.join();
     }
     // Stop the reception thread.
     if(receiver != null){
       receiver.terminate();
       receiver.join();
     }
   } catch (InterruptedException e) {
     System.err.println("Main    : " + e.getMessage());
   }

   try {
     // Close the connector.
     connector.close();
   } catch (SDPClientException sce) {
     System.err.println("Main    : " + sce.getMessage());
   }
   //...[3]
 }
}

The content of the source code is explained as follows:

  1. In this application, the Inprocess_Main class is one in which the StreamInprocessUP interface is implemented. Therefore, the execute and stop methods defined in the StreamInprocessUP interface are implemented.
  2. The execute method, which is executed when you start the application, starts the data reception thread and the data transmission thread.
  3. The stop method, which is executed when you stop the application, stops the data reception thread and the data transmission thread started in step 2. Afterwards, the close method of the SDPConnector type object is called to close SDPConnector.