本文整理匯總了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());
}
}