protected void removeNetwork(ContentNetworkImpl network) {
    synchronized (this) {
      if (!networks.remove(network)) {

        return;
      }

      network.destroy();

      saveConfig();
    }

    log("Removed network: " + network.getString());

    Iterator<ContentNetworkListener> it = (Iterator<ContentNetworkListener>) listeners.iterator();

    while (it.hasNext()) {

      try {
        it.next().networkRemoved(network);

      } catch (Throwable e) {

        Debug.out(e);
      }
    }
  }
 public void columnSizeChanged(TableColumnCore tableColumn, int diff) {
   Iterator iter = listeners.iterator();
   while (iter.hasNext()) {
     TableStructureModificationListener listener =
         (TableStructureModificationListener) iter.next();
     listener.columnSizeChanged(tableColumn, diff);
   }
 }
  public void columnOrderChanged(int[] iPositions) {

    Iterator iter = listeners.iterator();
    while (iter.hasNext()) {
      TableStructureModificationListener listener =
          (TableStructureModificationListener) iter.next();
      listener.columnOrderChanged(iPositions);
    }
  }
  public void cellInvalidate(TableColumnCore tableColumn, Object data_source) {

    Iterator iter = listeners.iterator();
    while (iter.hasNext()) {
      TableStructureModificationListener listener =
          (TableStructureModificationListener) iter.next();
      listener.cellInvalidate(tableColumn, data_source);
    }
  }
  public void columnInvalidate(TableColumnCore tableColumn) {

    Iterator iter = listeners.iterator();
    while (iter.hasNext()) {
      TableStructureModificationListener listener =
          (TableStructureModificationListener) iter.next();
      listener.columnInvalidate(tableColumn);
    }
  }
  public void tableStructureChanged(boolean columnAddedOrRemoved, Class forPluginDataSourceType) {

    Iterator iter = listeners.iterator();
    while (iter.hasNext()) {
      TableStructureModificationListener listener =
          (TableStructureModificationListener) iter.next();
      try {
        listener.tableStructureChanged(columnAddedOrRemoved, forPluginDataSourceType);
      } catch (Throwable e) {
        Debug.printStackTrace(e);
      }
    }
  }
Ejemplo n.º 7
0
  protected void informListeners(int type) {
    Iterator it = listeners.iterator();

    while (it.hasNext()) {

      try {
        ((SpeedManagerListener) it.next()).propertyChanged(type);

      } catch (Throwable e) {

        Debug.printStackTrace(e);
      }
    }
  }
Ejemplo n.º 8
0
  protected void informResults(DHTSpeedTesterContact[] contacts, int[] rtts) {
    Iterator it = listeners.iterator();

    while (it.hasNext()) {

      try {
        ((DHTSpeedTesterListener) it.next()).resultGroup(contacts, rtts);

      } catch (Throwable e) {

        Debug.printStackTrace(e);
      }
    }
  }
  public Set<Class<?>> prepareForTableReset() {
    Set<Class<?>> dataSourceTypes = new HashSet<Class<?>>();

    Iterator iter = listeners.iterator();
    while (iter.hasNext()) {
      TableStructureModificationListener listener =
          (TableStructureModificationListener) iter.next();
      try {
        dataSourceTypes.addAll(listener.prepareForTableReset());
      } catch (Throwable e) {
        Debug.printStackTrace(e);
      }
    }

    return (dataSourceTypes);
  }
Ejemplo n.º 10
0
    protected void informDead() {
      if (informed_alive) {

        Iterator it = listeners.iterator();

        while (it.hasNext()) {

          try {
            ((DHTSpeedTesterContactListener) it.next()).contactDied(this);

          } catch (Throwable e) {

            Debug.printStackTrace(e);
          }
        }
      }
    }
  public static void addListener(TRTrackerServerFactoryListener l) {
    try {
      class_mon.enter();

      listeners.add(l);

      Iterator it = servers.iterator();

      while (it.hasNext()) {

        l.serverCreated((TRTrackerServer) it.next());
      }
    } finally {

      class_mon.exit();
    }
  }
  protected void closedownComplete() {
    Iterator it = listeners.iterator();

    while (it.hasNext()) {

      try {
        ((PluginListener) it.next()).closedownComplete();

      } catch (Throwable e) {

        Debug.printStackTrace(e);
      }
    }

    for (int i = 0; i < children.size(); i++) {

      ((PluginInterfaceImpl) children.get(i)).closedownComplete();
    }
  }
  protected void initialisationComplete() {
    Iterator<PluginListener> it = listeners.iterator();

    while (it.hasNext()) {

      try {
        fireInitComplete(it.next());

      } catch (Throwable e) {

        Debug.printStackTrace(e);
      }
    }

    for (int i = 0; i < children.size(); i++) {

      ((PluginInterfaceImpl) children.get(i)).initialisationComplete();
    }
  }
