Logo
Distributed Genetic Programming Framework
print print

File org.sfc.net.cs.Server.java

Here you can find all the information about the file org.sfc.net.cs.Server.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-04-11 13:26:21
 * Original Filename: org.sfc.net.cs.Server.java
 * Version          : 1.0.1
 * Last modification: 2006-04-30
 *                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.cs;

import java.net.Socket;

import org.sfc.events.ErrorEvent;
import org.sfc.events.EventPropagator;
import org.sfc.net.Net;
import org.sfc.parallel.Activity;
import org.sfc.parallel.SfcThread;
import org.sfc.parallel.SfcThreadGroup;

/**
 * The server object provides basic ability to create server applications.
 *
 * @author Thomas Weise
 */

public class Server extends Activity
  {
/**
 * The server thread.
 */

          final     SfcThread       m_server  ;
/**
 * The port the server listens at.
 */

          final     int             m_port    ;

/**
 * Create a new server.
 * @param p_events  The <code>EventPropagator</code> to be used.
 * @param p_threads The <code>SfcThreadGroup</code> to host all threads
 *                  of the server.
 * @param p_port    The port the server listenes at.
 */

  protected Server  (final  SfcThreadGroup   p_threads,
                     final  EventPropagator  p_events,
                            int              p_port)
    {
    super(p_events, p_threads);

    if(p_port <= 1000) throw new IllegalArgumentException();
    this.m_server  = new ServerThread(this, p_threads, p_events);    
    this.m_port    = p_port;
    }


/**
 * Obtain the port this server component is running on.
 * @return The port this server component is running on.
 */

  public  final int get_port  ()
    {
    return this.m_port;
    }

/**
 * Startup the search. This method will be called by <code>start()</code>.
 * @see #start()
 */

  @Override
  protected  void  do_start  ()
    {
    super.do_start();
    this.m_server.start();
    }


/**
 * This method is called by the server thread whenever it receives an
 * incomming connection.
 * @param p_socket  The socket to process.
 * @return  <code>false</code> if the socket should immediately be closed,
 *          <code>true</code> if it should stay open.
 * @throws  Throwable When something goes wrong.
 */

  protected boolean process_socket (final Socket p_socket) throws Throwable
    {
    return true;
    }


/**
 * Close a socket.
 * @param p_socket  The socket to be closed.
 */

  protected final void  close_socket  (final Socket p_socket)
    {
    EventPropagator l_pep;

    try
      {
      p_socket.close();
      }
    catch(Throwable l_t)
      {
      l_pep = this.get_event_propagator();
      if(l_pep != null)
        {
        l_pep.receive(new ErrorEvent(this, l_t));
        }
      }
    }


/**
 * This method aborts the activity. It is guaranteed to be called only once
 * for aborting and once for shutdown.
 * @see #abort()
 * @see #shutdown()
 */

  @Override
  protected void  do_abort  ()
    {
    super.do_abort();
    this.m_server.abort();
    }

/**
 * Wait until this server node has aborted fully.
 */

  @Override
  public  void  wait_for  ()
    {
    super.wait_for();
    this.m_server.wait_for();
    }

/**
 * Obtain a string representation of this peer-to-peer node.
 * @return A string representation of this peer-to-peer node.
 */

  @Override
  public  String  toString()
    {
    return "Server " + Net.LOCAL_HOST + " at port " + this.get_port();
    }

/**
 * Obtain the event propagator suitable for this activity.
 * @return The event propagator suitable for this activity.
 */

  final EventPropagator do_get_event_propagator  ()
    {
    return this.get_event_propagator();
    }
  }

File Information:

file name:Server.java
package:org.sfc.net.cs
qualified name:org.sfc.net.cs.Server.java
file type:Java Source File
download location:download http://dgpf.sourceforge.net/source/org/sfc/net/cs/Server.java
size:4.478 KB (4586 B)
uploaded: 2015-07-22 04:11:12 GMT+0000
last update: 2006-08-25 14:52:37 GMT+0000
last access: 2018-01-23 19:32:14 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 2018-01-23 19:32:14 GMT+0000.
Valid CSS Valid XHTML 1.1
Valid RSS SourceForge.net Logo