I have a simple Java web client that connects to a WSDL service on HTTP Binding running on localhost. I have written a method in the WSDL service that returns a double variable to the client. And I will use that variable in my further classes. I am using ScheduledExceutorService thread for periodically scanning the price from the WSDL service at a rate of 10ms.
Sometimes I get the data from the service and some times I don't get. This is not an issue and it happens like that. All I want is, this needs be event based now. That is, only when I get the data from the WSDL service then only I have to catch that. My executor thread continuously scans the wsdl service. How can I eliminate this by writing an event based program. I have seen the below link , but I am a little bit confused with my situation.
This is my code:
import com.microsoft.schemas._2003._10.serialization.arrays.ArrayOfstring;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
public class GetLTPData implements Runnable{
public static ArrayOfstring al=new ArrayOfstring();
public static List<String> list = new ArrayList<String>();
String symbol ="GC";
String exg = "NDF";
String expiry = "201706";
String security = "FUT";
public static double getLTPdata(String symbol,String exchange,String expiry,String securitytp) throws InterruptedException {
try{
al = javaItem(symbol,exchange,expiry,securitytp);
}
catch( Exception e ){
}
list = al.getString();
if(list.size()== 0)
throw new InterruptedException();
else
return Double.parseDouble(list.get(0));
}
@Override
public void run() {
try{
getLTPdata(symbol,exg,expiry,security);
}
catch(InterruptedException ie){
System.err.println(ie.getMessage());
}
}
//Below is the C# service I am calling private static ArrayOfstring javaItem(java.lang.String symbol, java.lang.String exchange, java.lang.String expiryDate, java.lang.String securityType) {
org.tempuri.JavaBroadCastEx service = new org.tempuri.JavaBroadCastEx();
org.tempuri.IJavaBroadCast port = service.getBasicHttpBindingIJavaBroadCast();
return port.javaItem(symbol, exchange, expiryDate, securityType);
}
public static void main(String[] args){
GetLTPData data = new GetLTPData();
ScheduledExecutorService executor1 = Executors.newScheduledThreadPool(2);
// Create Repetitive task for every 100ms
ScheduledFuture<?> result = executor1.scheduleAtFixedRate(data, 10, 10, TimeUnit.MILLISECONDS);
}
}