Java 类java.nio.channels.NoConnectionPendingException 实例源码

项目:javify    文件:SocketChannelImpl.java   
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;
}
项目:appJavou    文件:Util.java   
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;
    }
项目:jvm-stm    文件:SocketChannelImpl.java   
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;
}
项目:Gcm    文件:Util.java   
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;
    }
项目:LiveoProject    文件:Util.java   
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;
    }
项目:In-the-Box-Fork    文件:NoConnectionPendingExceptionTest.java   
/**
 * @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());
}
项目:In-the-Box-Fork    文件:NoConnectionPendingExceptionTest.java   
/**
 * @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());
}
项目:In-the-Box-Fork    文件:OldSocketChannelTest.java   
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());
}
项目:cn1    文件:SocketChannelTest.java   
/**
 * 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();

}
项目:cn1    文件:SocketChannelTest.java   
/**
 * 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();
}
项目:JamVM-PH    文件:SocketChannelImpl.java   
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;
}
项目:dsys-snio    文件:TCPProcessor.java   
/**
 * {@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);
    }
}
项目:classpath    文件:SocketChannelImpl.java   
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;
}
项目:freeVM    文件:SocketChannelTest.java   
/**
 * 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();

}
项目:freeVM    文件:SocketChannelTest.java   
/**
 * 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();
}
项目:freeVM    文件:SocketChannelTest.java   
/**
 * 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();

}
项目:freeVM    文件:SocketChannelTest.java   
/**
 * 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();
}
项目:Pronghorn    文件:ClientConnection.java   
/**
 * 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;
        }
    }
}
项目:j2objc    文件:SocketChannelImpl.java   
@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;
}
项目:In-the-Box-Fork    文件:NoConnectionPendingExceptionTest.java   
/**
 * @tests {@link java.nio.channels.NoConnectionPendingException#NoConnectionPendingException()}
 */
public void test_Constructor() {
    NoConnectionPendingException e = new NoConnectionPendingException();
    assertNull(e.getMessage());
    assertNull(e.getLocalizedMessage());
    assertNull(e.getCause());
}
项目:minha    文件:SocketChannelImpl.java   
@Override
public boolean finishConnect() throws IOException {
    if (tcp.isConnecting() == false) throw new NoConnectionPendingException();

    // throw exception?

    return tcp.connectors.isReady();
}
项目:cn1    文件:NoConnectionPendingExceptionTest.java   
/**
 * @tests {@link java.nio.channels.NoConnectionPendingException#NoConnectionPendingException()}
 */
