views:

39

answers:

0

I am using Adobe AIR 2.0 native process API to launch a java executable jar. I/O is handled by writing to the input stream of the java process and reading from the output stream.

The application is event based where several events are fired from the server. We catch these events in java code, handle them and write the output to the outputstream using the synchronized static method below.

public class ReaderWriter {
        static Logger logger = Logger.getLogger(ReaderWriter.class);

        public synchronized static void writeToAir(String output){
            try{            
                 byte[] byteArray = output.getBytes();
                 DataOutputStream dataOutputStream = new DataOutputStream(System.out);
                 dataOutputStream.write(byteArray);
                 dataOutputStream.flush();
               }
            catch (IOException e) {         
                 logger.info("Exception while writing the output. " + e);
              }
        }
}

The issue is that some messages are lost between the transfer and not all messages reach the AIR client. If I run the java application from the console I am receiving all the messages.

It would be great if somebody could point out what I am missing.

Following are some of the listeners used to send the event data to the AIR client.

// class used to process Shutdown events from the Session
private class SessionShutdownListener implements SessionListener{
    public void onEvent(Event e) {
        Session.Shutdown sd = (Session.Shutdown) e;
        Session.ShutdownReason sr = sd.getReason();

        String eventOutput = "eo;" + "Session Shutdown event ocurred reason=" + sr.strValue() + "\n";           
        ReaderWriter.writeToAir(eventOutput);
    }
}

// class used to process OperationSucceeded events from the Session
private class SessionOperationSucceededListener implements SessionListener{
    public void onEvent(Event e) {
        Session.OperationSucceeded os = (Session.OperationSucceeded) e;

        String eventOutput = "eo;" + "Session OperationSucceeded event ocurred" + "\n";         
        ReaderWriter.writeToAir(eventOutput);
    }
}