public void addListener(TableStructureModificationListener listener) {
    try {
      listeners_mon.enter();

      if (!listeners.contains(listener)) {
        listeners.add(listener);
      }

    } finally {

      listeners_mon.exit();
    }
  }
Beispiel #2
0
  public void removeListener(DeviceListener listener) {
    synchronized (this) {
      if (device_listeners != null) {

        device_listeners.remove(listener);

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

          device_listeners = null;
        }
      }
    }
  }
  public SpeedManagerPingMapper createTransientPingMapper() {
    SpeedManagerPingMapper res =
        new SpeedManagerPingMapperImpl(this, "Transient", LONG_PERIOD_TICKS, true, true);

    transient_mappers.add(res);

    if (transient_mappers.size() > 32) {

      Debug.out("Transient mappers are growing too large");
    }

    return (res);
  }
  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);
      }
    }
  }
Beispiel #5
0
  protected void fireChanged() {
    List<DeviceListener> l;

    synchronized (this) {
      if (device_listeners != null) {

        l = device_listeners.getList();

      } else {

        return;
      }
    }

    for (DeviceListener listener : l) {

      try {
        listener.deviceChanged(this);

      } catch (Throwable e) {

        Debug.out(e);
      }
    }
  }
  protected int getPeerCacheLimit() {
    synchronized (this) {
      if (activated.size() < announcers.size()) {

        return (0);
      }
    }

    if (SystemTime.getMonotonousTime() - create_time < 15 * 1000) {

      return (0);
    }

    TRTrackerAnnouncer active = getBestActive();

    if (active != null
        && provider != null
        && active.getStatus() == TRTrackerAnnouncerResponse.ST_ONLINE) {

      if (provider.getMaxNewConnectionsAllowed() > 0 && provider.getPendingConnectionCount() == 0) {

        return (5);

      } else {

        return (0);
      }
    }

    return (10);
  }
  public void addListener(PluginListener l) {
    listeners.add(l);

    if (initialiser.isInitialisationComplete()) {

      fireInitComplete(l);
    }
  }
 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 columnInvalidate(TableColumnCore tableColumn) {

    Iterator iter = listeners.iterator();
    while (iter.hasNext()) {
      TableStructureModificationListener listener =
          (TableStructureModificationListener) iter.next();
      listener.columnInvalidate(tableColumn);
    }
  }
  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 columnOrderChanged(int[] iPositions) {

    Iterator iter = listeners.iterator();
    while (iter.hasNext()) {
      TableStructureModificationListener listener =
          (TableStructureModificationListener) iter.next();
      listener.columnOrderChanged(iPositions);
    }
  }
  public void addListener(long min_delta_bytes, final LongTermStatsListener listener) {
    listeners.add(new Object[] {listener, min_delta_bytes, session_total});

    dispatcher.dispatch(
        new AERunnable() {
          public void runSupport() {
            listener.updated(LongTermStatsImpl.this);
          }
        });
  }
Beispiel #13
0
  public void addListener(DeviceListener listener) {
    synchronized (this) {
      if (device_listeners == null) {

        device_listeners = new CopyOnWriteList<DeviceListener>();
      }

      device_listeners.add(listener);
    }
  }
  public void removeListener(TableStructureModificationListener listener) {
    try {
      listeners_mon.enter();

      listeners.remove(listener);
    } finally {

      listeners_mon.exit();
    }
  }
  public void removeListener(LongTermStatsListener listener) {
    for (Object[] entry : listeners) {

      if (entry[0] == listener) {

        listeners.remove(entry);

        break;
      }
    }
  }
  public void update(boolean force) {
    List<TRTrackerAnnouncerHelper> to_update;

    synchronized (this) {
      to_update =
          is_manual ? announcers.getList() : new ArrayList<TRTrackerAnnouncerHelper>(activated);
    }

    for (TRTrackerAnnouncer announcer : to_update) {

      announcer.update(force);
    }
  }
  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);
      }
    }
  }
  protected void setupActivationCheck(int delay) {
    if (announcers.size() > activated.size()) {

      event =
          SimpleTimer.addEvent(
              "TRMuxer:check",
              SystemTime.getOffsetTime(delay),
              new TimerEventPerformer() {
                public void perform(TimerEvent event) {
                  checkActivation(false);
                }
              });
    }
  }
  public void setAnnounceDataProvider(TRTrackerAnnouncerDataProvider _provider) {
    List<TRTrackerAnnouncerHelper> to_set;

    synchronized (this) {
      provider = _provider;

      to_set = announcers.getList();
    }

    for (TRTrackerAnnouncer announcer : to_set) {

      announcer.setAnnounceDataProvider(provider);
    }
  }
  public void clearIPOverride() {
    List<TRTrackerAnnouncerHelper> to_clear;

    synchronized (this) {
      to_clear = announcers.getList();

      ip_override = null;
    }

    for (TRTrackerAnnouncer announcer : to_clear) {

      announcer.clearIPOverride();
    }
  }
  protected void informListeners(int type) {
    Iterator it = listeners.iterator();

    while (it.hasNext()) {

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

      } catch (Throwable e) {

        Debug.printStackTrace(e);
      }
    }
  }
  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 void setIPOverride(String override) {
    List<TRTrackerAnnouncerHelper> to_set;

    synchronized (this) {
      to_set = announcers.getList();

      ip_override = override;
    }

    for (TRTrackerAnnouncer announcer : to_set) {

      announcer.setIPOverride(override);
    }
  }
  public void complete(boolean already_reported) {
    List<TRTrackerAnnouncerHelper> to_complete;

    synchronized (this) {
      complete = true;

      to_complete =
          is_manual ? announcers.getList() : new ArrayList<TRTrackerAnnouncerHelper>(activated);
    }

    for (TRTrackerAnnouncer announcer : to_complete) {

      announcer.complete(already_reported);
    }
  }
  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);
  }
  public void stop(boolean for_queue) {
    List<TRTrackerAnnouncerHelper> to_stop;

    synchronized (this) {
      stopped = true;

      to_stop =
          is_manual ? announcers.getList() : new ArrayList<TRTrackerAnnouncerHelper>(activated);

      activated.clear();
    }

    for (TRTrackerAnnouncer announcer : to_stop) {

      announcer.stop(for_queue);
    }
  }
    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();
    }
  }
  public void removeListener(final PluginListener l) {
    listeners.remove(l);

    // we want to remove this ref, but there is a *small* chance that there's a parallel thread
    // firing the complete so
    // decrease chance of hanging onto unwanted ref

    new DelayedEvent(
        "PIL:clear",
        10000,
        new AERunnable() {
          public void runSupport() {
            synchronized (init_complete_fired_set) {
              init_complete_fired_set.remove(l);
            }
          }
        });
  }
  protected static void close(TRTrackerServerImpl server) {
    try {
      class_mon.enter();

      server.closeSupport();

      if (servers.remove(server)) {

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

          ((TRTrackerServerFactoryListener) listeners.get(i)).serverDestroyed(server);
        }
      }
    } finally {

      class_mon.exit();
    }
  }