本文整理汇总了Java中java.nio.channels.NoConnectionPendingException类的典型用法代码示例。如果您正苦于以下问题:Java NoConnectionPendingException类的具体用法?Java NoConnectionPendingException怎么用?Java NoConnectionPendingException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NoConnectionPendingException类属于java.nio.channels包,在下文中一共展示了NoConnectionPendingException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: finishConnect
import java.nio.channels.NoConnectionPendingException; //导入依赖的package包/类
public boolean finishConnect()
throws IOException
{
if (!isOpen())
throw new ClosedChannelException();
InetSocketAddress remote = channel.getPeerAddress();
if (remote != null)
{
connectionPending = false;
return true;
}
if (!connectionPending)
throw new NoConnectionPendingException();
return false;
}
示例2: checkConnection
import java.nio.channels.NoConnectionPendingException; //导入依赖的package包/类
public static boolean checkConnection(Context context) throws NoConnectionPendingException {
ConnectivityManager connectivity = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity == null) {
return false;
} else {
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null) {
for (NetworkInfo anInfo : info) {
if (anInfo.getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
}
}
return false;
}
示例3: finishConnect
import java.nio.channels.NoConnectionPendingException; //导入依赖的package包/类
public boolean finishConnect()
throws IOException
{
if (!isOpen())
throw new ClosedChannelException();
InetSocketAddress remote = channel.getPeerAddress();
if (remote != null)
{
connectionPending = false;
return true;
}
if (!connectionPending)
throw new NoConnectionPendingException();
return false;
}
示例4: checkConnection
import java.nio.channels.NoConnectionPendingException; //导入依赖的package包/类
public static boolean checkConnection(Context context) throws NoConnectionPendingException {
ConnectivityManager connectivity = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity == null) {
return false;
} else {
NetworkInfo info = connectivity.getActiveNetworkInfo();
if (info != null) {
if (info.getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
}
return false;
}
示例5: testSerializationSelf
import java.nio.channels.NoConnectionPendingException; //导入依赖的package包/类
/**
* @tests serialization/deserialization compatibility.
*/
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "Verifies serialization/deserialization compatibility.",
method = "!SerializationSelf",
args = {}
),
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies serialization/deserialization compatibility.",
method = "NoConnectionPendingException",
args = {}
)
})
public void testSerializationSelf() throws Exception {
SerializationTest.verifySelf(new NoConnectionPendingException());
}
示例6: testSerializationCompatibility
import java.nio.channels.NoConnectionPendingException; //导入依赖的package包/类
/**
* @tests serialization/deserialization compatibility with RI.
*/
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "Verifies serialization/deserialization compatibility.",
method = "!SerializationGolden",
args = {}
),
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies serialization/deserialization compatibility.",
method = "NoConnectionPendingException",
args = {}
)
})
public void testSerializationCompatibility() throws Exception {
SerializationTest
.verifyGolden(this, new NoConnectionPendingException());
}
示例7: testIsConnectionPending
import java.nio.channels.NoConnectionPendingException; //导入依赖的package包/类
public void testIsConnectionPending() throws Exception {
// ensure
ensureServerClosed();
this.channel1.configureBlocking(false);
assertFalse(this.channel1.isConnectionPending());
// finish
try {
this.channel1.finishConnect();
fail("Should throw NoConnectionPendingException");
} catch (NoConnectionPendingException e) {
// OK.
}
assertFalse(this.channel1.isConnectionPending());
// connect
assertFalse(this.channel1.connect(localAddr1));
assertTrue(this.channel1.isConnectionPending());
this.channel1.close();
assertFalse(this.channel1.isConnectionPending());
}
示例8: testCFII_FinishFirst_Server_Block
import java.nio.channels.NoConnectionPendingException; //导入依赖的package包/类
/**
* 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();
}
示例9: testCFII_FinishFirst_Server_NonBlock
import java.nio.channels.NoConnectionPendingException; //导入依赖的package包/类
/**
* 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();
}
示例10: connect
import java.nio.channels.NoConnectionPendingException; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void connect(final SelectionKey key) {
final SocketChannel client = (SocketChannel) key.channel();
try {
if (client.finishConnect()) {
key.interestOps(key.interestOps() & ~SelectionKey.OP_CONNECT | SelectionKey.OP_READ);
if (!(key.attachment() instanceof TCPChannel)) {
throw new Bug("Unsupported key attachment: " + key.attachment());
}
((TCPChannel<?>) key.attachment()).register();
}
} catch (final IOException | NoConnectionPendingException e) {
getConnectReadFuture().fail(e);
}
}
示例11: testCFII_FinishFirst_Server_NonBlock
import java.nio.channels.NoConnectionPendingException; //导入依赖的package包/类
/**
* 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
assertFalse(this.channel1.connect(localAddr1));
statusNotConnected_Pending();
tryFinish();
this.channel1.close();
statusChannelClosed();
}
示例12: isFinishConnect
import java.nio.channels.NoConnectionPendingException; //导入依赖的package包/类
/**
* After construction this must be called until it returns true before using this connection.
*/
public boolean isFinishConnect() {
if (isFinishedConnection) {
return true;
} else {
try {
boolean finishConnect = getSocketChannel().finishConnect();
isFinishedConnection |= finishConnect;
if (!finishConnect ) {
if (System.nanoTime() > creationTimeNS+(resolveWithDNSTimeoutMS*1000000L)) {
logger.info("connection timeout {} {}ms",this,resolveWithDNSTimeoutMS);
beginDisconnect();
}
} else {
clearWaitingForNetwork();
}
return finishConnect;
} catch (IOException io) {
logger.info("finish connection exception ",io);
return false;
} catch (NoConnectionPendingException ncpe) {
close();
logger.warn("no pending connection ",ncpe);
return false;
}
}
}
示例13: finishConnect
import java.nio.channels.NoConnectionPendingException; //导入依赖的package包/类
@Override
public boolean finishConnect() throws IOException {
synchronized (this) {
if (!isOpen()) {
throw new ClosedChannelException();
}
if (status == SOCKET_STATUS_CONNECTED) {
return true;
}
if (status != SOCKET_STATUS_PENDING) {
throw new NoConnectionPendingException();
}
}
boolean finished = false;
try {
begin();
InetAddress inetAddress = connectAddress.getAddress();
int port = connectAddress.getPort();
finished = IoBridge.isConnected(fd, inetAddress, port, 0, 0); // Return immediately.
} catch (ConnectException e) {
if (isOpen()) {
close();
finished = true;
}
throw e;
} finally {
end(finished);
}
synchronized (this) {
status = (finished ? SOCKET_STATUS_CONNECTED : status);
if (finished && socket != null) {
socket.onConnect(connectAddress.getAddress(), connectAddress.getPort());
}
}
return finished;
}
示例14: test_Constructor
import java.nio.channels.NoConnectionPendingException; //导入依赖的package包/类
/**
* @tests {@link java.nio.channels.NoConnectionPendingException#NoConnectionPendingException()}
*/
public void test_Constructor() {
NoConnectionPendingException e = new NoConnectionPendingException();
assertNull(e.getMessage());
assertNull(e.getLocalizedMessage());
assertNull(e.getCause());
}
示例15: finishConnect
import java.nio.channels.NoConnectionPendingException; //导入依赖的package包/类
@Override
public boolean finishConnect() throws IOException {
if (tcp.isConnecting() == false) throw new NoConnectionPendingException();
// throw exception?
return tcp.connectors.isReady();
}