Tabnine Logo
OrderedMemoryAwareThreadPoolExecutor
Code IndexAdd Tabnine to your IDE (free)

How to use
OrderedMemoryAwareThreadPoolExecutor
in
org.jboss.netty.handler.execution

Best Java code snippets using org.jboss.netty.handler.execution.OrderedMemoryAwareThreadPoolExecutor (Showing top 18 results out of 315)

origin: menacher/java-game-server

public synchronized static ExecutionHandler getExecutionHandler()
{
  if(null == EXECUTION_HANDLER){
    EXECUTION_HANDLER = new ExecutionHandler( new OrderedMemoryAwareThreadPoolExecutor(16, 1048576, 1048576));
  }
  return EXECUTION_HANDLER;
}
 
origin: io.netty/netty

void onAfterExecute(Runnable r, Throwable t) {
  afterExecute(r, t);
}
origin: io.netty/netty

  beforeExecute(thread, task);
  try {
    task.run();
    ran = true;
    onAfterExecute(task, null);
  } catch (RuntimeException e) {
    if (!ran) {
      onAfterExecute(task, e);
doUnorderedExecute(this);
origin: com.proofpoint.platform/http-client-experimental

@SuppressWarnings("deprecation")
@PreDestroy
@Override
public void close()
{
  try {
    executor.shutdownNow();
  }
  catch (Exception e) {
    // ignored
  }
  Closeables.closeQuietly(nettyConnectionPool);
  try {
    timer.stop();
  }
  catch(Exception e) {
    // ignored
  }
}
origin: apache/james-project

@Override
protected void beforeExecute(Thread t, Runnable r) {
  super.beforeExecute(t, r);
  inProgress.add(r);
  startTime.set(System.currentTimeMillis());
}
origin: apache/james-project

@Override
public synchronized List<Runnable> shutdownNow() {
  // synchronized, because there is no way to access super.mainLock, which
  // would be
  // the preferred way to make this threadsafe
  if (!isShutdown()) {
    unregisterMBean();
  }
  return super.shutdownNow();
}
origin: resteasy/Resteasy

public HttpServerPipelineFactory(final RequestDispatcher dispatcher, final String root, final int executorThreadCount, final int maxRequestSize, final boolean isKeepAlive, final List<ChannelHandler> additionalChannelHandlers)
{
 this.resteasyDecoder = new RestEasyHttpRequestDecoder(dispatcher.getDispatcher(), root, getProtocol(), isKeepAlive);
 this.resteasyEncoder = new RestEasyHttpResponseEncoder(dispatcher);
 this.resteasyRequestHandler = new RequestHandler(dispatcher);
 if (executorThreadCount > 0)
 {
   this.executionHandler = new ExecutionHandler(new OrderedMemoryAwareThreadPoolExecutor(executorThreadCount, 0L, 0L));
 }
 else
 {
   this.executionHandler = null;
 }
 this.maxRequestSize = maxRequestSize;
 this.additionalChannelHandlers = additionalChannelHandlers;
}
origin: apache/james-project

@Override
protected void afterExecute(Runnable r, Throwable t) {
  long time = System.currentTimeMillis() - startTime.get();
  synchronized (this) {
    totalTime += time;
    ++totalTasks;
  }
  inProgress.remove(r);
  super.afterExecute(r, t);
}
origin: org.openmobster.core/dataService

public TextProtocolPipelineFactory()
{
  this.eventExecutor = new OrderedMemoryAwareThreadPoolExecutor(5, 1000000, 10000000, 100,
  TimeUnit.MILLISECONDS);
}

origin: org.apache.james.protocols/protocols-netty

protected ExecutionHandler createExecutionHandler(int size) {
  return new ExecutionHandler(new OrderedMemoryAwareThreadPoolExecutor(size, 0, 0));
}

origin: apache/james-project

protected ExecutionHandler createExecutionHandler(int size) {
  return new ExecutionHandler(new OrderedMemoryAwareThreadPoolExecutor(size, 0, 0));
}

origin: org.jboss.resteasy/resteasy-netty

public HttpServerPipelineFactory(RequestDispatcher dispatcher, String root, int executorThreadCount, int maxRequestSize, boolean isKeepAlive, List<ChannelHandler> additionalChannelHandlers)
{
 this.resteasyDecoder = new RestEasyHttpRequestDecoder(dispatcher.getDispatcher(), root, getProtocol(), isKeepAlive);
 this.resteasyEncoder = new RestEasyHttpResponseEncoder(dispatcher);
 this.resteasyRequestHandler = new RequestHandler(dispatcher);
 if (executorThreadCount > 0) 
 {
   this.executionHandler = new ExecutionHandler(new OrderedMemoryAwareThreadPoolExecutor(executorThreadCount, 0L, 0L));
 } 
 else 
 {
   this.executionHandler = null;
 }
 this.maxRequestSize = maxRequestSize;
 this.additionalChannelHandlers = additionalChannelHandlers;
}
origin: com.proofpoint.platform/http-client-experimental

this.executor = new OrderedMemoryAwareThreadPoolExecutor(asyncConfig.getWorkerThreads(), 0, 0, 30, TimeUnit.SECONDS, workerThreadFactory);
origin: org.apache.camel/camel-netty

protected OrderedMemoryAwareThreadPoolExecutor createExecutorService() {
  // use ordered thread pool, to ensure we process the events in order, and can send back
  // replies in the expected order. eg this is required by TCP.
  // and use a Camel thread factory so we have consistent thread namings
  // we should use a shared thread pool as recommended by Netty
  
  // NOTE: if we don't specify the MaxChannelMemorySize and MaxTotalMemorySize, the thread pool
  // could eat up all the heap memory when the tasks are added very fast
  
  String pattern = getCamelContext().getExecutorServiceManager().getThreadNamePattern();
  ThreadFactory factory = new CamelThreadFactory(pattern, "NettyOrderedWorker", true);
  return new OrderedMemoryAwareThreadPoolExecutor(getMaximumPoolSize(),
      configuration.getMaxChannelMemorySize(), configuration.getMaxTotalMemorySize(),
      30, TimeUnit.SECONDS, factory);
}
origin: org.graylog2/graylog2-shared

new OrderedMemoryAwareThreadPoolExecutor(
    configuration.getRestThreadPoolSize(),
    1048576,
origin: xose/netty-xmpp

@Override
protected void startUp() throws Exception {
  executionHandler = new ExecutionHandler(new OrderedMemoryAwareThreadPoolExecutor(4, 0, 0));
  bootstrap = new ClientBootstrap(new NioClientSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));
  bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
    @Override
    public ChannelPipeline getPipeline() throws Exception {
      final ChannelPipeline pipeline = Channels.pipeline();
      //pipeline.addLast("logger", new LoggingHandler(InternalLogLevel.INFO));
      pipeline.addLast("xmlFramer", new XMLFrameDecoder());
      pipeline.addLast("xmlDecoder", new XMLElementDecoder());
      pipeline.addLast("xmppDecoder", new XEP0114Decoder(xmppHost, xmppSecret));
      pipeline.addLast("executor", executionHandler);
      pipeline.addLast("xmppHandler", new XMPPStreamHandler(component));
      return pipeline;
    }
  });
  final ChannelFuture future = bootstrap.connect(serverAddress).await();
  if (!future.isSuccess()) {
    bootstrap.releaseExternalResources();
    executionHandler.releaseExternalResources();
    future.rethrowIfFailed();
  }
  channel = future.getChannel();
  component.init(channel, JID.jid("localhost"), JID.jid(xmppHost)); // FIXME
}
origin: os-libera/OpenVirteX

