1 17 18 package org.objectweb.jac.core.dist; 19 20 21 import org.objectweb.jac.core.AspectComponent; 22 import org.objectweb.jac.core.NameRepository; 23 import org.objectweb.jac.core.Wrappee; 24 import org.objectweb.jac.core.Wrapping; 25 import java.io.Serializable ; 26 27 37 38 public class Deployment implements Serializable { 39 40 41 Topology topology; 42 43 transient AspectComponent ac; 44 45 46 52 public Deployment(AspectComponent ac, Topology topology) { 53 this.topology = topology; 54 this.ac = ac; 55 } 56 57 70 71 public RemoteRef[] deployStruct(Object [] objects, boolean forward) { 72 73 RemoteContainer[] rcs = topology.getDistContainers (); 74 RemoteRef[] ret = new RemoteRef[objects.length]; 75 76 for (int i = 0; i < objects.length; i++) { 77 78 System.out.println( "Deploying " + 79 NameRepository.get().getName(objects[i]) + 80 " on " + rcs[i].getName()); 81 RemoteRef rr = RemoteRef.create( 82 NameRepository.get().getName( objects[i] ) ); 83 84 88 rr.remoteNew( rcs[i].getName(), 89 objects[i].getClass().getName() ); 90 if ( forward ) { 91 StubWrapper w = new StubWrapper(ac,rr); 92 Wrapping.wrapAll((Wrappee)objects[i],null,w); 93 } 94 ret[i] = rr; 95 } 96 return ret; 97 } 98 99 107 108 public RemoteRef[] deployStruct(Object [] objects) { 109 return deployStruct(objects, false); 110 } 111 112 126 127 public RemoteRef[] deploy(Object [] objects, boolean forward) { 128 129 RemoteRef[] ret = new RemoteRef[objects.length]; 130 131 for (int i = 0; i < objects.length; i++) { 132 133 System.out.println( "Deploying " + NameRepository.get().getName(objects[i]) + 134 " on " + topology.getContainer(i).getName()); 135 RemoteRef rr = RemoteRef.create( NameRepository.get().getName( objects[i] ) ); 136 137 141 rr.remoteNewWithCopy( topology.getContainer(i).getName(), 142 objects[i].getClass().getName(), 143 objects[i] ); 144 if ( forward ) { 145 StubWrapper w = new StubWrapper(ac,rr); 146 Wrapping.wrapAll((Wrappee)objects[i],null,w); 147 } 148 ret[i] = rr; 149 } 150 return ret; 151 } 152 153 161 162 public RemoteRef[] deploy(Object [] objects) { 163 return deploy (objects, false); 164 } 165 166 177 178 public RemoteRef[] replicate(Object object, int forwardTo) { 179 180 RemoteContainer[] rcs = topology.getDistContainers (); 181 RemoteRef[] ret = new RemoteRef[rcs.length]; 182 RemoteRef rr = null; 183 String name = NameRepository.get().getName(object); 184 185 for (int i = 0; i < rcs.length; i++) { 186 187 System.out.println( "Replicating " + name + 188 " on " + rcs[i].getName()); 189 190 if( rcs[i].bindTo( name ) != null ) { 191 System.out.println( name + " already replicated on " 192 + rcs[i].getName()); 193 continue; 194 } 195 196 198 201 202 rr = RemoteRef.create( name ); 203 rr.remoteNewWithCopy( rcs[i].getName(), 204 object.getClass().getName(), 205 object ); 206 207 if ( forwardTo == i ) { 208 StubWrapper w = new StubWrapper(ac,rr); 209 Wrapping.wrapAll((Wrappee)object,null,w); 210 } 211 ret[i] = rr; 212 } 213 return ret; 214 } 215 216 224 225 public RemoteRef[] replicate(Object object) { 226 return replicate(object, -1); 227 } 228 229 242 243 public RemoteRef[] replicateStruct(Object object, int forwardTo) { 244 245 RemoteContainer[] rcs = topology.getDistContainers (); 246 RemoteRef[] ret = new RemoteRef[rcs.length]; 247 RemoteRef rr = null; 248 String name = NameRepository.get().getName(object); 249 250 for (int i = 0; i < rcs.length; i++) { 251 252 if( rcs[i].bindTo( name ) != null ) { 253 System.out.println( name + " already replicated on " 254 + rcs[i].getName()); 255 continue; 256 } 257 258 System.out.println( "Replicating (struct) " + 259 NameRepository.get().getName(object) + 260 " on " + rcs[i].getName()); 261 262 264 267 268 rr = RemoteRef.create( NameRepository.get().getName( object ) ); 269 rr.remoteNew( rcs[i].getName(), object.getClass().getName() ); 270 if ( forwardTo == i ) { 271 StubWrapper w = new StubWrapper(ac,rr); 272 Wrapping.wrapAll((Wrappee)object,null,w); 273 } 274 ret[i] = rr; 275 } 276 return ret; 277 } 278 279 287 288 public RemoteRef[] replicateStruct(Object object) { 289 return replicateStruct (object, -1); 290 } 291 292 293 } 294 295 296 297 298 299 300 301 | Popular Tags |