This is my Reader




/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package midletehs8sms; /** * * @author Morten */ /*****************************************************************************/ // Isolate blocking I/O on a separate thread, // so callback can return immediately. /*****************************************************************************/ public class Reader implements Runnable { /*****************************************************************************/ /*****************************************************************************/ public MidletEHS8SMS parent; public Notify_Incoming_Messages nim; public Process_Message pm; public Subrutine subrutine; private int pending_messages = 0; public String event_read = null; public String get_the_response_code_as_a_string = null; public Reader( MidletEHS8SMS parent ,Notify_Incoming_Messages nim ,Process_Message pm ,Subrutine subrutine ) { super(); //--------------------------------------------------------- this.parent = parent; this.nim = nim; this.pm = pm; this.subrutine = subrutine; //--------------------------------------------------------- // System.out.println("Processing Reader End"); }//Reader /*---------------------------------------------------------------------------*/ /*****************************************************************************/ /*****************************************************************************/ /*****************************************************************************/ // System.out.println(""); /*****************************************************************************/ /*********************** Processing Reader run *******************************/ /*****************************************************************************/ // The run method performs the actual message reading. public void run() { /*---------------------------------------------------------------------------*/ while (event_read == null) { /*---------------------------------------------------------------------------*/ synchronized(this) { /*---------------------------------------------------------------------------*/ if (pending_messages == 0){ //----------------------------------------------------------------------------- try{ //----------------------------------------------------------------------------- System.out.println("Awaiting messages to arrive!"); wait(); //----------------------------------------------------------------------------- }catch(InterruptedException in) { System.out.println("Exception in Reader() -> " + in); }//Exception //----------------------------------------------------------------------------- }//if... /*---------------------------------------------------------------------------*/ }//synchronized(this) /*---------------------------------------------------------------------------*/ // The benefit of the MessageListener is here. // This thread could via similar triggers be // handling other kind of events as well in // addition to just receiving the messages. /*---------------------------------------------------------------------------*/ try{ /*---------------------------------------------------------------------------*/ synchronized(this){ /*---------------------------------------------------------------------------*/ // System.out.println("Synchronized(Reader) Begin"); System.out.println("From within Reader: event_read = " + event_read); //----------------------------------------------------------------------------- if(event_read != null){ pm.Extract_Incoming_Message_Format(event_read); event_read = null; } //----------------------------------------------------------------------------- // System.out.println("Synchronized(Reader) End"); /*---------------------------------------------------------------------------*/ }//synchronized(this) /*---------------------------------------------------------------------------*/ }catch(Exception ioe){ System.out.println("" + "Exception in Reader afther a call to ProcessMessage -> " + ioe); } //----------------------------------------------------------------------------- if(pending_messages > 0){ pending_messages--;} /*---------------------------------------------------------------------------*/ }//while /*---------------------------------------------------------------------------*/ }//run /*****************************************************************************/ /*****************************************************************************/ // System.out.println(""); /*****************************************************************************/ /*****************************************************************************/ public synchronized void Handle_Message() { pending_messages++; // System.out.println("Handle Pending Messages(" + pending_messages + ")"); notifyAll(); } /*---------------------------------------------------------------------------*/ }// CLASS Reader() ends here /*****************************************************************************/ /*****************************************************************************/ /*****************************************************************************/ /*****************************************************************************/