use of java.net.SocketAddress in project wildfly by wildfly.
the class ManagedSocketFactoryTest method createMulticastSocket.
@Test
public void createMulticastSocket() throws IOException {
MulticastSocket socket1 = mock(MulticastSocket.class);
MulticastSocket socket2 = mock(MulticastSocket.class);
MulticastSocket socket3 = mock(MulticastSocket.class);
MulticastSocket socket4 = mock(MulticastSocket.class);
SocketAddress address = new InetSocketAddress(InetAddress.getLocalHost(), 1);
when(this.manager.createMulticastSocket("test", new InetSocketAddress(0))).thenReturn(socket1);
when(this.manager.createMulticastSocket("test", new InetSocketAddress(1))).thenReturn(socket2);
when(this.manager.createMulticastSocket("test", address)).thenReturn(socket3);
when(this.manager.createMulticastSocket("test")).thenReturn(socket4);
MulticastSocket result1 = this.subject.createMulticastSocket("test");
MulticastSocket result2 = this.subject.createMulticastSocket("test", 1);
MulticastSocket result3 = this.subject.createMulticastSocket("test", address);
MulticastSocket result4 = this.subject.createMulticastSocket("test", null);
assertSame(socket1, result1);
assertSame(socket2, result2);
assertSame(socket3, result3);
assertSame(socket4, result4);
}
use of java.net.SocketAddress in project heron by twitter.
the class HeronServer method handleError.
// Clean the stuff when meeting some errors
public void handleError(SelectableChannel channel) {
SocketAddress channelAddress = ((SocketChannel) channel).socket().getRemoteSocketAddress();
LOG.info("Handling error from channel: " + channelAddress);
SocketChannelHelper helper = activeConnections.get(channel);
if (helper == null) {
LOG.severe("Inactive channel had error?");
return;
}
helper.clear();
LOG.info("Removing all interest on channel: " + channelAddress);
nioLooper.removeAllInterest(channel);
try {
channel.close();
} catch (IOException e) {
LOG.severe("Error closing connection in handleError");
}
activeConnections.remove(channel);
onClose((SocketChannel) channel);
}
use of java.net.SocketAddress in project jackrabbit-oak by apache.
the class Utils method setProxyIfNeeded.
public static void setProxyIfNeeded(final Properties properties) {
String proxyHost = properties.getProperty(AzureConstants.PROXY_HOST);
String proxyPort = properties.getProperty(AzureConstants.PROXY_PORT);
if (!Strings.isNullOrEmpty(proxyHost) && Strings.isNullOrEmpty(proxyPort)) {
int port = Integer.parseInt(proxyPort);
SocketAddress proxyAddr = new InetSocketAddress(proxyHost, port);
Proxy proxy = new Proxy(Proxy.Type.HTTP, proxyAddr);
OperationContext.setDefaultProxy(proxy);
}
}
use of java.net.SocketAddress in project geode by apache.
the class JmxManagerFinder method askLocatorForJmxManager.
/**
* Ask a locator to find a jmx manager. The locator will start one if one is not already running.
*
* @param addr the host address the locator is listening on
* @param port the port the locator is listening on
* @param timeout the number of milliseconds to wait for a response; 15000 is a reasonable default
* @return describes the location of the jmx manager. The port will be zero if no jmx manager was
* found.
* @throws IOException if a problem occurs trying to connect to the locator or communicate with
* it.
*/
public static JmxManagerInfo askLocatorForJmxManager(InetAddress addr, int port, int timeout, boolean usessl) throws IOException {
SocketAddress sockaddr = new InetSocketAddress(addr, port);
Socket sock = ConnectionUtil.getSocketFactory(usessl).createSocket();
try {
sock.connect(sockaddr, timeout);
sock.setSoTimeout(timeout);
DataOutputStream out = new DataOutputStream(sock.getOutputStream());
out.writeInt(GOSSIPVERSION);
out.writeByte(DS_FIXED_ID_SHORT);
out.writeShort(JMX_MANAGER_LOCATOR_REQUEST);
out.flush();
DataInputStream in = new DataInputStream(sock.getInputStream());
byte header = in.readByte();
if (header != DS_FIXED_ID_SHORT) {
throw new IllegalStateException("Expected " + DS_FIXED_ID_SHORT + " but found " + header);
}
int msgType = in.readShort();
if (msgType != JMX_MANAGER_LOCATOR_RESPONSE) {
throw new IllegalStateException("Expected " + JMX_MANAGER_LOCATOR_RESPONSE + " but found " + msgType);
}
byte hostHeader = in.readByte();
String host;
if (hostHeader == NULL_STRING) {
host = "";
} else if (hostHeader == STRING_BYTES) {
int len = in.readUnsignedShort();
byte[] buf = new byte[len];
in.readFully(buf, 0, len);
@SuppressWarnings("deprecation") String str = new String(buf, 0);
host = str;
} else {
throw new IllegalStateException("Expected " + STRING_BYTES + " or " + NULL_STRING + " but found " + hostHeader);
}
int jmport = in.readInt();
boolean ssl = in.readBoolean();
if (host.equals("")) {
jmport = 0;
}
return new JmxManagerInfo(host, jmport, ssl);
} finally {
try {
sock.close();
} catch (Exception e) {
}
}
}
use of java.net.SocketAddress in project jackrabbit-oak by apache.
the class ClientFilterHandler method channelActive.
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
SocketAddress address = ctx.channel().remoteAddress();
if (filter.isAllowed(address)) {
log.debug("Client {} is allowed", address);
ctx.fireChannelActive();
} else {
log.debug("Client {} is rejected", address);
ctx.close();
}
}
Aggregations