public OpenVirteXController(CmdLineSettings settings) {
  this.ofHost = settings.getOFHost();
  this.ofPort = settings.getOFPort();
  this.dbHost = settings.getDBHost();
  this.dbPort = settings.getDBPort();
  this.dbClear = settings.getDBClear();
  this.maxVirtual = settings.getNumberOfVirtualNets();
  this.statsRefresh = settings.getStatsRefresh();
  this.nClientThreads = settings.getClientThreads();
  this.nServerThreads = settings.getServerThreads();
  this.useBDDP = settings.getUseBDDP();
  // by default, use Mac addresses to store vLinks informations
  this.ovxLinkField = OVXLinkField.MAC_ADDRESS;
  this.clientThreads = new OrderedMemoryAwareThreadPoolExecutor(
      nClientThreads, 1048576, 1048576, 5, TimeUnit.SECONDS);
  this.serverThreads = new OrderedMemoryAwareThreadPoolExecutor(
      nServerThreads, 1048576, 1048576, 5, TimeUnit.SECONDS);
  this.pfact = new SwitchChannelPipeline(this, this.serverThreads);
  OpenVirteXController.instance = this;
  OpenVirteXController.tenantIdCounter = new BitSetIndex(
      IndexType.TENANT_ID);
}
origin: kakaochatfriend/KakaoChatFriendAPI

  new OrderedMemoryAwareThreadPoolExecutor( coreThreadCnt, maxMemory, maxMemory);
final ExecutionHandler executionHandler = new ExecutionHandler(executor);
  new OrderedMemoryAwareThreadPoolExecutor( coreThreadCnt, maxMemory, maxMemory);
