use of org.springframework.scheduling.concurrent.CustomizableThreadFactory in project spring-integration by spring-projects.
the class ExecutorChannelTests method verifyFailoverWithLoadBalancing.
@Test
public void verifyFailoverWithLoadBalancing() throws Exception {
int numberOfMessages = 11;
ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor(new CustomizableThreadFactory("test-"));
ConcurrentTaskExecutor taskExecutor = new ConcurrentTaskExecutor(exec);
ExecutorChannel channel = new ExecutorChannel(taskExecutor, new RoundRobinLoadBalancingStrategy());
CountDownLatch latch = new CountDownLatch(numberOfMessages);
TestHandler handler1 = new TestHandler(latch);
TestHandler handler2 = new TestHandler(latch);
TestHandler handler3 = new TestHandler(latch);
channel.subscribe(handler1);
channel.subscribe(handler2);
channel.subscribe(handler3);
handler2.shouldFail = true;
for (int i = 0; i < numberOfMessages; i++) {
channel.send(new GenericMessage<String>("test-" + i));
}
latch.await(3000, TimeUnit.MILLISECONDS);
assertEquals(0, latch.getCount());
assertNotNull(handler1.thread);
assertFalse(Thread.currentThread().equals(handler1.thread));
assertTrue(handler1.thread.getName().startsWith("test-"));
assertNotNull(handler2.thread);
assertFalse(Thread.currentThread().equals(handler2.thread));
assertTrue(handler2.thread.getName().startsWith("test-"));
assertNotNull(handler3.thread);
assertFalse(Thread.currentThread().equals(handler3.thread));
assertTrue(handler3.thread.getName().startsWith("test-"));
assertEquals(0, handler2.count.get());
assertEquals(4, handler1.count.get());
assertEquals(7, handler3.count.get());
exec.shutdownNow();
}
use of org.springframework.scheduling.concurrent.CustomizableThreadFactory in project spring-integration by spring-projects.
the class ExecutorChannelTests method roundRobinLoadBalancing.
@Test
public void roundRobinLoadBalancing() throws Exception {
int numberOfMessages = 11;
ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor(new CustomizableThreadFactory("test-"));
ConcurrentTaskExecutor taskExecutor = new ConcurrentTaskExecutor(exec);
ExecutorChannel channel = new ExecutorChannel(taskExecutor, new RoundRobinLoadBalancingStrategy());
CountDownLatch latch = new CountDownLatch(numberOfMessages);
TestHandler handler1 = new TestHandler(latch);
TestHandler handler2 = new TestHandler(latch);
TestHandler handler3 = new TestHandler(latch);
channel.subscribe(handler1);
channel.subscribe(handler2);
channel.subscribe(handler3);
for (int i = 0; i < numberOfMessages; i++) {
channel.send(new GenericMessage<String>("test-" + i));
}
latch.await(3000, TimeUnit.MILLISECONDS);
assertEquals(0, latch.getCount());
assertNotNull(handler1.thread);
assertFalse(Thread.currentThread().equals(handler1.thread));
assertTrue(handler1.thread.getName().startsWith("test-"));
assertNotNull(handler2.thread);
assertFalse(Thread.currentThread().equals(handler2.thread));
assertTrue(handler2.thread.getName().startsWith("test-"));
assertNotNull(handler3.thread);
assertFalse(Thread.currentThread().equals(handler3.thread));
assertTrue(handler3.thread.getName().startsWith("test-"));
assertEquals(4, handler1.count.get());
assertEquals(4, handler2.count.get());
assertEquals(3, handler3.count.get());
exec.shutdownNow();
}
use of org.springframework.scheduling.concurrent.CustomizableThreadFactory in project spring-integration by spring-projects.
the class UnicastSendingMessageHandler method doStart.
@Override
public void doStart() {
if (this.acknowledge) {
if (this.taskExecutor == null) {
CustomizableThreadFactory threadFactory = new CustomizableThreadFactory("UDP-Ack-Handler-");
threadFactory.setDaemon(true);
this.taskExecutor = Executors.newSingleThreadExecutor(threadFactory);
}
startAckThread();
}
}
use of org.springframework.scheduling.concurrent.CustomizableThreadFactory in project spring-integration by spring-projects.
the class ExecutorChannelTests method verifyFailoverWithoutLoadBalancing.
@Test
public void verifyFailoverWithoutLoadBalancing() throws Exception {
int numberOfMessages = 11;
ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor(new CustomizableThreadFactory("test-"));
ConcurrentTaskExecutor taskExecutor = new ConcurrentTaskExecutor(exec);
ExecutorChannel channel = new ExecutorChannel(taskExecutor, null);
CountDownLatch latch = new CountDownLatch(numberOfMessages);
TestHandler handler1 = new TestHandler(latch);
TestHandler handler2 = new TestHandler(latch);
TestHandler handler3 = new TestHandler(latch);
channel.subscribe(handler1);
channel.subscribe(handler2);
channel.subscribe(handler3);
handler1.shouldFail = true;
for (int i = 0; i < numberOfMessages; i++) {
channel.send(new GenericMessage<String>("test-" + i));
}
latch.await(3000, TimeUnit.MILLISECONDS);
assertEquals(0, latch.getCount());
assertNotNull(handler1.thread);
assertFalse(Thread.currentThread().equals(handler1.thread));
assertTrue(handler1.thread.getName().startsWith("test-"));
assertNotNull(handler2.thread);
assertFalse(Thread.currentThread().equals(handler2.thread));
assertTrue(handler2.thread.getName().startsWith("test-"));
assertNull(handler3.thread);
assertEquals(0, handler1.count.get());
assertEquals(0, handler3.count.get());
assertEquals(numberOfMessages, handler2.count.get());
exec.shutdownNow();
}
Aggregations