1 16 package org.mortbay.j2ee.session; 17 18 import java.lang.reflect.InvocationHandler ; 20 import java.lang.reflect.Method ; 21 import java.lang.reflect.Proxy ; 22 import java.rmi.RemoteException ; 23 import java.util.Map ; 24 25 import org.jfox.ioc.logger.Logger; 26 28 32 public class PublishingInterceptor 33 extends StateInterceptor 34 { 35 protected static final Logger _log=Logger.getLogger(PublishingInterceptor.class); 36 37 protected AbstractReplicatedStore 38 getStore() 39 { 40 AbstractReplicatedStore store=null; 41 try 42 { 43 store=(AbstractReplicatedStore)getManager().getStore(); 44 } 45 catch (Exception e) 46 { 47 _log.error("could not get AbstractReplicatedStore"); 48 } 49 50 return store; 51 } 52 53 public class PublishingInvocationHandler 57 implements InvocationHandler 58 { 59 public Object 60 invoke(Object proxy, Method method, Object [] args) 61 throws RemoteException 62 { 63 if (!AbstractReplicatedStore.getReplicating()) 64 { 65 AbstractReplicatedStore store = getStore(); 66 if (store != null) 67 store.publish(getId(), method, args); 68 } 69 70 return null; 71 } 72 } 73 74 public void 75 start() 76 { 77 _publisher=createProxy(); 78 } 79 80 public void 81 stop() 82 { 83 _publisher=null; 84 } 85 86 public State 87 createProxy() 88 { 89 AbstractReplicatedStore store=getStore(); 90 if (store==null) 91 return null; 92 InvocationHandler handler = new PublishingInvocationHandler(); 93 return (State) Proxy.newProxyInstance(store.getLoader(), new Class [] { State.class }, handler); 94 } 95 96 protected State _publisher; 97 98 102 public void 103 setLastAccessedTime(long time) 104 throws RemoteException 105 { 106 if (_publisher!=null) _publisher.setLastAccessedTime(time); 107 super.setLastAccessedTime(time); 108 } 109 110 public void 111 setMaxInactiveInterval(int interval) 112 throws RemoteException 113 { 114 if (_publisher!=null) _publisher.setMaxInactiveInterval(interval); 115 super.setMaxInactiveInterval(interval); 116 } 117 118 public Object 119 setAttribute(String name, Object value, boolean returnValue) 120 throws RemoteException 121 { 122 if (_publisher!=null) _publisher.setAttribute(name, value, returnValue); 123 return super.setAttribute(name, value, returnValue); 124 } 125 126 public void 127 setAttributes(Map attributes) 128 throws RemoteException 129 { 130 if (_publisher!=null) _publisher.setAttributes(attributes); 131 super.setAttributes(attributes); 132 } 133 134 public Object 135 removeAttribute(String name, boolean returnValue) 136 throws RemoteException 137 { 138 if (_publisher!=null) _publisher.removeAttribute(name, returnValue); 139 return super.removeAttribute(name, returnValue); 140 } 141 } 142 | Popular Tags |