title: Passing a List of data from serial communication between some Java classes asynchronously
body: <p>I'd like to develop an application with JSerialComm and JavaFX. I use async delimiter-mode data receiving mode in JSeialComm:</p>
  <pre><code>class MessageListener implements SerialPortMessageListener {
  
      private List&lt;Byte&gt; list;
  
      public List&lt;Byte&gt; getList() {
          return list;
      }
  
      public MessageListener() {
          list = new ArrayList&lt;Byte&gt;();
  
      }
  
      public void addToList(Byte number) {
          list.add(number);
      }
      
      public void flushList()
      {
          list.clear();
      }
  
      @Override
      public int getListeningEvents() {
          return SerialPort.LISTENING_EVENT_DATA_RECEIVED;
      }
  
      @Override
      public byte[] getMessageDelimiter() {
          return new byte[] { (byte) 0x0D, (byte) 0x0A };
      }
  
      @Override
      public boolean delimiterIndicatesEndOfMessage() {
          return true;
      }
  
      @Override
      public void serialEvent(SerialPortEvent event) {
          byte[] delimitedMessage = event.getReceivedData();
  
          for (byte b : delimitedMessage) {
              addToList(b);
          }
  
      }
  }
  </code></pre>
  <p>The total functionality is OK. I open the port in my Main class and send data to the serial receiver. (Actually, the Main class itself is not important here but could be found in the link below.)</p>
  <p>Since data receiving is performed asynchronously, data is received in MessageListener class and temporarily stored in <em>list</em> variable. I am searching for a way to inform the Main class about any new data so that it can update the GUI and do some businesses on them. On way may be constant polling for new data but it is not efficient.</p>
  <p>The whole project is accessible <a href="https://github.com/ImanHz/java-arduino-serial" rel="nofollow noreferrer"><strong>here</strong></a>.</p>