final ExecutionHandler executionHandler2 = new ExecutionHandler(executor2);
org.jboss.netty.handler.executionOrderedMemoryAwareThreadPoolExecutor

Javadoc

A MemoryAwareThreadPoolExecutor which makes sure the events from the same Channel are executed sequentially.

NOTE: This thread pool inherits most characteristics of its super type, so please make sure to refer to MemoryAwareThreadPoolExecutorto understand how it works basically.

Event execution order

For example, let's say there are two executor threads that handle the events from the two channels:
 
-------------------------------------> Timeline ------------------------------------> 
Thread X: --- Channel A (Event A1) --.   .-- Channel B (Event B2) --- Channel B (Event B3) ---> 
\ / 
X 
/ \ 
Thread Y: --- Channel B (Event B1) --'   '-- Channel A (Event A2) --- Channel A (Event A3) ---> 
As you see, the events from different channels are independent from each other. That is, an event of Channel B will not be blocked by an event of Channel A and vice versa, unless the thread pool is exhausted.

Also, it is guaranteed that the invocation will be made sequentially for the events from the same channel. For example, the event A2 is never executed before the event A1 is finished. (Although not recommended, if you want the events from the same channel to be executed simultaneously, please use MemoryAwareThreadPoolExecutor instead.)

However, it is not guaranteed that the invocation will be made by the same thread for the same channel. The events from the same channel can be executed by different threads. For example, the Event A2 is executed by the thread Y while the event A1 was executed by the thread X.

Using a different key other than Channel to maintain event order

OrderedMemoryAwareThreadPoolExecutor uses a Channel as a key that is used for maintaining the event execution order, as explained in the previous section. Alternatively, you can extend it to change its behavior. For example, you can change the key to the remote IP of the peer:

 
public class RemoteAddressBasedOMATPE extends  
OrderedMemoryAwareThreadPoolExecutor { 
... Constructors ... 
 @Overrideprotected ConcurrentMap<Object, Executor> newChildExecutorMap() { 
// The default implementation returns a special ConcurrentMap that 
// uses identity comparison only (see  
IdentityHashMap). 
// Because SocketAddress does not work with identity comparison, 
// we need to employ more generic implementation. 
return new ConcurrentHashMap<Object, Executor> 
} 
protected Object getChildExecutorKey( 
ChannelEvent e) { 
// Use the IP of the remote peer as a key. 
return ((InetSocketAddress) e.getChannel().getRemoteAddress()).getAddress(); 
} 
// Make public so that you can call from anywhere. 
public boolean removeChildExecutor(Object key) { 
super.removeChildExecutor(key); 
} 
} 
Please be very careful of memory leak of the child executor map. You must call #removeChildExecutor(Object) when the life cycle of the key ends (e.g. all connections from the same IP were closed.) Also, please keep in mind that the key can appear again after calling #removeChildExecutor(Object)(e.g. a new connection could come in from the same old IP after removal.) If in doubt, prune the old unused or stall keys from the child executor map periodically:
 
RemoteAddressBasedOMATPE executor = ...; 
on every 3 seconds: 
for (Iterator<Object> i = executor.getChildExecutorKeySet().iterator; i.hasNext();) { 
InetAddress ip = (InetAddress) i.next(); 
if (there is no active connection from 'ip' now && 
there has been no incoming connection from 'ip' for last 10 minutes) { 
i.remove(); 
} 
} 
If the expected maximum number of keys is small and deterministic, you could use a weak key map such as ConcurrentWeakHashMap or synchronized WeakHashMap instead of managing the life cycle of the keys by yourself.

Most used methods

  • <init>
    Creates a new instance.
  • afterExecute
  • beforeExecute
  • shutdownNow
  • doUnorderedExecute
  • getChildExecutor
  • getChildExecutorKey
  • onAfterExecute
  • removeChildExecutor
  • shutdown

Popular in Java

  • Making http requests using okhttp
  • scheduleAtFixedRate (ScheduledExecutorService)
  • getResourceAsStream (ClassLoader)
  • runOnUiThread (Activity)
  • Point (java.awt)
    A point representing a location in (x,y) coordinate space, specified in integer precision.
  • FileNotFoundException (java.io)
    Thrown when a file specified by a program cannot be found.
  • Selector (java.nio.channels)
    A controller for the selection of SelectableChannel objects. Selectable channels can be registered w
  • Queue (java.util)
    A collection designed for holding elements prior to processing. Besides basic java.util.Collection o
  • JFileChooser (javax.swing)
  • DateTimeFormat (org.joda.time.format)
    Factory that creates instances of DateTimeFormatter from patterns and styles. Datetime formatting i
  • Top 12 Jupyter Notebook extensions
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now