/** * Creates an instance of WorkerThreadImpl. * * @param name {@link String} * @param initialByteBufferSize initial {@link ByteBuffer} size */ protected WorkerThreadImpl createWorkerThread(String name, int initialByteBufferSize) { return new WorkerThreadImpl(this, name, initialByteBufferSize); } }
@Override protected void afterExecute(Runnable r, Throwable t) { ((WorkerThreadImpl) Thread.currentThread()).reset(); }
/** * Create a new {@link WorkerThread}. * @param r a Runabble * @return */ public Thread newThread(Runnable r){ WorkerThreadImpl t = new WorkerThreadImpl(threadGroup, r); t.setDaemon(true); return t; }
public Thread newThread(Runnable r) { WorkerThreadImpl workerThread = new WorkerThreadImpl(threadPool, threadPool.name + "WorkerThread-" + threadPool.port + "-" + threadPool.workerThreadCounter.getAndIncrement(), r, threadPool.initialByteBufferSize); workerThread.setByteBufferType(threadPool.byteBufferType); workerThread.setPriority(threadPool.priority); return workerThread; } }
/** * Start using the Controller's internal Thread Pool. */ public void start() { if (port == 0){ selectorThreads.put(getSelectorThreadLookupKey(inet, port), this); } new WorkerThreadImpl("SelectorThread-" + port,this).start(); }
public ThreadAttachment detach() { ThreadAttachment currentAttachment = getAttachment(); int mode = currentAttachment.getMode(); updateAttachment(mode); // Re-create a new ByteBuffer if ((mode & Mode.BYTE_BUFFER) != 0) { createByteBuffer(true); } if ((mode & Mode.SSL_ENGINE) != 0) { sslEngine = null; } if ((mode & Mode.INPUT_BB) != 0) { inputBB = null; } if ((mode & Mode.OUTPUT_BB) != 0) { outputBB = null; } // Switch to the new ThreadAttachment. this.threadAttachment = null; currentAttachment.deassociate(); return currentAttachment; }
public ThreadAttachment detach() { ThreadAttachment currentAttachment = getAttachment(); int mode = currentAttachment.getMode(); updateAttachment(mode); // Re-create a new ByteBuffer if ((mode & Mode.BYTE_BUFFER) != 0) { byteBuffer = null; } if ((mode & Mode.SSL_ENGINE) != 0) { sslEngine = null; } if ((mode & Mode.INPUT_BB) != 0) { inputBB = null; } if ((mode & Mode.OUTPUT_BB) != 0) { outputBB = null; } // Switch to the new ThreadAttachment. this.threadAttachment = null; currentAttachment.deassociate(); return currentAttachment; }
/** * Create new {@link WorkerThreadImpl}. This method must be invoked * from a synchronized block. * @param increment - how many additional {@link WorkerThreadImpl} * objects to add * @param startThread - should newly added {@link WorkerThreadImpl} * objects be started after creation? */ protected void increaseWorkerThread(int increment, boolean startThread){ WorkerThreadImpl workerThread; int currentCount = threadCount; int increaseCount = threadCount + increment; for (int i=currentCount; i < increaseCount; i++){ workerThread = createWorkerThread( name + "WorkerThread-" + port + "-" + i, initialByteBufferSize); workerThread.setByteBufferType(byteBufferType); workerThread.setPriority(priority); if (startThread) workerThread.start(); workerThreads[i] = workerThread; threadCount++; } }
/** * Create a Thread that will synchronizes/block on * {@link DefaultThreadPool} instance. * @param threadGroup <code>ThreadGroup</code> * @param runnable <code>Runnable</code> * @param initialByteBufferSize initial {@link ByteBuffer} size */ public WorkerThreadImpl(ThreadGroup threadGroup, Runnable runnable, int initialByteBufferSize){ super(threadGroup, runnable); setDaemon(true); this.initialByteBufferSize = initialByteBufferSize; }
processTask(t); t = null; } catch (Throwable t) { reset();
public ThreadAttachment updateAttachment(int mode) { ThreadAttachment currentAttachment = getAttachment(); currentAttachment.reset(); if ((mode & Mode.BYTE_BUFFER) != 0) { currentAttachment.setByteBuffer(byteBuffer); } if ((mode & Mode.SSL_ENGINE) != 0) { currentAttachment.setSSLEngine(sslEngine); } if ((mode & Mode.INPUT_BB) != 0) { currentAttachment.setInputBB(inputBB); } if ((mode & Mode.OUTPUT_BB) != 0) { currentAttachment.setOutputBB(outputBB); } currentAttachment.setMode(mode); return currentAttachment; }
/** * Start the {@link Pipeline} and all associated * {@link WorkerThreadImpl} */ public synchronized void startPipeline(){ if (!isStarted) { for (int i=0; i < minThreads; i++){ workerThreads[i].start(); } isStarted = true; } }
/** * must hold statelock while calling this method. * @param wt */ protected void startWorker(Worker wt) { final Thread thread = threadFactory.newThread(wt); thread.setName(getName() + "(" + nextThreadId() + ")"); thread.setUncaughtExceptionHandler(this); thread.setPriority(getPriority()); thread.setDaemon(true); if (thread instanceof WorkerThreadImpl) { final WorkerThreadImpl workerThread = (WorkerThreadImpl) thread; workerThread.setByteBufferType(getByteBufferType()); workerThread.setInitialByteBufferSize(getInitialByteBufferSize()); } wt.t = thread; workers.put(wt, System.currentTimeMillis()); wt.t.start(); }
@Override protected void beforeExecute(Thread t, Runnable r) { ((WorkerThreadImpl) t).createByteBuffer(false); }
new WorkerThreadImpl("ControllerWorker", controller).start();
public ThreadAttachment detach() { ThreadAttachment currentAttachment = getAttachment(); int mode = currentAttachment.getMode(); updateAttachment(mode); // Re-create a new ByteBuffer if ((mode & Mode.BYTE_BUFFER) != 0) { byteBuffer = ByteBufferFactory.allocate(byteBufferType, initialByteBufferSize); } if ((mode & Mode.SSL_ENGINE) != 0) { sslEngine = null; } if ((mode & Mode.INPUT_BB) != 0) { inputBB = null; } if ((mode & Mode.OUTPUT_BB) != 0) { outputBB = null; } // Switch to the new ThreadAttachment. this.threadAttachment = null; currentAttachment.deassociate(); return currentAttachment; }
/** * Create a Thread that will synchronizes/block on * {@link DefaultThreadPool} instance. * @param threadPool {@link DefaultThreadPool} * @param name <code>String</code> * @param initialByteBufferSize initial {@link ByteBuffer} size */ public WorkerThreadImpl(DefaultThreadPool threadPool, String name, int initialByteBufferSize){ super(threadGroup, name); this.threadPool = threadPool; setDaemon(true); this.initialByteBufferSize = initialByteBufferSize; }
public ThreadAttachment updateAttachment(int mode) { ThreadAttachment currentAttachment = getAttachment(); currentAttachment.reset(); if ((mode & Mode.BYTE_BUFFER) != 0) { currentAttachment.setByteBuffer(byteBuffer); } if ((mode & Mode.SSL_ENGINE) != 0) { currentAttachment.setSSLEngine(sslEngine); } if ((mode & Mode.INPUT_BB) != 0) { currentAttachment.setInputBB(inputBB); } if ((mode & Mode.OUTPUT_BB) != 0) { currentAttachment.setOutputBB(outputBB); } currentAttachment.setMode(mode); return currentAttachment; }
/** * Method invoked prior to executing the given Runnable in the * given thread. This method is invoked by thread <tt>t</tt> that * will execute task <tt>r</tt>, and may be used to re-initialize * ThreadLocals, or to perform logging. * * <p>This implementation does nothing, but may be customized in * subclasses. Note: To properly nest multiple overridings, subclasses * should generally invoke <tt>super.beforeExecute</tt> at the end of * this method. * * @param t the thread that will run task r. * @param r the task that will be executed. */ protected void beforeExecute(Thread t, Runnable r) { if (t instanceof WorkerThreadImpl) ((WorkerThreadImpl) t).createByteBuffer(false); }
public Thread newThread(Runnable r) { return new WorkerThreadImpl(new ThreadGroup("Grizzly"),r); } });