@SuppressWarnings("unchecked") @Override public synchronized void deserializeCookiepack(byte[] bytes) { cookiepack = (Map<String, Serializable>) UTILS.deserialize(bytes); }
@Override public synchronized byte[] serializeCookiepack() { return cookiepack != null ? UTILS.serialize(cookiepack) : null; }
public static void benchmarkMT(int threadsN, final String name, final int count, final Runnable runnable) { benchmarkMT(threadsN, name, count, null, runnable); }
@Override public Void execute(BufferedReader in, DataOutputStream out) throws Exception { List<String> lines = new ArrayList<String>(); String line; while ((line = in.readLine()) != null) { if (line.isEmpty()) { break; } lines.add(line); } if (!lines.isEmpty()) { String req = lines.get(0); if (req.startsWith("GET /")) { int pos = req.indexOf(' ', 4); String path = urlDecode(req.substring(4, pos)); String response = handler.execute(path, lines); out.writeBytes(response); } else { out.writeBytes("Only GET requests are supported!"); } } else { out.writeBytes("Invalid HTTP request!"); } return null; }
public static void benchmark(String name, int count, Runnable runnable) { long start = U.time(); for (int i = 0; i < count; i++) { runnable.run(); } benchmarkComplete(name, count, start); }
long prefix = UTILS.intFrom(b0, b1, b2, b3);
public static String fillIn(String template, Object... namesAndValues) { String text = template.toString(); for (int i = 0; i < namesAndValues.length / 2; i++) { String placeholder = (String) namesAndValues[i * 2]; String value = Cls.str(namesAndValues[i * 2 + 1]); text = fillIn(text, placeholder, value); } return text; }
public void run() { Ctxs.attach(ctx != null ? ctx.span() : null); try { benchmark(name, countPerThread, runnable); if (outsideLatch == null) { latch.countDown(); } } finally { if (ctx != null) { Ctxs.close(); } } }; }.start();
@Override public String get(String name) { Buf buf = src.buffer(); Range range = ranges.get(buf, name.getBytes(), false); return range != null ? UTILS.urlDecode(range.str(buf)) : null; }
public static void benchmarkMT(int threadsN, final String name, final int count, final CountDownLatch outsideLatch, final Runnable runnable) { final int countPerThread = count / threadsN; final CountDownLatch latch = outsideLatch != null ? outsideLatch : new CountDownLatch(threadsN); long time = U.time(); final Ctx ctx = Ctxs.get(); for (int i = 1; i <= threadsN; i++) { new Thread() { public void run() { Ctxs.attach(ctx != null ? ctx.span() : null); try { benchmark(name, countPerThread, runnable); if (outsideLatch == null) { latch.countDown(); } } finally { if (ctx != null) { Ctxs.close(); } } }; }.start(); } try { latch.await(); } catch (InterruptedException e) { throw U.rte(e); } benchmarkComplete("avg(" + name + ")", threadsN * countPerThread, time); }
long prefix = UTILS.intFrom(b0, b1, b2, b3);
public Map<String, String> toMap(Buf src, boolean urlDecodeKeys, boolean urlDecodeVals) { Map<String, String> map = U.map(); for (int i = 0; i < count; i++) { String key = keys[i].str(src.bytes()); String val = values[i].str(src.bytes()); if (urlDecodeKeys) { key = UTILS.urlDecode(key); } if (urlDecodeVals) { val = UTILS.urlDecode(val); } map.put(key, val); } return map; }
@SuppressWarnings("unchecked") @Override public synchronized void deserializeLocals(byte[] bytes) { locals = (Map<String, Serializable>) UTILS.deserialize(bytes); }
@Override public synchronized byte[] serializeLocals() { return locals != null ? UTILS.serialize(locals) : null; }
public Map<String, byte[]> toBinaryMap(Buf src, boolean urlDecodeKeys) { Map<String, byte[]> map = U.map(); for (int i = 0; i < count; i++) { String key = keys[i].str(src.bytes()); byte[] val = values[i].bytes(src); if (urlDecodeKeys) { key = UTILS.urlDecode(key); } map.put(key, val); } return map; }
public static Object deserialize(ByteBuffer buf) { int len = buf.getInt(); byte[] bytes = new byte[len]; buf.get(bytes); return deserialize(bytes); }
public static void serialize(Object value, ByteBuffer buf) { byte[] bytes = serialize(value); buf.putInt(bytes.length); buf.put(bytes); }
@Override public String get() { return !range.isEmpty() ? UTILS.urlDecode(src.buffer().get(range)) : ""; }
return deserialize(buf);