FileDocCategorySizeDatePackage
TimerEventFactory.javaAPI DocGlassfish v2 API6500Fri May 04 22:33:46 BST 2007com.sun.enterprise.admin.selfmanagement.event

TimerEventFactory

public final class TimerEventFactory extends EventAbstractFactory
This is the factory to build and configure Timer Event
author
Sun Micro Systems, Inc

Fields Summary
private static final TimerEventFactory
instance
private static final String
defaultPattern
private static Timer
timer
Constructors Summary
TimerEventFactory()
Creates a new instance of LogEventFactory

        super();
        EventBuilder.getInstance().addEventFactory(EVENT_TIMER, this);
    
Methods Summary
static com.sun.enterprise.admin.selfmanagement.event.TimerEventFactorygetInstance()

        return instance;
    
private synchronized javax.management.timer.TimergetTimer()

        if (timer != null)
            return timer;
        try {
            timer = (Timer)getMBeanServer().instantiate("javax.management.timer.Timer");
            getMBeanServer().registerMBean(timer,TimerEvent.getTimerObjectName());
            timer.start();
            return timer;
        } catch (Exception ex) {
            _logger.log(Level.WARNING,"smgt.internal_error", ex);
        }
        return timer;
    
public EventinstrumentEvent(com.sun.enterprise.config.serverbeans.ElementProperty[] properties, java.lang.String description)

        // expected properties:
        // datestring : one which DateFormatter.parse understands
        // pattern : format dd/mm/yyyy hh:mm:ss
        // period
        // message
        // numberofoccurrences
        
        String datePattern = null;
        String dateString = null;
        long period = 0;
        long numberOfOccurrences = 0;
        String message = "timer notification";
        String type = "timer";
        SimpleDateFormat format  = null;
        
        for( int i = 0; i < properties.length; i++ ){
            ElementProperty property = properties[i];
            String propertyName = property.getName( ).toLowerCase( );
            if (propertyName.equals(PROPERTY_TIMER_PATTERN))
                datePattern = property.getValue();
            if (propertyName.equals(PROPERTY_TIMER_DATESTRING))
                dateString = property.getValue();
            if (propertyName.equals(PROPERTY_TIMER_PERIOD))
                period = Long.parseLong(property.getValue());
            if (propertyName.equals(PROPERTY_TIMER_NUMBER_OF_OCCURRENCES) )
                numberOfOccurrences = Long.parseLong(property.getValue());
            if (propertyName.equals(PROPERTY_TIMER_MESSAGE) )
                message = property.getValue();
            
        }
        
        /**
        if (dateString == null)
            throw new IllegalArgumentException(
                    sm.getString("selfmgmt_event.invalid_event_property","dateString","timer"));
        **/
        if (datePattern == null)
            datePattern = defaultPattern;
        
        
        Date d = null;
        try {
            if (dateString ==  null)
                d = new Date();
            else
                d = new SimpleDateFormat(datePattern).parse(dateString);
        } catch (java.text.ParseException pex) {
            throw new IllegalArgumentException(
                    sm.getString("selfmgmt_event.invalid_event_property","dateString","timer"),pex);
        }
        Integer id = 0;
        if (period > 0) {
            if (numberOfOccurrences > 0 )
                id = getTimer().addNotification(type,message,null,d,period,numberOfOccurrences);
            else id = getTimer().addNotification(type,message,null,d,period);
            
        } else {
            id = getTimer().addNotification(type,message,null,d);
        }
        return new TimerEvent(id, new TimerEventFilter(id), description);
    
voidremoveEvent(int id)

        try {
            getTimer().removeNotification(id);
        } catch (javax.management.InstanceNotFoundException iex) {
            _logger.log(Level.WARNING,"smgt.internal_error", iex);
        }