1 22 package org.jboss.aop.standalone; 23 24 import java.lang.instrument.ClassDefinition ; 25 import java.lang.instrument.Instrumentation ; 26 import java.lang.instrument.UnmodifiableClassException ; 27 import java.util.ArrayList ; 28 import java.util.Collection ; 29 30 import org.jboss.aop.instrument.HotSwapper; 31 32 38 class InstrumentationAdapter implements HotSwapper 39 { 40 41 private Instrumentation instrumentation; private Collection <ClassDefinition > classDefinitions; 43 44 48 public InstrumentationAdapter(Instrumentation instrumentation) 49 { 50 this.instrumentation = instrumentation; 51 this.classDefinitions = new ArrayList <ClassDefinition >(); 52 } 53 54 59 public synchronized void registerChange(Class clazz, byte[] classCode) 60 { 61 ClassDefinition classDef = new ClassDefinition (clazz, classCode); 62 this.classDefinitions.add(classDef); 63 } 64 65 70 public synchronized void hotSwap() 71 { 72 ClassDefinition [] definitions = new ClassDefinition [this.classDefinitions.size()]; 73 definitions = (ClassDefinition []) this.classDefinitions.toArray(definitions); 74 try 75 { 76 instrumentation.redefineClasses(definitions); 77 } 78 catch(ClassNotFoundException e) 79 { 80 throw new RuntimeException (e); 81 } 82 catch(UnmodifiableClassException e) 83 { 84 throw new RuntimeException (e); 85 } 86 this.classDefinitions.clear(); 87 } 88 } | Popular Tags |