use of java.net.SocketAddress in project hazelcast by hazelcast.
the class InitConnectionTask method bindSocket.
private void bindSocket(SocketChannel socketChannel) throws IOException {
InetAddress inetAddress = getInetAddress();
Socket socket = socketChannel.socket();
if (connectionManager.useAnyOutboundPort()) {
SocketAddress socketAddress = new InetSocketAddress(inetAddress, 0);
socket.bind(socketAddress);
} else {
IOException ex = null;
int retryCount = connectionManager.getOutboundPortCount() * 2;
for (int i = 0; i < retryCount; i++) {
int port = connectionManager.acquireOutboundPort();
SocketAddress socketAddress = new InetSocketAddress(inetAddress, port);
try {
socket.bind(socketAddress);
return;
} catch (IOException e) {
ex = e;
logger.finest("Could not bind port[ " + port + "]: " + e.getMessage());
}
}
throw ex;
}
}
use of java.net.SocketAddress in project gitblit by gitblit.
the class SshServerSessionFactory method createSession.
@Override
protected AbstractSession createSession(final IoSession io) throws Exception {
log.info("creating ssh session from {}", io.getRemoteAddress());
if (io instanceof MinaSession) {
if (((MinaSession) io).getSession().getConfig() instanceof SocketSessionConfig) {
((SocketSessionConfig) ((MinaSession) io).getSession().getConfig()).setKeepAlive(true);
}
}
final SshServerSession session = (SshServerSession) super.createSession(io);
SocketAddress peer = io.getRemoteAddress();
SshDaemonClient client = new SshDaemonClient(peer);
session.setAttribute(SshDaemonClient.KEY, client);
// TODO(davido): Log a session close without authentication as a
// failure.
session.addCloseSessionListener(new SshFutureListener<CloseFuture>() {
@Override
public void operationComplete(CloseFuture future) {
log.info("closed ssh session from {}", io.getRemoteAddress());
}
});
return session;
}
use of java.net.SocketAddress in project j2objc by google.
the class DatagramChannelImpl method receiveImpl.
private SocketAddress receiveImpl(ByteBuffer target, boolean loop) throws IOException {
SocketAddress retAddr = null;
DatagramPacket receivePacket;
int oldposition = target.position();
int received;
// TODO: disallow mapped buffers and lose this conditional?
if (target.hasArray()) {
receivePacket = new DatagramPacket(target.array(), target.position() + target.arrayOffset(), target.remaining());
} else {
receivePacket = new DatagramPacket(new byte[target.remaining()], target.remaining());
}
do {
received = NetworkBridge.recvfrom(false, fd, receivePacket.getData(), receivePacket.getOffset(), receivePacket.getLength(), 0, receivePacket, isConnected());
if (receivePacket.getAddress() != null) {
if (received > 0) {
if (target.hasArray()) {
target.position(oldposition + received);
} else {
// copy the data of received packet
target.put(receivePacket.getData(), 0, received);
}
}
retAddr = receivePacket.getSocketAddress();
break;
}
} while (loop);
return retAddr;
}
use of java.net.SocketAddress in project j2objc by google.
the class DatagramChannelImpl method onBind.
/**
* Initialise the isBound, localAddress and localPort state from the file descriptor. Used when
* some or all of the bound state has been left to the OS to decide, or when the Socket handled
* bind() or connect().
*
* @param updateSocketState
* if the associated socket (if present) needs to be updated
* @hide used to sync state, non-private to avoid synthetic method
*/
void onBind(boolean updateSocketState) {
SocketAddress sa;
try {
sa = NetworkOs.getsockname(fd);
} catch (ErrnoException errnoException) {
throw new AssertionError(errnoException);
}
isBound = true;
InetSocketAddress localSocketAddress = (InetSocketAddress) sa;
localAddress = localSocketAddress.getAddress();
localPort = localSocketAddress.getPort();
if (updateSocketState && socket != null) {
socket.onBind(localAddress, localPort);
}
}
use of java.net.SocketAddress in project grpc-java by grpc.
the class PickFirstLoadBalancerTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
for (int i = 0; i < 3; i++) {
SocketAddress addr = new FakeSocketAddress("server" + i);
servers.add(ResolvedServerInfoGroup.builder().add(new ResolvedServerInfo(addr)).build());
socketAddresses.add(addr);
}
when(mockSubchannel.getAddresses()).thenReturn(new EquivalentAddressGroup(socketAddresses));
when(mockHelper.createSubchannel(any(EquivalentAddressGroup.class), any(Attributes.class))).thenReturn(mockSubchannel);
loadBalancer = (PickFirstBalancer) PickFirstBalancerFactory.getInstance().newLoadBalancer(mockHelper);
}
Aggregations