Logo
Distributed Genetic Programming Framework
print print

File org.sfc.net.p2p.SocketThread.java

Here you can find all the information about the file org.sfc.net.p2p.SocketThread.java. You may explore it here or download it onto your local disk.
/*
 * Copyright (c) 2006 Thomas Weise
 *
 * E-Mail           : tweise@gmx.de
 * Creation Date    : 2006-02-27 10:14:31
 * Original Filename: org.sfc.net.p2p.SocketThread.java
 * Version          : 3.0.1
 * Last modification: 2006-06-04
 *                by: Thomas Weise
 *
 * 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.sfc.net.p2p;

import java.io.OutputStream;
import java.net.Socket;

import org.sfc.events.ErrorEvent;
import org.sfc.events.IEventListener;
import org.sfc.parallel.SfcThread;

/**
 * The thread processing the buffered sockets. It grabs sockets from the
 * circular socket buffer and calls the peer-to-peer's
 * <code>handle_socker</code>-method.
 * @see PeerToPeer#handle_socket(Socket)
 * @author Thomas Weise
 */

final class SocketThread  extends SfcThread
  {
/**
 * The owning p2p node.
 */

  private final PeerToPeer    m_owner ;
/**
 * The socket buffer.
 */

  private final SocketBuffer  m_buffer  ;

/**
 * Create a new socket processing thread.
 * @param p_owner   The owning p2p node.
 * @param p_buffer  The buffer holding the sockets.
 */

  SocketThread  (final PeerToPeer   p_owner,
                 final SocketBuffer p_buffer)
    {
    super(p_owner.do_get_thread_group(), p_owner.do_get_events());
    this.m_owner  = p_owner;
    this.m_buffer = p_buffer;
    }

/**
 * This method must be overriden to contain the thread's code. It will be
 * executed in a loop as long as it returns <code>true</code> and throws
 * <b>no</b> <code>Throwable</code>.
 * @return  <code>true</code> if this method should be executed again.
 */

  @Override
  protected final boolean do_run  ()
    {
    Socket         l_sock;
    IEventListener l_pep;
    OutputStream   l_os;

    l_sock = this.m_buffer.dequeue();
    if(l_sock == null) return false;

    try
      {
      l_os = l_sock.getOutputStream();
      l_os.write(1);
      l_os.flush();
      this.m_owner.handle_socket(l_sock);
      }
    catch(Throwable l_t)
      {
      l_pep = this.m_owner.do_get_events();
      if(l_pep != null)
        {
        l_pep.receive(new ErrorEvent(l_sock.getRemoteSocketAddress(), l_t));
        }
      }
    finally
      {
      this.m_owner.do_close_socket(l_sock);
      }

    return true;
    }



/**
 * Obtain a string representation of this socket buffer.
 * @return A string representation of this socket buffer.
 */

  @Override
  public  String  toString()
    {
    return "Socket Worker of " + this.m_owner.toString();
    }
  }

File Information:

file name:SocketThread.java
package:org.sfc.net.p2p
qualified name:org.sfc.net.p2p.SocketThread.java
file type:Java Source File
download location:download http://dgpf.sourceforge.net/source/org/sfc/net/p2p/SocketThread.java
size:3.257 KB (3336 B)
uploaded: 2018-01-07 12:03:36 GMT+0000
last update: 2006-08-27 10:40:56 GMT+0000
last access: 2018-04-23 23:10:46 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 2018-01-07 12:03:34 GMT+0000 served at 2018-04-23 23:10:46 GMT+0000.
Valid CSS Valid XHTML 1.1
Valid RSS SourceForge.net Logo