java.nio.channels.AlreadyConnectedException Java Examples
The following examples show how to use
java.nio.channels.AlreadyConnectedException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SocketMultipleConnectTest.java From netty-4.1.22 with Apache License 2.0 | 6 votes |
public void testMultipleConnect(ServerBootstrap sb, Bootstrap cb) throws Exception { Channel sc = null; Channel cc = null; try { sb.childHandler(new ChannelInboundHandlerAdapter()); sc = sb.bind(NetUtil.LOCALHOST, 0).syncUninterruptibly().channel(); cb.handler(new ChannelInboundHandlerAdapter()); cc = cb.register().syncUninterruptibly().channel(); cc.connect(sc.localAddress()).syncUninterruptibly(); ChannelFuture connectFuture2 = cc.connect(sc.localAddress()).await(); assertTrue(connectFuture2.cause() instanceof AlreadyConnectedException); } finally { if (cc != null) { cc.close(); } if (sc != null) { sc.close(); } } }
Example #2
Source File: Errors.java From netty-4.1.22 with Apache License 2.0 | 6 votes |
static void throwConnectException(String method, NativeConnectException refusedCause, int err) throws IOException { if (err == refusedCause.expectedErr()) { throw refusedCause; } if (err == ERROR_EALREADY_NEGATIVE) { throw new ConnectionPendingException(); } if (err == ERROR_ENETUNREACH_NEGATIVE) { throw new NoRouteToHostException(); } if (err == ERROR_EISCONN_NEGATIVE) { throw new AlreadyConnectedException(); } if (err == ERRNO_ENOENT_NEGATIVE) { throw new FileNotFoundException(); } throw new ConnectException(method + "(..) failed: " + ERRORS[-err]); }
Example #3
Source File: SctpChannelImpl.java From hottub with GNU General Public License v2.0 | 5 votes |
private void ensureOpenAndUnconnected() throws IOException { synchronized (stateLock) { if (!isOpen()) throw new ClosedChannelException(); if (isConnected()) throw new AlreadyConnectedException(); if (state == ChannelState.PENDING) throw new ConnectionPendingException(); } }
Example #4
Source File: AlreadyConnectedExceptionTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * @tests {@link java.nio.channels.AlreadyConnectedException#AlreadyConnectedException()} */ public void test_Constructor() { AlreadyConnectedException e = new AlreadyConnectedException(); assertNull(e.getMessage()); assertNull(e.getLocalizedMessage()); assertNull(e.getCause()); }
Example #5
Source File: SocketChannelTest.java From j2objc with Apache License 2.0 | 5 votes |
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(); }
Example #6
Source File: SocketChannelTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * * '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(); }
Example #7
Source File: SctpChannelImpl.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
private void ensureOpenAndUnconnected() throws IOException { synchronized (stateLock) { if (!isOpen()) throw new ClosedChannelException(); if (isConnected()) throw new AlreadyConnectedException(); if (state == ChannelState.PENDING) throw new ConnectionPendingException(); } }
Example #8
Source File: SctpChannelImpl.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
private void ensureOpenAndUnconnected() throws IOException { synchronized (stateLock) { if (!isOpen()) throw new ClosedChannelException(); if (isConnected()) throw new AlreadyConnectedException(); if (state == ChannelState.PENDING) throw new ConnectionPendingException(); } }
Example #9
Source File: SctpChannelImpl.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
private void ensureOpenAndUnconnected() throws IOException { synchronized (stateLock) { if (!isOpen()) throw new ClosedChannelException(); if (isConnected()) throw new AlreadyConnectedException(); if (state == ChannelState.PENDING) throw new ConnectionPendingException(); } }
Example #10
Source File: SctpChannelImpl.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
private void ensureOpenAndUnconnected() throws IOException { synchronized (stateLock) { if (!isOpen()) throw new ClosedChannelException(); if (isConnected()) throw new AlreadyConnectedException(); if (state == ChannelState.PENDING) throw new ConnectionPendingException(); } }
Example #11
Source File: SctpChannelImpl.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
private void ensureOpenAndUnconnected() throws IOException { synchronized (stateLock) { if (!isOpen()) throw new ClosedChannelException(); if (isConnected()) throw new AlreadyConnectedException(); if (state == ChannelState.PENDING) throw new ConnectionPendingException(); } }
Example #12
Source File: SctpChannelImpl.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
private void ensureOpenAndUnconnected() throws IOException { synchronized (stateLock) { if (!isOpen()) throw new ClosedChannelException(); if (isConnected()) throw new AlreadyConnectedException(); if (state == ChannelState.PENDING) throw new ConnectionPendingException(); } }
Example #13
Source File: SctpChannelImpl.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
private void ensureOpenAndUnconnected() throws IOException { synchronized (stateLock) { if (!isOpen()) throw new ClosedChannelException(); if (isConnected()) throw new AlreadyConnectedException(); if (state == ChannelState.PENDING) throw new ConnectionPendingException(); } }
Example #14
Source File: SctpChannelImpl.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private void ensureOpenAndUnconnected() throws IOException { synchronized (stateLock) { if (!isOpen()) throw new ClosedChannelException(); if (isConnected()) throw new AlreadyConnectedException(); if (state == ChannelState.PENDING) throw new ConnectionPendingException(); } }
Example #15
Source File: SctpChannelImpl.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
private void ensureOpenAndUnconnected() throws IOException { synchronized (stateLock) { if (!isOpen()) throw new ClosedChannelException(); if (isConnected()) throw new AlreadyConnectedException(); if (state == ChannelState.PENDING) throw new ConnectionPendingException(); } }
Example #16
Source File: SctpChannelImpl.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private void ensureOpenAndUnconnected() throws IOException { synchronized (stateLock) { if (!isOpen()) throw new ClosedChannelException(); if (isConnected()) throw new AlreadyConnectedException(); if (state == ChannelState.PENDING) throw new ConnectionPendingException(); } }
Example #17
Source File: VirtualChannel.java From quarkus with Apache License 2.0 | 5 votes |
@Override public void connect(final SocketAddress remoteAddress, SocketAddress localAddress, final ChannelPromise promise) { if (!promise.setUncancellable() || !ensureOpen(promise)) { return; } if (state == State.CONNECTED) { Exception cause = new AlreadyConnectedException(); safeSetFailure(promise, cause); pipeline().fireExceptionCaught(cause); return; } if (connectPromise != null) { throw new ConnectionPendingException(); } connectPromise = promise; if (state != State.BOUND) { // Not bound yet and no localAddress specified - get one. if (localAddress == null) { localAddress = new VirtualAddress(VirtualChannel.this); } } if (localAddress != null) { try { doBind(localAddress); } catch (Throwable t) { safeSetFailure(promise, t); close(voidPromise()); return; } } }
Example #18
Source File: SctpChannelImpl.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
private void ensureOpenAndUnconnected() throws IOException { synchronized (stateLock) { if (!isOpen()) throw new ClosedChannelException(); if (isConnected()) throw new AlreadyConnectedException(); if (state == ChannelState.PENDING) throw new ConnectionPendingException(); } }
Example #19
Source File: SctpChannelImpl.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private void ensureOpenAndUnconnected() throws IOException { synchronized (stateLock) { if (!isOpen()) throw new ClosedChannelException(); if (isConnected()) throw new AlreadyConnectedException(); if (state == ChannelState.PENDING) throw new ConnectionPendingException(); } }
Example #20
Source File: AbstractEpollChannel.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
/** * Connect to the remote peer */ protected boolean doConnect(SocketAddress remoteAddress, SocketAddress localAddress) throws Exception { if (localAddress instanceof InetSocketAddress) { checkResolvable((InetSocketAddress) localAddress); } InetSocketAddress remoteSocketAddr = remoteAddress instanceof InetSocketAddress ? (InetSocketAddress) remoteAddress : null; if (remoteSocketAddr != null) { checkResolvable(remoteSocketAddr); } if (remote != null) { // Check if already connected before trying to connect. This is needed as connect(...) will not return -1 // and set errno to EISCONN if a previous connect(...) attempt was setting errno to EINPROGRESS and finished // later. throw new AlreadyConnectedException(); } if (localAddress != null) { socket.bind(localAddress); } boolean connected = doConnect0(remoteAddress); if (connected) { remote = remoteSocketAddr == null ? remoteAddress : computeRemoteAddr(remoteSocketAddr, socket.remoteAddress()); } // We always need to set the localAddress even if not connected yet as the bind already took place. // // See https://github.com/netty/netty/issues/3463 local = socket.localAddress(); return connected; }
Example #21
Source File: AbstractKQueueChannel.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
/** * Connect to the remote peer */ protected boolean doConnect(SocketAddress remoteAddress, SocketAddress localAddress) throws Exception { if (localAddress instanceof InetSocketAddress) { checkResolvable((InetSocketAddress) localAddress); } InetSocketAddress remoteSocketAddr = remoteAddress instanceof InetSocketAddress ? (InetSocketAddress) remoteAddress : null; if (remoteSocketAddr != null) { checkResolvable(remoteSocketAddr); } if (remote != null) { // Check if already connected before trying to connect. This is needed as connect(...) will not return -1 // and set errno to EISCONN if a previous connect(...) attempt was setting errno to EINPROGRESS and finished // later. throw new AlreadyConnectedException(); } if (localAddress != null) { socket.bind(localAddress); } boolean connected = doConnect0(remoteAddress); if (connected) { remote = remoteSocketAddr == null ? remoteAddress : computeRemoteAddr(remoteSocketAddr, socket.remoteAddress()); } // We always need to set the localAddress even if not connected yet as the bind already took place. // // See https://github.com/netty/netty/issues/3463 local = socket.localAddress(); return connected; }
Example #22
Source File: DatagramChannelImpl.java From Bytecoder with Apache License 2.0 | 4 votes |
/** * Connects the channel's socket. * * @param sa the remote address to which this channel is to be connected * @param check true to check if the channel is already connected. */ DatagramChannel connect(SocketAddress sa, boolean check) throws IOException { InetSocketAddress isa = Net.checkAddress(sa, family); SecurityManager sm = System.getSecurityManager(); if (sm != null) { InetAddress ia = isa.getAddress(); if (ia.isMulticastAddress()) { sm.checkMulticast(ia); } else { sm.checkConnect(ia.getHostAddress(), isa.getPort()); sm.checkAccept(ia.getHostAddress(), isa.getPort()); } } readLock.lock(); try { writeLock.lock(); try { synchronized (stateLock) { ensureOpen(); if (check && state == ST_CONNECTED) throw new AlreadyConnectedException(); // ensure that the socket is bound if (localAddress == null) { bindInternal(null); } // capture local address before connect initialLocalAddress = localAddress; int n = Net.connect(family, fd, isa.getAddress(), isa.getPort()); if (n <= 0) throw new Error(); // Can't happen // connected remoteAddress = isa; state = ST_CONNECTED; // refresh local address localAddress = Net.localAddress(fd); // flush any packets already received. boolean blocking = isBlocking(); if (blocking) { IOUtil.configureBlocking(fd, false); } try { ByteBuffer buf = ByteBuffer.allocate(100); while (receive(buf, false) >= 0) { buf.clear(); } } finally { if (blocking) { IOUtil.configureBlocking(fd, true); } } } } finally { writeLock.unlock(); } } finally { readLock.unlock(); } return this; }
Example #23
Source File: AlreadyConnectedExceptionTest.java From j2objc with Apache License 2.0 | 4 votes |
/** * @tests serialization/deserialization compatibility. */ public void testSerializationSelf() throws Exception { SerializationTest.verifySelf(new AlreadyConnectedException()); }
Example #24
Source File: AlreadyConnectedExceptionTest.java From j2objc with Apache License 2.0 | 4 votes |
/** * @tests serialization/deserialization compatibility with RI. */ public void testSerializationCompatibility() throws Exception { SerializationTest.verifyGolden(this, new AlreadyConnectedException()); }
Example #25
Source File: PipelinesErrorHandlingTest.java From appengine-pipelines with Apache License 2.0 | 4 votes |
public Value<Integer> handleException(AlreadyConnectedException e) { assertNotNull(e); trace("ImmediateThrowCatchJob.handleException.AlreadyBoundException"); return immediate(EXPECTED_RESULT1); }
Example #26
Source File: PipelinesErrorHandlingTest.java From appengine-pipelines with Apache License 2.0 | 4 votes |
public Value<Integer> handleException(AlreadyConnectedException e) { assertNotNull(e); trace("TestSimpleCatchJob.handleException.AlreadyBoundException"); return immediate(EXPECTED_RESULT1); }