Ejemplo n.º 14
0
  protected void addPingHistory(int rtt, boolean re_base) {
    int x =
        (adapter.getCurrentDataUploadSpeed(SPEED_AVERAGE_PERIOD)
            + adapter.getCurrentProtocolUploadSpeed(SPEED_AVERAGE_PERIOD));
    int y =
        (adapter.getCurrentDataDownloadSpeed(SPEED_AVERAGE_PERIOD)
            + adapter.getCurrentProtocolDownloadSpeed(SPEED_AVERAGE_PERIOD));

    for (int i = 0; i < ping_mappers.length; i++) {

      ping_mappers[i].addPing(x, y, rtt, re_base);
    }

    Iterator it = transient_mappers.iterator();

    while (it.hasNext()) {

      ((SpeedManagerPingMapperImpl) it.next()).addPing(x, y, rtt, re_base);
    }
  }
  protected void firePluginEventSupport(PluginEvent event) {
    Iterator<PluginEventListener> it = event_listeners.iterator();

    while (it.hasNext()) {

      try {
        PluginEventListener listener = it.next();

        listener.handleEvent(event);

      } catch (Throwable e) {

        Debug.printStackTrace(e);
      }
    }

    for (int i = 0; i < children.size(); i++) {

      ((PluginInterfaceImpl) children.get(i)).firePluginEvent(event);
    }
  }
  protected void split() throws TRTrackerAnnouncerException {

    String[] networks = f_provider == null ? null : f_provider.getNetworks();

    TRTrackerAnnouncerHelper to_activate = null;

    synchronized (this) {
      if (stopped || destroyed) {

        return;
      }

      TOTorrent torrent = getTorrent();

      TOTorrentAnnounceURLSet[] sets = torrent.getAnnounceURLGroup().getAnnounceURLSets();

      // sanitise dht entries

      if (sets.length == 0) {

        sets =
            new TOTorrentAnnounceURLSet[] {
              torrent
                  .getAnnounceURLGroup()
                  .createAnnounceURLSet(new URL[] {torrent.getAnnounceURL()})
            };

      } else {

        boolean found_decentralised = false;
        boolean modified = false;

        for (int i = 0; i < sets.length; i++) {

          TOTorrentAnnounceURLSet set = sets[i];

          URL[] urls = set.getAnnounceURLs().clone();

          for (int j = 0; j < urls.length; j++) {

            URL u = urls[j];

            if (u != null && TorrentUtils.isDecentralised(u)) {

              if (found_decentralised) {

                modified = true;

                urls[j] = null;

              } else {

                found_decentralised = true;
              }
            }
          }
        }

        if (modified) {

          List<TOTorrentAnnounceURLSet> s_list = new ArrayList<TOTorrentAnnounceURLSet>();

          for (TOTorrentAnnounceURLSet set : sets) {

            URL[] urls = set.getAnnounceURLs();

            List<URL> u_list = new ArrayList<URL>(urls.length);

            for (URL u : urls) {

              if (u != null) {

                u_list.add(u);
              }
            }

            if (u_list.size() > 0) {

              s_list.add(
                  torrent
                      .getAnnounceURLGroup()
                      .createAnnounceURLSet(u_list.toArray(new URL[u_list.size()])));
            }
          }

          sets = s_list.toArray(new TOTorrentAnnounceURLSet[s_list.size()]);
        }
      }

      List<TOTorrentAnnounceURLSet[]> new_sets = new ArrayList<TOTorrentAnnounceURLSet[]>();

      if (is_manual || sets.length < 2) {

        new_sets.add(sets);

      } else {

        List<TOTorrentAnnounceURLSet> list =
            new ArrayList<TOTorrentAnnounceURLSet>(Arrays.asList(sets));

        // often we have http:/xxxx/ and udp:/xxxx/ as separate groups - keep these together

        while (list.size() > 0) {

          TOTorrentAnnounceURLSet set1 = list.remove(0);

          boolean done = false;

          URL[] urls1 = set1.getAnnounceURLs();

          if (urls1.length == 1) {

            URL url1 = urls1[0];

            String prot1 = url1.getProtocol().toLowerCase();
            String host1 = url1.getHost();

            for (int i = 0; i < list.size(); i++) {

              TOTorrentAnnounceURLSet set2 = list.get(i);

              URL[] urls2 = set2.getAnnounceURLs();

              if (urls2.length == 1) {

                URL url2 = urls2[0];

                String prot2 = url2.getProtocol().toLowerCase();
                String host2 = url2.getHost();

                if (host1.equals(host2)) {

                  if ((prot1.equals("udp") && prot2.startsWith("http"))
                      || (prot2.equals("udp") && prot1.startsWith("http"))) {

                    list.remove(i);

                    new_sets.add(new TOTorrentAnnounceURLSet[] {set1, set2});

                    done = true;
                  }
                }
              }
            }
          }

          if (!done) {

            new_sets.add(new TOTorrentAnnounceURLSet[] {set1});
          }
        }
      }

      // work out the difference

      Iterator<TOTorrentAnnounceURLSet[]> ns_it = new_sets.iterator();

      // need to copy list as we modify it and returned list ain't thread safe

      List<TRTrackerAnnouncerHelper> existing_announcers =
          new ArrayList<TRTrackerAnnouncerHelper>(announcers.getList());

      List<TRTrackerAnnouncerHelper> new_announcers = new ArrayList<TRTrackerAnnouncerHelper>();

      // first look for unchanged sets

      while (ns_it.hasNext()) {

        TOTorrentAnnounceURLSet[] ns = ns_it.next();

        Iterator<TRTrackerAnnouncerHelper> a_it = existing_announcers.iterator();

        while (a_it.hasNext()) {

          TRTrackerAnnouncerHelper a = a_it.next();

          TOTorrentAnnounceURLSet[] os = a.getAnnounceSets();

          if (same(ns, os)) {

            ns_it.remove();
            a_it.remove();

            new_announcers.add(a);

            break;
          }
        }
      }

      // reuse existing announcers

      // first remove dht ones from the equation

      TRTrackerAnnouncerHelper existing_dht_announcer = null;
      TOTorrentAnnounceURLSet[] new_dht_set = null;

      ns_it = new_sets.iterator();

      while (ns_it.hasNext()) {

        TOTorrentAnnounceURLSet[] x = ns_it.next();

        if (TorrentUtils.isDecentralised(x[0].getAnnounceURLs()[0])) {

          new_dht_set = x;

          ns_it.remove();

          break;
        }
      }

      Iterator<TRTrackerAnnouncerHelper> an_it = existing_announcers.iterator();

      while (an_it.hasNext()) {

        TRTrackerAnnouncerHelper a = an_it.next();

        TOTorrentAnnounceURLSet[] x = a.getAnnounceSets();

        if (TorrentUtils.isDecentralised(x[0].getAnnounceURLs()[0])) {

          existing_dht_announcer = a;

          an_it.remove();

          break;
        }
      }

      if (existing_dht_announcer != null && new_dht_set != null) {

        new_announcers.add(existing_dht_announcer);

      } else if (existing_dht_announcer != null) {

        activated.remove(existing_dht_announcer);

        existing_dht_announcer.destroy();

      } else if (new_dht_set != null) {

        TRTrackerAnnouncerHelper a = create(torrent, networks, new_dht_set);

        new_announcers.add(a);
      }

      // now do the non-dht ones

      ns_it = new_sets.iterator();

      while (ns_it.hasNext() && existing_announcers.size() > 0) {

        TRTrackerAnnouncerHelper a = existing_announcers.remove(0);

        TOTorrentAnnounceURLSet[] s = ns_it.next();

        ns_it.remove();

        if (activated.contains(a)
            && torrent.getPrivate()
            && a instanceof TRTrackerBTAnnouncerImpl) {

          URL url = a.getTrackerURL();

          if (url != null) {

            forceStop((TRTrackerBTAnnouncerImpl) a, networks, url);
          }
        }

        a.setAnnounceSets(s, networks);

        new_announcers.add(a);
      }

      // create any new ones required

      ns_it = new_sets.iterator();

      while (ns_it.hasNext()) {

        TOTorrentAnnounceURLSet[] s = ns_it.next();

        TRTrackerAnnouncerHelper a = create(torrent, networks, s);

        new_announcers.add(a);
      }

      // finally fix up the announcer list to represent the new state

      Iterator<TRTrackerAnnouncerHelper> a_it = announcers.iterator();

      while (a_it.hasNext()) {

        TRTrackerAnnouncerHelper a = a_it.next();

        if (!new_announcers.contains(a)) {

          a_it.remove();

          try {
            if (activated.contains(a)
                && torrent.getPrivate()
                && a instanceof TRTrackerBTAnnouncerImpl) {

              URL url = a.getTrackerURL();

              if (url != null) {

                forceStop((TRTrackerBTAnnouncerImpl) a, networks, url);
              }
            }
          } finally {

            if (Logger.isEnabled()) {
              Logger.log(
                  new LogEvent(
                      getTorrent(), LOGID, "Deactivating " + getString(a.getAnnounceSets())));
            }

            activated.remove(a);

            a.destroy();
          }
        }
      }

      a_it = new_announcers.iterator();

      while (a_it.hasNext()) {

        TRTrackerAnnouncerHelper a = a_it.next();

        if (!announcers.contains(a)) {

          announcers.add(a);
        }
      }

      if (!is_manual && announcers.size() > 0) {

        if (activated.size() == 0) {

          TRTrackerAnnouncerHelper a = announcers.get(0);

          if (Logger.isEnabled()) {
            Logger.log(
                new LogEvent(getTorrent(), LOGID, "Activating " + getString(a.getAnnounceSets())));
          }

          activated.add(a);

          last_activation_time = SystemTime.getMonotonousTime();

          if (provider != null) {

            to_activate = a;
          }
        }

        setupActivationCheck(ACT_CHECK_INIT_DELAY);
      }
    }

    if (to_activate != null) {

      if (complete) {

        to_activate.complete(true);

      } else {

        to_activate.update(false);
      }
    }
  }
  protected ContentNetworkImpl addNetwork(ContentNetworkImpl network) {
    boolean replace = false;

    synchronized (this) {
      Iterator<ContentNetworkImpl> it = networks.iterator();

      while (it.hasNext()) {

        ContentNetworkImpl existing_network = it.next();

        if (existing_network.getID() == network.getID()) {

          if (network.getVersion() > existing_network.getVersion()) {

            try {
              existing_network.updateFrom(network);

            } catch (Throwable e) {

              Debug.printStackTrace(e);
            }

            network = existing_network;

            replace = true;

            break;

          } else {

            log("Network " + existing_network.getString() + " already up to date");

            return (existing_network);
          }
        }
      }

      if (replace) {

        log("Updated network: " + network.getString());

      } else {

        log("Added network: " + network.getString());

        networks.add(network);
      }

      // we never persist the vuze network

      if (network.getID() != ContentNetwork.CONTENT_NETWORK_VUZE) {

        saveConfig();
      }
    }

    Iterator<ContentNetworkListener> it = (Iterator<ContentNetworkListener>) listeners.iterator();

    while (it.hasNext()) {

      try {
        if (replace) {

          it.next().networkChanged(network);

        } else {

          it.next().networkAdded(network);
        }
      } catch (Throwable e) {

        Debug.out(e);
      }
    }

    return (network);
  }
