Source Code Cross Referenced for InstrumentationServiceImpl.java in  » Content-Management-System » apache-lenya-2.0 » org » apache » cocoon » webservices » instrument » 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 » Content Management System » apache lenya 2.0 » org.apache.cocoon.webservices.instrument 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.cocoon.webservices.instrument;
018:
019:        import org.apache.avalon.framework.logger.AbstractLogEnabled;
020:
021:        import org.apache.excalibur.instrument.InstrumentManager;
022:        import org.apache.excalibur.instrument.manager.DefaultInstrumentManager;
023:        import org.apache.excalibur.instrument.manager.InstrumentDescriptor;
024:        import org.apache.excalibur.instrument.manager.InstrumentSampleDescriptor;
025:        import org.apache.excalibur.instrument.manager.InstrumentableDescriptor;
026:
027:        import java.util.ArrayList;
028:        import java.util.List;
029:
030:        /**
031:         * Implementation of {@link InstrumentationService} component. This component
032:         * allows you to access sample information from the InstrumentManager.
033:         *
034:         * @author <a href="mailto:crafterm@apache.org">Marcus Crafter</a>
035:         * @version $Id: InstrumentationServiceImpl.java 433543 2006-08-22 06:22:54Z crossley $
036:         */
037:        public final class InstrumentationServiceImpl extends
038:                AbstractLogEnabled implements  InstrumentationService {
039:
040:            private static final int[] EMPTY_INT_ARRAY = {};
041:            private static final String[] EMPTY_STRING_ARRAY = {};
042:
043:            // instrument manager reference
044:            private DefaultInstrumentManager m_iManager;
045:
046:            /**
047:             * Sets the {@link InstrumentManager} for this service object.
048:             *
049:             * @param iManager an {@link InstrumentManager} instance
050:             */
051:            public void setInstrumentManager(final InstrumentManager iManager) {
052:
053:                if (iManager == null) {
054:                    if (getLogger().isWarnEnabled())
055:                        getLogger()
056:                                .warn(
057:                                        "No instrument manager available,"
058:                                                + "please enable instrumentation in your web.xml");
059:                }
060:
061:                // we require a DefaultInstrumentManager, attempt a cast.
062:                if (iManager instanceof  DefaultInstrumentManager) {
063:                    m_iManager = (DefaultInstrumentManager) iManager;
064:                } else {
065:                    throw new UnsupportedOperationException(
066:                            "InstrumentationService only supports DefaultInstrumentManager");
067:                }
068:            }
069:
070:            /**
071:             * Obtain an array of samples from a specified sample name.
072:             *
073:             * <p>
074:             *  The specified path parameter identifies a sample, hierarchically from
075:             *  Instrumentable name to Instrument name, to Instrument sample name
076:             *  (including any child Instrumentables) using the '.' character as a
077:             *  separator.
078:             * </p>
079:             *
080:             * <pre>
081:             *  eg: instrument-manager.active-thread-count.maximum_1000_600
082:             * </pre>
083:             *
084:             * <p>
085:             *  The above example identifies the sample 'maximum_1000_600' on instrument
086:             *  'active-thread-count', on instrumentable 'instrument-manager'.
087:             * </p>
088:             *
089:             * <p>
090:             *  The length of the returned array is dependant on the configuration of the
091:             *  sample being accessed. Check instrumentation.xconf for the length of pre-
092:             *  defined samples that operate constantly, when instrumentation is enabled.
093:             * </p>
094:             *
095:             * @param path path value
096:             * @return an <code>int[]</code> array of samples
097:             * @exception Exception if an error occurs
098:             */
099:            public int[] getSampleSnapshot(final String path) throws Exception {
100:
101:                // ensure we have an instrument manager available
102:                if (!haveInstrumentManager()) {
103:                    getLogger()
104:                            .warn(
105:                                    "No instrument manager available,"
106:                                            + "please enable instrumentation in your web.xml");
107:                    return EMPTY_INT_ARRAY;
108:                }
109:
110:                // return the samples
111:                return m_iManager.locateInstrumentSampleDescriptor(path)
112:                        .getSnapshot().getSamples();
113:            }
114:
115:            /**
116:             * Obtain a list of available samples, useful for browsing
117:             * available samples.
118:             *
119:             * @return an {@link String}[] array of sample names
120:             */
121:            public String[] getSampleNames() {
122:
123:                // ensure we have an instrument manager available
124:                if (!haveInstrumentManager()) {
125:                    getLogger()
126:                            .warn(
127:                                    "No instrument manager available,"
128:                                            + "please enable instrumentation in your web.xml");
129:                    return EMPTY_STRING_ARRAY;
130:                }
131:
132:                // list all instrumentables
133:                final InstrumentableDescriptor[] descriptors = m_iManager
134:                        .getInstrumentableDescriptors();
135:                final List names = new ArrayList();
136:
137:                for (int i = 0; i < descriptors.length; ++i) {
138:                    // list all instruments
139:                    InstrumentDescriptor[] insts = descriptors[i]
140:                            .getInstrumentDescriptors();
141:
142:                    for (int k = 0; k < insts.length; ++k) {
143:
144:                        // list all samples
145:                        InstrumentSampleDescriptor[] samples = insts[k]
146:                                .getInstrumentSampleDescriptors();
147:
148:                        for (int j = 0; j < samples.length; ++j) {
149:                            names.add(samples[j].getName());
150:                        }
151:                    }
152:                }
153:
154:                return (String[]) names.toArray(new String[] {});
155:            }
156:
157:            /**
158:             * Helper method to determine if a valid instrument manager is available
159:             *
160:             * @return true if an instrument manager is present, false otherwise
161:             */
162:            private boolean haveInstrumentManager() {
163:                return (m_iManager != null);
164:            }
165:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.