1 4 5 package com.tc.aspectwerkz.definition.deployer; 6 7 import com.tc.aspectwerkz.DeploymentModel; 8 import com.tc.aspectwerkz.definition.SystemDefinition; 9 import com.tc.aspectwerkz.definition.SystemDefinitionContainer; 10 import com.tc.aspectwerkz.transform.Properties; 11 import com.tc.aspectwerkz.util.Strings; 12 import com.tc.logging.CustomerLogging; 13 import com.tc.logging.TCLogger; 14 16 import java.util.ArrayList ; 17 import java.util.HashMap ; 18 import java.util.HashSet ; 19 import java.util.Iterator ; 20 import java.util.List ; 21 import java.util.Map ; 22 import java.util.Set ; 23 24 29 public class StandardAspectModuleDeployer implements AspectModuleDeployer { 30 31 public static final String [] ASPECT_MODULES; 32 static { 33 ASPECT_MODULES = Strings.splitString(Properties.ASPECT_MODULES, ","); 34 } 35 36 private final static Map modules = new HashMap (); 37 private final static TCLogger logger = CustomerLogging.getDSOInstrumentationLogger(); 38 39 private final List m_builders = new ArrayList (); 40 private final SystemDefinition m_systemDef; 41 private final ClassLoader m_loader; 42 43 44 50 public static void deploy(final ClassLoader loader, String [] moduleNames) { 51 for (int i = 0; i < moduleNames.length; i++) { 52 deploy(loader, moduleNames[i]); 53 } 54 } 55 56 public static void deploy(final ClassLoader loader, String moduleName) { 57 synchronized(modules) { 58 Set loaders = (Set ) modules.get(moduleName); 60 if(loaders==null) { 61 loaders = new HashSet (); 62 modules.put(moduleName, loaders); 63 } 64 65 if(!loaders.contains(loader)) { 66 logger.info("Loading aspect module [" + moduleName + "] in loader " + getLoaderName(loader)); 67 new StandardAspectModuleDeployer(loader).doDeploy(moduleName); 68 loaders.add(loader); 69 } 70 } 71 } 72 73 private static String getLoaderName(final ClassLoader loader) { 74 return loader.getClass().getName()+"@"+System.identityHashCode(loader); 79 } 80 81 82 92 public synchronized AspectDefinitionBuilder newAspectBuilder(final String aspectClass, 93 final DeploymentModel scope, 94 final String containerClassName) { 95 AspectDefinitionBuilder aspectDefinitionBuilder = new AspectDefinitionBuilder( 96 aspectClass, scope, containerClassName, m_systemDef, m_loader 97 ); 98 m_builders.add(aspectDefinitionBuilder); 99 return aspectDefinitionBuilder; 100 } 101 102 109 public synchronized void addMixin(final String aspectClass, 110 final DeploymentModel deploymentModel, 111 final String pointcut, 112 final boolean isTransient) { 113 m_builders.add(new MixinDefinitionBuilder(aspectClass, deploymentModel, pointcut, isTransient, m_systemDef, m_loader)); 114 } 115 116 public ClassLoader getClassLoader() { 117 return m_loader; 118 } 119 120 125 private StandardAspectModuleDeployer(final ClassLoader loader) { 126 m_systemDef = SystemDefinitionContainer.getVirtualDefinitionFor(loader); 127 m_loader = loader; 128 } 129 130 private synchronized void doDeploy(String moduleName) { 131 loadModule(moduleName); 132 buildModule(); 133 SystemDefinitionContainer.printDeploymentInfoFor(m_loader); 134 } 135 136 private void loadModule(String moduleName) { 137 try { 138 Class aspectModuleClass = getClass().getClassLoader().loadClass(moduleName); 139 AspectModule aspectModule = (AspectModule) aspectModuleClass.newInstance(); 140 aspectModule.deploy(this); 141 } catch (Throwable e) { 142 logger.error("Aspect module [" + moduleName + "] could not be deployed in "+getLoaderName(m_loader)+"; "+e.toString(), e); 143 } 144 } 145 146 private void buildModule() { 147 for (Iterator it = m_builders.iterator(); it.hasNext();) { 148 ((DefinitionBuilder) it.next()).build(); 149 } 150 } 151 152 } 153 154 | Popular Tags |