KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > selfmanagement > event > EventBuilder


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * EventBuilder.java
26  *
27  */

28
29 package com.sun.enterprise.admin.selfmanagement.event;
30
31 import java.util.concurrent.ConcurrentHashMap JavaDoc;
32 import com.sun.enterprise.config.serverbeans.ElementProperty;
33 import com.sun.enterprise.util.i18n.StringManager;
34 import java.util.Hashtable JavaDoc;
35
36 /**
37  *
38  * @author Sun Micro Systems, Inc
39  */

40 public class EventBuilder {
41     
42     private static final EventBuilder instance = new EventBuilder( );
43     
44     private static ConcurrentHashMap JavaDoc<String JavaDoc,EventAbstractFactory>
45             eventFactoryMap = new ConcurrentHashMap JavaDoc<String JavaDoc,EventAbstractFactory>(10, 0.75f, 2);
46     private boolean initialized = false;
47     
48     protected static StringManager sm = StringManager.getManager(EventBuilder.class);
49     
50     /** Creates a new instance of EventBuilder */
51     private EventBuilder() {
52     }
53     
54     public static EventBuilder getInstance( ) {
55         return instance;
56     }
57     
58     public synchronized void addEventFactory(String JavaDoc eventType, EventAbstractFactory factory) {
59         if ( eventFactoryMap.get( eventType ) == null)
60             eventFactoryMap.put(eventType, factory);
61     }
62     
63     /**
64      * Given an event type, an event is returned. As of now, supported events
65      * are "log","monitor","lifecycle","notification" and "timer" in PE and
66      * in addition "gms" in EE.
67      * @param eventType one of the supported event types
68      * @param properties properties associated with the event
69      * @param description event description
70      * @return Event constructed event
71      */

72     public Event getEvent( String JavaDoc eventType,
73             ElementProperty[] properties, String JavaDoc description ) {
74         if (!initialized) {
75             initialized = true;
76             LogEventFactory.getInstance();
77             NotificationEventFactory.getInstance();
78             LifeCycleEventFactory.getInstance();
79             MonitorEventFactory.getInstance();
80             TimerEventFactory.getInstance();
81             TraceEventFactory.getInstance();
82         }
83         EventAbstractFactory factory =
84                 eventFactoryMap.get( eventType );
85         
86         if( factory == null ) {
87             throw new IllegalArgumentException JavaDoc(
88                     sm.getString("selfmgmt_event.unknown_event_type",eventType));
89         }
90         
91         return factory.instrumentEvent(properties, description);
92     }
93
94     public Event getEvent( String JavaDoc eventType, String JavaDoc description,
95                   Hashtable JavaDoc attributes, ElementProperty[] properties) {
96         return getEvent(eventType,properties, description);
97     }
98     
99     
100 }
101
Popular Tags