protected SimpleBucket<T> createBucket(int bucketSize, boolean unbounded) { U.must(unbounded, "Only unbounded buckets are supported!"); return new SimpleList<>(bucketSize); }
private void wantToWriteAsync(RapidoidConnection conn) { touch(conn); synchronized (done) { done.add(conn); } selector.wakeup(); }
@Override public String toString() { StringBuilder sb = new StringBuilder(); for (int i = 0; i < size; i++) { if (i > 0) { sb.append(", "); } sb.append(get(i)); } return "[" + sb.toString() + "]"; }
@Override protected synchronized void stopLoop() { super.stopLoop(); done.clear(); connected.clear(); connections.clear(); bufs.clear(); }
public Handler findHandler(Buf buf, Range action, Range path) { long hash = hash(buf.bytes(), action, path); SimpleList<Route> candidates = routes.get(hash); if (candidates != null) { for (int i = 0; i < candidates.size(); i++) { Route route = candidates.get(i); if (BytesUtil.matches(buf.bytes(), action, route.action, true) && BytesUtil.startsWith(buf.bytes(), path, route.path, true)) { int pos = path.start + route.path.length; if (path.limit() == pos || buf.get(pos) == '/') { return route.handler; } } } } return null; }
@Override public String toString() { StringBuilder sb = new StringBuilder(); for (int i = 0; i < size; i++) { if (i > 0) { sb.append(", "); } sb.append(get(i)); } return "[" + sb.toString() + "]"; }
@Override protected synchronized void stopLoop() { super.stopLoop(); done.clear(); connected.clear(); connections.clear(); bufs.clear(); }
private Handler findHandler(HttpExchangeImpl x) { Buf buf = x.input(); Range action = x.verb_().range(); Range path = x.path_().range(); // serveStaticFileIfExists(x, buf, path); long hash = hash(buf.bytes(), action, path); synchronized (this) { SimpleList<Route> candidates = routes.get(hash); candidates = routes.get(hash); if (candidates != null) { for (int i = 0; i < candidates.size(); i++) { Route route = candidates.get(i); if (BytesUtil.matches(buf.bytes(), action, route.action, true) && BytesUtil.startsWith(buf.bytes(), path, route.path, true)) { int pos = path.start + route.path.length; if (path.limit() == pos || buf.get(pos) == '/') { x.setSubpath(pos, path.limit()); return route.handler; } } } } if (genericHandler != null) { x.setSubpath(path.start, path.limit()); return genericHandler; } } throw x.notFound(); }
public RapidoidWorker(String name, final 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.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.connected = new ArrayBlockingQueue<>(queueSize); this.done = new SimpleList<>(queueSize / 10, growFactor); connections = Pools.create("connections", () -> newConnection(false), 100000); if (idleConnectionsCrawler != null) { idleConnectionsCrawler.register(allConnections); } }
private void wantToWriteAsync(RapidoidConnection conn) { touch(conn); synchronized (done) { done.add(conn); } selector.wakeup(); }
protected void clearBucket(int index) { bucket(index).clear(); }
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); } }
public void addRotating(T obj) { if (size < array.length) { add(obj); } else { array[position++] = obj; if (position >= array.length) { position = 0; } } }
protected SimpleList<T> newList(int initialBucketSize) { return new SimpleList<T>(initialBucketSize); }
private void wantToWriteAsync(RapidoidConnection conn) { synchronized (waitingToWrite) { waitingToWrite.add(conn); } selector.wakeup(); }
public RapidoidWorker(String name, final BufGroup bufs, final Protocol protocol, final RapidoidHelper helper, int bufSizeKB, boolean noNelay) { super(name); this.bufs = bufs; this.serverProtocol = protocol; this.helper = helper; this.maxPipelineSize = Conf.option("pipeline-max", 1000000L); this.selectorTimeout = Conf.option("selector-timeout", 5); this.bufSizeLimit = Conf.option("buffer-limit", 1024L * 1024); // 1 MB final int queueSize = Conf.micro() ? 1000 : 1000000; final int growFactor = Conf.micro() ? 2 : 10; this.restarting = new ArrayBlockingQueue<RapidoidConnection>(queueSize); this.connecting = new ArrayBlockingQueue<ConnectionTarget>(queueSize); this.connected = new ArrayBlockingQueue<RapidoidChannel>(queueSize); this.waitingToWrite = new SimpleList<RapidoidConnection>(queueSize / 10, growFactor); this.dataIn = Insights.stats(name + ":datain"); this.dataOut = Insights.stats(name + ":dataout"); connections = Pools.create("connections", new Callable<RapidoidConnection>() { @Override public RapidoidConnection call() throws Exception { return newConnection(); } }, 100000); this.bufSize = bufSizeKB * 1024; this.noDelay = noNelay; }