Source Code Cross Referenced for ListenerType.java in  » Profiler » JAMon » com » jamonapi » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Profiler » JAMon » com.jamonapi 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.jamonapi;
002:
003:        import com.jamonapi.utils.DetailData;
004:
005:        /** Object that contains a listener type such as value, max, min or maxactive.  
006:         * This object can contain multiple objects per listener type.
007:         * @author steve souza
008:         *
009:         */
010:        public final class ListenerType implements  DetailData {
011:
012:            JAMonListener listener;
013:            // will lock on MonInternal to allow direct access to listener which improves performance.
014:            // This brought my TestPerformanceClass performance from about 600 ms. to 484 ms.	  
015:            private Object lockObj;
016:
017:            ListenerType(Object lockObj) {
018:                this .lockObj = lockObj;
019:            }
020:
021:            // Add the listner to the addTo listener.  If addto is already a composite
022:            // listener simply add it.  If it is not then create a new CompositeListener
023:            // and add the current listener as well as the new one being passed in to the new
024:            // CompositeListener.  Note this code is only called if there is already a Listener
025:            private CompositeListener addCompositeListener(
026:                    JAMonListener listenerToAdd) {
027:                if (listener instanceof  CompositeListener)
028:                    return ((CompositeListener) listener)
029:                            .addListener(listenerToAdd);
030:                else
031:                    return new CompositeListener().addListener(listener)
032:                            .addListener(listenerToAdd);
033:
034:            }
035:
036:            /** Get underlying listener class */
037:            public final JAMonListener getListener() {
038:                return listener;
039:            }
040:
041:            /**
042:             * Add a listener that receives notification every time this monitors
043:             * add method is called. If null is passed all associated Listeners will
044:             * be detached.
045:             */
046:
047:            // Some jamon 2.4 introduced methods. Mostly listener related.
048:            /** Add a listener to this listener type.  Any number of listeners are supported. */
049:            public void addListener(JAMonListener listenerToAdd) {
050:                synchronized (lockObj) {
051:                    // this first case is either 1) the first listener for this type.
052:                    // in this case for performance reasons there is no reason to create 
053:                    // a compositeListener at this point, 2) a null was passed so the listener
054:                    // will be nullified. Either way the listener is assigned to the variable
055:                    // representing the Listenertype
056:                    if (listener == null || listenerToAdd == null)
057:                        listener = listenerToAdd;
058:                    else
059:                        // else add the listener to the composite (create the composite if necessary)
060:                        listener = addCompositeListener(listenerToAdd);
061:                }
062:
063:            }
064:
065:            /** Get a handle to the listener by name.  This handle could be used to access and display a buffer for example */
066:            public JAMonListener getListener(String listenerName) {
067:                synchronized (lockObj) {
068:                    // first look at listener to see if it is named that.  if this doesn't match
069:                    // and if it is composite listener and it has a child of given name then
070:                    // return it.	
071:                    if (listener == null)
072:                        return null;
073:                    else if (listener.getName().equalsIgnoreCase(listenerName))
074:                        return listener;
075:                    else if (listener instanceof  CompositeListener)
076:                        return ((CompositeListener) listener)
077:                                .getListener(listenerName);
078:                    else
079:                        return null;
080:                }
081:
082:            }
083:
084:            /** Remove the named listener */
085:            public void removeListener(String listenerName) {
086:                synchronized (lockObj) {
087:                    // if passed value, max, min, or maxactive
088:                    if (listener == null)
089:                        return;
090:                    else if (listener.getName().equalsIgnoreCase(listenerName))
091:                        listener = null;
092:                    else if (listener instanceof  CompositeListener) {
093:                        CompositeListener compListener = (CompositeListener) listener;
094:                        compListener.removeListener(listenerName);
095:
096:                        // If the composite listener is empty nullify it
097:                        // else if it has one listener use it by itself and get rid
098:                        // of the CompositeListener.
099:                        if (compListener.getNumListeners() == 0)
100:                            listener = null;
101:                        else if (compListener.getNumListeners() == 1)
102:                            listener = compListener.getListener(0);// get the only listener
103:
104:                    }
105:                }
106:
107:            }
108:
109:            /** Returns true if any listeners exist */
110:            public boolean hasListeners() {
111:                synchronized (lockObj) {
112:                    return (listener == null) ? false : true;
113:                }
114:
115:            }
116:
117:            /** Returns true if listener type exists (value/max/min/maxactive) or listener exists
118:             * by name.   
119:             */
120:            public boolean hasListener(String listenerName) {
121:                synchronized (lockObj) {
122:
123:                    if (listener == null)
124:                        return false;
125:                    else if (listener.getName().equalsIgnoreCase(listenerName))
126:                        return true;
127:                    else if (listener instanceof  CompositeListener)
128:                        return ((CompositeListener) listener)
129:                                .hasListener(listenerName);
130:                    else
131:                        return false;
132:                }
133:            }
134:
135:            /** Return listeners for display purposes in menus for example */
136:
137:            public Object[][] getData() {
138:                synchronized (lockObj) {
139:
140:                    if (listener == null)
141:                        return null;
142:                    else if (listener instanceof  CompositeListener) {
143:                        CompositeListener compListener = (CompositeListener) listener;
144:                        return compListener.getData();
145:                    } else
146:                        return new CompositeListener().addListener(listener)
147:                                .getData();
148:                }
149:            }
150:
151:            /** Return header info for display purposes */
152:            public String[] getHeader() {
153:                synchronized (lockObj) {
154:
155:                    if (listener instanceof  CompositeListener) {
156:                        CompositeListener compListener = (CompositeListener) listener;
157:                        return compListener.getHeader();
158:                    } else
159:                        return new CompositeListener().getHeader();
160:                }
161:            }
162:
163:            private static void test(ListenerType lt, String name) {
164:
165:                System.out.print(lt.hasListener(name) + "-");
166:                JAMonListener l = lt.getListener(name);
167:                if (l != null)
168:                    System.out.print(l.getName() + ",");
169:
170:            }
171:
172:            private static void testDisp(ListenerType lt) {
173:                System.out.println();
174:                System.out.print("*");
175:
176:                Object[][] data = lt.getData();
177:                int rows = (data == null) ? 0 : data.length;
178:                for (int i = 0; i < rows; i++)
179:                    for (int j = 0; j < data[0].length; j++)
180:                        System.out.print(data[i][j] + ", ");
181:            }
182:
183:            /** Test method */
184:            public static void main(String[] args) {
185:                System.out.println("\n*****ListenerType.main()");
186:                ListenerType lt = new ListenerType(new Object());
187:                CompositeListener cl1 = new CompositeListener("cl1");
188:                CompositeListener cl2 = new CompositeListener("cl2");
189:                cl1.addListener(new JAMonBufferListener("buff1"));
190:                cl1.addListener(new JAMonBufferListener("buff2"));
191:                cl2.addListener(new JAMonBufferListener("buff3"));
192:                cl2.addListener(new JAMonBufferListener("buff4"));
193:                cl1.addListener(cl2);
194:                lt.addListener(cl1);
195:                lt.addListener(new JAMonBufferListener("buff5"));
196:
197:                test(lt, "cl1");
198:                test(lt, "cl2");
199:                test(lt, "buff2");
200:                test(lt, "buff4");
201:                test(lt, "buffX");
202:
203:                testDisp(lt);
204:
205:                lt.removeListener("buff4");
206:                testDisp(lt);
207:
208:                lt.removeListener("cl2");
209:                testDisp(lt);
210:
211:                lt.removeListener("buff1");
212:                lt.removeListener("buff2");
213:                testDisp(lt);
214:
215:                lt.removeListener("buff5");
216:                testDisp(lt);
217:
218:                lt.addListener(cl2);
219:                testDisp(lt);
220:
221:            }
222:
223:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.