Search in sources :

Example 1 with VirtualChannelSelectorImpl

use of com.biglybt.core.networkmanager.impl.tcp.VirtualChannelSelectorImpl in project BiglyBT by BiglySoftware.

the class VirtualChannelSelector method cancel.

/**
 * Cancel the selection operations for the given channel.
 * @param channel channel originally registered
 */
public void cancel(AbstractSelectableChannel channel) {
    if (SAFE_SELECTOR_MODE_ENABLED) {
        try {
            selectors_mon.enter();
            // System.out.println( "cancel - " + channel.hashCode()  + " - " + Debug.getCompressedStackTrace());
            for (Map.Entry<VirtualChannelSelectorImpl, ArrayList<AbstractSelectableChannel>> entry : selectors.entrySet()) {
                VirtualChannelSelectorImpl sel = entry.getKey();
                ArrayList<AbstractSelectableChannel> channels = entry.getValue();
                if (channels.remove(channel)) {
                    sel.cancel(channel);
                    return;
                }
            }
        } finally {
            selectors_mon.exit();
        }
    } else {
        if (selector_impl != null)
            selector_impl.cancel(channel);
    }
}
Also used : VirtualChannelSelectorImpl(com.biglybt.core.networkmanager.impl.tcp.VirtualChannelSelectorImpl) AbstractSelectableChannel(java.nio.channels.spi.AbstractSelectableChannel)

Example 2 with VirtualChannelSelectorImpl

use of com.biglybt.core.networkmanager.impl.tcp.VirtualChannelSelectorImpl in project BiglyBT by BiglySoftware.

the class VirtualChannelSelector method initSafeMode.

private void initSafeMode() {
    if (Logger.isEnabled()) {
        Logger.log(new LogEvent(LOGID, "***************** SAFE SOCKET SELECTOR MODE ENABLED *****************"));
    }
    selector_impl = null;
    selectors = new HashMap<>();
    selectors_mon = new AEMonitor("VirtualChannelSelector:FM");
    selectors.put(new VirtualChannelSelectorImpl(this, op, pause, randomise_keys), new ArrayList<AbstractSelectableChannel>());
    selectors_keyset_cow = new HashSet<>(selectors.keySet());
}
Also used : VirtualChannelSelectorImpl(com.biglybt.core.networkmanager.impl.tcp.VirtualChannelSelectorImpl) LogEvent(com.biglybt.core.logging.LogEvent) AEMonitor(com.biglybt.core.util.AEMonitor) AbstractSelectableChannel(java.nio.channels.spi.AbstractSelectableChannel)

Example 3 with VirtualChannelSelectorImpl

use of com.biglybt.core.networkmanager.impl.tcp.VirtualChannelSelectorImpl in project BiglyBT by BiglySoftware.

the class VirtualChannelSelector method resumeSelects.

/**
 * Resume selection operations for the given channel
 * @param channel to resume
 */
public void resumeSelects(AbstractSelectableChannel channel) {
    if (SAFE_SELECTOR_MODE_ENABLED) {
        try {
            selectors_mon.enter();
            // System.out.println( "resume - " + channel.hashCode() + " - " + Debug.getCompressedStackTrace());
            for (Map.Entry<VirtualChannelSelectorImpl, ArrayList<AbstractSelectableChannel>> entry : selectors.entrySet()) {
                VirtualChannelSelectorImpl sel = entry.getKey();
                ArrayList<AbstractSelectableChannel> channels = entry.getValue();
                if (channels.contains(channel)) {
                    sel.resumeSelects(channel);
                    return;
                }
            }
            Debug.out("resumeSelects():: channel not found!");
        } finally {
            selectors_mon.exit();
        }
    } else {
        selector_impl.resumeSelects(channel);
    }
}
Also used : VirtualChannelSelectorImpl(com.biglybt.core.networkmanager.impl.tcp.VirtualChannelSelectorImpl) AbstractSelectableChannel(java.nio.channels.spi.AbstractSelectableChannel)

Example 4 with VirtualChannelSelectorImpl

use of com.biglybt.core.networkmanager.impl.tcp.VirtualChannelSelectorImpl in project BiglyBT by BiglySoftware.

the class VirtualChannelSelector method pauseSelects.

/**
 * Pause selection operations for the given channel
 * @param channel to pause
 */
public void pauseSelects(AbstractSelectableChannel channel) {
    if (SAFE_SELECTOR_MODE_ENABLED) {
        try {
            selectors_mon.enter();
            // System.out.println( "pause - " + channel.hashCode() + " - " + Debug.getCompressedStackTrace());
            for (Map.Entry<VirtualChannelSelectorImpl, ArrayList<AbstractSelectableChannel>> entry : selectors.entrySet()) {
                VirtualChannelSelectorImpl sel = entry.getKey();
                ArrayList<AbstractSelectableChannel> channels = entry.getValue();
                if (channels.contains(channel)) {
                    sel.pauseSelects(channel);
                    return;
                }
            }
            Debug.out("pauseSelects():: channel not found!");
        } finally {
            selectors_mon.exit();
        }
    } else {
        selector_impl.pauseSelects(channel);
    }
}
Also used : VirtualChannelSelectorImpl(com.biglybt.core.networkmanager.impl.tcp.VirtualChannelSelectorImpl) AbstractSelectableChannel(java.nio.channels.spi.AbstractSelectableChannel)

Example 5 with VirtualChannelSelectorImpl

use of com.biglybt.core.networkmanager.impl.tcp.VirtualChannelSelectorImpl in project BiglyBT by BiglySoftware.

the class VirtualChannelSelector method select.

/**
 * Run a virtual select() operation, with the given selection timeout value;
 * (1) cancellations are processed (2) the select operation is performed; (3)
 * listener notification of completed selects (4) new registrations are processed
 * @param timeout in ms; if zero, block indefinitely
 * @return number of sockets selected
 */
public int select(long timeout) {
    if (SAFE_SELECTOR_MODE_ENABLED) {
        boolean was_destroyed = destroyed;
        try {
            int count = 0;
            for (VirtualChannelSelectorImpl sel : selectors_keyset_cow) {
                count += sel.select(timeout);
            }
            return count;
        } finally {
            if (was_destroyed) {
                try {
                    selectors_mon.enter();
                    selectors.clear();
                    selectors_keyset_cow = new HashSet<>();
                } finally {
                    selectors_mon.exit();
                }
            }
        }
    }
    return selector_impl.select(timeout);
}
Also used : VirtualChannelSelectorImpl(com.biglybt.core.networkmanager.impl.tcp.VirtualChannelSelectorImpl)

Aggregations

VirtualChannelSelectorImpl (com.biglybt.core.networkmanager.impl.tcp.VirtualChannelSelectorImpl)6 AbstractSelectableChannel (java.nio.channels.spi.AbstractSelectableChannel)5 LogEvent (com.biglybt.core.logging.LogEvent)1 AEMonitor (com.biglybt.core.util.AEMonitor)1