1 package org.jboss.mx.loading; 2 3 import java.net.URL ; 4 import java.security.CodeSource ; 5 import java.security.Permission ; 6 import java.security.PermissionCollection ; 7 import java.security.Policy ; 8 import java.security.ProtectionDomain ; 9 import java.util.Enumeration ; 10 11 import javax.management.MBeanServer ; 12 import javax.management.MalformedObjectNameException ; 13 import javax.management.ObjectName ; 14 15 import org.jboss.logging.Logger; 16 17 27 public class DomainClassLoaderUCLImpl extends LegacyDomainClassLoader 28 implements UnifiedClassLoaderMBean 29 { 30 32 private static final Logger log = Logger.getLogger(DomainClassLoaderUCLImpl.class); 33 34 36 43 public DomainClassLoaderUCLImpl(URL [] cp, LoaderRepositoryDomain repository) 44 { 45 super(cp, null); 46 47 repository.addClassLoader(this); 49 } 50 51 53 57 public ObjectName getObjectName() throws MalformedObjectNameException 58 { 59 String name = "jmx.loading:UCL="+Integer.toHexString(super.hashCode()); 60 return new ObjectName (name); 61 } 62 63 66 public String [] getPackageNames() 67 { 68 UnifiedLoaderRepositoryDCL ulr = (UnifiedLoaderRepositoryDCL) domain; 69 return ulr.getPackageNames(this); 70 } 71 72 public void unregister() 73 { 74 super.unregister(); 75 } 76 77 public synchronized Class loadClassImpl(String name, boolean resolve, int stopAt) 78 throws ClassNotFoundException 79 { 80 loadClassDepth ++; 81 boolean trace = log.isTraceEnabled(); 82 83 if( trace ) 84 log.trace("loadClassImpl, name="+name+", resolve="+resolve); 85 if( domain == null ) 86 { 87 try 89 { 90 return super.loadClass(name, resolve); 91 } 92 catch (ClassNotFoundException ignored) 93 { 94 } 95 String msg = "Invalid use of destroyed classloader, UCL destroyed at:"; 96 throw new ClassNotFoundException (msg, this.unregisterTrace); 97 } 98 99 104 boolean acquired = attempt(1); 105 while( acquired == false ) 106 { 107 111 try 112 { 113 if( trace ) 114 log.trace("Waiting for loadClass lock"); 115 this.wait(); 116 } 117 catch(InterruptedException ignore) 118 { 119 } 120 acquired = attempt(1); 121 } 122 123 ClassLoadingTaskDCL task = null; 124 try 125 { 126 Thread t = Thread.currentThread(); 127 if( loadLock.holds() == 1 ) 129 LoadMgrDCL.registerLoaderThread(this, t); 130 131 task = new ClassLoadingTaskDCL(name, this, t, stopAt); 133 136 UnifiedLoaderRepositoryDCL repository = (UnifiedLoaderRepositoryDCL) domain; 137 if( LoadMgrDCL.beginLoadTask(task, repository) == false ) 138 { 139 while( task.threadTaskCount != 0 ) 140 { 141 try 142 { 143 LoadMgrDCL.nextTask(t, task, repository); 144 } 145 catch(InterruptedException e) 146 { 147 break; 149 } 150 } 151 } 152 } 153 finally 154 { 155 if( loadLock.holds() == 1 ) 157 LoadMgrDCL.endLoadTask(task); 158 this.release(); 160 this.notifyAll(); 161 loadClassDepth --; 162 } 163 164 if( task.loadedClass == null ) 165 { 166 if( task.loadException instanceof ClassNotFoundException ) 167 throw (ClassNotFoundException ) task.loadException; 168 else if( task.loadException instanceof NoClassDefFoundError ) 169 throw (NoClassDefFoundError ) task.loadException; 170 else if( task.loadException != null ) 171 { 172 if( log.isTraceEnabled() ) 173 log.trace("Unexpected error during load of:"+name, task.loadException); 174 String msg = "Unexpected error during load of: "+name 175 + ", msg="+task.loadException.getMessage(); 176 ClassNotFoundException cnfe = new ClassNotFoundException (msg, task.loadException); 177 throw cnfe; 178 } 179 else 181 throw new IllegalStateException ("ClassLoadingTask.loadedTask is null, name: "+name); 182 } 183 184 return task.loadedClass; 185 } 186 187 189 203 protected PermissionCollection getPermissions(CodeSource cs) 204 { 205 CodeSource permCS = cs; 206 Policy policy = Policy.getPolicy(); 207 PermissionCollection perms = super.getPermissions(permCS); 208 PermissionCollection perms2 = super.getPermissions(cs); 209 PermissionCollection perms3 = policy.getPermissions(permCS); 210 Enumeration iter = perms2.elements(); 211 while( iter.hasMoreElements() ) 212 perms.add((Permission ) iter.nextElement()); 213 iter = perms3.elements(); 214 while( iter.hasMoreElements() ) 215 perms.add((Permission ) iter.nextElement()); 216 if( log.isTraceEnabled() ) 217 log.trace("getPermissions, cp: "+getURLs()+" -> "+perms); 218 return perms; 219 } 220 221 } 222 | Popular Tags |