public void buildNetwork() throws ConfigurationException { // build transport Configuration transportConfigs = _config.subset(TRANSPORT_CONFIG_PREFIX); TransportClientConf conf = new TransportClientConf(); conf.init(transportConfigs); _registry = new MetricsRegistry(); MetricsHelper.initializeMetrics(_config.subset(METRICS_CONFIG_PREFIX)); MetricsHelper.registerMetricsRegistry(_registry); _brokerMetrics = new BrokerMetrics(_registry); _brokerMetrics.initializeGlobalMeters(); _state.set(State.INIT); _eventLoopGroup = new NioEventLoopGroup(); /** * Some of the client metrics uses histogram which is doing synchronous operation. These are * fixed overhead per request/response. TODO: Measure the overhead of this. */ final NettyClientMetrics clientMetrics = new NettyClientMetrics(_registry, "client_"); // Setup Netty Connection Pool _resourceManager = new PooledNettyClientResourceManager( _eventLoopGroup, new HashedWheelTimer(), clientMetrics); _poolTimeoutExecutor = new ScheduledThreadPoolExecutor(50); // _requestSenderPool = MoreExecutors.sameThreadExecutor(); final ConnectionPoolConfig cfg = conf.getConnPool(); _requestSenderPool = Executors.newCachedThreadPool(); ConnectionPoolConfig connPoolCfg = conf.getConnPool(); _connPool = new KeyedPoolImpl<ServerInstance, NettyClientConnection>( connPoolCfg.getMinConnectionsPerServer(), connPoolCfg.getMaxConnectionsPerServer(), connPoolCfg.getIdleTimeoutMs(), connPoolCfg.getMaxBacklogPerServer(), _resourceManager, _poolTimeoutExecutor, _requestSenderPool, _registry); // MoreExecutors.sameThreadExecutor(), _registry); _resourceManager.setPool(_connPool); // Setup Routing Table if (conf.getRoutingMode() == RoutingMode.CONFIG) { final CfgBasedRouting rt = new CfgBasedRouting(); rt.init(conf.getCfgBasedRouting()); _routingTable = rt; } else { // Helix based routing is already initialized. } // Setup ScatterGather _scatterGather = new ScatterGatherImpl(_connPool, _requestSenderPool); // Setup Broker Request Handler long brokerTimeOut = DEFAULT_BROKER_TIME_OUT; if (_config.containsKey(BROKER_TIME_OUT_CONFIG)) { try { brokerTimeOut = _config.getLong(BROKER_TIME_OUT_CONFIG); } catch (Exception e) { LOGGER.warn( "Caught exception while reading broker timeout from config, using default value", e); } } LOGGER.info("Broker timeout is - " + brokerTimeOut + " ms"); _requestHandler = new BrokerRequestHandler( _routingTable, _timeBoundaryService, _scatterGather, new DefaultReduceService(), _brokerMetrics, brokerTimeOut); // TODO: Start Broker Server : Code goes here. Broker Server part should use request handler to // submit requests LOGGER.info("Network initialized !!"); }