protected int doClearRead() throws IOException{ Utils.Result r = Utils.readWithTemporarySelector(key.channel(), byteBuffer, readTimeout); byteBuffer.flip(); isClosed = r.isClosed; return r.bytesRead; }
/** * Introspect the request and determine if the target url can * execute under {@link AsyncHandler} or not. * @param bb The current byteBuffer. * @param handlerCode - no used. * @return An {@link Interceptor} value determining if an {@link AsyncHandler} * should be allowed to execute or not. * @throws java.io.IOException */ public int handle(ByteBuffer bb, int handlerCode) throws IOException { int pos = bb.position(); int limit = bb.limit(); try{ // TODO: Add patten matching. for (byte[] b: allowed){ if (Utils.findBytes(bb,b) > -1){ return Interceptor.CONTINUE; } } } finally { bb.position(pos); bb.limit(limit); } return Interceptor.BREAK; }
public static List<String> toHexStrings(byte[] bytes) { return toHexStrings(bytes, 0, bytes.length); }
/** * Please ensure to use try finally around get and return of selector so avoid leaks. * Get a exclusive {@link Selector} * @return {@link Selector} */ public static Selector getSelector() { Selector selector = selectors.poll(); if (selector != null) { poolSize.decrementAndGet(); } else { try { selector = Utils.openSelector(); } catch (IOException e) { LoggerUtils.getLogger().log(Level.WARNING, "SelectorFactory. Can not create a selector", e); } final int missesCount = missesCounter.incrementAndGet(); if (missesCount % MISS_THRESHOLD == 0) { LoggerUtils.getLogger().log(Level.WARNING, "SelectorFactory. Pool encounters a lot of misses {0}. " + "Increase default {1} pool size", new Object[] {missesCount, maxSelectors}); } } return selector; }
/** * Configures an HTTP grizzlyListener with the given request-processing config. */ private void configureThreadPool(NetworkListener networkListener, ThreadPool threadPool, final String transactionTimeoutSec) { if (threadPool == null) { return; } try { final int maxQueueSize = Integer.parseInt(threadPool.getMaxQueueSize()); final int minThreads = Integer.parseInt(threadPool.getMinThreadPoolSize()); final int maxThreads = Integer.parseInt(threadPool.getMaxThreadPoolSize()); final int keepAlive = Integer.parseInt(threadPool.getIdleThreadTimeoutSeconds()); final int ttSec = Integer.parseInt(transactionTimeoutSec); final String name = Utils.composeThreadPoolName(networkListener); setThreadPool(newThreadPool(name, minThreads, maxThreads, maxQueueSize, keepAlive < 0 ? Long.MAX_VALUE : keepAlive * 1000, TimeUnit.MILLISECONDS)); setCoreThreads(minThreads); setMaxThreads(maxThreads); if (!com.sun.grizzly.util.Utils.isDebugVM() && ttSec > 0) { // Idle Threads cannot be alive more than 15 minutes by default setTransactionTimeout(ttSec * 1000); } else { // Disable the mechanism setTransactionTimeout(-1); } } catch (NumberFormatException ex) { logger.log(Level.WARNING, " Invalid thread-pool attribute", ex); } }
protected int doClearRead() throws IOException{ int bytesRead = Utils.readWithTemporarySelector(key.channel(), byteBuffer, readTimeout); byteBuffer.flip(); return bytesRead; }
private List<String> getByteList(final int start, final int end) { return Utils.toHexStrings(chunk.getBytes(), start, end); }
while(iterator.hasNext()){ matchBytes = iterator.next(); if (Utils.findBytes(bb,matchBytes) > -1){ log("Find match: " + (new String(matchBytes)) + " Suspending: " + ctx.getSelectionKey());
protected int doClearRead() throws IOException{ int bytesRead = Utils.readWithTemporarySelector(key.channel(), byteBuffer, readTimeout); byteBuffer.flip(); return bytesRead; }
int bytesRead = Utils.readWithTemporarySelector(channel, inputBB, timeout);
int bytesRead = Utils.readWithTemporarySelector(channel, inputBB, timeout);
r = Utils.readWithTemporarySelector(channel, inputBB, timeout);
int count = Utils.readWithTemporarySelector( protocolRequest.getChannel(), tmpBuffer, 20).bytesRead; if (count == -1) {
return Utils.readWithTemporarySelector(key.channel(), thread.getByteBuffer(), timeout).bytesRead; } else {
int count = Utils.readWithTemporarySelector( protocolRequest.getChannel(), tmpBuffer, 2); if (count == -1) {
Utils.Result result = null; try { result = Utils.readWithTemporarySelector(channel, bb, 20); } catch (Exception ignored) {
int bytesRead = Utils.readWithTemporarySelector( selectionKey.channel(), protocolRequest.getByteBuffer(), readTimeout);
bytesRead = Utils.readWithTemporarySelector( selectionKey.channel(), protocolRequest.getByteBuffer(), readTimeout).bytesRead;
int bytesRead = Utils.readWithTemporarySelector( selectionKey.channel(), protocolRequest.getByteBuffer(), readTimeout);