@Override public Socket createSocket(final String host, final int port) throws IOException { return SocketUtils.createAndConnect(host, port, config); }
/** * Create, configure and connect a socket. * @param address The address to connect to * @param options The socket options to configure. If null, no socket options will be configured * @return The configured and connected socket * @throws IOException */ public static Socket createAndConnect(SocketAddress address, SocketOptionsConfig options) throws IOException { final Socket result = new Socket(); configureSocketOptions(result, options); logger.debug("Connecting socket"); if (options != null && options.hasConnectTimeout()) { result.connect(address, options.getConnectTimeout()); } else { result.connect(address); } logger.debug("Socket connected"); return result; }
/** * Create, configure and connect a socket. * @param address The address to connect to * @param options The socket options to configure. If null, no socket options will be configured * @return The configured and connected socket * @throws IOException */ public static Socket createAndConnect(SocketAddress address, SocketOptionsConfig options) throws IOException { final Socket result = new Socket(); configureSocketOptions(result, options); logger.debug("Connecting socket"); if (options != null && options.hasConnectTimeout()) { result.connect(address, options.getConnectTimeout()); } else { result.connect(address); } logger.debug("Socket connected"); return result; }
@Override public Socket createSocket(final String host, final int port) throws IOException { return SocketUtils.createAndConnect(host, port, config); }
public static Socket createAndConnect(String host, int port, SocketOptionsConfig options) throws IOException { final InetAddress addr = InetAddress.getByName(host); final SocketAddress endpoint = new InetSocketAddress(addr, port); return createAndConnect(endpoint, options); } }
public static Socket createAndConnect(String host, int port, SocketOptionsConfig options) throws IOException { final InetAddress addr = InetAddress.getByName(host); final SocketAddress endpoint = new InetSocketAddress(addr, port); return createAndConnect(endpoint, options); } }
@Override public Metrics readAllMetrics() throws MetricReadException { try(final Socket socket = createAndConnect(config.getHost(), config.getPort(), config.getSocketOptions())) { final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), ASCII_CHARSET)); final BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), ASCII_CHARSET)); final Metrics result = new Metrics(); fetchStatistics("general", reader, writer, result); quit(writer); return result; } catch (IOException e) { throw new MetricReadException(e); } }