public void test_Constructor() {
    NoConnectionPendingException e = new NoConnectionPendingException();
    assertNull(e.getMessage());
    assertNull(e.getLocalizedMessage());
    assertNull(e.getCause());
}
项目:CryptMeme    文件:EventPumper.java   
private void processConnect(SelectionKey key) {
    NTCPConnection con = (NTCPConnection)key.attachment();
    try {
        SocketChannel chan = con.getChannel();
        boolean connected = chan.finishConnect();
        if (_log.shouldLog(Log.DEBUG))
            _log.debug("processing connect for " + con + ": connected? " + connected);
        if (connected) {
            // BUGFIX for firewalls. --Sponge
            if (_context.commSystem().getReachabilityStatus() != CommSystemFacade.STATUS_OK)
                chan.socket().setKeepAlive(true);
            con.setKey(key);
            con.outboundConnected();
            _context.statManager().addRateData("ntcp.connectSuccessful", 1);
        } else {
            con.close();
            _transport.markUnreachable(con.getRemotePeer().calculateHash());
            _context.statManager().addRateData("ntcp.connectFailedTimeout", 1);
        }
    } catch (IOException ioe) {   // this is the usual failure path for a timeout or connect refused
        if (_log.shouldLog(Log.INFO))
            _log.info("Failed outbound " + con, ioe);
        con.close();
        //_context.banlist().banlistRouter(con.getRemotePeer().calculateHash(), "Error connecting", NTCPTransport.STYLE);
        _transport.markUnreachable(con.getRemotePeer().calculateHash());
        _context.statManager().addRateData("ntcp.connectFailedTimeoutIOE", 1);
    } catch (NoConnectionPendingException ncpe) {
        // ignore
        if (_log.shouldLog(Log.WARN))
            _log.warn("error connecting on " + con, ncpe);
    }
}
项目:CryptMeme    文件:EventPumper.java   
private void processConnect(SelectionKey key) {
    NTCPConnection con = (NTCPConnection)key.attachment();
    try {
        SocketChannel chan = con.getChannel();
        boolean connected = chan.finishConnect();
        if (_log.shouldLog(Log.DEBUG))
            _log.debug("processing connect for " + con + ": connected? " + connected);
        if (connected) {
            // BUGFIX for firewalls. --Sponge
            if (_context.commSystem().getReachabilityStatus() != CommSystemFacade.STATUS_OK)
                chan.socket().setKeepAlive(true);
            con.setKey(key);
            con.outboundConnected();
            _context.statManager().addRateData("ntcp.connectSuccessful", 1);
        } else {
            con.close();
            _transport.markUnreachable(con.getRemotePeer().calculateHash());
            _context.statManager().addRateData("ntcp.connectFailedTimeout", 1);
        }
    } catch (IOException ioe) {   // this is the usual failure path for a timeout or connect refused
        if (_log.shouldLog(Log.INFO))
            _log.info("Failed outbound " + con, ioe);
        con.close();
        //_context.banlist().banlistRouter(con.getRemotePeer().calculateHash(), "Error connecting", NTCPTransport.STYLE);
        _transport.markUnreachable(con.getRemotePeer().calculateHash());
        _context.statManager().addRateData("ntcp.connectFailedTimeoutIOE", 1);
    } catch (NoConnectionPendingException ncpe) {
        // ignore
        if (_log.shouldLog(Log.WARN))
            _log.warn("error connecting on " + con, ncpe);
    }
}
项目:CryptMeme    文件:EventPumper.java   
private void processConnect(SelectionKey key) {
    NTCPConnection con = (NTCPConnection)key.attachment();
    try {
        SocketChannel chan = con.getChannel();
        boolean connected = chan.finishConnect();
        if (_log.shouldLog(Log.DEBUG))
            _log.debug("processing connect for " + con + ": connected? " + connected);
        if (connected) {
            // BUGFIX for firewalls. --Sponge
            if (shouldSetKeepAlive(chan))
                chan.socket().setKeepAlive(true);
            con.setKey(key);
            con.outboundConnected();
            _context.statManager().addRateData("ntcp.connectSuccessful", 1);
        } else {
            con.closeOnTimeout("connect failed", null);
            _transport.markUnreachable(con.getRemotePeer().calculateHash());
            _context.statManager().addRateData("ntcp.connectFailedTimeout", 1);
        }
    } catch (IOException ioe) {   // this is the usual failure path for a timeout or connect refused
        if (_log.shouldLog(Log.INFO))
            _log.info("Failed outbound " + con, ioe);
        con.closeOnTimeout("connect failed", ioe);
        //_context.banlist().banlistRouter(con.getRemotePeer().calculateHash(), "Error connecting", NTCPTransport.STYLE);
        _transport.markUnreachable(con.getRemotePeer().calculateHash());
        _context.statManager().addRateData("ntcp.connectFailedTimeoutIOE", 1);
    } catch (NoConnectionPendingException ncpe) {
        // ignore
        if (_log.shouldLog(Log.WARN))
            _log.warn("error connecting on " + con, ncpe);
    }
}
项目:freeVM    文件:NoConnectionPendingExceptionTest.java   
/**
 * @tests {@link java.nio.channels.NoConnectionPendingException#NoConnectionPendingException()}
 */
public void test_Constructor() {
    NoConnectionPendingException e = new NoConnectionPendingException();
    assertNull(e.getMessage());
    assertNull(e.getLocalizedMessage());
    assertNull(e.getCause());
}
项目:In-the-Box-Fork    文件:SocketChannelImpl.java   
@Override
public boolean finishConnect() throws IOException {
    // status check
    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();
        final int WAIT_FOREVER = -1;
        final int POLL = 0;
        finished = networkSystem.isConnected(fd, isBlocking() ? WAIT_FOREVER : POLL);
        isBound = finished;
        initLocalAddressAndPort();
    } catch (ConnectException e) {
        if (isOpen()) {
            close();
            finished = true;
        }
        throw e;
    } finally {
        end(finished);
    }

    synchronized (this) {
        status = (finished ? SOCKET_STATUS_CONNECTED : status);
        isBound = finished;
        // TPE: Workaround for bug that turns socket back to blocking
        if (!isBlocking()) implConfigureBlocking(false);
    }
    return finished;
}
项目:cn1    文件:SocketChannelImpl.java   
/**
 * @see java.nio.channels.SocketChannel#finishConnect()
 */
