use of org.springframework.integration.leader.event.DefaultLeaderEventPublisher in project spring-integration by spring-projects.
the class LockRegistryLeaderInitiatorTests method testExceptionFromEvent.
@Test
public void testExceptionFromEvent() throws Exception {
CountDownLatch onGranted = new CountDownLatch(1);
this.initiator.setLeaderEventPublisher(new DefaultLeaderEventPublisher() {
@Override
public void publishOnGranted(Object source, Context context, String role) {
try {
throw new RuntimeException("intentional");
} finally {
onGranted.countDown();
}
}
});
this.initiator.start();
assertTrue(onGranted.await(10, TimeUnit.SECONDS));
assertTrue(initiator.getContext().isLeader());
this.initiator.stop();
}
use of org.springframework.integration.leader.event.DefaultLeaderEventPublisher in project spring-integration by spring-projects.
the class LeaderInitiatorFactoryBean method afterPropertiesSet.
@Override
public void afterPropertiesSet() throws Exception {
if (this.leaderInitiator == null) {
this.leaderInitiator = new LeaderInitiator(this.client, this.candidate, this.path);
this.leaderInitiator.setPhase(this.phase);
this.leaderInitiator.setAutoStartup(this.autoStartup);
if (this.leaderEventPublisher != null) {
this.leaderInitiator.setLeaderEventPublisher(this.leaderEventPublisher);
} else if (this.applicationEventPublisher != null) {
this.leaderInitiator.setLeaderEventPublisher(new DefaultLeaderEventPublisher(this.applicationEventPublisher));
}
}
}
use of org.springframework.integration.leader.event.DefaultLeaderEventPublisher in project spring-integration by spring-projects.
the class LockRegistryLeaderInitiator method start.
/**
* Start the registration of the {@link #candidate} for leader election.
*/
@Override
public void start() {
if (this.leaderEventPublisher == null && this.applicationEventPublisher != null) {
this.leaderEventPublisher = new DefaultLeaderEventPublisher(this.applicationEventPublisher);
}
synchronized (this.lifecycleMonitor) {
if (!this.running) {
this.leaderSelector = new LeaderSelector(buildLeaderPath());
this.running = true;
this.future = this.executorService.submit(this.leaderSelector);
logger.debug("Started LeaderInitiator");
}
}
}
use of org.springframework.integration.leader.event.DefaultLeaderEventPublisher in project spring-integration by spring-projects.
the class LeaderInitiatorFactoryBeanTests method testExceptionFromEvent.
@Test
public void testExceptionFromEvent() throws Exception {
CountDownLatch onGranted = new CountDownLatch(1);
LeaderInitiator initiator = new LeaderInitiator(client, new DefaultCandidate());
initiator.setLeaderEventPublisher(new DefaultLeaderEventPublisher() {
@Override
public void publishOnGranted(Object source, Context context, String role) {
try {
throw new RuntimeException("intentional");
} finally {
onGranted.countDown();
}
}
});
initiator.start();
assertTrue(onGranted.await(10, TimeUnit.SECONDS));
assertTrue(initiator.getContext().isLeader());
initiator.stop();
}
Aggregations