Source Code Cross Referenced for ClassLoadingTask.java in  » EJB-Server-JBoss-4.2.1 » jmx » org » jboss » mx » loading » 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 » EJB Server JBoss 4.2.1 » jmx » org.jboss.mx.loading 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * JBoss, Home of Professional Open Source.
003:         * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004:         * as indicated by the @author tags. See the copyright.txt file in the
005:         * distribution for a full listing of individual contributors.
006:         *
007:         * This is free software; you can redistribute it and/or modify it
008:         * under the terms of the GNU Lesser General Public License as
009:         * published by the Free Software Foundation; either version 2.1 of
010:         * the License, or (at your option) any later version.
011:         *
012:         * This software is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this software; if not, write to the Free
019:         * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021:         */
022:        package org.jboss.mx.loading;
023:
024:        import java.security.CodeSource;
025:        import java.security.ProtectionDomain;
026:        import java.util.Comparator;
027:        import java.io.StringWriter;
028:        import java.io.PrintWriter;
029:        import org.jboss.logging.Logger;
030:
031:        /** An encapsulation of a UCL3.loadClass task.
032:         * @author Scott.Stark@jboss.org
033:         * @version $Revision: 63208 $
034:         */
035:        public class ClassLoadingTask {
036:            protected static Logger log = Logger
037:                    .getLogger(ClassLoadingTask.class);
038:            protected static Comparator taskComparator = new ThreadTaskComparator();
039:
040:            public static final int FOUND_CLASS_LOADER = 1;
041:            public static final int NEXT_EVENT = 2;
042:            public static final int WAIT_ON_EVENT = 3;
043:            public static final int FINISHED = 4;
044:
045:            protected String classname;
046:            protected Thread requestingThread;
047:            protected RepositoryClassLoader requestingClassLoader;
048:            protected Class loadedClass;
049:            protected int loadOrder = Integer.MAX_VALUE;
050:            protected int stopOrder = Integer.MAX_VALUE;
051:            protected Throwable loadException;
052:            /** The number of ThreadTasks remaining */
053:            protected int threadTaskCount;
054:            /** The state of the requestingThread */
055:            protected int state;
056:            /** The Logger trace level flag */
057:            protected boolean trace;
058:
059:            protected int numCCE;
060:
061:            /** Compare ThreadTask first based on their order ivar, and then the
062:             * relative ordering with which their UCLs were added to the ULR.
063:             */
064:            static class ThreadTaskComparator implements  Comparator {
065:                public int compare(Object o1, Object o2) {
066:                    ThreadTask t1 = (ThreadTask) o1;
067:                    ThreadTask t2 = (ThreadTask) o2;
068:                    int compare = t1.order - t2.order;
069:                    if (compare == 0) {
070:                        compare = t1.ucl.getAddedOrder()
071:                                - t2.ucl.getAddedOrder();
072:                    }
073:                    return compare;
074:                }
075:            }
076:
077:            /** An ecapsulation of a <Thread, UCL3> task used when requestingClassLoader
078:             * needs to ask another UCL3 to perform the class loading.
079:             */
080:            class ThreadTask {
081:                /** The class loader for the classname package */
082:                RepositoryClassLoader ucl;
083:                /** The thread that owns the ucl monitor */
084:                Thread t;
085:                /** The relative order of the task. If o0 < o1 then the class loaded
086:                   by task o0 is preferred to o1.
087:                 */
088:                int order;
089:                boolean releaseInNextTask;
090:
091:                ThreadTask(RepositoryClassLoader ucl, Thread t, int order,
092:                        boolean releaseInNextTask) {
093:                    this .ucl = ucl;
094:                    this .t = t;
095:                    this .order = order;
096:                    this .releaseInNextTask = releaseInNextTask;
097:                }
098:
099:                public String toString() {
100:                    return "{t=" + t + ", ucl=" + ucl + ", name=" + classname
101:                            + ", requestingThread=" + requestingThread
102:                            + ", order=" + order + ", releaseInNextTask="
103:                            + releaseInNextTask + "}";
104:                }
105:
106:                String getClassname() {
107:                    return classname;
108:                }
109:
110:                Class getLoadedClass() {
111:                    return loadedClass;
112:                }
113:
114:                ClassLoadingTask getLoadTask() {
115:                    return ClassLoadingTask.this ;
116:                }
117:
118:                void run() throws ClassNotFoundException {
119:                    Class theClass = null;
120:                    try {
121:                        if (loadedClass == null) {
122:                            theClass = ucl.loadClassLocally(classname, false);
123:                            setLoadedClass(theClass, order);
124:                        } else if (trace) {
125:                            log.trace("Already found class(" + loadedClass
126:                                    + "), skipping loadClassLocally");
127:                        }
128:                    } finally {
129:                        ;//setLoadedClass(theClass, order);
130:                    }
131:                }
132:            }
133:
134:            protected ClassLoadingTask(String classname,
135:                    RepositoryClassLoader requestingClassLoader,
136:                    Thread requestingThread) {
137:                this (classname, requestingClassLoader, requestingThread,
138:                        Integer.MAX_VALUE);
139:            }
140:
141:            protected ClassLoadingTask(String classname,
142:                    RepositoryClassLoader requestingClassLoader,
143:                    Thread requestingThread, int stopAt) {
144:                this .requestingThread = requestingThread;
145:                this .requestingClassLoader = requestingClassLoader;
146:                this .classname = classname;
147:                this .stopOrder = stopAt;
148:                this .trace = log.isTraceEnabled();
149:            }
150:
151:            synchronized int incNumCCE() {
152:                int cce = numCCE++;
153:                return cce;
154:            }
155:
156:            public String toString() {
157:                StringBuffer buffer = new StringBuffer(super .toString());
158:                buffer.append('{');
159:                buffer.append("classname: " + classname);
160:                buffer.append(", requestingThread: " + requestingThread);
161:                buffer.append(", requestingClassLoader: "
162:                        + requestingClassLoader);
163:                buffer.append(", loadedClass: " + loadedClass);
164:                ClassToStringAction.toString(loadedClass, buffer);
165:                buffer.append(", loadOrder: " + loadOrder);
166:                buffer.append(", loadException: " + loadException);
167:                buffer.append(", threadTaskCount: " + threadTaskCount);
168:                buffer.append(", state: " + state);
169:                buffer.append(", #CCE: " + numCCE);
170:                buffer.append('}');
171:                if (trace && loadException != null) {
172:                    StringWriter sw = new StringWriter();
173:                    PrintWriter pw = new PrintWriter(sw);
174:                    loadException.printStackTrace(pw);
175:                    buffer.append("loadException details:\n");
176:                    buffer.append(sw.toString());
177:                }
178:                return buffer.toString();
179:            }
180:
181:            ThreadTask newThreadTask(RepositoryClassLoader ucl, Thread t,
182:                    int order, boolean reschedule, boolean releaseInNextTask) {
183:                // Only update the threadTaskCount if this is not a reschedule
184:                if (reschedule == false)
185:                    threadTaskCount++;
186:                return new ThreadTask(ucl, t, order, releaseInNextTask);
187:            }
188:
189:            synchronized void setLoadError(Throwable t) {
190:                this .threadTaskCount--;
191:                if (trace)
192:                    log.trace("setLoadedError, error=" + t);
193:                loadException = t;
194:            }
195:
196:            /** This is called from run on success or failure to mark the end
197:             * of the load attempt. This must decrement the threadTaskCount or
198:             * the ClassLoadingTask will never complete.
199:             */
200:            private synchronized void setLoadedClass(Class theClass, int order) {
201:                this .threadTaskCount--;
202:                if (trace)
203:                    log.trace("setLoadedClass, theClass=" + theClass
204:                            + ", order=" + order);
205:
206:                // Warn about duplicate classes
207:                if (this .loadedClass != null && order == loadOrder
208:                        && theClass != null) {
209:                    StringBuffer tmp = new StringBuffer(
210:                            "Duplicate class found: " + classname);
211:                    tmp.append('\n');
212:                    ProtectionDomain pd = this .loadedClass
213:                            .getProtectionDomain();
214:                    CodeSource cs = pd != null ? pd.getCodeSource() : null;
215:                    tmp.append("Current CS: " + cs);
216:                    tmp.append('\n');
217:                    pd = theClass.getProtectionDomain();
218:                    cs = pd != null ? pd.getCodeSource() : null;
219:                    tmp.append("Duplicate CS: " + cs);
220:                    log.warn(tmp.toString());
221:                }
222:
223:                // Accept the lowest order source of the class
224:                if (theClass != null) {
225:                    if (loadedClass == null || order <= loadOrder) {
226:                        this .loadedClass = theClass;
227:                        this .loadOrder = order;
228:                    } else {
229:                        ProtectionDomain pd = this .loadedClass
230:                                .getProtectionDomain();
231:                        CodeSource cs = pd != null ? pd.getCodeSource() : null;
232:                        ProtectionDomain pd2 = theClass.getProtectionDomain();
233:                        CodeSource cs2 = pd != null ? pd2.getCodeSource()
234:                                : null;
235:                        log.debug("Ignoring source of: " + classname
236:                                + " from CodeSource: " + cs2
237:                                + ", due to order(" + order + ">=" + loadOrder
238:                                + "), " + "accepted CodeSource: " + cs);
239:                    }
240:                }
241:            }
242:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.