I/O between AIR client using Native process and executable java .jar

Posted by aseem behl on Stack Overflow See other posts from Stack Overflow or by aseem behl
Published on 2010-06-16T12:45:47Z Indexed on 2010/06/16 12:52 UTC
Read the original article Hit count: 380

Filed under:
|
|
|
|

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);
    }
}

© Stack Overflow or respective owner

Related posts about java

Related posts about flex