1 17 18 package org.objectweb.jac.aspects.distribution; 19 20 21 import java.util.HashSet ; 23 import java.util.Iterator ; 24 import org.apache.log4j.Logger; 25 import org.objectweb.jac.core.*; 26 import org.objectweb.jac.core.dist.*; 27 import org.objectweb.jac.core.rtti.ClassItem; 28 import org.objectweb.jac.core.rtti.ClassRepository; 29 import org.objectweb.jac.core.rtti.FieldItem; 30 import org.objectweb.jac.core.rtti.MethodItem; 31 import org.objectweb.jac.util.*; 32 33 40 41 public class DeploymentAC extends AspectComponent implements DeploymentConf { 42 static Logger logger = Logger.getLogger("deployment"); 43 static Logger loggerSerial = Logger.getLogger("serialization"); 44 45 47 public static final String REFS= "DeploymentAC.REFS"; 48 49 50 transient HashSet treated = new HashSet (); 51 52 63 64 public Wrappee whenSerialized(Wrappee orgObject, 65 SerializedJacObject finalObject) { 66 67 NameRepository nr = (NameRepository)NameRepository.get(); 68 String name = nr.getName(orgObject); 69 loggerSerial.debug("DeploymentAC.whenSerialize " + name); 70 finalObject.disableForwarding(); 72 73 if (Collaboration.get().getAttribute(SerializedJacObject.STATELESS)==null) { 74 75 Object [] state = ObjectState.getState(orgObject); 76 String [] fieldsName = (String [])state[0]; 77 Object [] fieldsValue = (Object [])state[1]; 78 79 ClassItem cl = ClassRepository.get().getClass(orgObject.getClass()); 80 for (int i = 0; i < fieldsName.length; i++) { 81 loggerSerial.debug(" serializing field " + fieldsName[i] + " - " + fieldsValue[i]); 82 FieldItem fi = cl.getField(fieldsName[i]); 83 if (fi != null && fi.getAttribute("deployment.transient") == null) { 84 finalObject.addField(fieldsName[i], fieldsValue[i]); 85 } 86 } 87 88 } else { 89 loggerSerial.debug(name+" is stateless in this context"); 90 } 91 92 101 return orgObject; 102 } 103 104 109 110 public Wrappee whenDeserialized(SerializedJacObject orgObject, 111 Wrappee finalObject) { 112 loggerSerial.debug("DeploymentAC.whenDeserialize "+ 113 orgObject.getJacObjectClassName()); 114 if (!orgObject.isForwarder()) { 115 loggerSerial.debug("not a forwarder, deserialize..."); 116 RemoteRef server = 117 (RemoteRef)orgObject.getACInfos(ACManager.get().getName(this)); 118 if (server != null) { 119 Wrapping.wrapAll(finalObject,null, 120 new StubWrapper(this,server)); 121 } else { 122 Iterator it = orgObject.getFields().keySet().iterator(); 123 while (it.hasNext()) { 124 String fn = (String )it.next(); 125 loggerSerial.debug("setting field "+fn+" <- "+ 126 orgObject.getField(fn)); 127 ObjectState.setFieldValue( 128 finalObject,fn,orgObject.getField(fn)); 129 } 130 } 131 } else { 132 loggerSerial.debug("forwarder, do not deserialize..."); 133 } 134 return finalObject; 135 } 136 137 144 145 162 163 public void deploy(String deploymentHost, 164 String nameRegexp, String containerName) { 165 166 pointcut(nameRegexp,".* && !org.objectweb.jac.lib.java.util.*","CONSTRUCTORS", 167 "org.objectweb.jac.aspects.distribution.DeploymentWrapper", 168 new Object [] {this,containerName,new Boolean (true)}, 169 deploymentHost,null,true); 170 171 174 } 175 176 public void replicate(String deploymentHost, String nameRegexp, 177 String contRegexp) { 178 179 pointcut(nameRegexp,".* && !org.objectweb.jac.lib.java.util.*","CONSTRUCTORS", 180 "org.objectweb.jac.aspects.distribution.DeploymentWrapper", 181 new Object [] {this,contRegexp,new Boolean (true)}, 182 deploymentHost,null,true); 183 } 184 185 public void createTypedStubsFor(String name, String serverHost, 186 String hosts, 187 String stubType) { 188 pointcut(name,".* && !org.objectweb.jac.lib.java.util.*","CONSTRUCTORS", 189 "org.objectweb.jac.aspects.distribution.DeploymentWrapper", 190 new Object [] {this,hosts,new Boolean (true)}, 191 serverHost,null,true); 192 195 try { 196 pointcut(name, ".*", ".*", 197 (Wrapper)Class.forName(stubType) 198 .getConstructor(new Class []{String .class}) 199 .newInstance(new Object []{serverHost}), 200 hosts+" && !"+serverHost, null); 201 } catch ( Exception e ) { 202 logger.error("createTypedStubsFor: pointcut creation failed",e); 203 } 204 } 205 206 public void createStubsFor(String name, String serverHost, String hosts) { 207 createTypedStubsFor(name, serverHost, hosts, 208 "org.objectweb.jac.core.dist.StubWrapper"); 209 } 210 211 public void createAsynchronousStubsFor(String name, String serverHost, 212 String hosts) { 213 createTypedStubsFor(name, serverHost, hosts, 214 "org.objectweb.jac.core.dist.NonBlockingStubWrapper"); 215 } 216 217 public void setTransient(ClassItem classItem, String fieldName) { 218 FieldItem fi = classItem.getField(fieldName); 219 fi.setAttribute("deployment.transient","true"); 220 } 221 222 public void setParametersPassingMode(MethodItem method, Boolean [] refs) { 223 method.setAttribute(REFS, refs); 224 } 225 226 } 227 228 229 | Popular Tags |