use of org.apache.geode.internal.admin.remote.AlertListenerMessage in project geode by apache.
the class AlertAppender method append.
/**
* This method is optimized with the assumption that at least one listener has set a level which
* requires that the event be sent. This is ensured by modifying the appender's configuration
* whenever a listener is added or removed.
*/
@Override
public void append(final LogEvent event) {
if (this.alertingDisabled) {
return;
}
// If already appending then don't send to avoid infinite recursion
if ((alerting.get())) {
return;
}
setIsAlerting(true);
try {
final boolean isDebugEnabled = logger.isDebugEnabled();
if (isDebugEnabled) {
logger.debug("Delivering an alert event: {}", event);
}
InternalDistributedSystem ds = this.systemRef.get();
if (ds == null) {
// Use info level to avoid triggering another alert
logger.info("Did not append alert event because the distributed system is set to null.");
return;
}
DistributionManager distMgr = (DistributionManager) ds.getDistributionManager();
final int intLevel = logLevelToAlertLevel(event.getLevel().intLevel());
final Date date = new Date(event.getTimeMillis());
final String threadName = event.getThreadName();
final String logMessage = event.getMessage().getFormattedMessage();
final String stackTrace = ThreadUtils.stackTraceToString(event.getThrown(), true);
final String connectionName = ds.getConfig().getName();
for (Listener listener : this.listeners) {
if (event.getLevel().intLevel() > listener.getLevel().intLevel()) {
break;
}
try {
AlertListenerMessage alertMessage = AlertListenerMessage.create(listener.getMember(), intLevel, date, connectionName, threadName, Thread.currentThread().getId(), logMessage, stackTrace);
if (listener.getMember().equals(distMgr.getDistributionManagerId())) {
if (isDebugEnabled) {
logger.debug("Delivering local alert message: {}, {}, {}, {}, {}, [{}], [{}].", listener.getMember(), intLevel, date, connectionName, threadName, logMessage, stackTrace);
}
alertMessage.process(distMgr);
} else {
if (isDebugEnabled) {
logger.debug("Delivering remote alert message: {}, {}, {}, {}, {}, [{}], [{}].", listener.getMember(), intLevel, date, connectionName, threadName, logMessage, stackTrace);
}
distMgr.putOutgoing(alertMessage);
}
} catch (ReenteredConnectException e) {
// OK. We can't send to this recipient because we're in the middle of
// trying to connect to it.
}
}
} finally {
setIsAlerting(false);
}
}
use of org.apache.geode.internal.admin.remote.AlertListenerMessage in project geode by apache.
the class GMSMembershipManagerJUnitTest method testSendAdminMessageFailsDuringShutdown.
@Test
public void testSendAdminMessageFailsDuringShutdown() throws Exception {
AlertListenerMessage m = AlertListenerMessage.create(mockMembers[0], 1, new Date(System.currentTimeMillis()), "thread", "", 1L, "", "");
manager.start();
manager.started();
manager.installView(new NetView(myMemberId, 1, members));
manager.setShutdown();
Set<InternalDistributedMember> failures = manager.send(m);
verify(messenger, never()).send(m);
assertEquals(1, failures.size());
assertEquals(mockMembers[0], failures.iterator().next());
}
Aggregations