protected void subscribeToTopicsAndRegisterListeners() {
if(log.isDebugEnabled()) {
log.debug("Starting instance notifier event message receiver thread");
}
InstanceNotifierEventReceiver eventReceiver = new InstanceNotifierEventReceiver();
eventReceiver.addEventListener(new ArtifactUpdateEventListener() {
@Override
protected void onEvent(Event event) {
onArtifactUpdateEvent((ArtifactUpdatedEvent) event);
}
});
eventReceiver.addEventListener(new InstanceCleanupMemberEventListener() {
@Override
protected void onEvent(Event event) {
String memberIdInPayload = CartridgeAgentConfiguration.getInstance().getMemberId();
InstanceCleanupMemberEvent instanceCleanupMemberEvent = (InstanceCleanupMemberEvent) event;
if (memberIdInPayload.equals(instanceCleanupMemberEvent.getMemberId())) {
onInstanceCleanupEvent();
}
}
});
eventReceiver.addEventListener(new InstanceCleanupClusterEventListener() {
@Override
protected void onEvent(Event event) {
String clusterIdInPayload = CartridgeAgentConfiguration.getInstance().getClusterId();
InstanceCleanupClusterEvent instanceCleanupClusterEvent = (InstanceCleanupClusterEvent) event;
if (clusterIdInPayload.equals(instanceCleanupClusterEvent.getClusterId())) {
onInstanceCleanupEvent();
}
}
});
Thread eventReceiverThread = new Thread(eventReceiver);
eventReceiverThread.start();
// Wait until message receiver is subscribed to the topic to
// send the instance started event
while (!eventReceiver.isSubscribed()) {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
}
}