Logo
Distributed Genetic Programming Framework
print print

File org.dgpf.search.control.protocol.ReceivingThread.java

Here you can find all the information about the file org.dgpf.search.control.protocol.ReceivingThread.java. You may explore it here or download it onto your local disk.
/*
 * Copyright (c) 2006 Universitaet Kassel
 *
 * E-Mail           : mirko.dietrich@hrz.uni-kassel.de
 * Original Filename: org.dgpf.search.control.DGPFGuiThread.java
 *
 * License          : GNU LESSER GENERAL PUBLIC LICENSE
 *                    Version 2.1, February 1999
 *                    You should have received a copy of this license along
 *                    with this library; if not, write to the Free Software
 *                    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *                    MA 02111-1307, USA or download the license under
 *                    http://www.gnu.org/copyleft/lesser.html.
 *
 * Warranty         : This software is provided "as is" without any
 *                    warranty; without even the implied warranty of
 *                    merchantability or fitness for a particular purpose.
 *                    See the Gnu Lesser General Public License for more
 *                    details.
 */


package org.dgpf.search.control.protocol;

import java.io.IOException;
import java.io.ObjectInputStream;

import org.sfc.events.SfcEvent;

/**
 * This class handles incoming communication for a single
 * <code>Daemon</code>. It recieves <code>Events</code> from the
 * connected <code>NetworkCommunicationPeer</code> and puts them into a
 * <code>ProtCircularBuffer</code>.
 */

public class ReceivingThread extends Thread
  {
  /**
   * The parent <code>NetworkCommunicationPeer</code>.
   */

  private NetworkCommunicationPeer     m_ncp;

  /**
   * The input stream.
   */

  private ObjectInputStream            m_ois;

  /**
   * The buffer where recieved <code>Events</code> are stored.
   */

  private ProtCircularBuffer<SfcEvent> m_cb;

  /**
   * Assigns the <code>Socket</code> and parent
   * <code>DGPFInternalFrame</code>.
   * 
   * @param p_ncp
   *          The parent <code>NetworkCommunicationPeer</code>.
   * @param p_ois
   *          The stream messages are received from.
   * @param p_cb
   *          is the buffer where received <code>SfcEvents</code> are
   *          stored.
   */

  public ReceivingThread(NetworkCommunicationPeer p_ncp,
      ObjectInputStream p_ois, ProtCircularBuffer<SfcEvent> p_cb)
    {
    this.m_ncp = p_ncp;
    this.m_ois = p_ois;
    this.m_cb = p_cb;
    }

  /**
   * Thread's run loop.
   */

  @SuppressWarnings("unchecked")
  @Override
  public void run()
    {
    short l_cmd;
    try
      {
      // Try to initiate session.
      l_cmd = this.m_ois.readShort();
      if(l_cmd == Commands.INIT)
        {
        this.m_ncp.sendCmd(Commands.INITOK);
        }
      l_cmd = this.m_ois.readShort();
      if(l_cmd == Commands.INITOK)
        {
        synchronized(this.m_ncp)
          {
          this.m_ncp.notify();
          }
        }
      /* Process incoming network traffic */
      while(!this.isInterrupted())
        {
        l_cmd = this.m_ois.readShort();
        switch(l_cmd)
          {
          /* incoming object */
          case Commands.SEND_OBJECT:
          Object l_o = this.m_ois.readUnshared();
          if(l_o instanceof SfcEvent)
            {
            this.m_cb.enqueue(l_o);
            }
          break;
          default:
          }
        }
      }
    catch(IOException ioe)
      {
      System.err.println("Connection to peer "
          + this.m_ncp.getRemotePeerName() + " closed!");
      }
    catch(ClassNotFoundException e)
      {
      e.printStackTrace();
      }
    }

  /**
   * Close connection.
   * 
   * @throws IOException
   */

  public void close() throws IOException
    {
    this.m_ois.close();
    }

  }

File Information:

file name:ReceivingThread.java
package:org.dgpf.search.control.protocol
qualified name:org.dgpf.search.control.protocol.ReceivingThread.java
file type:Java Source File
download location:download http://dgpf.sourceforge.net/source/org/dgpf/search/control/protocol/ReceivingThread.java
size:3.515 KB (3600 B)
uploaded: 2015-07-22 04:11:00 GMT+0000
last update: 2006-09-24 23:47:04 GMT+0000
last access: 2017-11-18 06:38:49 GMT+0000

statistics online since 2006-01-02.   RSS Feed
Contact us by sending an email to tweise@gmx.de to receive further information, to report errors, or to join our project.
All content on this site (http://dgpf.sourceforge.net/) is LGPL-licensed.
http://dgpf.sourceforge.net/scripts/source/source.php last modified at 2015-07-22 04:10:53 GMT+0000 served at 2017-11-18 06:38:49 GMT+0000.
Valid CSS Valid XHTML 1.1
Valid RSS SourceForge.net Logo