1 17 18 package org.objectweb.jac.aspects.distribution.consistency; 19 20 import java.lang.reflect.*; 21 import org.objectweb.jac.core.*; 22 import org.objectweb.jac.core.dist.*; 23 24 36 37 public class WeakConsistencyWrapper extends ConsistencyWrapper { 38 39 40 RemoteRef owner = null; 41 42 boolean isOwner = false; 43 44 public WeakConsistencyWrapper(AspectComponent ac) { 45 super(ac); 46 } 47 48 55 56 public Object whenWrite(Interaction interaction) { 57 58 if(!isOwner) { 59 60 Object [] ownerState = (Object []) owner.invokeRoleMethod( 61 "acceptRemoteWrite", new Object [] {} 62 ); 63 64 65 Field[] fields = interaction.wrappee.getClass().getDeclaredFields(); 66 for ( int i = 0; i < fields.length; i++ ) { 67 try { 68 fields[i].set( interaction.wrappee, ownerState[i] ); 69 } catch (Exception e) {} 70 } 71 72 73 for (int i = 0; i < knownReplicas.size(); i++) { 74 ((RemoteRef)knownReplicas.get(i)).invokeRoleMethod( 75 "setOwner", 76 new Object [] { interaction.wrappee } 77 ); 78 } 79 } 80 81 82 return proceed(interaction); 83 } 84 85 94 95 public Object acceptRemoteWrite(Wrappee wrappee, RemoteRef remoteReplica, 96 Object [] data) { 97 Field[] fields = wrappee.getClass().getDeclaredFields(); 98 Object [] state = new Object [fields.length]; 99 for ( int i = 0; i < fields.length; i++ ) { 100 try { 101 state[i] = fields[i].get(wrappee); 102 } catch (Exception e) {} 103 } 104 isOwner = false; 105 return state; 106 } 107 108 113 114 public Object setOwner (RemoteRef newOwner) { 115 owner = newOwner; 116 isOwner = false; 117 return null; 118 } 119 120 } 121 | Popular Tags |