下面列出了javax.management.Notification#setUserData ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
void createGCNotification(long timestamp,
String gcName,
String gcAction,
String gcCause,
GcInfo gcInfo) {
if (!hasListeners()) {
return;
}
Notification notif = new Notification(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION,
getObjectName(),
getNextSeqNumber(),
timestamp,
gcName);
GarbageCollectionNotificationInfo info =
new GarbageCollectionNotificationInfo(gcName,
gcAction,
gcCause,
gcInfo);
CompositeData cd =
GarbageCollectionNotifInfoCompositeData.toCompositeData(info);
notif.setUserData(cd);
sendNotification(notif);
}
void createGCNotification(long timestamp,
String gcName,
String gcAction,
String gcCause,
GcInfo gcInfo) {
if (!hasListeners()) {
return;
}
Notification notif = new Notification(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION,
getObjectName(),
getNextSeqNumber(),
timestamp,
gcName);
GarbageCollectionNotificationInfo info =
new GarbageCollectionNotificationInfo(gcName,
gcAction,
gcCause,
gcInfo);
CompositeData cd =
GarbageCollectionNotifInfoCompositeData.toCompositeData(info);
notif.setUserData(cd);
sendNotification(notif);
}
static void createNotification(String notifType,
String poolName,
MemoryUsage usage,
long count) {
MemoryImpl mbean = (MemoryImpl) ManagementFactory.getMemoryMXBean();
if (!mbean.hasListeners()) {
// if no listener is registered.
return;
}
long timestamp = System.currentTimeMillis();
String msg = getNotifMsg(notifType);
Notification notif = new Notification(notifType,
mbean.getObjectName(),
getNextSeqNumber(),
timestamp,
msg);
MemoryNotificationInfo info =
new MemoryNotificationInfo(poolName,
usage,
count);
CompositeData cd =
MemoryNotifInfoCompositeData.toCompositeData(info);
notif.setUserData(cd);
mbean.sendNotification(notif);
}
void createGCNotification(long timestamp,
String gcName,
String gcAction,
String gcCause,
GcInfo gcInfo) {
if (!hasListeners()) {
return;
}
Notification notif = new Notification(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION,
getObjectName(),
getNextSeqNumber(),
timestamp,
gcName);
GarbageCollectionNotificationInfo info =
new GarbageCollectionNotificationInfo(gcName,
gcAction,
gcCause,
gcInfo);
CompositeData cd =
GarbageCollectionNotifInfoCompositeData.toCompositeData(info);
notif.setUserData(cd);
sendNotification(notif);
}
/**
* Implementation should handle loss of region by extracting the details from
* the given event object and sending the
* {@link SystemMemberJmx#NOTIF_REGION_LOST} notification to the connected
* JMX Clients. Region Path is set as User Data in Notification. Additionally,
* it also clears the ManagedResources created for the region that is lost.
*
* @param event
* event object corresponding to the loss of a region
*/
public void handleRegionLoss(SystemMemberRegionEvent event) {
SystemMemberCacheJmxImpl cacheResource = this.managedSystemMemberCache;
if (cacheResource != null) {
ManagedResource cleanedUp =
cacheResource.cleanupRegionResources(event.getRegionPath());
if (cleanedUp != null) {
MBeanUtil.unregisterMBean(cleanedUp);
}
}
LogWriterI18n logWriterI18n =
this.getDistributedSystem().getLogWriter().convertToLogWriterI18n();
Notification notification = new Notification(NOTIF_REGION_LOST,
this.modelMBean,
Helper.getNextNotificationSequenceNumber(),
Helper.getRegionEventDetails(event));
notification.setUserData(event.getRegionPath());
Helper.sendNotification(logWriterI18n, this, notification);
}
static void createNotification(String notifType,
String poolName,
MemoryUsage usage,
long count) {
MemoryImpl mbean = (MemoryImpl) ManagementFactory.getMemoryMXBean();
if (!mbean.hasListeners()) {
// if no listener is registered.
return;
}
long timestamp = System.currentTimeMillis();
String msg = getNotifMsg(notifType);
Notification notif = new Notification(notifType,
mbean.getObjectName(),
getNextSeqNumber(),
timestamp,
msg);
MemoryNotificationInfo info =
new MemoryNotificationInfo(poolName,
usage,
count);
CompositeData cd =
MemoryNotifInfoCompositeData.toCompositeData(info);
notif.setUserData(cd);
mbean.sendNotification(notif);
}
void createGCNotification(long timestamp,
String gcName,
String gcAction,
String gcCause,
GcInfo gcInfo) {
if (!hasListeners()) {
return;
}
Notification notif = new Notification(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION,
getObjectName(),
getNextSeqNumber(),
timestamp,
gcName);
GarbageCollectionNotificationInfo info =
new GarbageCollectionNotificationInfo(gcName,
gcAction,
gcCause,
gcInfo);
CompositeData cd =
GarbageCollectionNotifInfoCompositeData.toCompositeData(info);
notif.setUserData(cd);
sendNotification(notif);
}
/**
* Implementation should handle loss of region by extracting the details from
* the given event object and sending the
* {@link SystemMemberJmx#NOTIF_REGION_LOST} notification to the connected
* JMX Clients. Region Path is set as User Data in Notification. Additionally,
* it also clears the ManagedResources created for the region that is lost.
*
* @param event
* event object corresponding to the loss of a region
*/
public void handleRegionLoss(SystemMemberRegionEvent event) {
SystemMemberCacheJmxImpl cacheResource = this.managedSystemMemberCache;
if (cacheResource != null) {
ManagedResource cleanedUp =
cacheResource.cleanupRegionResources(event.getRegionPath());
if (cleanedUp != null) {
MBeanUtil.unregisterMBean(cleanedUp);
}
}
LogWriterI18n logWriterI18n =
this.getDistributedSystem().getLogWriter().convertToLogWriterI18n();
Notification notification = new Notification(NOTIF_REGION_LOST, this.modelMBean,
Helper.getNextNotificationSequenceNumber(),
Helper.getRegionEventDetails(event));
notification.setUserData(event.getRegionPath());
Helper.sendNotification(logWriterI18n, this, notification);
}
static void createNotification(String notifType,
String poolName,
MemoryUsage usage,
long count) {
MemoryImpl mbean = (MemoryImpl) ManagementFactory.getMemoryMXBean();
if (!mbean.hasListeners()) {
// if no listener is registered.
return;
}
long timestamp = System.currentTimeMillis();
String msg = getNotifMsg(notifType);
Notification notif = new Notification(notifType,
mbean.getObjectName(),
getNextSeqNumber(),
timestamp,
msg);
MemoryNotificationInfo info =
new MemoryNotificationInfo(poolName,
usage,
count);
CompositeData cd =
MemoryNotifInfoCompositeData.toCompositeData(info);
notif.setUserData(cd);
mbean.sendNotification(notif);
}
void createGCNotification(long timestamp,
String gcName,
String gcAction,
String gcCause,
GcInfo gcInfo) {
if (!hasListeners()) {
return;
}
Notification notif = new Notification(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION,
getObjectName(),
getNextSeqNumber(),
timestamp,
gcName);
GarbageCollectionNotificationInfo info =
new GarbageCollectionNotificationInfo(gcName,
gcAction,
gcCause,
gcInfo);
CompositeData cd =
GarbageCollectionNotifInfoCompositeData.toCompositeData(info);
notif.setUserData(cd);
sendNotification(notif);
}
static void createNotification(String notifType,
String poolName,
MemoryUsage usage,
long count) {
MemoryImpl mbean = (MemoryImpl) ManagementFactory.getMemoryMXBean();
if (!mbean.hasListeners()) {
// if no listener is registered.
return;
}
long timestamp = System.currentTimeMillis();
String msg = getNotifMsg(notifType);
Notification notif = new Notification(notifType,
mbean.getObjectName(),
getNextSeqNumber(),
timestamp,
msg);
MemoryNotificationInfo info =
new MemoryNotificationInfo(poolName,
usage,
count);
CompositeData cd =
MemoryNotifInfoCompositeData.toCompositeData(info);
notif.setUserData(cd);
mbean.sendNotification(notif);
}
/**
* Sends the alert with the Object source as member. This notification will
* get filtered out for particular alert level
*
* @param details
*/
public void handleSystemNotification(AlertDetails details) {
if (!isServiceInitialised("handleSystemNotification")) {
return;
}
if (service.isManager()) {
String systemSource = "DistributedSystem(" + service.getDistributedSystemMXBean().getDistributedSystemId() + ")";
Notification notification = new Notification(ResourceNotification.SYSTEM_ALERT, systemSource, SequenceNumber
.next(), details.getMsgTime().getTime(), details.toString());
InternalDistributedMember sender = details.getSender();
String nameOrId = memberSource; // TODO Rishi/Abhishek - what if sender is
// null?
if (sender != null) {
nameOrId = sender.getName();
nameOrId = nameOrId != null && !nameOrId.trim().isEmpty() ? nameOrId : sender.getId();
}
notification.setUserData(nameOrId);
service.handleNotification(notification);
}
}
/**
* Implementation handles creation of region by extracting the details from
* the given event object and sending the
* {@link SystemMemberJmx#NOTIF_REGION_CREATED} notification to the connected
* JMX Clients. Region Path is set as User Data in Notification.
*
* @param event
* event object corresponding to the creation of a region
*/
public void handleRegionCreate(SystemMemberRegionEvent event) {
LogWriterI18n logWriterI18n =
this.getDistributedSystem().getLogWriter().convertToLogWriterI18n();
Notification notification = new Notification(NOTIF_REGION_CREATED, this.modelMBean,
Helper.getNextNotificationSequenceNumber(),
Helper.getRegionEventDetails(event));
notification.setUserData(event.getRegionPath());
Helper.sendNotification(logWriterI18n, this, notification);
}
/**
* sendNotification
*
* @param eventType
* @param data
* @param msg
*/
public void sendNotification(String eventType, Object data, String msg) {
Notification notif = new Notification(eventType, this, sequenceNumber
.incrementAndGet(), System.currentTimeMillis(), msg);
if (data != null) {
notif.setUserData(data);
}
emitter.sendNotification(notif);
}
public void onSuccess(StreamState result)
{
Notification notif = new Notification(StreamEvent.class.getCanonicalName() + ".success",
StreamManagerMBean.OBJECT_NAME,
seq.getAndIncrement());
notif.setUserData(StreamStateCompositeData.toCompositeData(result));
sendNotification(notif);
}
private void createDiagnosticFrameworkNotification() {
if (!hasListeners()) {
return;
}
ObjectName on = null;
try {
on = ObjectName.getInstance(PlatformMBeanProviderImpl.DIAGNOSTIC_COMMAND_MBEAN_NAME);
} catch (MalformedObjectNameException e) { }
Notification notif = new Notification("jmx.mbean.info.changed",
on,
getNextSeqNumber());
notif.setUserData(getMBeanInfo());
sendNotification(notif);
}
public void onFailure(Throwable t)
{
Notification notif = new Notification(StreamEvent.class.getCanonicalName() + ".failure",
StreamManagerMBean.OBJECT_NAME,
seq.getAndIncrement());
notif.setUserData(t.fillInStackTrace().toString());
sendNotification(notif);
}
public void sendNotification(long runId, String type, String message, Object userData) {
Notification notification = new Notification(type, MBEAN_NAME, 0); // CLO-13065: the sequence number will be set by JmxNotificationSender
notification.setUserData(new JMXNotificationMessage(runId, userData));
sendNotification(notification);
}
/**
* Consumes the given record by sending a notification.
*
* @param record
* The record to consume.
*
* @return Always true.
*/
public final boolean newMonitoringRecord(final IMonitoringRecord record) {
final Notification notification = new Notification(MESSAGE_TYPE, this.kiekerMonitoringLogName, 0L, 0L);
notification.setUserData(record);
super.sendNotification(notification);
return true;
}
/**
* Sends JMX notification to subscribers.
*
* @param type Message type
* @param message Message itself
* @param userObject Arbitrary object to attach to notification
*/
public void sendNotification(String type, String message, Object userObject)
{
Notification jmxNotification = new Notification(type, jmxObjectName, notificationSerialNumber.incrementAndGet(), message);
jmxNotification.setUserData(userObject);
sendNotification(jmxNotification);
}