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

项目:javify    文件:SocketChannelImpl.java   
public boolean connect (SocketAddress remote, int timeout) throws IOException
{
  if (!isOpen())
    throw new ClosedChannelException();

  if (isConnected())
    throw new AlreadyConnectedException();

  if (connectionPending)
    throw new ConnectionPendingException();

  if (!(remote instanceof InetSocketAddress))
    throw new UnsupportedAddressTypeException();

  connectAddress = (InetSocketAddress) remote;

  if (connectAddress.isUnresolved())
    throw new UnresolvedAddressException();

  connected = channel.connect(connectAddress, timeout);
  connectionPending = !connected;
  return connected;
}
项目:jvm-stm    文件:SocketChannelImpl.java   
public boolean connect (SocketAddress remote, int timeout) throws IOException
{
  if (!isOpen())
    throw new ClosedChannelException();

  if (isConnected())
    throw new AlreadyConnectedException();

  if (connectionPending)
    throw new ConnectionPendingException();

  if (!(remote instanceof InetSocketAddress))
    throw new UnsupportedAddressTypeException();

  connectAddress = (InetSocketAddress) remote;

  if (connectAddress.isUnresolved())
    throw new UnresolvedAddressException();

  connected = channel.connect(connectAddress, timeout);
  connectionPending = !connected;
  return connected;
}
项目:j2objc    文件:SocketChannelImpl.java   
@Override
public void connect(SocketAddress remoteAddr, int timeout) throws IOException {
    if (!channel.isBlocking()) {
        throw new IllegalBlockingModeException();
    }
    if (isConnected()) {
        throw new AlreadyConnectedException();
    }
    super.connect(remoteAddr, timeout);
    channel.onBind(false);
    if (super.isConnected()) {
        InetSocketAddress remoteInetAddress = (InetSocketAddress) remoteAddr;
        channel.onConnectStatusChanged(
                remoteInetAddress, SOCKET_STATUS_CONNECTED, false /* updateSocketState */);
    }
}
项目:In-the-Box-Fork    文件:AlreadyConnectedExceptionTest.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 = "AlreadyConnectedException",
        args = {}
    )
})
public void testSerializationSelf() throws Exception {

    SerializationTest.verifySelf(new AlreadyConnectedException());
}
项目:In-the-Box-Fork    文件:AlreadyConnectedExceptionTest.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 = "AlreadyConnectedException",
        args = {}
    )
})
public void testSerializationCompatibility() throws Exception {

    SerializationTest.verifyGolden(this, new AlreadyConnectedException());
}
项目:cn1    文件:SocketChannelImpl.java   
/**
 * @see java.net.Socket#connect(java.net.SocketAddress, int)
 */
