public NetworkingParams(BasicConfig cfg) { address = cfg.entry("address").or("0.0.0.0"); port = cfg.entry("port").or(8080); workers = cfg.entry("workers").or(Runtime.getRuntime().availableProcessors()); bufSizeKB = cfg.entry("bufSizeKB").or(16); noDelay = cfg.entry("noDelay").or(false); maxPipeline = cfg.entry("maxPipeline").or(0); syncBufs = cfg.entry("syncBufs").or(true); blockingAccept = cfg.entry("blockingAccept").or(false); }
public static synchronized int cpus() { return Conf.ROOT.entry("cpus").or(Runtime.getRuntime().availableProcessors()); }
private static ThreadPoolExecutor newExecutor() { int threads = CONFIG.entry("threads").or(64); int maxThreads = CONFIG.entry("maxThreads").or(1024); int maxQueueSize = CONFIG.entry("maxQueueSize").or(1000000); BlockingQueue<Runnable> queue = new ArrayBlockingQueue<>(maxQueueSize); return new ThreadPoolExecutor(threads, maxThreads, 300, TimeUnit.SECONDS, queue, new RapidoidThreadFactory("executor", true)); }
public static synchronized String id() { if (state.uid == null) { state.uid = Conf.ROOT.entry("id").or(processName()); } return state.uid; }
public static String getContextPath(Req req) { return zone(req).entry("contextPath").or(""); }
public static String localUrl(String urlPath) { U.must(urlPath.startsWith("/"), "Invalid URL path, it must start with '/'!"); int port = Conf.ON.entry("port").or(8080); return Msc.http() + "://localhost:" + port + urlPath; }
private static ScheduledThreadPoolExecutor newScheduler() { int threads = CONFIG.entry("threads").or(64); return new ScheduledThreadPoolExecutor(threads, new RapidoidThreadFactory("scheduler", true)); }
private Map<String, Object> createRoot() { Map<String, Object> spec = Coll.deepCopyOf(cfg.toMap()); if (spec.isEmpty()) { Map<String, Object> info = U.map( "version", cfg.entry("version").or("0"), "title", cfg.entry("title").or("Untitled") ); spec.put("info", info); Map<String, Object> servers = U.map( "url", Msc.http() + "://localhost:" + Conf.ON.entry("port").or(8080) + "/" ); spec.put("servers", servers); } return spec; }
@Override public int port() { if (port == null) { port = serverConfig.entry("port").or(DEFAULT_PORT); } U.must(port >= 0, "The port of server setup '%s' is negative!", name()); return port; }
public JdbcWorkers(JdbcClient jdbc, BlockingQueue<Operation<Connection>> queue) { this.queue = queue; int workersN = Conf.JDBC.entry("workers").or(ConfigUtil.cpus()); long batchTimeMs = Conf.JDBC.entry("batchTimeMs").or(5000); this.workers = new JdbcWorker[workersN]; for (int i = 0; i < workers.length; i++) { workers[i] = new JdbcWorker(jdbc, queue, batchTimeMs); workers[i].start(); } Log.info("Started JDBC workers", "workers", workersN, "batchTimeMs", batchTimeMs); }
@Override public void authorize(UserInfo user) { Ctxs.required().setUser(user); req.token().put(Tokens._USER, user.username); long ttl = Conf.TOKEN.entry("ttl").or(0); long expiresOn = ttl > 0 ? U.time() + ttl : Long.MAX_VALUE; req.token().put(Tokens._EXPIRES, expiresOn); req.tokenChanged.set(true); }
@Override public String address() { if (address == null) { address = serverConfig.entry("address").or(DEFAULT_ADDRESS); } U.must(U.notEmpty(address), "The address of server setup '%s' is empty!", name()); return address; }
public ExtendedWorker(String name, RapidoidHelper helper, NetworkingParams net, SSLContext sslContext) { super(name); this.bufSize = net.bufSizeKB() * 1024; this.noDelay = net.noDelay(); this.bufs = new BufGroup(bufSize, net.syncBufs()); this.bufSizeLimit = 1024L * Conf.NET.entry("bufSizeLimit").or(1024); // in KB this.serverProtocol = net.protocol(); this.helper = helper; this.sslContext = sslContext; this.maxPipeline = net.maxPipeline(); final int queueSize = ConfigUtil.micro() ? 1000 : 1000000; final int growFactor = ConfigUtil.micro() ? 2 : 10; this.restarting = new ArrayBlockingQueue<>(queueSize); this.connecting = new ArrayBlockingQueue<>(queueSize); this.connected = new ArrayBlockingQueue<>(queueSize); this.done = new SimpleList<>(queueSize / 10, growFactor); this.dataIn = Insights.stats(name + ":datain"); this.dataOut = Insights.stats(name + ":dataout"); connections = Pools.create("connections", () -> newConnection(false), 100000); if (idleConnectionsCrawler != null) { idleConnectionsCrawler.register(allConnections); } }
protected Object page(Req req, Resp resp, Throwable error) { if (error instanceof SecurityException) { resp.model("embedded", req.attr("_embedded", false)); resp.model("req", req); resp.model("loginUri", Msc.specialUri("login")); return resp.code(403).view("login").mvc(true); } else { BasicConfig zone = HttpUtils.zone(req); String home = zone.entry("home").or("/"); Map<String, ?> errorInfo = HttpUtils.getErrorInfo(resp, error); resp.model("req", req); resp.model("error", errorInfo); resp.model("home", home); return resp.mvc(true).view("error"); } }
private static void activateRootConfig() { U.must(Env.isInitialized()); String root = Env.root(); if (U.notEmpty(root) && !APP.has("jar")) { APP.set("jar", Msc.path(root, "app.jar")); } String appJar = APP.entry("jar").str().getOrNull(); if (U.notEmpty(appJar)) { ClasspathUtil.appJar(appJar); } boolean fancyByDefault = Env.dev() || System.console() != null; Log.options().fancy(LOG.entry("fancy").bool().or(fancyByDefault)); LogLevel logLevel = LOG.entry("level").to(LogLevel.class).getOrNull(); if (logLevel != null && !Env.test()) { Log.setLogLevel(logLevel); } if (GlobalCfg.quiet()) { Log.setLogLevel(LogLevel.ERROR); // overwrite the configured log level in quiet mode } }
public void configure() { url(config.entry("url").str().getOrNull()); username(config.entry("username").str().getOrNull()); password(config.entry("password").str().getOrNull()); driver(config.entry("driver").str().getOrNull()); poolProvider(config.entry("poolProvider").or(DEFAULT_POOL_PROVIDER)); if (U.isEmpty(driver) && U.notEmpty(url)) { driver(inferDriverFromUrl(url)); } }
public Booter entities() { setup.page(uri("entities")) .internal(true) .roles(Role.ADMINISTRATOR) .zone(CENTER) .menu(50, "Application", 30, "Entities") .mvc(new EntitiesHandler()); if (MscOpts.hasJPA()) { for (Class<?> type : JPA.getEntityJavaTypes()) { String uri = GUI.typeUri(type); BasicConfig zone = HttpUtils.zone(setup.custom(), setup.zone()); String contextPath = zone.entry("home").or(uri("")); X.scaffold(type) .internal(true) .baseUri(Msc.uri(contextPath, uri)) .roles(Role.ADMINISTRATOR) .on(setup); } } return this; }
public JdbcWorkers(JdbcClient jdbc, BlockingQueue<Operation<Connection>> queue) { this.queue = queue; int workersN = Conf.JDBC.entry("workers").or(ConfigUtil.cpus()); long batchTimeMs = Conf.JDBC.entry("batchTimeMs").or(5000); this.workers = new JdbcWorker[workersN]; for (int i = 0; i < workers.length; i++) { workers[i] = new JdbcWorker(jdbc, queue, batchTimeMs); workers[i].start(); } Log.info("Started JDBC workers", "workers", workersN, "batchTimeMs", batchTimeMs); }
public String address() { if (address == null) { address = serverConfig.entry("address").or(DEFAULT_ADDRESS); } U.must(U.notEmpty(address), "The address of server setup '%s' is empty!", name()); return address; }
public void configure() { url(config.entry("url").str().getOrNull()); username(config.entry("username").str().getOrNull()); password(config.entry("password").str().getOrNull()); driver(config.entry("driver").str().getOrNull()); poolProvider(config.entry("poolProvider").or(DEFAULT_POOL_PROVIDER)); if (U.isEmpty(driver) && U.notEmpty(url)) { driver(inferDriverFromUrl(url)); } }