Search in sources :

Example 1 with DHTPluginContactImpl

use of com.biglybt.plugin.dht.impl.DHTPluginContactImpl in project BiglyBT by BiglySoftware.

the class DHTPlugin method remove.

@Override
public void remove(DHTPluginContact[] targets, byte[] key, String description, DHTPluginOperationListener listener) {
    if (!isEnabled()) {
        throw (new RuntimeException("DHT isn't enabled"));
    }
    Map dht_map = new HashMap();
    for (int i = 0; i < targets.length; i++) {
        DHTPluginContactImpl target = (DHTPluginContactImpl) targets[i];
        DHTPluginImpl dht = target.getDHT();
        List c = (List) dht_map.get(dht);
        if (c == null) {
            c = new ArrayList();
            dht_map.put(dht, c);
        }
        c.add(target);
    }
    Iterator it = dht_map.entrySet().iterator();
    boolean primary = true;
    while (it.hasNext()) {
        Map.Entry entry = (Map.Entry) it.next();
        DHTPluginImpl dht = (DHTPluginImpl) entry.getKey();
        List contacts = (List) entry.getValue();
        DHTPluginContact[] dht_targets = new DHTPluginContact[contacts.size()];
        contacts.toArray(dht_targets);
        if (primary) {
            primary = false;
            dht.remove(dht_targets, key, description, listener);
        } else {
            // lazy - just report ops on one dht
            dht.remove(dht_targets, key, description, new DHTPluginOperationListener() {

                @Override
                public boolean diversified() {
                    return (true);
                }

                @Override
                public void starts(byte[] key) {
                }

                @Override
                public void valueRead(DHTPluginContact originator, DHTPluginValue value) {
                }

                @Override
                public void valueWritten(DHTPluginContact target, DHTPluginValue value) {
                }

                @Override
                public void complete(byte[] key, boolean timeout_occurred) {
                }
            });
        }
    }
}
Also used : DHTPluginImpl(com.biglybt.plugin.dht.impl.DHTPluginImpl) DHTPluginContactImpl(com.biglybt.plugin.dht.impl.DHTPluginContactImpl)

Aggregations

DHTPluginContactImpl (com.biglybt.plugin.dht.impl.DHTPluginContactImpl)1 DHTPluginImpl (com.biglybt.plugin.dht.impl.DHTPluginImpl)1