@Override
public void connect(SocketAddress remoteAddr, int timeout)
        throws IOException {
    if (!channel.isBlocking()) {
        throw new IllegalBlockingModeException();
    }
    if (isConnected()) {
        throw new AlreadyConnectedException();
    }
    super.connect(remoteAddr, timeout);
    channel.localAddress = networkSystem.getSocketLocalAddress(
            channel.fd, false);
    if (super.isConnected()) {
        channel.setConnected();
        channel.isBound = super.isBound();
    }
}
项目:cn1    文件:SocketChannelTest.java   
private void assertSocketAction_Block_BeforeConnect(Socket s)
        throws IOException {
    assertFalse(this.channel1.isConnected());
    this.server2 = new ServerSocket(localAddr2.getPort());
    s.connect(localAddr2);
    assertTrue(this.channel1.isConnected());
    assertTrue(s.isConnected());

    assertSocketAfterConnect(s, localAddr2);

    try {
        s.bind(localAddr2);
        fail("Should throw AlreadyConnectedException");
    } catch (AlreadyConnectedException e) {
        // OK.
    }

    s.close();
    assertTrue(s.isClosed());
    assertFalse(this.channel1.isOpen());
}
项目:JamVM-PH    文件:SocketChannelImpl.java   
public boolean connect (SocketAddress remote, int timeout) throws IOException
{
  if (!isOpen())
    throw new ClosedChannelException();

  if (isConnected())
    throw new AlreadyConnectedException();

  if (connectionPending)
    throw new ConnectionPendingException();

  if (!(remote instanceof InetSocketAddress))
    throw new UnsupportedAddressTypeException();

  connectAddress = (InetSocketAddress) remote;

  if (connectAddress.isUnresolved())
    throw new UnresolvedAddressException();

  connected = channel.connect(connectAddress, timeout);
  connectionPending = !connected;
  return connected;
}
项目:classpath    文件:SocketChannelImpl.java   
public boolean connect (SocketAddress remote, int timeout) throws IOException
{
  if (!isOpen())
    throw new ClosedChannelException();

  if (isConnected())
    throw new AlreadyConnectedException();

  if (connectionPending)
    throw new ConnectionPendingException();

  if (!(remote instanceof InetSocketAddress))
    throw new UnsupportedAddressTypeException();

  connectAddress = (InetSocketAddress) remote;

  if (connectAddress.isUnresolved())
    throw new UnresolvedAddressException();

  connected = channel.connect(connectAddress, timeout);
  connectionPending = !connected;
  return connected;
}
项目:freeVM    文件:SocketChannelImpl.java   
@Override
public void connect(SocketAddress remoteAddr, int timeout)
        throws IOException {
    if (!channel.isBlocking()) {
        throw new IllegalBlockingModeException();
    }
    if (isConnected()) {
        throw new AlreadyConnectedException();
    }
    super.connect(remoteAddr, timeout);
    channel.localAddress = networkSystem.getSocketLocalAddress(
            channel.fd, false);
    if (super.isConnected()) {
        channel.setConnected();
        channel.isBound = super.isBound();
    }
}
项目:freeVM    文件:SocketChannelTest.java   
private void assertSocketAction_Block_BeforeConnect(Socket s)
        throws IOException {
    assertFalse(this.channel1.isConnected());
    this.server2 = new ServerSocket(localAddr2.getPort());
    s.connect(localAddr2);
    assertTrue(this.channel1.isConnected());
    assertTrue(s.isConnected());

    assertSocketAfterConnect(s, localAddr2);

    try {
        s.bind(localAddr2);
        fail("Should throw AlreadyConnectedException");
    } catch (AlreadyConnectedException e) {
        // OK.
    }

    s.close();
    assertTrue(s.isClosed());
    assertFalse(this.channel1.isOpen());
}
项目:freeVM    文件:SocketChannelImpl.java   
/**
 * @see java.net.Socket#connect(java.net.SocketAddress, int)
 */
