本文整理汇总了Java中java.nio.channels.AlreadyConnectedException类的典型用法代码示例。如果您正苦于以下问题:Java AlreadyConnectedException类的具体用法?Java AlreadyConnectedException怎么用?Java AlreadyConnectedException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AlreadyConnectedException类属于java.nio.channels包,在下文中一共展示了AlreadyConnectedException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: connect
import java.nio.channels.AlreadyConnectedException; //导入依赖的package包/类
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;
}
示例2: connect
import java.nio.channels.AlreadyConnectedException; //导入依赖的package包/类
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;
}
示例3: connect
import java.nio.channels.AlreadyConnectedException; //导入依赖的package包/类
@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 */);
}
}
示例4: testSerializationSelf
import java.nio.channels.AlreadyConnectedException; //导入依赖的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 = "AlreadyConnectedException",
args = {}
)
})
public void testSerializationSelf() throws Exception {
SerializationTest.verifySelf(new AlreadyConnectedException());
}
示例5: testSerializationCompatibility
import java.nio.channels.AlreadyConnectedException; //导入依赖的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 = "AlreadyConnectedException",
args = {}
)
})
public void testSerializationCompatibility() throws Exception {
SerializationTest.verifyGolden(this, new AlreadyConnectedException());
}
示例6: connect
import java.nio.channels.AlreadyConnectedException; //导入依赖的package包/类
/**
* @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();
}
}
示例7: assertSocketAction_Block_BeforeConnect
import java.nio.channels.AlreadyConnectedException; //导入依赖的package包/类
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());
}
示例8: connect
import java.nio.channels.AlreadyConnectedException; //导入依赖的package包/类
@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();
}
}
示例9: ensureOpenAndUnconnected
import java.nio.channels.AlreadyConnectedException; //导入依赖的package包/类
private void ensureOpenAndUnconnected() throws IOException {
synchronized (stateLock) {
if (!isOpen())
throw new ClosedChannelException();
if (isConnected())
throw new AlreadyConnectedException();
if (state == ChannelState.PENDING)
throw new ConnectionPendingException();
}
}
示例10: bind
import java.nio.channels.AlreadyConnectedException; //导入依赖的package包/类
@Override
public void bind(SocketAddress localAddr) throws SocketException {
if (channelImpl.isConnected()) {
throw new AlreadyConnectedException();
}
super.bind(localAddr);
channelImpl.onBind(false /* updateSocketState */);
}
示例11: checkUnconnected
import java.nio.channels.AlreadyConnectedException; //导入依赖的package包/类
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();
}
}
示例12: bind
import java.nio.channels.AlreadyConnectedException; //导入依赖的package包/类
@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);
}
示例13: setTarget
import java.nio.channels.AlreadyConnectedException; //导入依赖的package包/类
public void setTarget( SocketAddress target )
{
synchronized( generalSync ) {
if( isConnected() ) throw new AlreadyConnectedException();
this.target = target;
}
}
示例14: bind
import java.nio.channels.AlreadyConnectedException; //导入依赖的package包/类
/**
* @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;
}
示例15: connect
import java.nio.channels.AlreadyConnectedException; //导入依赖的package包/类
@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();
}
}