本文整理汇总了Java中javax.management.Notification类的典型用法代码示例。如果您正苦于以下问题:Java Notification类的具体用法?Java Notification怎么用?Java Notification使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Notification类属于javax.management包,在下文中一共展示了Notification类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkNotifs
import javax.management.Notification; //导入依赖的package包/类
/**
* Check received notifications
*/
public int checkNotifs(int size,
List<Notification> received,
List<ObjectName> expected) {
if (received.size() != size) {
echo("Error: expecting " + size + " notifications, got " +
received.size());
return 1;
} else {
for (Notification n : received) {
echo("Received notification: " + n);
if (!n.getType().equals("nb")) {
echo("Notification type must be \"nb\"");
return 1;
}
ObjectName o = (ObjectName) n.getSource();
int index = (int) n.getSequenceNumber();
ObjectName nb = expected.get(index);
if (!o.equals(nb)) {
echo("Notification source must be " + nb);
return 1;
}
}
}
return 0;
}
示例2: handleNotification
import javax.management.Notification; //导入依赖的package包/类
@Override
public void handleNotification(Notification notification,
Object handback) {
notificationCount.incrementAndGet();
System.out.println("\nReceived notification:");
System.out.println("\tClassName: " + notification.getClass().getName());
System.out.println("\tSource: " + notification.getSource());
System.out.println("\tType: " + notification.getType());
System.out.println("\tMessage: " + notification.getMessage());
if (notification instanceof AttributeChangeNotification) {
AttributeChangeNotification acn =
(AttributeChangeNotification) notification;
System.out.println("\tAttributeName: " + acn.getAttributeName());
System.out.println("\tAttributeType: " + acn.getAttributeType());
System.out.println("\tNewValue: " + acn.getNewValue());
System.out.println("\tOldValue: " + acn.getOldValue());
}
}
示例3: handleGatewaySenderCreation
import javax.management.Notification; //导入依赖的package包/类
/**
* Handles GatewaySender creation
*
* @param sender the specific gateway sender
* @throws ManagementException
*/
public void handleGatewaySenderCreation(GatewaySender sender) throws ManagementException {
if (!isServiceInitialised("handleGatewaySenderCreation")) {
return;
}
GatewaySenderMBeanBridge bridge = new GatewaySenderMBeanBridge(sender);
GatewaySenderMXBean senderMBean = new GatewaySenderMBean(bridge);
ObjectName senderObjectName = MBeanJMXAdapter.getGatewaySenderMBeanName(
cacheImpl.getDistributedSystem().getDistributedMember(), sender.getId());
ObjectName changedMBeanName = service.registerInternalMBean(senderMBean, senderObjectName);
service.federate(changedMBeanName, GatewaySenderMXBean.class, true);
Notification notification = new Notification(JMXNotificationType.GATEWAY_SENDER_CREATED,
memberSource, SequenceNumber.next(), System.currentTimeMillis(),
ManagementConstants.GATEWAY_SENDER_CREATED_PREFIX);
memberLevelNotifEmitter.sendNotification(notification);
}
示例4: createGatewayReceiverMBean
import javax.management.Notification; //导入依赖的package包/类
private void createGatewayReceiverMBean(GatewayReceiver recv) {
GatewayReceiverMBeanBridge bridge = new GatewayReceiverMBeanBridge(recv);
GatewayReceiverMXBean receiverMBean = new GatewayReceiverMBean(bridge);
ObjectName recvObjectName = MBeanJMXAdapter
.getGatewayReceiverMBeanName(cacheImpl.getDistributedSystem().getDistributedMember());
ObjectName changedMBeanName = service.registerInternalMBean(receiverMBean, recvObjectName);
service.federate(changedMBeanName, GatewayReceiverMXBean.class, true);
Notification notification = new Notification(JMXNotificationType.GATEWAY_RECEIVER_CREATED,
memberSource, SequenceNumber.next(), System.currentTimeMillis(),
ManagementConstants.GATEWAY_RECEIVER_CREATED_PREFIX);
memberLevelNotifEmitter.sendNotification(notification);
}
示例5: destroyInternal
import javax.management.Notification; //导入依赖的package包/类
/** Destroy needs to clean up the context completely.
*
* The problem is that undoing all the config in start() and restoring
* a 'fresh' state is impossible. After stop()/destroy()/init()/start()
* we should have the same state as if a fresh start was done - i.e
* read modified web.xml, etc. This can only be done by completely
* removing the context object and remapping a new one, or by cleaning
* up everything.
*
* XXX Should this be done in stop() ?
*
*/
@Override
protected void destroyInternal() throws LifecycleException {
// If in state NEW when destroy is called, the object name will never
// have been set so the notification can't be created
if (getObjectName() != null) {
// Send j2ee.object.deleted notification
Notification notification =
new Notification("j2ee.object.deleted", this.getObjectName(),
sequenceNumber.getAndIncrement());
broadcaster.sendNotification(notification);
}
if (namingResources != null) {
namingResources.destroy();
}
synchronized (instanceListenersLock) {
instanceListeners = new String[0];
}
super.destroyInternal();
}
示例6: handleSystemNotification
import javax.management.Notification; //导入依赖的package包/类
/**
* 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() + ")";
Map<String, String> userData = prepareUserData(details);
Notification notification = new Notification(JMXNotificationType.SYSTEM_ALERT, systemSource,
SequenceNumber.next(), details.getMsgTime().getTime(), details.getMsg());
notification.setUserData(userData);
service.handleNotification(notification);
}
}
示例7: handleNotification
import javax.management.Notification; //导入依赖的package包/类
public void handleNotification(Notification n, Object hb) {
System.out.println("\tReceived notification: " + n.getType());
if (n instanceof MonitorNotification) {
MonitorNotification mn = (MonitorNotification) n;
System.out.println("\tSource: " +
mn.getSource());
System.out.println("\tType: " +
mn.getType());
System.out.println("\tTimeStamp: " +
mn.getTimeStamp());
System.out.println("\tObservedObject: " +
mn.getObservedObject());
System.out.println("\tObservedAttribute: " +
mn.getObservedAttribute());
System.out.println("\tDerivedGauge: " +
mn.getDerivedGauge());
System.out.println("\tTrigger: " +
mn.getTrigger());
}
}
示例8: handleGatewayReceiverStop
import javax.management.Notification; //导入依赖的package包/类
/**
* Handles Gateway receiver creation
*
* @param recv specific gateway receiver
* @throws ManagementException
*/
public void handleGatewayReceiverStop(GatewayReceiver recv) throws ManagementException {
if (!isServiceInitialised("handleGatewayReceiverStop")) {
return;
}
GatewayReceiverMBean mbean = (GatewayReceiverMBean) service.getLocalGatewayReceiverMXBean();
GatewayReceiverMBeanBridge bridge = mbean.getBridge();
bridge.stopServer();
Notification notification = new Notification(JMXNotificationType.GATEWAY_RECEIVER_STOPPED,
memberSource, SequenceNumber.next(), System.currentTimeMillis(),
ManagementConstants.GATEWAY_RECEIVER_STOPPED_PREFIX);
memberLevelNotifEmitter.sendNotification(notification);
}
示例9: initInternal
import javax.management.Notification; //导入依赖的package包/类
@Override
protected void initInternal() throws LifecycleException {
super.initInternal();
if (processTlds) {
this.addLifecycleListener(new TldConfig());
}
// Register the naming resources
if (namingResources != null) {
namingResources.init();
}
// Send j2ee.object.created notification
if (this.getObjectName() != null) {
Notification notification = new Notification("j2ee.object.created", this.getObjectName(),
sequenceNumber.getAndIncrement());
broadcaster.sendNotification(notification);
}
}
示例10: handleNotification
import javax.management.Notification; //导入依赖的package包/类
@Override
public void handleNotification(Notification notification, Object handback) {
String nType = notification.getType();
String poolName
= CodeCacheUtils.getPoolNameFromNotification(notification);
// consider code cache events only
if (CodeCacheUtils.isAvailableCodeHeapPoolName(poolName)) {
Asserts.assertEQ(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED,
nType, "Unexpected event received: " + nType);
// receiving events from available CodeCache-related beans only
if (counters.get(poolName) != null) {
counters.get(poolName).incrementAndGet();
lastEventTimestamp = System.currentTimeMillis();
}
}
}
示例11: handleNotification
import javax.management.Notification; //导入依赖的package包/类
public void handleNotification(Notification notification, Object handback) {
echo(">>> Received notification: " + notification);
if (notification instanceof MonitorNotification) {
String type = notification.getType();
if (type.equals(MonitorNotification.RUNTIME_ERROR)) {
MonitorNotification mn = (MonitorNotification) notification;
echo("\tType: " + mn.getType());
echo("\tTimeStamp: " + mn.getTimeStamp());
echo("\tObservedObject: " + mn.getObservedObject());
echo("\tObservedAttribute: " + mn.getObservedAttribute());
echo("\tDerivedGauge: " + mn.getDerivedGauge());
echo("\tTrigger: " + mn.getTrigger());
synchronized (this) {
messageReceived = true;
notifyAll();
}
}
}
}
示例12: sendNotification
import javax.management.Notification; //导入依赖的package包/类
/**
* Send the supplied {@link Notification} using the wrapped
* {@link ModelMBean} instance.
* @param notification the {@link Notification} to be sent
* @throws IllegalArgumentException if the supplied {@code notification} is {@code null}
* @throws UnableToSendNotificationException if the supplied {@code notification} could not be sent
*/
@Override
public void sendNotification(Notification notification) {
Assert.notNull(notification, "Notification must not be null");
replaceNotificationSourceIfNecessary(notification);
try {
if (notification instanceof AttributeChangeNotification) {
this.modelMBean.sendAttributeChangeNotification((AttributeChangeNotification) notification);
}
else {
this.modelMBean.sendNotification(notification);
}
}
catch (MBeanException ex) {
throw new UnableToSendNotificationException("Unable to send notification [" + notification + "]", ex);
}
}
示例13: checkNotifs
import javax.management.Notification; //导入依赖的package包/类
public int checkNotifs(int size,
List<Notification> received,
List<ObjectName> expected) {
if (received.size() != size) {
echo("Error: expecting " + size + " notifications, got " +
received.size());
return 1;
} else {
for (Notification n : received) {
echo("Received notification: " + n);
if (!n.getType().equals("nb")) {
echo("Notification type must be \"nb\"");
return 1;
}
ObjectName o = (ObjectName) n.getSource();
int index = (int) n.getSequenceNumber();
ObjectName nb = expected.get(index);
if (!o.equals(nb)) {
echo("Notification source must be " + nb);
return 1;
}
}
}
return 0;
}
示例14: destroy
import javax.management.Notification; //导入依赖的package包/类
/** Destroy needs to clean up the context completely.
*
* The problem is that undoing all the config in start() and restoring
* a 'fresh' state is impossible. After stop()/destroy()/init()/start()
* we should have the same state as if a fresh start was done - i.e
* read modified web.xml, etc. This can only be done by completely
* removing the context object and remapping a new one, or by cleaning
* up everything.
*
* XXX Should this be done in stop() ?
*
*/
public void destroy() throws Exception {
if( oname != null ) {
// Send j2ee.object.deleted notification
Notification notification =
new Notification("j2ee.object.deleted", this.getObjectName(),
sequenceNumber++);
broadcaster.sendNotification(notification);
}
super.destroy();
// Notify our interested LifecycleListeners
lifecycle.fireLifecycleEvent(DESTROY_EVENT, null);
instanceListeners = new String[0];
}
示例15: handleNotification
import javax.management.Notification; //导入依赖的package包/类
@Override
public void handleNotification(Notification notification, Object handback) {
if (notification.getType().equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
System.out.println("0XDEADBEAF");
GarbageCollectionNotificationInfo notifInfo = GarbageCollectionNotificationInfo.from((CompositeData) notification.getUserData());
GcInfo gcInfo = notifInfo.getGcInfo();
System.out.printf("Action: %s, %s, %s\n", notifInfo.getGcAction(), notifInfo.getGcCause(), notifInfo.getGcName());
System.out.printf("Time: %d, %d, %d\n", gcInfo.getStartTime(), gcInfo.getEndTime(), gcInfo.getDuration());
System.out.printf("Memory: %s, %s\n", gcInfo.getMemoryUsageBeforeGc().toString(), gcInfo.getMemoryUsageAfterGc().toString());
Map<String, MemoryUsage> memBefore = notifInfo.getGcInfo().getMemoryUsageBeforeGc();
Map<String, MemoryUsage> memAfter = notifInfo.getGcInfo().getMemoryUsageAfterGc();
StringBuilder sb = new StringBuilder();
sb.append("[").append(notifInfo.getGcAction()).append(" / ").append(notifInfo.getGcCause())
.append(" / ").append(notifInfo.getGcName()).append(" / (");
appendMemUsage(sb, memBefore);
sb.append(") -> (");
appendMemUsage(sb, memAfter);
sb.append("), ").append(notifInfo.getGcInfo().getDuration()).append(" ms]");
System.out.println(sb.toString());
}
}