1 22 package org.jboss.mx.loading; 23 24 import java.net.URL ; 25 26 import javax.management.MalformedObjectNameException ; 27 import javax.management.ObjectName ; 28 import javax.management.loading.MLet ; 29 30 import org.jboss.logging.Logger; 31 32 38 class MLetRepositoryClassLoader extends RepositoryClassLoader 39 { 40 42 43 private static final Logger log = Logger.getLogger(MLetRepositoryClassLoader.class); 44 45 47 48 private MLet mlet; 49 50 52 54 60 protected MLetRepositoryClassLoader(MLet mlet) 61 { 62 super(mlet.getURLs(), mlet); 63 this.mlet = mlet; 64 } 65 66 68 73 public ObjectName getObjectName() throws MalformedObjectNameException 74 { 75 throw new UnsupportedOperationException ("Not relevent"); 76 } 77 78 84 public URL [] getClasspath() 85 { 86 return mlet.getURLs(); 87 } 88 89 94 public URL [] getAllURLs() 95 { 96 return repository.getURLs(); 97 } 98 99 public synchronized Class loadClassImpl(String name, boolean resolve, int stopAt) 100 throws ClassNotFoundException 101 { 102 loadClassDepth ++; 103 boolean trace = log.isTraceEnabled(); 104 105 if( trace ) 106 log.trace("loadClassImpl, name="+name+", resolve="+resolve); 107 if( repository == null ) 108 { 109 String msg = "Invalid use of destroyed classloader, UCL destroyed at:"; 110 throw new ClassNotFoundException (msg, this.unregisterTrace); 111 } 112 113 118 boolean acquired = attempt(1); 119 while( acquired == false ) 120 { 121 125 try 126 { 127 if( trace ) 128 log.trace("Waiting for loadClass lock"); 129 this.wait(); 130 } 131 catch(InterruptedException ignore) 132 { 133 } 134 acquired = attempt(1); 135 } 136 137 ClassLoadingTask task = null; 138 try 139 { 140 Thread t = Thread.currentThread(); 141 if( loadLock.holds() == 1 ) 143 LoadMgr3.registerLoaderThread(this, t); 144 145 task = new ClassLoadingTask(name, this, t, stopAt); 147 150 UnifiedLoaderRepository3 ulr3 = (UnifiedLoaderRepository3) repository; 151 if( LoadMgr3.beginLoadTask(task, ulr3) == false ) 152 { 153 while( task.threadTaskCount != 0 ) 154 { 155 try 156 { 157 LoadMgr3.nextTask(t, task, ulr3); 158 } 159 catch(InterruptedException e) 160 { 161 break; 163 } 164 } 165 } 166 } 167 finally 168 { 169 if( loadLock.holds() == 1 ) 171 LoadMgr3.endLoadTask(task); 172 this.release(); 174 this.notifyAll(); 175 loadClassDepth --; 176 } 177 178 if( task.loadedClass == null ) 179 { 180 if( task.loadException instanceof ClassNotFoundException ) 181 throw (ClassNotFoundException ) task.loadException; 182 else if( task.loadException != null ) 183 { 184 if( log.isTraceEnabled() ) 185 log.trace("Unexpected error during load of:"+name, task.loadException); 186 String msg = "Unexpected error during load of: "+name 187 + ", msg="+task.loadException.getMessage(); 188 throw new ClassNotFoundException (msg); 189 } 190 else 192 throw new IllegalStateException ("ClassLoadingTask.loadedTask is null, name: "+name); 193 } 194 195 return task.loadedClass; 196 } 197 198 200 public Class loadClassLocally(String name, boolean resolve) 201 throws ClassNotFoundException 202 { 203 boolean trace = log.isTraceEnabled(); 204 if( trace ) 205 log.trace("loadClassLocally, " + this + " name=" + name); 206 Class result = null; 207 try 208 { 209 result = mlet.loadClass(name, null); 210 return result; 211 } 212 finally 213 { 214 if (trace) 215 { 216 if (result != null) 217 log.trace("loadClassLocally, " + this + " name=" + name + " class=" + result + " cl=" + result.getClassLoader()); 218 else 219 log.trace("loadClassLocally, " + this + " name=" + name + " not found"); 220 } 221 } 222 } 223 224 226 228 230 232 } 234 | Popular Tags |