PageRenderTime 20ms CodeModel.GetById 8ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/jwatch/src/main/java/org/jwatch/listener/notification/Listener.java

http://jwatch.googlecode.com/
Java | 124 lines | 67 code | 11 blank | 46 comment | 4 complexity | 3ff777052fec1f0f24d3e846910d834c MD5 | raw file
Possible License(s): LGPL-3.0
  1/**
  2 * JWatch - Quartz Monitor: http://code.google.com/p/jwatch/
  3 * Copyright (C) 2011 Roy Russo and the original author or authors.
  4 *
  5 * This library is free software; you can redistribute it and/or
  6 * modify it under the terms of the GNU Lesser General Public
  7 * License as published by the Free Software Foundation; either
  8 * version 3 of the License, or (at your option) any later version.
  9 *
 10 * This library is distributed in the hope that it will be useful,
 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 13 * Lesser General Public License for more details.
 14 *
 15 * You should have received a copy of the GNU Lesser General
 16 * Public License along with this library; if not, write to the
 17 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 18 * Boston, MA 02110-1301 USA
 19 **/
 20package org.jwatch.listener.notification;
 21
 22import org.jwatch.util.JMXUtil;
 23
 24import javax.management.Notification;
 25import javax.management.NotificationListener;
 26import javax.management.openmbean.CompositeDataSupport;
 27import java.util.Date;
 28
 29/**
 30 * One notification listener per scheduler/QuartzInstance combo.
 31 *
 32 * @author <a href="mailto:royrusso@gmail.com">Roy Russo</a>
 33 *         Date: Apr 13, 2011 5:28:59 PM
 34 */
 35public class Listener implements NotificationListener
 36{
 37   private String UUID;
 38   private int _count;
 39
 40   public String getUUID()
 41   {
 42      return UUID;
 43   }
 44
 45   public void setUUID(String UUID)
 46   {
 47      this.UUID = UUID;
 48   }
 49
 50   public Listener()
 51   {
 52      System.out.println("BLAH");
 53   }
 54
 55   @Override
 56   public void handleNotification(Notification notification, Object handback)
 57   {
 58      String type = notification.getType();
 59      Object object = notification.getUserData();
 60      try
 61      {
 62         if ("jobWasExecuted".equalsIgnoreCase(type))
 63         {
 64            if (object != null && object instanceof CompositeDataSupport)
 65            {
 66               CompositeDataSupport compositeDataSupport = (CompositeDataSupport) object;
 67               JobEvent event = new JobEvent();
 68               event.setJobName((String) JMXUtil.convertToType(compositeDataSupport, "jobName"));
 69               event.setCalendarName((String) JMXUtil.convertToType(compositeDataSupport, "calendarName"));
 70               event.setFireTime((Date) JMXUtil.convertToType(compositeDataSupport, "fireTime"));
 71               event.setJobGroup((String) JMXUtil.convertToType(compositeDataSupport, "jobGroup"));
 72               event.setJobRunTime(((Long) JMXUtil.convertToType(compositeDataSupport, "jobRunTime")).longValue());
 73               event.setNextFireTime((Date) JMXUtil.convertToType(compositeDataSupport, "nextFireTime"));
 74               event.setPreviousFireTime((Date) JMXUtil.convertToType(compositeDataSupport, "previousFireTime"));
 75               event.setRecovering(((Boolean) JMXUtil.convertToType(compositeDataSupport, "recovering")).booleanValue());
 76               event.setRefireCount(((Integer) JMXUtil.convertToType(compositeDataSupport, "refireCount")).intValue());
 77               event.setScheduledFireTime((Date) JMXUtil.convertToType(compositeDataSupport, "scheduledFireTime"));
 78               event.setSchedulerName((String) JMXUtil.convertToType(compositeDataSupport, "schedulerName"));
 79               event.setTriggerGroup((String) JMXUtil.convertToType(compositeDataSupport, "triggerGroup"));
 80               event.setTriggerName((String) JMXUtil.convertToType(compositeDataSupport, "triggerName"));
 81               String[] arr = this.getUUID().split("@@");
 82               String uuid = arr[0];
 83               String scheduleID = arr[1];
 84               event.setSchedulerId(scheduleID);
 85               event.setQuartzInstanceId(uuid);
 86               //System.out.println("Event: " + event);
 87
 88               // publish the event
 89               EventService.addEvent(event);
 90            }
 91         }
 92      }
 93      catch (Throwable t)
 94      {
 95         t.printStackTrace();
 96      }
 97
 98      /**
 99       * {calendarName=javax.management.openmbean.SimpleType(name=java.lang.String),
100       * fireTime=javax.management.openmbean.SimpleType(name=java.util.Date),
101       * jobDataMap=javax.management.openmbean.TabularType(name=JobDataMap,
102       * rowType=javax.management.openmbean.CompositeType(name=JobDataMap,i
103       * tems=((itemName=key,itemType=javax.management.openmbean.SimpleType(name=java.lang.String))
104       * ,(itemName=value,itemType=javax.management.openmbean.SimpleType(name=java.lang.String)))),indexNames=(key)),
105       * jobGroup=javax.management.openmbean.SimpleType(name=java.lang.String),
106       * jobName=javax.management.openmbean.SimpleType(name=java.lang.String),
107       * jobRunTime=javax.management.openmbean.SimpleType(name=java.lang.Long),
108       * nextFireTime=javax.management.openmbean.SimpleType(name=java.util.Date),
109       * previousFireTime=javax.management.openmbean.SimpleType(name=java.util.Date),
110       * recovering=javax.management.openmbean.SimpleType(name=java.lang.Boolean),
111       * refireCount=javax.management.openmbean.SimpleType(name=java.lang.Integer),
112       * scheduledFireTime=javax.management.openmbean.SimpleType(name=java.util.Date),
113       * schedulerName=javax.management.openmbean.SimpleType(name=java.lang.String),
114       * triggerGroup=javax.management.openmbean.SimpleType(name=java.lang.String),
115       * triggerName=javax.management.openmbean.SimpleType(name=java.lang.String)}
116       */
117   }
118
119   public int getNotificationCount()
120   {
121      return _count;
122   }
123}
124