@Override public void start() throws Exception { allocator = bootstrapAllocator.newChildAllocator("fabric-allocator", reservationInBytes, maxAllocationInBytes); logger.info("fabric service has {} bytes reserved", reservationInBytes); eventLoop = TransportCheck.createEventLoopGroup(threadCount, "FABRIC-"); eventLoopCloseable = new EventLoopCloseable(eventLoop); registry = new ConnectionManagerRegistry(getRpcConfig(), eventLoop, allocator, handler, getSSLEngineFactory()); server = newFabricServer(); port = server.bind(initialPort, allowPortHunting); registry.setIdentity(FabricIdentity.newBuilder() .setAddress(address) .setPort(port) .build()); }
@Override public FabricCommandRunner getCommandRunner(String address, int port) { final FabricConnectionManager manager = registry.getConnectionManager(FabricIdentity.newBuilder().setAddress(address).setPort(port).build()); return new CommandRunner(protocol, manager); } }
@Override public MessageLite getHandshakeResponse(FabricHandshake inbound) throws Exception { // logger.debug("Handling handshake from other bit. {}", inbound); if (inbound.getRpcVersion() != FabricRpcConfig.RPC_VERSION) { throw new RpcException(String.format("Invalid rpc version. Expected %d, actual %d.", inbound.getRpcVersion(), FabricRpcConfig.RPC_VERSION)); } if (!inbound.hasIdentity() || inbound.getIdentity().getAddress().isEmpty() || inbound.getIdentity().getPort() < 1) { throw new RpcException(String.format("RPC didn't provide valid counter identity. Received %s.", inbound.getIdentity())); } connection.setIdentity(inbound.getIdentity()); final boolean isLoopback = inbound.getIdentity().getAddress().equals(address) && inbound.getIdentity().getPort() == port; if (!isLoopback) { FabricConnectionManager manager = connectionRegistry.getConnectionManager(inbound.getIdentity()); // update the close handler. connection.wrapCloseHandler(manager.getCloseHandlerCreator()); // add to the connection manager. manager.addExternalConnection(connection); } return FabricHandshake.newBuilder().setRpcVersion(FabricRpcConfig.RPC_VERSION).build(); }