Ejemplo n.º 18
0
  protected void pingContacts(int tick_count) {
    List copy = null;

    synchronized (new_listeners) {
      if (new_listeners.size() > 0) {

        copy = new ArrayList(new_listeners);

        new_listeners.clear();
      }
    }

    if (copy != null) {

      for (int i = 0; i < copy.size(); i++) {

        DHTSpeedTesterListener listener = (DHTSpeedTesterListener) copy.get(i);

        listeners.add(listener);

        for (int j = 0; j < active_pings.size(); j++) {

          activePing ping = (activePing) active_pings.get(j);

          if (ping.isInformedAlive()) {

            try {

              listener.contactAdded(ping);

            } catch (Throwable e) {

              Debug.printStackTrace(e);
            }
          }
        }
      }
    }

    Iterator pit = active_pings.iterator();

    pingInstanceSet ping_set = new pingInstanceSet(true);

    while (pit.hasNext()) {

      activePing ping = (activePing) pit.next();

      if (ping.update(ping_set, tick_count)) {

        if (!ping.isInformedAlive()) {

          ping.setInformedAlive();

          Iterator it = listeners.iterator();

          while (it.hasNext()) {

            try {
              ((DHTSpeedTesterListener) it.next()).contactAdded(ping);

            } catch (Throwable e) {

              Debug.printStackTrace(e);
            }
          }
        }
      }

      if (ping.isDead()) {

        pit.remove();

        ping.informDead();
      }
    }

    ping_set.setFull();

    // we try and keep three active pings running so we can spot overall trends in ping time
    // each active ping is selected from the best rtt from the current 3 best three rtt estimates

    int num_active = active_pings.size();

    if (num_active < contact_num) {

      Set pc =
          new TreeSet(
              new Comparator() {
                public int compare(Object o1, Object o2) {
                  potentialPing p1 = (potentialPing) o1;
                  potentialPing p2 = (potentialPing) o2;

                  return (p1.getRTT() - p2.getRTT());
                }
              });

      synchronized (pending_contacts) {
        pc.addAll(pending_contacts);
      }

      Iterator it = pc.iterator();

      if (pc.size() >= 3) {

        // find best candidates

        List pps = new ArrayList();

        for (int i = 0; i < 3; i++) {

          potentialPing pp = (potentialPing) it.next();

          pps.add(pp);

          it.remove();

          synchronized (pending_contacts) {
            pending_contacts.remove(pp);
          }
        }

        active_pings.add(new activePing(pps));
      }
    } else if (num_active > contact_num) {

      for (int i = 0; i < num_active - contact_num; i++) {

        ((activePing) active_pings.get(i)).destroy();
      }
    }
  }