下面列出了怎么用java.nio.channels.NoConnectionPendingException的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Marks the beginning of a finishConnect operation that might block.
*
* @throws ClosedChannelException if the channel is closed
* @throws NoConnectionPendingException if no connection is pending
*/
private void beginFinishConnect(boolean blocking) throws ClosedChannelException {
if (blocking) {
// set hook for Thread.interrupt
begin();
}
synchronized (stateLock) {
ensureOpen();
if (state != ST_CONNECTIONPENDING)
throw new NoConnectionPendingException();
if (blocking) {
// record thread so it can be signalled if needed
readerThread = NativeThread.current();
}
}
}
/**
* finish-->connect-->finish-->close
*/
public void testCFII_FinishFirst_Server_Block() throws Exception {
// ensure
ensureServerOpen();
assertTrue(this.channel1.isBlocking());
statusNotConnected_NotPending();
// finish
try {
this.channel1.finishConnect();
fail("Should throw NoConnectionPendingException");
} catch (NoConnectionPendingException e) {
// OK.
}
statusNotConnected_NotPending();
// connect
assertTrue(this.channel1.connect(localAddr1));
statusConnected_NotPending();
tryFinish();
this.channel1.close();
statusChannelClosed();
}
/**
* finish-->connect-->finish-->close
*/
public void testCFII_FinishFirst_Server_NonBlock() throws Exception {
// ensure
ensureServerOpen();
this.channel1.configureBlocking(false);
statusNotConnected_NotPending();
// finish
try {
this.channel1.finishConnect();
fail("Should throw NoConnectionPendingException");
} catch (NoConnectionPendingException e) {
// OK.
}
statusNotConnected_NotPending();
// connect
boolean connected = channel1.connect(localAddr1);
if (!connected) {
statusNotConnected_Pending();
}
tryFinish();
this.channel1.close();
statusChannelClosed();
}
/**
* @tests {@link java.nio.channels.NoConnectionPendingException#NoConnectionPendingException()}
*/
public void test_Constructor() {
NoConnectionPendingException e = new NoConnectionPendingException();
assertNull(e.getMessage());
assertNull(e.getLocalizedMessage());
assertNull(e.getCause());
}
/**
* @tests serialization/deserialization compatibility.
*/
public void testSerializationSelf() throws Exception {
SerializationTest.verifySelf(new NoConnectionPendingException());
}
/**
* @tests serialization/deserialization compatibility with RI.
*/
public void testSerializationCompatibility() throws Exception {
SerializationTest
.verifyGolden(this, new NoConnectionPendingException());
}