Changeset 1251


Ignore:
Timestamp:
Oct 22, 2010, 8:25:01 AM (13 years ago)
Author:
Nicklas Nordborg
Message:

The torrent service is now also creating a Bittorrent Client in it's start() method and closing it in the stop() method.

Location:
extensions/net.sf.basedb.torrent/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.torrent/trunk/.classpath

    r1246 r1251  
    11<?xml version="1.0" encoding="UTF-8"?>
    22<classpath>
     3  <classpathentry kind="src" path="src/main"/>
    34  <classpathentry kind="src" path="src/external/hpbtc"/>
    4   <classpathentry kind="src" path="src/main"/>
    55  <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
    66  <classpathentry kind="lib" path="lib/compile/BASE2Core.jar"/>
  • extensions/net.sf.basedb.torrent/trunk/build.xml

    r1246 r1251  
    4949
    5050  <!-- set up classpath for compiling -->
    51   <path id="classpath">
     51  <path id="external.classpath">
    5252    <fileset dir="lib">
    5353      <include name="**/*.jar" />
    5454    </fileset>
     55  </path>
     56
     57  <path id="classpath">
     58    <path refid="external.classpath" />
     59    <pathelement location="${build}/external/hpbtc" />
    5560  </path>
    5661
     
    8287        prefix="${tar.prefix}"
    8388        preserveLeadingSlashes="true"
    84         includes="${jar.name},README,LICENSE*,lib/torrent/*"
     89        includes="${jar.name},README,LICENSE*,torrent.properties,lib/torrent/*"
    8590      />
    8691    </tar>
     
    140145      destdir="${build}/external/hpbtc"
    141146      debug="true"
    142       classpathref="classpath"
     147      classpathref="external.classpath"
    143148      encoding="${javac.encoding}"
    144149      source="${javac.source}"
  • extensions/net.sf.basedb.torrent/trunk/src/main/net/sf/basedb/clients/torrent/service/TorrentService.java

    r1246 r1251  
    2525
    2626
     27import hpbtc.protocol.processor.Client;
     28
     29import java.io.IOException;
    2730import java.util.Properties;
    2831
     
    8386  private final java.io.File workDir;
    8487  private final int port;
    85   private boolean isRunning;
     88  private volatile boolean isRunning;
     89  private Client btClient;
    8690 
    8791  /**
     
    110114    Starts the core service if it is not already running.
    111115  */
    112   public void start()
     116  public synchronized void start()
    113117  {
    114118    if (isRunning()) return;
     
    128132    }
    129133   
     134      // Start bittorrent service
     135      Client tmpClient = null;
     136      try
     137      {
     138        tmpClient = new Client();
     139        tmpClient.startProtocol(port);
     140      }
     141      catch (IOException ex)
     142      {
     143        log.error("Could not start bittorrent client", ex);
     144        throw new RuntimeException(ex);
     145      }
     146     
     147      btClient = tmpClient;
     148     
    130149    isRunning = true;
    131150    log.info("Bittorrent Download Service has been started");
     
    136155    must be created by calling {@link #getInstance(Properties)}.
    137156  */
    138   public void stop()
     157  public synchronized void stop()
    139158  {
    140159    if (!isRunning()) return;
    141160    log.info("Stopping Bittorrent Download Service");
    142     isRunning = false;
    143     service = null;
    144     log.info("Bittorrent Download Service has been stopped");
     161   
     162    try
     163    {
     164      if (btClient != null)
     165      {
     166        btClient.stopProtocol();
     167        btClient = null;
     168      }
     169    }
     170    finally
     171    {
     172      isRunning = false;
     173      service = null;
     174      log.info("Bittorrent Download Service has been stopped");
     175    }
    145176  }
    146177
Note: See TracChangeset for help on using the changeset viewer.