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());
}
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());
}
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
}
}
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);
}
}
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;
}
Aggregations