Search in sources :

Example 16 with ClosedSelectorException

use of java.nio.channels.ClosedSelectorException in project j2objc by google.

the class ClosedSelectorExceptionTest method test_Constructor.

/**
 * @tests {@link java.nio.channels.ClosedSelectorException#ClosedSelectorException()}
 */
public void test_Constructor() {
    ClosedSelectorException e = new ClosedSelectorException();
    assertNull(e.getMessage());
    assertNull(e.getLocalizedMessage());
    assertNull(e.getCause());
}
Also used : ClosedSelectorException(java.nio.channels.ClosedSelectorException)

Example 17 with ClosedSelectorException

use of java.nio.channels.ClosedSelectorException in project j2objc by google.

the class AbstractSelectorTest method test_register_LSelectorI_error.

/**
 * @tests AbstractSelector#register(Selector,int)
 */
public void test_register_LSelectorI_error() throws IOException {
    Selector acceptSelector = SelectorProvider.provider().openSelector();
    ServerSocketChannel ssc = ServerSocketChannel.open();
    ssc.configureBlocking(false);
    acceptSelector.close();
    assertFalse(acceptSelector.isOpen());
    try {
        ssc.register(acceptSelector, SelectionKey.OP_ACCEPT);
        fail("should throw ClosedSelectorException");
    } catch (ClosedSelectorException e) {
    // expected
    }
    assertFalse(ssc.isRegistered());
    acceptSelector = Selector.open();
    ssc.configureBlocking(true);
    try {
        ssc.register(acceptSelector, SelectionKey.OP_ACCEPT);
        fail("should throw IllegalBlockingModeException");
    } catch (IllegalBlockingModeException e) {
    // expected
    }
    assertFalse(ssc.isRegistered());
    ssc.configureBlocking(false);
    SelectionKey acceptKey = ssc.register(acceptSelector, SelectionKey.OP_ACCEPT);
    assertNotNull(acceptKey);
    assertTrue(acceptSelector.keys().contains(acceptKey));
    assertTrue(ssc.isRegistered());
}
Also used : SelectionKey(java.nio.channels.SelectionKey) IllegalBlockingModeException(java.nio.channels.IllegalBlockingModeException) ServerSocketChannel(java.nio.channels.ServerSocketChannel) Selector(java.nio.channels.Selector) ClosedSelectorException(java.nio.channels.ClosedSelectorException)

Example 18 with ClosedSelectorException

use of java.nio.channels.ClosedSelectorException in project robovm by robovm.

the class SelectorTest method test_keys.

/**
     * @tests java.nio.channels.Selector#keys()
     */
public void test_keys() throws IOException {
    SelectionKey key = ssc.register(selector, SelectionKey.OP_ACCEPT);
    Set<SelectionKey> keySet = selector.keys();
    Set<SelectionKey> keySet2 = selector.keys();
    assertSame(keySet, keySet2);
    assertEquals(1, keySet.size());
    SelectionKey key2 = keySet.iterator().next();
    assertEquals(key, key2);
    // Any attempt to modify keys will cause UnsupportedOperationException
    SocketChannel sc = SocketChannel.open();
    sc.configureBlocking(false);
    SelectionKey key3 = sc.register(selector, SelectionKey.OP_READ);
    try {
        keySet2.add(key3);
        fail("should throw UnsupportedOperationException");
    } catch (UnsupportedOperationException e) {
    // expected
    }
    try {
        keySet2.remove(key3);
        fail("should throw UnsupportedOperationException");
    } catch (UnsupportedOperationException e) {
    // expected
    }
    try {
        keySet2.clear();
        fail("should throw UnsupportedOperationException");
    } catch (UnsupportedOperationException e) {
    // expected
    }
    selector.close();
    try {
        selector.keys();
        fail("should throw ClosedSelectorException");
    } catch (ClosedSelectorException e) {
    // expected
    }
}
Also used : SelectionKey(java.nio.channels.SelectionKey) ServerSocketChannel(java.nio.channels.ServerSocketChannel) SocketChannel(java.nio.channels.SocketChannel) ClosedSelectorException(java.nio.channels.ClosedSelectorException)

Example 19 with ClosedSelectorException

use of java.nio.channels.ClosedSelectorException in project jdk8u_jdk by JetBrains.

the class WindowsSelectorImpl method putEventOps.

public void putEventOps(SelectionKeyImpl sk, int ops) {
    synchronized (closeLock) {
        if (pollWrapper == null)
            throw new ClosedSelectorException();
        // make sure this sk has not been removed yet
        int index = sk.getIndex();
        if (index == -1)
            throw new CancelledKeyException();
        pollWrapper.putEventOps(index, ops);
    }
}
Also used : CancelledKeyException(java.nio.channels.CancelledKeyException) ClosedSelectorException(java.nio.channels.ClosedSelectorException)

Example 20 with ClosedSelectorException

use of java.nio.channels.ClosedSelectorException in project jdk8u_jdk by JetBrains.

the class WindowsSelectorImpl method doSelect.

protected int doSelect(long timeout) throws IOException {
    if (channelArray == null)
        throw new ClosedSelectorException();
    // set selector timeout
    this.timeout = timeout;
    processDeregisterQueue();
    if (interruptTriggered) {
        resetWakeupSocket();
        return 0;
    }
    // Calculate number of helper threads needed for poll. If necessary
    // threads are created here and start waiting on startLock
    adjustThreadsCount();
    // reset finishLock
    finishLock.reset();
    // Wakeup helper threads, waiting on startLock, so they start polling.
    // Redundant threads will exit here after wakeup.
    startLock.startThreads();
    // first MAX_SELECTABLE_FDS entries in pollArray.
    try {
        begin();
        try {
            subSelector.poll();
        } catch (IOException e) {
            // Save this exception
            finishLock.setException(e);
        }
        // Main thread is out of poll(). Wakeup others and wait for them
        if (threads.size() > 0)
            finishLock.waitForHelperThreads();
    } finally {
        end();
    }
    // Done with poll(). Set wakeupSocket to nonsignaled  for the next run.
    finishLock.checkForException();
    processDeregisterQueue();
    int updated = updateSelectedKeys();
    // Done with poll(). Set wakeupSocket to nonsignaled  for the next run.
    resetWakeupSocket();
    return updated;
}
Also used : IOException(java.io.IOException) ClosedSelectorException(java.nio.channels.ClosedSelectorException)

Aggregations

ClosedSelectorException (java.nio.channels.ClosedSelectorException)30 SelectionKey (java.nio.channels.SelectionKey)20 IOException (java.io.IOException)16 ServerSocketChannel (java.nio.channels.ServerSocketChannel)8 SocketChannel (java.nio.channels.SocketChannel)8 CancelledKeyException (java.nio.channels.CancelledKeyException)6 ClosedChannelException (java.nio.channels.ClosedChannelException)5 Selector (java.nio.channels.Selector)4 NioConnectionException (com.cloud.utils.exception.NioConnectionException)2 Iterator (java.util.Iterator)2 EOFException (java.io.EOFException)1 InterruptedIOException (java.io.InterruptedIOException)1 ServerSocket (java.net.ServerSocket)1 Socket (java.net.Socket)1 ByteBuffer (java.nio.ByteBuffer)1 ClosedByInterruptException (java.nio.channels.ClosedByInterruptException)1 IllegalBlockingModeException (java.nio.channels.IllegalBlockingModeException)1 SelectableChannel (java.nio.channels.SelectableChannel)1 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)1 HashMap (java.util.HashMap)1