use of fish.payara.nucleus.eventbus.ClusterMessage in project Payara by payara.
the class RequestTracingService method endTrace.
/**
*/
public void endTrace() {
if (!isRequestTracingEnabled() || !isTraceInProgress()) {
return;
}
requestEventStore.endTrace();
Long thresholdValueInNanos = getThresholdValueInNanos();
long elapsedTime = requestEventStore.getElapsedTime();
long elapsedTimeInNanos = TimeUnit.NANOSECONDS.convert(elapsedTime, TimeUnit.MILLISECONDS);
if (elapsedTimeInNanos - thresholdValueInNanos > 0) {
// Determine whether to sample the request, if sampleRateFirstEnabled is false
if (!executionOptions.getSampleRateFirstEnabled()) {
if (!sampleFilter.sample()) {
requestEventStore.flushStore();
return;
}
}
RequestTrace requestTrace = requestEventStore.getTrace();
Runnable addTask = () -> {
RequestTrace removedTrace = requestTraceStore.addTrace(requestTrace);
// Store the trace in the historic trace store if it's enabled, avoiding recalculation
if (executionOptions.isHistoricTraceStoreEnabled()) {
historicRequestTraceStore.addTrace(requestTrace, removedTrace);
}
if (removedTrace != null) {
if (hazelcast.isEnabled()) {
eventBus.publish(EVENT_BUS_LISTENER_NAME, new ClusterMessage(RequestTracingEvents.STORE_FULL.toString()));
} else {
events.send(new EventListener.Event(RequestTracingEvents.STORE_FULL));
}
}
};
payaraExecutorService.submit(addTask);
for (NotifierExecutionOptions notifierExecutionOptions : executionOptions.getNotifierExecutionOptionsList().values()) {
if (notifierExecutionOptions.isEnabled()) {
NotificationEventFactory notificationEventFactory = eventFactoryStore.get(notifierExecutionOptions.getNotifierType());
String subject = "Request execution time: " + elapsedTime + "(ms) exceeded the acceptable threshold";
NotificationEvent notificationEvent = notificationEventFactory.buildNotificationEvent(subject, requestTrace);
notificationService.notify(EventSource.REQUESTTRACING, notificationEvent);
}
}
}
requestEventStore.flushStore();
}
use of fish.payara.nucleus.eventbus.ClusterMessage in project Payara by payara.
the class ExampleService method bootService.
/**
* This method is called after the service instance has been created
*/
@PostConstruct
public void bootService() {
LOGGER.info("Example Service has booted " + config.getMessage());
// this code demonstrates how you can hook into the server event system to
// be notified of events like when the server is running
events.register(this);
// this code hooks the service into the cluster wide messaging system
// based on Hazelcast
eventBus.addMessageReceiver("ExampleService", this);
eventBus.publish("ExampleService", new ClusterMessage("Hello World"));
// notify that I am interested in changes to the configuration class
transactions.addListenerForType(ExampleServiceConfiguration.class, this);
}
use of fish.payara.nucleus.eventbus.ClusterMessage in project Payara by payara.
the class ReadOnlyBeanMessageCallBack method notifyRefresh.
/**
* This is called by the container after it has called refresh
*
* @param ejbID
* the ejbID that uniquely identifies the container
* @param pk
* The primary key of the bean(s) that is to be refreshed
*/
public void notifyRefresh(long ejbID, byte[] pk) {
int size = pk.length;
byte[] payload = new byte[size + 8];
longToBytes(ejbID, payload, 0);
System.arraycopy(pk, 0, payload, 8, size);
try {
eventBus.publish(GMS_READ_ONLY_COMPONENT_NAME, new ClusterMessage(new RefreshPayload(payload)));
_logger.log(Level.WARNING, "ReadOnlyBeanMessageCallBack: " + " Sent message for ejbID: " + ejbID);
} catch (Exception ex) {
_logger.log(Level.WARNING, "ReadOnlyBeanMessageCallBack: " + "Got exception during notifyRefresh", ex);
}
}
use of fish.payara.nucleus.eventbus.ClusterMessage in project Payara by payara.
the class ReadOnlyBeanMessageCallBack method notifyRefreshAll.
/**
* This is called by the container after it has called refresh
*
* @param ejbID
* the ejbID that uniquely identifies the container
* @param pk
* The primary key of the bean(s) that is to be refreshed
*/
public void notifyRefreshAll(long ejbID) {
byte[] payload = new byte[8];
longToBytes(ejbID, payload, 0);
try {
eventBus.publish(GMS_READ_ONLY_COMPONENT_NAME, new ClusterMessage(new RefreshPayload(payload)));
} catch (Exception ex) {
_logger.log(Level.WARNING, "ReadOnlyBeanMessageCallBack: " + "Got exception during notifyRefreshAll", ex);
}
}
use of fish.payara.nucleus.eventbus.ClusterMessage in project Payara by payara.
the class PayaraInstanceImpl method event.
/**
* @param event
*/
@Override
@SuppressWarnings({ "unchecked" })
public void event(Event event) {
if (event.is(EventTypes.SERVER_READY)) {
initialiseInstanceDescriptor();
PayaraInternalEvent pie = new PayaraInternalEvent(PayaraInternalEvent.MESSAGE.ADDED, me);
ClusterMessage<PayaraInternalEvent> message = new ClusterMessage<>(pie);
this.cluster.getEventBus().publish(INTERNAL_EVENTS_NAME, message);
for (String appName : appRegistry.getAllApplicationNames()) {
me.addApplication(new ApplicationDescriptorImpl(appRegistry.get(appName)));
}
cluster.getClusteredStore().set(INSTANCE_STORE_NAME, myCurrentID, me);
} else // Adds the application to the clustered register of deployed applications
if (event.is(Deployment.APPLICATION_STARTED)) {
if (event.hook() != null && event.hook() instanceof ApplicationInfo) {
ApplicationInfo applicationInfo = (ApplicationInfo) event.hook();
if (me == null) {
// race check
initialiseInstanceDescriptor();
}
me.addApplication(new ApplicationDescriptorImpl(applicationInfo));
logger.log(Level.FINE, "App Loaded: {2}, Enabled: {0}, my ID: {1}", new Object[] { hazelcast.isEnabled(), myCurrentID, applicationInfo.getName() });
cluster.getClusteredStore().set(INSTANCE_STORE_NAME, myCurrentID, me);
}
} else // removes the application from the clustered registry of applications
if (event.is(Deployment.APPLICATION_UNLOADED)) {
if (event.hook() != null && event.hook() instanceof ApplicationInfo) {
ApplicationInfo applicationInfo = (ApplicationInfo) event.hook();
me.removeApplication(new ApplicationDescriptorImpl(applicationInfo));
cluster.getClusteredStore().set(INSTANCE_STORE_NAME, myCurrentID, me);
}
} else if (event.is(HazelcastEvents.HAZELCAST_SHUTDOWN_STARTED)) {
PayaraInternalEvent pie = new PayaraInternalEvent(PayaraInternalEvent.MESSAGE.REMOVED, me);
ClusterMessage<PayaraInternalEvent> message = new ClusterMessage<>(pie);
this.cluster.getClusteredStore().remove(INSTANCE_STORE_NAME, myCurrentID);
this.cluster.getEventBus().publish(INTERNAL_EVENTS_NAME, message);
}
// When Hazelcast is bootstrapped, update the instance descriptor with any new information
if (event.is(HazelcastEvents.HAZELCAST_BOOTSTRAP_COMPLETE)) {
initialiseInstanceDescriptor();
logger.log(Level.FINE, "Hz Bootstrap Complete, Enabled: {0}, my ID: {1}", new Object[] { hazelcast.isEnabled(), myCurrentID });
// remove listener first
cluster.getEventBus().removeMessageReceiver(INTERNAL_EVENTS_NAME, this);
cluster.getEventBus().removeMessageReceiver(CDI_EVENTS_NAME, this);
cluster.getEventBus().addMessageReceiver(INTERNAL_EVENTS_NAME, this);
cluster.getEventBus().addMessageReceiver(CDI_EVENTS_NAME, this);
}
// If the generated name had to be changed, update the instance descriptor with the new information
if (event.is(HazelcastEvents.HAZELCAST_GENERATED_NAME_CHANGE)) {
initialiseInstanceDescriptor();
}
}
Aggregations