KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > aspects > distribution > DeploymentWrapper


1 package org.objectweb.jac.aspects.distribution;
2
3
4 import org.aopalliance.intercept.ConstructorInvocation;
5 import org.aopalliance.intercept.MethodInvocation;
6 import org.apache.log4j.Logger;
7 import org.objectweb.jac.core.AspectComponent;
8 import org.objectweb.jac.core.Interaction;
9 import org.objectweb.jac.core.Wrapper;
10 import org.objectweb.jac.core.dist.Deployment;
11 import org.objectweb.jac.core.dist.Topology;
12 import org.objectweb.jac.util.Log;
13
14 /**
15  * This wrapper wraps constructors in order to deploy the objects on
16  * remote host(s) after their initialization. */

17
18 public class DeploymentWrapper extends Wrapper {
19     static Logger logger = Logger.getLogger("deployment");
20
21     String JavaDoc hostExpr;
22     boolean state = true;
23
24     /**
25      * The constructor.
26      *
27      * @param ac the aspect component that owns this wrapper
28      * @param hostExpr a regular expression that gives the host where
29      * the wrapped object should be deployed
30      * @param state a flag that tells if the state of the deployed
31      * object should be copied on the remote host(s) or not */

32
33     public DeploymentWrapper(
34         AspectComponent ac,
35         String JavaDoc hostExpr,
36         Boolean JavaDoc state) {
37         super(ac);
38         this.hostExpr = hostExpr;
39         this.state = state.booleanValue();
40     }
41
42     public Object JavaDoc invoke(MethodInvocation invocation) throws Throwable JavaDoc {
43         throw new Exception JavaDoc("This wrapper does not support invocation wrapping");
44     }
45
46     public Object JavaDoc construct(ConstructorInvocation invocation)
47         throws Throwable JavaDoc
48     {
49         return deploy((Interaction) invocation);
50     }
51
52     /**
53      * Actually performs the deployment on a constructor
54      * interaction. */

55
56     public Object JavaDoc deploy(Interaction i) {
57         Object JavaDoc o = proceed(i);
58         logger.debug("deploy upcalled with " + hostExpr
59                      + " wrappee=" + i.wrappee
60                      + ", topology=" + Topology.get());
61         Topology topology = Topology.getPartialTopology(hostExpr);
62         Deployment dep = new Deployment(ac, topology);
63         if (state) {
64             dep.replicate(i.wrappee);
65         } else {
66             dep.replicateStruct(i.wrappee);
67         }
68         return o;
69     }
70 }
71
Popular Tags