@Override
public boolean finishConnect() throws IOException {
    // status check
    synchronized (this) {
        if (!isOpen()) {
            throw new ClosedChannelException();
        }
        if (status == SOCKET_STATUS_CONNECTED) {
            return true;
        }
        if (status != SOCKET_STATUS_PENDING) {
            throw new NoConnectionPendingException();
        }
    }

    // finish result
    int result = EOF;
    boolean finished = false;

    try {
        begin();
        result = networkSystem.connectWithTimeout(fd,
                isBlocking() ? -1 : 0, trafficClass, connectAddress
                        .getAddress(), connectAddress.getPort(),
                HY_PORT_SOCKET_STEP_CHECK, connectContext);
        finished = (result == CONNECT_SUCCESS);
        isBound = finished;
        localAddress = networkSystem.getSocketLocalAddress(fd, false);
    } catch (ConnectException e) {
        if (isOpen()) {
            close();
            finished = true;
        }
        throw e;
    } finally {
        end(finished);
    }

    synchronized (this) {
        status = (finished ? SOCKET_STATUS_CONNECTED : status);
        isBound = finished;
        // TPE: Workaround for bug that turns socket back to blocking
        if (!isBlocking()) implConfigureBlocking(false);
    }
    return finished;
}
项目:cn1    文件:NoConnectionPendingExceptionTest.java   
/**
 * @tests serialization/deserialization compatibility.
 */
public void testSerializationSelf() throws Exception {

    SerializationTest.verifySelf(new NoConnectionPendingException());
}
项目:cn1    文件:NoConnectionPendingExceptionTest.java   
/**
 * @tests serialization/deserialization compatibility with RI.
 */
public void testSerializationCompatibility() throws Exception {

    SerializationTest
            .verifyGolden(this, new NoConnectionPendingException());
}
项目:freeVM    文件:SocketChannelImpl.java   
@Override
public boolean finishConnect() throws IOException {
    // status check
    synchronized (this) {
        if (!isOpen()) {
            throw new ClosedChannelException();
        }
        if (status == SOCKET_STATUS_CONNECTED) {
            return true;
        }
        if (status != SOCKET_STATUS_PENDING) {
            throw new NoConnectionPendingException();
        }
    }

    // finish result
    int result = EOF;
    boolean finished = false;

    try {
        begin();
        result = networkSystem.connectWithTimeout(fd,
                isBlocking() ? -1 : 0, trafficClass, connectAddress
                        .getAddress(), connectAddress.getPort(),
                HY_PORT_SOCKET_STEP_CHECK, connectContext);
        finished = (result == CONNECT_SUCCESS);
        isBound = finished;
        localAddress = networkSystem.getSocketLocalAddress(fd, false);
    } catch (ConnectException e) {
        if (isOpen()) {
            close();
            finished = true;
        }
        throw e;
    } finally {
        end(finished);
    }

    synchronized (this) {
        status = (finished ? SOCKET_STATUS_CONNECTED : status);
        isBound = finished;
    }
    return finished;
}
项目:freeVM    文件:NoConnectionPendingExceptionTest.java   
/**
 * @tests serialization/deserialization compatibility.
 */
public void testSerializationSelf() throws Exception {

    SerializationTest.verifySelf(new NoConnectionPendingException());
}
项目:freeVM    文件:NoConnectionPendingExceptionTest.java   
/**
 * @tests serialization/deserialization compatibility with RI.
 */
public void testSerializationCompatibility() throws Exception {

    SerializationTest
            .verifyGolden(this, new NoConnectionPendingException());
}
项目:freeVM    文件:SocketChannelImpl.java   
/**
 * @see java.nio.channels.SocketChannel#finishConnect()
 */
@Override
public boolean finishConnect() throws IOException {
    // status check
    synchronized (this) {
        if (!isOpen()) {
            throw new ClosedChannelException();
        }
        if (status == SOCKET_STATUS_CONNECTED) {
            return true;
        }
        if (status != SOCKET_STATUS_PENDING) {
            throw new NoConnectionPendingException();
        }
    }

    // finish result
    int result = EOF;
    boolean finished = false;

    try {
        begin();
        result = networkSystem.connectWithTimeout(fd,
                isBlocking() ? -1 : 0, trafficClass, connectAddress
                        .getAddress(), connectAddress.getPort(),
                HY_PORT_SOCKET_STEP_CHECK, connectContext);
        finished = (result == CONNECT_SUCCESS);
        isBound = finished;
        localAddress = networkSystem.getSocketLocalAddress(fd, false);
    } catch (ConnectException e) {
        if (isOpen()) {
            close();
            finished = true;
        }
        throw e;
    } finally {
        end(finished);
    }

    synchronized (this) {
        status = (finished ? SOCKET_STATUS_CONNECTED : status);
        isBound = finished;
        // TPE: Workaround for bug that turns socket back to blocking
        if (!isBlocking()) implConfigureBlocking(false);
    }
    return finished;
}
项目:freeVM    文件:NoConnectionPendingExceptionTest.java   
/**
 * @tests serialization/deserialization compatibility.
 */
public void testSerializationSelf() throws Exception {

    SerializationTest.verifySelf(new NoConnectionPendingException());
}
项目:freeVM    文件:NoConnectionPendingExceptionTest.java   
/**
 * @tests serialization/deserialization compatibility with RI.
 */
public void testSerializationCompatibility() throws Exception {

    SerializationTest
            .verifyGolden(this, new NoConnectionPendingException());
}