use of org.springframework.core.task.TaskRejectedException in project spring-framework by spring-projects.
the class TaskExecutorAdapter method submit.
@Override
public <T> Future<T> submit(Callable<T> task) {
try {
if (this.taskDecorator == null && this.concurrentExecutor instanceof ExecutorService) {
return ((ExecutorService) this.concurrentExecutor).submit(task);
} else {
FutureTask<T> future = new FutureTask<>(task);
doExecute(this.concurrentExecutor, this.taskDecorator, future);
return future;
}
} catch (RejectedExecutionException ex) {
throw new TaskRejectedException("Executor [" + this.concurrentExecutor + "] did not accept task: " + task, ex);
}
}
use of org.springframework.core.task.TaskRejectedException in project perun by CESNET.
the class MessageReceiver method run.
@Override
public void run() {
while (running) {
if (!queueAcquired) {
try {
// Step 1. Directly instantiate the JMS Queue object.
queue = HornetQJMSClient.createQueue(queueName);
// Step 9. Create a JMS Message Consumer
messageConsumer = session.createConsumer(queue);
queueAcquired = true;
// messageConsumer.receive(timeout) is a blocking operation!
waitTime = 0;
} catch (InvalidDestinationException e) {
queueAcquired = false;
waitTime = waitTime + 5000;
log.error("Queue doesn't exist yet. We gonna wait a bit (" + (waitTime / 1000) + "s) and try it again...", e);
} catch (JMSException e) {
queueAcquired = false;
waitTime = waitTime + 5000;
log.error("Something went wrong with JMS. We gonna wait a bit (" + (waitTime / 1000) + "s) and try it again...", e);
} catch (Exception e) {
queueAcquired = false;
waitTime = waitTime + 5000;
log.error("Can not continue. We gonna wait a bit (" + (waitTime / 1000) + "s) and try it again...", e);
}
} else {
// Step 11. Receive the message
TextMessage messageReceived = null;
try {
messageReceived = (TextMessage) messageConsumer.receive(timeout);
if (messageReceived != null) {
final String message = messageReceived.getText();
String messageType = message.split("\\|", 2)[0].trim();
log.debug("RECEIVED MESSAGE:" + message + ", Type:" + messageType);
if (messageType.equalsIgnoreCase("task")) {
try {
taskExecutorMessageProcess.execute(new Runnable() {
@Override
public void run() {
// TODO: Remove in future
log.info("I am going to call eventProcessor.receiveEvent(\"" + message + "\") in thread:" + Thread.currentThread().getName());
eventProcessor.receiveEvent(message);
}
});
} catch (TaskRejectedException ex) {
log.error("Task was rejected. Message {}", message);
throw ex;
}
} else if (messageType.equalsIgnoreCase("command")) {
// TODO: There is no need to put commandProcessor to
// a separate thread at the moment, however it is
// very likely to be so in a future.
commandProcessor.receiveCommand(message);
} else {
throw new UnknownMessageTypeException("UNKNOWN TYPE[" + messageType + "]");
}
}
} catch (InvalidDestinationException e) {
queueAcquired = false;
waitTime = waitTime + 5000;
log.error("Queue doesn't exist or the connection is broken. We gonna wait a bit (" + (waitTime / 1000) + "s) and try it again...", e);
} catch (JMSException e) {
queueAcquired = false;
waitTime = waitTime + 5000;
log.error("Something went wrong with JMS. We gonna wait a bit (" + (waitTime / 1000) + "s) and try it again...", e);
} catch (Exception e) {
queueAcquired = false;
waitTime = waitTime + 5000;
log.error("Can not continue. We gonna wait a bit (" + (waitTime / 1000) + "s) and try it again...", e);
}
}
if (waitTime > 0) {
if (waitTime > TOO_LONG) {
// gonna be back after trying to reinitialize the connection
return;
}
try {
Thread.sleep(waitTime);
} catch (InterruptedException e) {
log.error(e.toString(), e);
}
}
}
}
use of org.springframework.core.task.TaskRejectedException in project spring-framework by spring-projects.
the class ThreadPoolTaskExecutor method submitListenable.
@Override
public ListenableFuture<?> submitListenable(Runnable task) {
ExecutorService executor = getThreadPoolExecutor();
try {
ListenableFutureTask<Object> future = new ListenableFutureTask<>(task, null);
executor.execute(future);
return future;
} catch (RejectedExecutionException ex) {
throw new TaskRejectedException("Executor [" + executor + "] did not accept task: " + task, ex);
}
}
use of org.springframework.core.task.TaskRejectedException in project spring-framework by spring-projects.
the class ThreadPoolTaskScheduler method schedule.
@Override
public ScheduledFuture<?> schedule(Runnable task, Date startTime) {
ScheduledExecutorService executor = getScheduledExecutor();
long initialDelay = startTime.getTime() - System.currentTimeMillis();
try {
return executor.schedule(errorHandlingTask(task, false), initialDelay, TimeUnit.MILLISECONDS);
} catch (RejectedExecutionException ex) {
throw new TaskRejectedException("Executor [" + executor + "] did not accept task: " + task, ex);
}
}
use of org.springframework.core.task.TaskRejectedException in project spring-framework by spring-projects.
the class ThreadPoolTaskScheduler method scheduleAtFixedRate.
@Override
public ScheduledFuture<?> scheduleAtFixedRate(Runnable task, Date startTime, long period) {
ScheduledExecutorService executor = getScheduledExecutor();
long initialDelay = startTime.getTime() - System.currentTimeMillis();
try {
return executor.scheduleAtFixedRate(errorHandlingTask(task, true), initialDelay, period, TimeUnit.MILLISECONDS);
} catch (RejectedExecutionException ex) {
throw new TaskRejectedException("Executor [" + executor + "] did not accept task: " + task, ex);
}
}
Aggregations