File: java_jmx_notification_bridge_factory.jsp

package info (click to toggle)
gridengine 8.1.9%2Bdfsg-10
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 56,880 kB
  • sloc: ansic: 432,689; java: 87,068; cpp: 31,958; sh: 29,429; jsp: 7,757; perl: 6,336; xml: 5,828; makefile: 4,701; csh: 3,928; ruby: 2,221; tcl: 1,676; lisp: 669; yacc: 519; python: 503; lex: 361; javascript: 200
file content (176 lines) | stat: -rw-r--r-- 6,518 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*___INFO__MARK_BEGIN__*/
/*************************************************************************
 *
 *  The Contents of this file are made available subject to the terms of
 *  the Sun Industry Standards Source License Version 1.2
 *
 *  Sun Microsystems Inc., March, 2001
 *
 *
 *  Sun Industry Standards Source License Version 1.2
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.2 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *   The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *   Copyright: 2001 by Sun Microsystems, Inc.
 *
 *   All Rights Reserved.
 *
 ************************************************************************/
/*___INFO__MARK_END__*/
/**
 *  Generated from java_event_client.jsp
 *  !!! DO NOT EDIT THIS FILE !!!
 */
<%
  com.sun.grid.cull.JavaHelper jh = (com.sun.grid.cull.JavaHelper)params.get("javaHelper");
  com.sun.grid.cull.CullDefinition cullDef = (com.sun.grid.cull.CullDefinition)params.get("cullDef");
%>
package com.sun.grid.jgdi.management;

import javax.management.MBeanNotificationInfo;
import javax.management.Notification;
import com.sun.grid.jgdi.EventClient;
import com.sun.grid.jgdi.event.Event;
import java.util.*;
import java.util.logging.Logger;
import java.util.logging.Level;
/** 
 *  Helper class for mapping JGDI Events to JMX notifications
 *
 */
public class NotificationBridgeFactory {

    private static final Logger log = Logger.getLogger(NotificationBridgeFactory.class.getName());
    private static final Map<Class, EventToNotification> eventMap = new HashMap<Class, EventToNotification>();

    private static class EventToNotification {

        private final String eventName;
        private final Class eventClass;
        private final MBeanNotificationInfo notificationInfo;

        public EventToNotification(String eventName, Class eventClass) {
            this.eventName = eventName;
            this.eventClass = eventClass;
            this.notificationInfo = new MBeanNotificationInfo(new String[]{eventName}, eventClass.getName(), null);
        }

        public MBeanNotificationInfo getNotificationInfo() {
            return notificationInfo;
        }

        public Notification createNotification(Event event, long seqNumber) {
            Notification notification = new Notification(eventName, EventClient.class.getName(), seqNumber);
            notification.setUserData(event);
            return notification;
        }
    }

    public static Notification createNotification(Event evt, long seqNumber) {
        EventToNotification bridge = eventMap.get(evt.getClass());
        if (bridge != null) {
            log.log(Level.FINE, "create notification for event {0}", evt);
            return bridge.createNotification(evt, seqNumber);
        } else {
            return null;
        }
    }
    
    public static NotificationBridge newInstance(String url) {    
        return new NotificationBridge(url);
    }
    
    private static void registerEvent(String eventName, Class eventClass) {
        if (log.isLoggable(Level.FINER)) {
            log.entering("NotificationBridgeFactory", "registerEvent", new Object[]{eventName, eventClass});
        }
        EventToNotification evtNot = new EventToNotification(eventName, eventClass);
        eventMap.put(eventClass, evtNot);
        log.exiting("NotificationBridgeFactory", "registerEvent");
    }

    public static MBeanNotificationInfo[] createMBeanNotificationInfo() {
        log.entering("NotificationBridgeFactory", "createMBeanNotificationInfo");
        MBeanNotificationInfo [] ret = new MBeanNotificationInfo[eventMap.size()];
        int i = 0;
        for (Map.Entry<Class, EventToNotification> entry : eventMap.entrySet()) {
            ret[i++] = entry.getValue().getNotificationInfo();
        }
        log.exiting("NotificationBridgeFactory", "createMBeanNotificationInfo", ret);
        return ret;
    }
    
    
    static {
<%
    com.sun.grid.cull.CullObject cullObj = null;    
    for (String name : cullDef.getObjectNames()) {
      cullObj = cullDef.getCullObject(name); 
      name = cullObj.getIdlName();
//      System.out.println("name = " + name + ", cullname = " + cullObj.getName() + " " + 
//                         (cullObj.hasAddEvent() ? "A" : "") + 
//                         (cullObj.hasDeleteEvent() ? "D" : "") +
//                         (cullObj.hasGetListEvent() ? "L" : "") +
//                         (cullObj.hasGetEvent() ? "G" : "") +
//                         (cullObj.hasModifyEvent() ? "M" : ""));
      if(name == null) {
         throw new IllegalStateException("Have no idl name for " + cullObj.getName());
      }
      String notifType = null;
      String classname = null;
      if(cullObj.hasAddEvent()) {
%>
      registerEvent("Add<%=name%>", com.sun.grid.jgdi.event.<%=cullObj.getIdlName()%>AddEvent.class);
<%    } 
      
      if(cullObj.hasDeleteEvent()) {
%>
      registerEvent("Del<%=name%>", com.sun.grid.jgdi.event.<%=cullObj.getIdlName()%>DelEvent.class);
<%
      }
      if(cullObj.hasModifyEvent()) {
%>
      registerEvent("Mod<%=name%>", com.sun.grid.jgdi.event.<%=cullObj.getIdlName()%>ModEvent.class);
<%
      }
      if(cullObj.hasGetListEvent()) {
%>
      registerEvent("List<%=name%>", com.sun.grid.jgdi.event.<%=cullObj.getIdlName()%>ListEvent.class);
<%
      }
   } // end of for

   String [] specialEvents = {
       "QmasterGoesDown",
       "SchedulerRun",
       "Shutdown",
       "JobFinish",
       "JobUsage",
       "JobFinalUsage",
       "JobPriorityMod",
       "QueueInstanceSuspend",
       "QueueInstanceUnsuspend",
       "ConnectionClosed"
   };
   
   for (int i = 0; i < specialEvents.length; i++) {

%>
      registerEvent("<%=specialEvents[i]%>", com.sun.grid.jgdi.event.<%=specialEvents[i]%>Event.class);
<%
   } // end of for special events
%>
   }
}