List of usage examples for java.util.concurrent RejectedExecutionException RejectedExecutionException
public RejectedExecutionException()
From source file:com.l2jfree.util.concurrent.L2RejectedExecutionHandler.java
@Override public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) { if (executor.isShutdown()) return;/*w ww . j a v a 2 s. c o m*/ _log.warn(r + " from " + executor, new RejectedExecutionException()); if (Thread.currentThread().getPriority() > Thread.NORM_PRIORITY) new Thread(r).start(); else r.run(); }
From source file:io.kahu.hawaii.util.call.dispatch.HawaiiRejectedExecutionHandler.java
@Override public void rejectedExecution(Runnable task, ThreadPoolExecutor executor) { /*//from w w w. jav a 2 s . c o m * This does the actual put into the queue. Once the max threads have * been reached, the tasks will then queue up. */ try { executor.getQueue().add(task); } catch (IllegalStateException e) { try { ((HawaiiExecutorImpl) executor).rejectTask(); if (delegate != null) { delegate.rejectedExecution(task, executor); } } finally { logManager.info(CoreLoggers.SERVER, "Rejected '" + task + "' since the pool and queue size has been exceeded."); throw new RejectedExecutionException(); } } }
From source file:org.apache.camel.component.jms.JmsProducer.java
public boolean process(Exchange exchange, AsyncCallback callback) { // deny processing if we are not started if (!isRunAllowed()) { if (exchange.getException() == null) { exchange.setException(new RejectedExecutionException()); }//from w ww. ja v a 2 s . c o m // we cannot process so invoke callback callback.done(true); return true; } if (!endpoint.isDisableReplyTo() && exchange.getPattern().isOutCapable()) { // in out requires a bit more work than in only return processInOut(exchange, callback); } else { // in only return processInOnly(exchange, callback); } }
From source file:org.ros.concurrent.RetryingExecutorService.java
/** * Submit a new {@link Callable} to be executed. The submitted * {@link Callable} should return {@code true} to be retried, {@code false} * otherwise.//from w w w . j a va2s .c om * * @param callable * the {@link Callable} to execute * @throws RejectedExecutionException * if the {@link RetryingExecutorService} is shutting down */ public void submit(Callable<Boolean> callable) { synchronized (mutex) { if (running) { Future<Boolean> future = completionService.submit(callable); latches.put(callable, new CountDownLatch(1)); callables.put(future, callable); } else { throw new RejectedExecutionException(); } } }
From source file:org.apache.camel.component.netty4.NettyProducer.java
public boolean process(final Exchange exchange, AsyncCallback callback) { if (!isRunAllowed()) { if (exchange.getException() == null) { exchange.setException(new RejectedExecutionException()); }/*from w w w. j a va2s . c om*/ callback.done(true); return true; } Object body; try { body = getRequestBody(exchange); if (body == null) { noReplyLogger.log("No payload to send for exchange: " + exchange); callback.done(true); return true; } } catch (Exception e) { exchange.setException(e); callback.done(true); return true; } // set the exchange encoding property if (getConfiguration().getCharsetName() != null) { exchange.setProperty(Exchange.CHARSET_NAME, IOHelper.normalizeCharset(getConfiguration().getCharsetName())); } if (LOG.isTraceEnabled()) { LOG.trace("Pool[active={}, idle={}]", pool.getNumActive(), pool.getNumIdle()); } // get a channel from the pool Channel existing; try { existing = pool.borrowObject(); if (existing != null) { LOG.trace("Got channel from pool {}", existing); } } catch (Exception e) { exchange.setException(e); callback.done(true); return true; } // we must have a channel if (existing == null) { exchange.setException(new CamelExchangeException("Cannot get channel from pool", exchange)); callback.done(true); return true; } // need to declare as final final Channel channel = existing; final AsyncCallback producerCallback = new NettyProducerCallback(channel, callback); // setup state as attachment on the channel, so we can access the state later when needed putState(channel, new NettyCamelState(producerCallback, exchange)); // here we need to setup the remote address information here InetSocketAddress remoteAddress = null; if (!isTcp()) { remoteAddress = new InetSocketAddress(configuration.getHost(), configuration.getPort()); } // write body NettyHelper.writeBodyAsync(LOG, channel, remoteAddress, body, exchange, new ChannelFutureListener() { public void operationComplete(ChannelFuture channelFuture) throws Exception { LOG.trace("Operation complete {}", channelFuture); if (!channelFuture.isSuccess()) { // no success the set the caused exception and signal callback and break exchange.setException(channelFuture.cause()); producerCallback.done(false); return; } // if we do not expect any reply then signal callback to continue routing if (!configuration.isSync()) { try { // should channel be closed after complete? Boolean close; if (ExchangeHelper.isOutCapable(exchange)) { close = exchange.getOut().getHeader(NettyConstants.NETTY_CLOSE_CHANNEL_WHEN_COMPLETE, Boolean.class); } else { close = exchange.getIn().getHeader(NettyConstants.NETTY_CLOSE_CHANNEL_WHEN_COMPLETE, Boolean.class); } // should we disconnect, the header can override the configuration boolean disconnect = getConfiguration().isDisconnect(); if (close != null) { disconnect = close; } if (disconnect) { if (LOG.isTraceEnabled()) { LOG.trace("Closing channel when complete at address: {}", getEndpoint().getConfiguration().getAddress()); } NettyHelper.close(channel); } } finally { // signal callback to continue routing producerCallback.done(false); } } } }); // continue routing asynchronously return false; }
From source file:org.apache.camel.component.netty.NettyProducer.java
public boolean process(final Exchange exchange, AsyncCallback callback) { if (!isRunAllowed()) { if (exchange.getException() == null) { exchange.setException(new RejectedExecutionException()); }/*from w w w . jav a2 s .c o m*/ callback.done(true); return true; } Object body; try { body = getRequestBody(exchange); if (body == null) { noReplyLogger.log("No payload to send for exchange: " + exchange); callback.done(true); return true; } } catch (Exception e) { exchange.setException(e); callback.done(true); return true; } // set the exchange encoding property if (getConfiguration().getCharsetName() != null) { exchange.setProperty(Exchange.CHARSET_NAME, IOHelper.normalizeCharset(getConfiguration().getCharsetName())); } if (LOG.isTraceEnabled()) { LOG.trace("Pool[active={}, idle={}]", pool.getNumActive(), pool.getNumIdle()); } // get a channel from the pool Channel existing; try { existing = pool.borrowObject(); if (existing != null) { LOG.trace("Got channel from pool {}", existing); } } catch (Exception e) { exchange.setException(e); callback.done(true); return true; } // we must have a channel if (existing == null) { exchange.setException(new CamelExchangeException("Cannot get channel from pool", exchange)); callback.done(true); return true; } // need to declare as final final Channel channel = existing; final AsyncCallback producerCallback = new NettyProducerCallback(channel, callback); // setup state as attachment on the channel, so we can access the state later when needed channel.setAttachment(new NettyCamelState(producerCallback, exchange)); // write body NettyHelper.writeBodyAsync(LOG, channel, null, body, exchange, new ChannelFutureListener() { public void operationComplete(ChannelFuture channelFuture) throws Exception { LOG.trace("Operation complete {}", channelFuture); if (!channelFuture.isSuccess()) { // no success the set the caused exception and signal callback and break exchange.setException(channelFuture.getCause()); producerCallback.done(false); return; } // if we do not expect any reply then signal callback to continue routing if (!configuration.isSync()) { try { // should channel be closed after complete? Boolean close; if (ExchangeHelper.isOutCapable(exchange)) { close = exchange.getOut().getHeader(NettyConstants.NETTY_CLOSE_CHANNEL_WHEN_COMPLETE, Boolean.class); } else { close = exchange.getIn().getHeader(NettyConstants.NETTY_CLOSE_CHANNEL_WHEN_COMPLETE, Boolean.class); } // should we disconnect, the header can override the configuration boolean disconnect = getConfiguration().isDisconnect(); if (close != null) { disconnect = close; } if (disconnect) { if (LOG.isTraceEnabled()) { LOG.trace("Closing channel when complete at address: {}", getEndpoint().getConfiguration().getAddress()); } NettyHelper.close(channel); } } finally { // signal callback to continue routing producerCallback.done(false); } } } }); // continue routing asynchronously return false; }
From source file:com.amazonaws.services.kinesis.clientlibrary.lib.worker.ShardConsumerTest.java
/** * Test method to verify consumer stays in INITIALIZING state when InitializationTask fails. */// www . j av a 2 s .c om @SuppressWarnings("unchecked") @Test public final void testInitializationStateUponSubmissionFailure() throws Exception { ShardInfo shardInfo = new ShardInfo("s-0-0", "testToken", null, ExtendedSequenceNumber.TRIM_HORIZON); ExecutorService spyExecutorService = spy(executorService); when(checkpoint.getCheckpoint(anyString())).thenThrow(NullPointerException.class); when(leaseManager.getLease(anyString())).thenReturn(null); StreamConfig streamConfig = new StreamConfig(streamProxy, 1, 10, callProcessRecordsForEmptyRecordList, skipCheckpointValidationValue, INITIAL_POSITION_LATEST); ShardConsumer consumer = new ShardConsumer(shardInfo, streamConfig, checkpoint, processor, null, parentShardPollIntervalMillis, cleanupLeasesOfCompletedShards, spyExecutorService, metricsFactory, taskBackoffTimeMillis, KinesisClientLibConfiguration.DEFAULT_SKIP_SHARD_SYNC_AT_STARTUP_IF_LEASES_EXIST); assertThat(consumer.getCurrentState(), is(equalTo(ConsumerStates.ShardConsumerState.WAITING_ON_PARENT_SHARDS))); consumer.consumeShard(); // initialize Thread.sleep(50L); assertThat(consumer.getCurrentState(), is(equalTo(ConsumerStates.ShardConsumerState.WAITING_ON_PARENT_SHARDS))); doThrow(new RejectedExecutionException()).when(spyExecutorService).submit(any(InitializeTask.class)); consumer.consumeShard(); // initialize Thread.sleep(50L); assertThat(consumer.getCurrentState(), is(equalTo(ConsumerStates.ShardConsumerState.INITIALIZING))); consumer.consumeShard(); // initialize Thread.sleep(50L); assertThat(consumer.getCurrentState(), is(equalTo(ConsumerStates.ShardConsumerState.INITIALIZING))); consumer.consumeShard(); // initialize Thread.sleep(50L); assertThat(consumer.getCurrentState(), is(equalTo(ConsumerStates.ShardConsumerState.INITIALIZING))); }
From source file:com.amazon.mws.shared.MwsConnection.java
/** * Get the shared executor service that is used by async calls if no * executor is supplied./*from w w w. j a va2 s .c o m*/ * * @return The shared executor service. */ private ExecutorService getSharedES() { synchronized (this.getClass()) { if (sharedES != null) { return sharedES; } sharedES = new ThreadPoolExecutor(maxAsyncThreads / 10, maxAsyncThreads, 60L, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(maxAsyncQueueSize), new ThreadFactory() { private final AtomicInteger threadNumber = new AtomicInteger(1); public Thread newThread(Runnable task) { Thread thread = new Thread(task, "MWSClient-" + threadNumber.getAndIncrement()); thread.setDaemon(true); thread.setPriority(Thread.NORM_PRIORITY); return thread; } }, new RejectedExecutionHandler() { public void rejectedExecution(Runnable task, ThreadPoolExecutor executor) { if (!executor.isShutdown()) { log.warn("MWSClient async queue full, running on calling thread."); task.run(); } else { throw new RejectedExecutionException(); } } }); return sharedES; } }
From source file:com.amazonservices.mws.client.MwsConnection.java
/** * Get the shared executor service that is used by async calls if no * executor is supplied.//from w w w . j a v a2s. com * * @return The shared executor service. */ private ExecutorService getSharedES() { synchronized (this.getClass()) { if (sharedES != null) { return sharedES; } sharedES = new ThreadPoolExecutor(maxAsyncThreads / 10, maxAsyncThreads, 60L, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(maxAsyncQueueSize), new ThreadFactory() { private final AtomicInteger threadNumber = new AtomicInteger(1); //@Override public Thread newThread(Runnable task) { Thread thread = new Thread(task, "MWSClient-" + threadNumber.getAndIncrement()); thread.setDaemon(true); thread.setPriority(Thread.NORM_PRIORITY); return thread; } }, new RejectedExecutionHandler() { //@Override public void rejectedExecution(Runnable task, ThreadPoolExecutor executor) { if (!executor.isShutdown()) { log.warn("MWSClient async queue full, running on calling thread."); task.run(); } else { throw new RejectedExecutionException(); } } }); return sharedES; } }