@Override
public void connect(SocketAddress remoteAddr, int timeout)
        throws IOException {
    if (!channel.isBlocking()) {
        throw new IllegalBlockingModeException();
    }
    if (isConnected()) {
        throw new AlreadyConnectedException();
    }
    super.connect(remoteAddr, timeout);
    channel.localAddress = networkSystem.getSocketLocalAddress(
            channel.fd, false);
    if (super.isConnected()) {
        channel.setConnected();
        channel.isBound = super.isBound();
    }
}
项目:freeVM    文件:SocketChannelTest.java   
private void assertSocketAction_Block_BeforeConnect(Socket s)
        throws IOException {
    assertFalse(this.channel1.isConnected());
    this.server2 = new ServerSocket(localAddr2.getPort());
    s.connect(localAddr2);
    assertTrue(this.channel1.isConnected());
    assertTrue(s.isConnected());

    assertSocketAfterConnect(s, localAddr2);

    try {
        s.bind(localAddr2);
        fail("Should throw AlreadyConnectedException");
    } catch (AlreadyConnectedException e) {
        // OK.
    }

    s.close();
    assertTrue(s.isClosed());
    assertFalse(this.channel1.isOpen());
}
项目:OpenJSharp    文件:SctpChannelImpl.java   
private void ensureOpenAndUnconnected() throws IOException {
    synchronized (stateLock) {
        if (!isOpen())
            throw new ClosedChannelException();
        if (isConnected())
            throw new AlreadyConnectedException();
        if (state == ChannelState.PENDING)
            throw new ConnectionPendingException();
    }
}
项目:jdk8u-jdk    文件:SctpChannelImpl.java   
private void ensureOpenAndUnconnected() throws IOException {
    synchronized (stateLock) {
        if (!isOpen())
            throw new ClosedChannelException();
        if (isConnected())
            throw new AlreadyConnectedException();
        if (state == ChannelState.PENDING)
            throw new ConnectionPendingException();
    }
}
项目:openjdk-jdk10    文件:SctpChannelImpl.java   
private void ensureOpenAndUnconnected() throws IOException {
    synchronized (stateLock) {
        if (!isOpen())
            throw new ClosedChannelException();
        if (isConnected())
            throw new AlreadyConnectedException();
        if (state == ChannelState.PENDING)
            throw new ConnectionPendingException();
    }
}
项目:openjdk9    文件:SctpChannelImpl.java   
private void ensureOpenAndUnconnected() throws IOException {
    synchronized (stateLock) {
        if (!isOpen())
            throw new ClosedChannelException();
        if (isConnected())
            throw new AlreadyConnectedException();
        if (state == ChannelState.PENDING)
            throw new ConnectionPendingException();
    }
}
项目:jdk8u_jdk    文件:SctpChannelImpl.java   
private void ensureOpenAndUnconnected() throws IOException {
    synchronized (stateLock) {
        if (!isOpen())
            throw new ClosedChannelException();
        if (isConnected())
            throw new AlreadyConnectedException();
        if (state == ChannelState.PENDING)
            throw new ConnectionPendingException();
    }
}
项目:lookaside_java-1.8.0-openjdk    文件:SctpChannelImpl.java   
private void ensureOpenAndUnconnected() throws IOException {
    synchronized (stateLock) {
        if (!isOpen())
            throw new ClosedChannelException();
        if (isConnected())
            throw new AlreadyConnectedException();
        if (state == ChannelState.PENDING)
            throw new ConnectionPendingException();
    }
}
项目:j2objc    文件:DatagramChannelImpl.java   
@Override
public void bind(SocketAddress localAddr) throws SocketException {
    if (channelImpl.isConnected()) {
        throw new AlreadyConnectedException();
    }
    super.bind(localAddr);
    channelImpl.onBind(false /* updateSocketState */);
}
项目:j2objc    文件:SocketChannelImpl.java   
synchronized private void checkUnconnected() throws IOException {
    if (!isOpen()) {
        throw new ClosedChannelException();
    }
    if (status == SOCKET_STATUS_CONNECTED) {
        throw new AlreadyConnectedException();
    }
    if (status == SOCKET_STATUS_PENDING) {
        throw new ConnectionPendingException();
    }
}
项目:j2objc    文件:SocketChannelImpl.java   
@Override
public void bind(SocketAddress localAddr) throws IOException {
    if (channel.isConnected()) {
        throw new AlreadyConnectedException();
    }
    if (SocketChannelImpl.SOCKET_STATUS_PENDING == channel.status) {
        throw new ConnectionPendingException();
    }
    super.bind(localAddr);
    channel.onBind(false);
}
项目:ardroid-export    文件:OSCReceiver.java   
public void setTarget( SocketAddress target )
{
    synchronized( generalSync ) {
        if( isConnected() ) throw new AlreadyConnectedException();

        this.target = target;
    }
}
项目:infobip-open-jdk-8    文件:SctpChannelImpl.java   
private void ensureOpenAndUnconnected() throws IOException {
    synchronized (stateLock) {
        if (!isOpen())
            throw new ClosedChannelException();
        if (isConnected())
            throw new AlreadyConnectedException();
        if (state == ChannelState.PENDING)
            throw new ConnectionPendingException();
    }
}
项目:jdk8u-dev-jdk    文件:SctpChannelImpl.java   
private void ensureOpenAndUnconnected() throws IOException {
    synchronized (stateLock) {
        if (!isOpen())
            throw new ClosedChannelException();
        if (isConnected())
            throw new AlreadyConnectedException();
        if (state == ChannelState.PENDING)
            throw new ConnectionPendingException();
    }
}
项目:In-the-Box-Fork    文件:DatagramChannelImpl.java   
/**
 * @see java.net.DatagramSocket#bind(java.net.SocketAddress)
 */
