本文整理了Java中javax.management.Notification.getType()
方法的一些代码示例,展示了Notification.getType()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Notification.getType()
方法的具体详情如下:
包路径:javax.management.Notification
类名称:Notification
方法名:getType
暂无
代码示例来源:origin: apache/geode
/**
* Invoked before sending the specified notification to the listener. Returns whether the given
* notification is to be sent to the listener.
*
* @param notification The notification to be sent.
* @return true if the notification has to be sent to the listener, false otherwise.
*/
@Override
public boolean isNotificationEnabled(Notification notification) {
boolean isThisNotificationEnabled = false;
if (notification.getType().equals(JMXConnectionNotification.OPENED)
|| notification.getType().equals(JMXConnectionNotification.CLOSED)
|| notification.getType().equals(JMXConnectionNotification.FAILED)) {
isThisNotificationEnabled = true;
}
return isThisNotificationEnabled;
}
}
代码示例来源:origin: log4j/log4j
public
void handleNotification(Notification notification, Object handback) {
cat.debug("Received notification: "+notification.getType());
registerAppenderMBean((Appender) notification.getUserData() );
}
代码示例来源:origin: apache/hive
public void start() {
// unsupported if null
if (tenuredGenPool == null) {
return;
}
MemoryMXBean mxBean = ManagementFactory.getMemoryMXBean();
NotificationEmitter emitter = (NotificationEmitter) mxBean;
notificationListener = (n, hb) -> {
if (n.getType().equals(
MemoryNotificationInfo.MEMORY_COLLECTION_THRESHOLD_EXCEEDED)) {
long maxMemory = tenuredGenPool.getUsage().getMax();
long usedMemory = tenuredGenPool.getUsage().getUsed();
for (Listener listener : listeners) {
listener.memoryUsageAboveThreshold(usedMemory, maxMemory);
}
}
};
emitter.addNotificationListener(notificationListener, null, null);
}
代码示例来源:origin: groovy/groovy-core
private static Map buildOperationNotificationPacket(Notification note) {
Map<String, Object> result = new HashMap<String, Object>();
result.put("event", note.getType());
result.put("source", note.getSource());
result.put("sequenceNumber", note.getSequenceNumber());
result.put("timeStamp", note.getTimeStamp());
result.put("data", note.getUserData());
return result;
}
}
代码示例来源:origin: h2oai/h2o-2
/**
* Callback routine called by JVM after full gc run. Has two functions:
* 1) sets the amount of memory to be cleaned from the cache by the Cleaner
* 2) sets the CAN_ALLOC flag to false if memory level is critical
*
* The callback happens in a system thread, and hence not through the usual
* water.Boot loader - and so any touched classes are in the wrong class
* loader and you end up with new classes with uninitialized global vars.
* Limit to touching global vars in the Boot class.
*/
public void handleNotification(Notification notification, Object handback) {
String notifType = notification.getType();
if( notifType.equals(MemoryNotificationInfo.MEMORY_COLLECTION_THRESHOLD_EXCEEDED)) {
// Memory used after this FullGC
Boot.TIME_AT_LAST_GC = System.currentTimeMillis();
Boot.HEAP_USED_AT_LAST_GC = _allMemBean.getHeapMemoryUsage().getUsed();
MEM_LOW_CRITICAL = Boot.HEAP_USED_AT_LAST_GC > (MEM_MAX - (MEM_MAX >> 2));
if(Boot.HEAP_USED_AT_LAST_GC > (MEM_MAX - (MEM_MAX >> 1))) { // emergency measure - really low on memory, stop allocations right now!
setMemLow();
} else // enable new allocations (even if cleaner is still running, we have enough RAM)
setMemGood();
Boot.kick_store_cleaner();
}
}
}
代码示例来源:origin: apache/geode
/**
* Sends the given notification.
*
* @param notif notification to send
*
* @throws NullPointerException if resource or ModelMBean for resource is null
*/
/* default */static void sendNotification(ManagedResource resource, Notification notif) {
try {
if (MBeanUtil.isRegistered(resource.getObjectName())) {
resource.getModelMBean().sendNotification(notif);
if (logger.isDebugEnabled()) {
logger.debug("Sent '{}' notification", notif.getType());
}
}
} catch (RuntimeOperationsException e) {
logger
.info(String.format("Failed to send %s notification for %s",
new Object[] {"'" + notif.getType() + "'", "'" + notif.getMessage() + "'"}),
e);
} catch (MBeanException e) {
logger
.info(String.format("Failed to send %s notification for %s",
new Object[] {"'" + notif.getType() + "'", "'" + notif.getMessage() + "'"}),
e);
}
}
}
代码示例来源:origin: apache/geode
public void handleNotification(Notification notification, Object handback) {
Object notifSource = notification.getSource();
if (AdminDistributedSystemJmxImpl.NOTIF_MEMBER_JOINED.equals(notification.getType())) {
ObjectName source = (ObjectName) notifSource;
notification = new Notification(notification.getType(), notifSource,
notificationSequenceNumber.addAndGet(1L), notification.getTimeStamp(),
notification.getMessage());
代码示例来源:origin: btraceio/btrace
boolean entered = BTraceRuntime.enter(BTraceRuntime.this);
try {
String notifType = notif.getType();
if (notifType.equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED)) {
CompositeData cd = (CompositeData) notif.getUserData();
代码示例来源:origin: apache/geode
public static void handleNotification(SystemMemberJmx member, Notification notification,
Object hb) {
if (RefreshNotificationType.SYSTEM_MEMBER_CONFIG.getType().equals(notification.getType())
&& ((ManagedResource) member).getMBeanName().equals(notification.getUserData())) {
代码示例来源:origin: apache/geode
if (typeStatResourceStats.equals(notification.getType())
&& getMBeanName().equals(notification.getUserData())
&& !adminDSJmx.isRmiClientCountZero()) {
代码示例来源:origin: Graylog2/graylog2-server
@Override
public void handleNotification(javax.management.Notification notification, Object handback) {
if (GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION.equals(notification.getType())) {
final GcInfo gcInfo = GarbageCollectionNotificationInfo.from((CompositeData) notification.getUserData()).getGcInfo();
final Duration duration = Duration.milliseconds(gcInfo.getDuration());
if (duration.compareTo(gcWarningThreshold) > 0) {
LOG.warn("Last GC run with {} took longer than {} (last duration={})",
gc.getName(), gcWarningThreshold, duration);
final Notification systemNotification = notificationService.buildNow()
.addNode(nodeId.toString())
.addTimestamp(Tools.nowUTC())
.addSeverity(Notification.Severity.URGENT)
.addType(Notification.Type.GC_TOO_LONG)
.addDetail("gc_name", gc.getName())
.addDetail("gc_duration_ms", duration.toMilliseconds())
.addDetail("gc_threshold_ms", gcWarningThreshold.toMilliseconds())
.addDetail("gc_collection_count", gc.getCollectionCount())
.addDetail("gc_collection_time", gc.getCollectionTime());
if (!notificationService.publishIfFirst(systemNotification)) {
LOG.debug("Couldn't publish notification: {}", notification);
}
}
}
}
};
代码示例来源:origin: cloudfoundry/uaa
@Test
public void happy_path() throws Exception {
filter.setPerRequestMetrics(true);
String path = performTwoSimpleRequests();
Map<String, String> summary = filter.getSummary();
assertNotNull(summary);
assertFalse(summary.isEmpty());
assertEquals(2, summary.size());
for (String uri : Arrays.asList(path, MetricsUtil.GLOBAL_GROUP)) {
MetricsQueue totals = readValue(summary.get(filter.getUriGroup(request).getGroup()), MetricsQueue.class);
assertNotNull("URI:"+uri, totals);
for (StatusCodeGroup status : Arrays.asList(StatusCodeGroup.SUCCESS, StatusCodeGroup.SERVER_ERROR)) {
RequestMetricSummary total = totals.getDetailed().get(status);
assertEquals("URI:"+uri, 1, total.getCount());
}
}
assertNull(MetricsAccessor.getCurrent());
ArgumentCaptor<Notification> argumentCaptor = ArgumentCaptor.forClass(Notification.class);
verify(publisher, times(2)).sendNotification(argumentCaptor.capture());
List<Notification> capturedArg = argumentCaptor.getAllValues();
assertEquals(2, capturedArg.size());
assertEquals("/api" , capturedArg.get(0).getType());
}
代码示例来源:origin: cloudfoundry/uaa
@Test
public void intolerable_request() throws Exception {
TimeService slowRequestTimeService = new TimeService() {
long now = System.currentTimeMillis();
@Override
public long getCurrentTimeMillis() {
now += 5000;
return now;
}
};
for (TimeService timeService : Arrays.asList(slowRequestTimeService, new TimeServiceImpl())) {
reset(publisher);
filter = new UaaMetricsFilter();
filter.setPerRequestMetrics(true);
filter.setTimeService(timeService);
filter.setNotificationPublisher(publisher);
String path = "/authenticate/test";
setRequestData(path);
filter.getUriGroup(request).setLimit(1000);
filter.doFilterInternal(request, response, chain);
MetricsQueue metricsQueue = filter.getMetricsQueue(filter.getUriGroup(request).getGroup());
RequestMetricSummary totals = metricsQueue.getTotals();
assertEquals(1, totals.getCount());
assertEquals(timeService == slowRequestTimeService ? 1 : 0, totals.getIntolerableCount());
ArgumentCaptor<Notification> argumentCaptor = ArgumentCaptor.forClass(Notification.class);
verify(publisher).sendNotification(argumentCaptor.capture());
Notification capturedArg = argumentCaptor.getValue();
assertEquals("/api" , capturedArg.getType());
}
}
代码示例来源:origin: apache/log4j
public
void handleNotification(Notification notification, Object handback) {
cat.debug("Received notification: "+notification.getType());
registerAppenderMBean((Appender) notification.getUserData() );
}
代码示例来源:origin: hcoles/pitest
private static void addMemoryWatchDog(final Reporter r) {
final NotificationListener listener = (notification, handback) -> {
final String type = notification.getType();
if (type.equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED)) {
final CompositeData cd = (CompositeData) notification.getUserData();
final MemoryNotificationInfo memInfo = MemoryNotificationInfo
.from(cd);
CommandLineMessage.report(memInfo.getPoolName()
+ " has exceeded the shutdown threshold : " + memInfo.getCount()
+ " times.\n" + memInfo.getUsage());
r.done(ExitCode.OUT_OF_MEMORY);
} else {
LOG.warning("Unknown notification: " + notification);
}
};
MemoryWatchdog.addWatchDogToAllPools(90, listener);
}
代码示例来源:origin: spring-projects/spring-integration
@Test
public void testPublish() {
publishChannel.send(new GenericMessage<String>("bar"));
Message<?> message = publishInChannel.receive(100000);
assertNotNull(message);
assertTrue(message.getPayload() instanceof Notification);
Notification notification = (Notification) message.getPayload();
assertEquals("bar", notification.getMessage());
assertEquals("foo", notification.getType());
}
代码示例来源:origin: spring-projects/spring-integration
@Test
public void defaultNotificationType() throws Exception {
assertNull(listener.lastNotification);
Message<?> message = MessageBuilder.withPayload("test").build();
channel.send(message);
assertNotNull(listener.lastNotification);
Notification notification = listener.lastNotification;
assertEquals("default.type", notification.getType());
}
代码示例来源:origin: spring-projects/spring-integration
@Test
public void simplePublish() {
MessageHandler handler = context.getBean("testPublisher", MessageHandler.class);
assertEquals(0, this.listener.notifications.size());
handler.handleMessage(new GenericMessage<String>("foo"));
assertEquals(1, this.listener.notifications.size());
Notification notification = this.listener.notifications.get(0);
assertEquals(this.publisherObjectName, notification.getSource());
assertEquals("foo", notification.getMessage());
assertEquals("test.type", notification.getType());
}
代码示例来源:origin: spring-projects/spring-integration
@Test
public void publishUserData() throws Exception {
assertNull(listener.lastNotification);
TestData data = new TestData();
Message<?> message = MessageBuilder.withPayload(data)
.setHeader(JmxHeaders.NOTIFICATION_TYPE, "test.type").build();
channel.send(message);
assertNotNull(listener.lastNotification);
Notification notification = listener.lastNotification;
assertNull(notification.getMessage());
assertEquals(data, notification.getUserData());
assertEquals("test.type", notification.getType());
}
代码示例来源:origin: spring-projects/spring-integration
@Test
public void publishStringMessage() throws Exception {
adviceCalled = 0;
assertNull(listener.lastNotification);
Message<?> message = MessageBuilder.withPayload("XYZ")
.setHeader(JmxHeaders.NOTIFICATION_TYPE, "test.type").build();
channel.send(message);
assertNotNull(listener.lastNotification);
Notification notification = listener.lastNotification;
assertEquals("XYZ", notification.getMessage());
assertEquals("test.type", notification.getType());
assertNull(notification.getUserData());
assertEquals(1, adviceCalled);
}
内容来源于网络,如有侵权,请联系作者删除!