public Main() throws Exception { zkServer = new TestingServer(2181, true); server = Configurator.build(ConfigFactory.load().getConfig("xio.exampleApplication.settings")); }
public void run() throws Exception { server.start(); }
public void close() { log.debug("Closing " + this); servers.values().stream().forEach((v) -> v.close()); configurator.close(); } }
public Application build() { Map<String, XioServer> servers = new HashMap<>(); serverBootstraps.forEach((k, v) -> servers.put(k, v.build())); ZkClient zkClient = state.getZkClient(); zkClient.registerUpdater( new IpFilterConfig.Updater(config.getIpFilterPath(), state::setIpFilterConfig)); zkClient.registerUpdater( new Http1FilterConfig.Updater(config.getHttp1FilterPath(), state::setHttp1FilterConfig)); state.getZkClient().start(); Configurator configurator = Configurator.build(config.settings()); configurator.start(); Application application = new Application(config, servers, state, configurator); new ApplicationRunner(application).start(); return application; } }
public Configurator( UpdateHandler storage, Duration updateInterval, InetSocketAddress bindAddress, Ruleset existing, ZooKeeperValidator zkValidator) { this.storage = storage; this.updateInterval = updateInterval; this.bindAddress = bindAddress; this.zkValidator = zkValidator; serverThread = new Thread(this, "Configurator server thread"); service = newService(); processor = new ConfigurationService.Processor<>(service); ipRules = new IpRules(existing); http1Rules = new Http1Rules(existing); }
public void run() { log.info("Starting up!"); try { serverTransport = new TServerSocket(bindAddress); server = new TSimpleServer(new Args(serverTransport).processor(processor)); server.serve(); // blocks until stop() is called. // timer and timer task should be stopped at this point writeToStorage(); } catch (TTransportException e) { log.error("Couldn't start Configurator {}", this, e); } }
public static Configurator build(Config config) { Config configurationUpdateServer = config.getConfig("configurationUpdateServer"); if (configurationUpdateServer.getBoolean("enabled") == false) { return new NullConfigurator(); } CuratorFramework client = new ZooKeeperClientFactory(config.getConfig("zookeeper")).newClient(); client.start(); ZooKeeperWriteProvider zkWriter = new ZooKeeperWriteProvider(new ThriftMarshaller(), client); ZooKeeperReadProvider zkReader = new ZooKeeperReadProvider(new ThriftUnmarshaller(), client); Config configurationManager = config.getConfig("configurationManager"); Ruleset rules = new Ruleset(configurationManager); rules.read(zkReader); ZooKeeperUpdateHandler zkUpdater = new ZooKeeperUpdateHandler(zkWriter, rules); ZooKeeperValidator zkValidator = new ZooKeeperValidator(zkReader, rules, configurationManager); Duration writeInterval = configurationUpdateServer.getDuration("writeInterval"); InetSocketAddress serverAddress = new InetSocketAddress( configurationUpdateServer.getString("bindIp"), configurationUpdateServer.getInt("bindPort")); Configurator server = new Configurator(zkUpdater, writeInterval, serverAddress, rules, zkValidator); return server; } }