@Override
public void bind(SocketAddress localAddr) throws SocketException {
    if (channelImpl.isConnected()) {
        throw new AlreadyConnectedException();
    }
    super.bind(localAddr);
    channelImpl.isBound = true;
}
项目:In-the-Box-Fork    文件:SocketChannelImpl.java   
synchronized private void checkUnconnected() throws IOException {
    if (!isOpen()) {
        throw new ClosedChannelException();
    }
    if (status == SOCKET_STATUS_CONNECTED) {
        throw new AlreadyConnectedException();
    }
    if (status == SOCKET_STATUS_PENDING) {
        throw new ConnectionPendingException();
    }
}
项目:In-the-Box-Fork    文件:SocketChannelImpl.java   
@Override
public void connect(SocketAddress remoteAddr, int timeout) throws IOException {
    if (!channel.isBlocking()) {
        throw new IllegalBlockingModeException();
    }
    if (isConnected()) {
        throw new AlreadyConnectedException();
    }
    super.connect(remoteAddr, timeout);
    channel.initLocalAddressAndPort();
    if (super.isConnected()) {
        channel.setConnected();
        channel.isBound = super.isBound();
    }
}
项目:In-the-Box-Fork    文件:SocketChannelImpl.java   
@Override
public void bind(SocketAddress localAddr) throws IOException {
    if (channel.isConnected()) {
        throw new AlreadyConnectedException();
    }
    if (SocketChannelImpl.SOCKET_STATUS_PENDING == channel.status) {
        throw new ConnectionPendingException();
    }
    super.bind(localAddr);
    // keep here to see if need next version
    // channel.Address = getLocalSocketAddress();
    // channel.localport = getLocalPort();
    channel.isBound = true;
}
项目:In-the-Box-Fork    文件:AlreadyConnectedExceptionTest.java   
/**
 * @tests {@link java.nio.channels.AlreadyConnectedException#AlreadyConnectedException()}
 */
public void test_Constructor() {
    AlreadyConnectedException e = new AlreadyConnectedException();
    assertNull(e.getMessage());
    assertNull(e.getLocalizedMessage());
    assertNull(e.getCause());
}
项目:jdk7-jdk    文件:SctpChannelImpl.java   
private void ensureOpenAndUnconnected() throws IOException {
    synchronized (stateLock) {
        if (!isOpen())
            throw new ClosedChannelException();
        if (isConnected())
            throw new AlreadyConnectedException();
        if (state == ChannelState.PENDING)
            throw new ConnectionPendingException();
    }
}
项目:openjdk-source-code-learn    文件:SctpChannelImpl.java   
private void ensureOpenAndUnconnected() throws IOException {
    synchronized (stateLock) {
        if (!isOpen())
            throw new ClosedChannelException();
        if (isConnected())
            throw new AlreadyConnectedException();
        if (state == ChannelState.PENDING)
            throw new ConnectionPendingException();
    }
}
项目:OLD-OpenJDK8    文件:SctpChannelImpl.java   
private void ensureOpenAndUnconnected() throws IOException {
    synchronized (stateLock) {
        if (!isOpen())
            throw new ClosedChannelException();
        if (isConnected())
            throw new AlreadyConnectedException();
        if (state == ChannelState.PENDING)
            throw new ConnectionPendingException();
    }
}
项目:cn1    文件:DatagramChannelImpl.java   
/**
 * @see java.net.DatagramSocket#bind(java.net.SocketAddress)
 */
@Override
public void bind(SocketAddress localAddr) throws SocketException {
    if (channelImpl.isConnected()) {
        throw new AlreadyConnectedException();
    }
    super.bind(localAddr);
    channelImpl.isBound = true;
}
项目:cn1    文件:SocketChannelImpl.java   
synchronized private void checkUnconnected() throws IOException {
    if (!isOpen()) {
        throw new ClosedChannelException();
    }
    if (status == SOCKET_STATUS_CONNECTED) {
        throw new AlreadyConnectedException();
    }
    if (status == SOCKET_STATUS_PENDING) {
        throw new ConnectionPendingException();
    }
}
项目:cn1    文件:SocketChannelImpl.java   
/**
 * @see java.net.Socket#bind(java.net.SocketAddress)
 */
