title: Java and event driven programming
body: <p>I am using <a href="http://code.google.com/p/javaeventing/wiki/Examples" rel="nofollow noreferrer">javaeventing</a> to write an even driven shell to access a database. So, my use case is:</p>
  
  <ol>
  <li>open up the shell in command line. </li>
  <li>Now, the shell connects to database and listens for the command coming in.  </li>
  <li>when it gets a command, it executes it and gives back the required output.</li>
  </ol>
  
  <p>Now, how can I avoid <code>while(!exit){ //do stuff }</code> kind of loop here? How to use Java eventing correctly?</p>
  
  <p>The straight forward way can be:</p>
  
  <pre><code>while(!exit)
  {
     exit = myClass.execute("command"); //when command is exit, return true.
  }
  </code></pre>
  
  <p>But, I am looking if java eventing can give a better solution.</p>
  
  <p><strong>Update1:</strong></p>
  
  <p>Here is what I am trying to implement:</p>
  
  <p><strong>1</strong> My application is a shell (like mongodb shell) to try out a key-value database.<br>
  <strong>2</strong> The simple code:</p>
  
  <pre><code>init(); //Initialize the connection with database
  while(!exit)
  {  
      //exit = myClass.execute("put(5)"); //This returns false  
      exit = myClass.execute("exit"); //returns true, i.e. the user wants to exit the shell
  }
  </code></pre>
  
  <p>Now, here I do not see the use of java eventing and I solved my problem, can you please tell me, <strong>HOW java eventing will come in picture here?</strong> I want the user to trigger the event.</p>