Logo
Distributed Genetic Programming Framework
print print

File org.dgpf.search.api.SearchTaskThread.java

Here you can find all the information about the file org.dgpf.search.api.SearchTaskThread.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-03-31 06:30:38
 * Original Filename: org.dgpf.search.api.SearchTaskThread.java
 * Version          : 2.1.2
 * Last modification: 2006-07-15
 *                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.dgpf.search.api;

import java.io.Serializable;

/**
 * A search task thread is a thread that removes and processes tasks in a
 * cycle from a search queque.
 *
 * @param <Genotype>    The sort of genotype used to represent individuals.
 *                      This must be a serializable type.
 *                      
 * @author Thomas Weise
 */

public abstract class   SearchTaskThread<Genotype extends Serializable>
                extends SearchEngineThread<Genotype>
  {
/**
 * The search task queue.
 */

  private final     SearchTaskQueue<Genotype> m_queue;
/**
 * An internal marker boolean.
 */

  private volatile  boolean                   m_done ;
  
/**
 * Create a new search task thread.
 * @param p_se  The search engine to work for.
 * @param p_queue The search task queue to use. This must not be
 *                <code>null</code>.
 */

  public  SearchTaskThread (final SearchEngine<Genotype>        p_se,
                            final SearchTaskQueue<Genotype>     p_queue)
    {
    super(p_se);
    this.m_queue = p_queue;    
    this.m_done  = true;
    }
  
  
/**
 * Start this thread.
 */

  @Override
  protected final void  do_start()
    {
    this.m_queue.add_thread();
    super.do_start();
    }
  

/**
 * This method will be called whenever a new search task becomes available.
 * @param p_task  The search task that just became available.
 */

  protected abstract  void  process (final SearchTask<Genotype> p_task);
  
/**
 * Reject a task. The task will be added again to the search task queue.
 * @param p_task  The task to reject.
 */

  protected final void  reject  (final SearchTask<Genotype> p_task)
    {
    this.m_queue.add_task(p_task);
    this.m_queue.done();
    this.m_done = false;
    }
  
  
/**
 * 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.
 * @throws  Throwable Whenever it likes to, however, the execution loop
 *                    will be stopped when something is thrown.
 */

  @Override
  protected final boolean do_run  ()  throws Throwable
    {
          SearchTask<Genotype>      l_st;
    final SearchTaskQueue<Genotype> l_stq;
    
    l_stq = this.m_queue;
    
    while(this.is_running())
      {
      l_st = l_stq.next_task();
      if(l_st != null)
        {
        try
          {
          this.process(l_st);
          }
        finally
          {
          if(this.m_done) l_stq.done();
          else            this.m_done = true;
          }
        }
      else
        {
        this.abort();
        return false;
        }
      }
    
    return false;
    }
  

/**
 * Obtain the name of the thread.
 * @return  A human readable name of the sfc thread.
 */

  @Override
  public   String  toString()
    {
    return "Search Task Thread (" + this.getThreadGroup() + ')';
    }
  
/**
 * Override this method to perform something when the thread dies.
 */

  @Override
  protected void  after_termination ()
    {
    this.m_queue.remove_thread();
    super.after_termination();
    }
  }

File Information:

file name:SearchTaskThread.java
package:org.dgpf.search.api
qualified name:org.dgpf.search.api.SearchTaskThread.java
file type:Java Source File
download location:download http://dgpf.sourceforge.net/source/org/dgpf/search/api/SearchTaskThread.java
size:4.344 KB (4449 B)
uploaded: 2015-07-22 04:11:00 GMT+0000
last update: 2006-07-15 09:37:29 GMT+0000
last access: 2017-11-18 23:09: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 2015-07-22 04:10:53 GMT+0000 served at 2017-11-18 23:09:46 GMT+0000.
Valid CSS Valid XHTML 1.1
Valid RSS SourceForge.net Logo