@Override
public void bind(SocketAddress localAddr) throws IOException {
    if (channel.isConnected()) {
        throw new AlreadyConnectedException();
    }
    if (SocketChannelImpl.SOCKET_STATUS_PENDING == channel.status) {
        throw new ConnectionPendingException();
    }
    super.bind(localAddr);
    channel.isBound = true;
    channel.localAddress = super.getLocalAddress();
    channel.localPort = super.getLocalPort();
}
项目:cn1    文件:SocketChannelTest.java   
/**
 * 
 * 'SocketChannelImpl.connect(SocketAddress)'
 */
public void testCFII_Data_ConnectWithServer() throws Exception {
    ensureServerOpen();
    java.nio.ByteBuffer writeBuf = java.nio.ByteBuffer
            .allocate(CAPACITY_NORMAL);
    java.nio.ByteBuffer[] writeBufArr = new java.nio.ByteBuffer[1];
    writeBufArr[0] = java.nio.ByteBuffer.allocate(CAPACITY_NORMAL);
    assertFalse(this.channel1.isRegistered());
    assertTrue(this.channel1.isBlocking());

    this.channel1.connect(localAddr1);

    assertTrue(this.channel1.isBlocking());
    assertTrue(this.channel1.isConnected());
    assertFalse(this.channel1.isConnectionPending());
    assertTrue(this.channel1.isOpen());
    assertEquals(CAPACITY_NORMAL, this.channel1.write(writeBuf));
    assertEquals(CAPACITY_NORMAL, this.channel1.write(writeBufArr, 0, 1));

    this.channel1.configureBlocking(false);
    try {
        this.channel1.connect(localAddr1);
        fail("Should throw AlreadyConnectedException");
    } catch (AlreadyConnectedException e) {
        // correct
    }

    assertFalse(this.channel1.isRegistered());
    tryFinish();
}
项目:cn1    文件:SocketChannelTest.java   
public void testCFII_Data_ConnectWithServer_nonBlocking() throws Exception {
    ensureServerOpen();
    java.nio.ByteBuffer writeBuf = java.nio.ByteBuffer
            .allocate(CAPACITY_NORMAL);
    java.nio.ByteBuffer[] writeBufArr = new java.nio.ByteBuffer[1];
    writeBufArr[0] = java.nio.ByteBuffer.allocate(CAPACITY_NORMAL);
    assertFalse(this.channel1.isRegistered());
    assertTrue(this.channel1.isBlocking());
    this.channel1.configureBlocking(false);
    this.channel1.connect(localAddr1);

    assertFalse(this.channel1.isBlocking());
    boolean connected = channel1.isConnected();
    if (!connected) {
        assertTrue(this.channel1.isConnectionPending());
        assertTrue(this.channel1.isOpen());
    }
    if (tryFinish()) {
        assertEquals(CAPACITY_NORMAL, this.channel1.write(writeBuf));
        assertEquals(CAPACITY_NORMAL, this.channel1.write(writeBufArr, 0, 1));

        this.channel1.configureBlocking(false);
        try {
            this.channel1.connect(localAddr1);
            fail("Should throw AlreadyConnectedException");
        } catch (AlreadyConnectedException e) {
            // correct
        }
    }

    assertFalse(this.channel1.isRegistered());
    tryFinish();
}
项目:cn1    文件:AlreadyConnectedExceptionTest.java   
/**
 * @tests {@link java.nio.channels.AlreadyConnectedException#AlreadyConnectedException()}
 */
public void test_Constructor() {
    AlreadyConnectedException e = new AlreadyConnectedException();
    assertNull(e.getMessage());
    assertNull(e.getLocalizedMessage());
    assertNull(e.getCause());
}
项目:openjdk-jdk7u-jdk    文件:SctpChannelImpl.java   
private void ensureOpenAndUnconnected() throws IOException {
    synchronized (stateLock) {
        if (!isOpen())
            throw new ClosedChannelException();
        if (isConnected())
            throw new AlreadyConnectedException();
        if (state == ChannelState.PENDING)
            throw new ConnectionPendingException();
    }
}