Skip to content

Commit

Permalink
PAYARA-1809 Payara Micro Eventbus uses hazelcast instance name (#1753)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cousjava authored and smillidge committed Jul 7, 2017
1 parent 138238a commit b9fbf3d
Showing 1 changed file with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
*/
package fish.payara.notification.eventbus.core;

import fish.payara.nucleus.hazelcast.HazelcastCore;
import fish.payara.nucleus.notification.configuration.NotifierType;
import fish.payara.nucleus.notification.domain.NotificationEventFactory;
import org.glassfish.api.StartupRunLevel;
Expand All @@ -48,6 +49,9 @@
import javax.annotation.PostConstruct;
import java.text.MessageFormat;
import java.util.logging.Level;
import javax.inject.Inject;
import org.glassfish.api.admin.ServerEnvironment;
import org.glassfish.hk2.api.ServiceLocator;

/**
* @author mertcaliskan
Expand All @@ -56,15 +60,28 @@
@RunLevel(StartupRunLevel.VAL)
public class EventbusNotificationEventFactory extends NotificationEventFactory<EventbusNotificationEvent> {

@Inject
private ServerEnvironment environment;

@Inject
private ServiceLocator habitat;

@Inject
HazelcastCore hazelcast;

@PostConstruct
void postConstruct() {
registerEventFactory(NotifierType.EVENTBUS, this);
}

@Override
public EventbusNotificationEvent buildNotificationEvent(String subject, String message) {
EventbusNotificationEvent event = initializeEvent(new EventbusNotificationEvent());
event.setSubject(subject);
event.setMessage(message);
if (environment.isMicro()){
setHazelcastAsInstanceName(event);
}

return event;
}
Expand All @@ -77,6 +94,19 @@ public EventbusNotificationEvent buildNotificationEvent(Level level, String subj
message = MessageFormat.format(message, parameters);
}
event.setMessage(message);
if (environment.isMicro()){
setHazelcastAsInstanceName(event);
}
return event;
}

/**
* If this is a Micro instance, use Hazelcast instance name instead of the payara instance name so we get a unique result
* @param e
*/
private void setHazelcastAsInstanceName(EventbusNotificationEvent e){
e.setInstanceName(hazelcast.getMemberName());

}

}

0 comments on commit b9fbf3d

Please sign in to comment.