private void cleanup() { for (Channel channel : openChannels) { NetworkUtil.closeQuietly(channel); } openChannels.clear(); NetworkUtil.closeQuietly(selector); }
private void register(SocketChannel channel) throws IOException { NetworkUtil.configure(channel); channel.configureBlocking(false); }
public static String toHostPort(InetSocketAddress address) { return toHostPort(address.getHostString(), address.getPort()); }
private void handleReadUnderflow() { if (engine.getSession().getPacketBufferSize() > inEncryptedData.capacity()) { inEncryptedData = NetworkUtil.enlargeSslPacketBuffer(engine, inEncryptedData); } else { inEncryptedData.compact(); } partialRecord = true; }
public static InetSocketAddress toInetSocketAddress(String maybeLiteralHost, int port) { return new InetSocketAddress(decodeIPv6LiteralHost(maybeLiteralHost), port); }
public static URI toUri(HttpHost host) throws URISyntaxException { return builderFrom(host).build(); }
public static ByteBuffer enlargeSslPacketBuffer(SSLEngine engine, ByteBuffer buffer) { return enlargeSslBuffer(buffer, engine.getSession().getPacketBufferSize()); }
private int decrypt() throws IOException { int decryptedBytes = 0; while (inEncryptedData.hasRemaining() && !partialRecord) { SSLEngineResult result = engine.unwrap(inEncryptedData, inAppData); switch (result.getStatus()) { case OK: decryptedBytes += result.bytesProduced(); partialRecord = false; break; case BUFFER_OVERFLOW: inAppData = NetworkUtil.enlargeSslApplicationBuffer(engine, inAppData); break; case BUFFER_UNDERFLOW: handleReadUnderflow(); break; case CLOSED: close(); return -1; default: throw new IllegalStateException("Invalid SSL result status: " + result.getStatus()); } } return decryptedBytes; }
public static List<InetSocketAddress> parseInetSocketAddresses(String... hostPortStrings) { List<InetSocketAddress> hosts = new ArrayList<>(); for (String node : hostPortStrings) { hosts.add(parseInetSocketAddress(node)); } return hosts; }
private ByteBuffer handleBufferUnderflow(SSLEngine engine, ByteBuffer buffer) { if (buffer.capacity() >= engine.getSession().getPacketBufferSize()) { return buffer; } else { final ByteBuffer replaceBuffer = NetworkUtil.enlargeSslPacketBuffer(engine, buffer); buffer.flip(); replaceBuffer.put(buffer); return replaceBuffer; } } }
public static InetSocketAddress parseInetSocketAddress(String hostPortString) { int lastColon = hostPortString.lastIndexOf(':'); String host = decodeIPv6LiteralHost(lastColon < 0 ? hostPortString : hostPortString.substring(0, lastColon)); int port = lastColon < 0 ? 0 : Integer.parseInt(hostPortString.substring(lastColon + 1)); return new InetSocketAddress(host, port); }
public static URI toUri(HttpHost host, String path) throws URISyntaxException { return builderFrom(host).setPath(path).build(); }
public static ByteBuffer enlargeSslApplicationBuffer(SSLEngine engine, ByteBuffer buffer) { return enlargeSslBuffer(buffer, engine.getSession().getApplicationBufferSize()); }
break; case BUFFER_OVERFLOW: handshakeInData = NetworkUtil.enlargeSslApplicationBuffer(engine, handshakeInData); break; case BUFFER_UNDERFLOW:
void stop() { stopped = true; NetworkUtil.closeQuietly(serverSocketChannel); networkThread.selector.wakeup(); }
private void register(SocketChannel channel) throws IOException { openChannels.add(channel); NetworkUtil.configure(channel); channel.configureBlocking(false); }
private JsonNode getStatus(Predicate<Integer> predicate) { final ArrayNode status = OBJECT_MAPPER.createArrayNode(); final IReplicaManager storageSubsystem = appCtx.getReplicaManager(); final Set<Integer> partitions = storageSubsystem.getPartitions().stream().filter(predicate).collect(Collectors.toSet()); for (Integer partition : partitions) { final ObjectNode partitionJson = OBJECT_MAPPER.createObjectNode(); partitionJson.put("partition", partition); final List<IPartitionReplica> replicas = storageSubsystem.getReplicas(partition); ArrayNode replicasArray = OBJECT_MAPPER.createArrayNode(); for (IPartitionReplica replica : replicas) { final ObjectNode replicaJson = OBJECT_MAPPER.createObjectNode(); replicaJson.put("location", toHostPort(replica.getIdentifier().getLocation())); replicaJson.put("status", replica.getStatus().toString()); replicasArray.add(replicaJson); } partitionJson.set("replicas", replicasArray); status.add(partitionJson); } return status; }
outEncryptedData = NetworkUtil.enlargeSslPacketBuffer(engine, outEncryptedData); break; case CLOSED:
public synchronized void close() { try { if (sc != null) { sendGoodBye(); NetworkUtil.closeQuietly(sc); } } finally { sc = null; } }
public static ISocketChannel establishReplicaConnection(INcApplicationContext appCtx, InetSocketAddress location) throws IOException { final SocketChannel socketChannel = SocketChannel.open(); NetworkUtil.configure(socketChannel); socketChannel.connect(location); // perform handshake in a non-blocking mode socketChannel.configureBlocking(false); final ISocketChannelFactory socketChannelFactory = appCtx.getServiceContext().getControllerService().getNetworkSecurityManager().getSocketChannelFactory(); final ISocketChannel clientChannel = socketChannelFactory.createClientChannel(socketChannel); if (clientChannel.requiresHandshake() && !clientChannel.handshake()) { throw new IllegalStateException("handshake failure"); } // switch to blocking mode after handshake success socketChannel.configureBlocking(true); return clientChannel; }