1 23 24 28 29 package com.sun.enterprise.admin.selfmanagement.event; 30 31 32 import javax.management.NotificationEmitter ; 33 import javax.management.MBeanServer ; 34 35 import com.sun.enterprise.config.serverbeans.ElementProperty; 36 import java.util.logging.Level ; 37 import static com.sun.enterprise.admin.selfmanagement.event.ManagementRuleConstants.*; 38 39 43 44 public class TraceEventFactory extends EventAbstractFactory { 45 46 private TraceEventFactory( ) { 47 super(); 48 EventBuilder.getInstance().addEventFactory(EVENT_TRACE, this); 49 try { 50 TraceEventImpl impl = (TraceEventImpl) getMBeanServer().instantiate( 51 "com.sun.enterprise.admin.selfmanagement.event.TraceEventImpl"); 52 getMBeanServer().registerMBean(impl,TraceEvent.getTraceImplObjectName()); 53 } catch (javax.management.ReflectionException rex) { 54 _logger.log(Level.WARNING,"smgt.internal_error", rex); 55 } catch (javax.management.InstanceAlreadyExistsException iex) { 56 _logger.log(Level.WARNING,"smgt.internal_error", iex); 57 } catch (Exception ex) { 58 _logger.log(Level.WARNING,"smgt.internal_error", ex); 59 60 } 61 } 62 63 private synchronized void enableNotifications(boolean enable) { 64 if (!notificationsEnabled) { 65 CallflowEventListener.register(); 66 notificationsEnabled = true; 67 } else if (!enable) { 68 CallflowEventListener.unregister(); 69 } 70 } 71 72 public Event instrumentEvent( 73 ElementProperty[] properties, String description ) { 74 enableNotifications(true); 75 String eventName = "*"; 76 String ipAddress = "*"; 77 String callerPrincipal = "*"; 78 String componentName = "*"; 79 for( int i = 0; i < properties.length; i++ ){ 80 ElementProperty property = properties[i]; 81 String propertyName = property.getName( ).toLowerCase( ); 82 if( propertyName.equals(PROPERTY_TRACE_NAME)) { 83 eventName = "trace." + property.getValue( ).toLowerCase( ); 84 if (!TraceEvent.isValidType(eventName)) 85 throw new IllegalArgumentException ( 86 sm.getString(PROPERTY_TRACE_NAME, 87 "selfmgmt_event.invalid_event_property",EVENT_TRACE)); 88 } 89 if(propertyName.equals(PROPERTY_TRACE_IPADDRESS)) { 90 ipAddress = property.getValue( ).toLowerCase( ); 91 } 92 if(propertyName.equals(PROPERTY_TRACE_CALLERPRINCIPAL)) { 93 callerPrincipal = property.getValue( ).toLowerCase( ); 94 } 95 if(propertyName.equals(PROPERTY_TRACE_COMPONENTNAME)) { 96 componentName = property.getValue( ).toLowerCase( ); 97 } 98 } 99 return new TraceEvent(eventName, 100 new TraceEventNotificationFilter(eventName, ipAddress, callerPrincipal, componentName), 101 description); 102 } 103 104 static TraceEventFactory getInstance() { 105 return instance; 106 } 107 private boolean notificationsEnabled = false; 108 private static TraceEventFactory instance = new TraceEventFactory(); 109 } 110 | Popular Tags |