1 6 7 package org.jfox.ioc.connector; 8 9 14 15 public class ClusterHandler extends AbstractHandler implements ClusterContainer { 16 19 private transient HandlerManager handlerManager = HandlerManager.getInstance(); 20 21 public ClusterHandler() { 22 23 } 24 25 public Class getInvocationClass() { 26 return ClusterInvocation.class; 27 } 28 29 public Object execute(Invocation invocation) throws Throwable { 30 ClassLoader oldCl = Thread.currentThread().getContextClassLoader(); 31 try { 32 sync(invocation); 33 } 34 finally{ 35 Thread.currentThread().setContextClassLoader(oldCl); 36 } 37 return null; 38 } 39 40 public void sync(Invocation invocation) { 41 42 ClusterInvocation clusterInvocation = (ClusterInvocation)invocation; 44 Invocation innerInvocation = clusterInvocation.getInvocation(); 45 Handler handler = handlerManager.getHandler(innerInvocation.getClass()); 46 47 Container container = handler.getContainer(); 48 if(!(container instanceof ClusterableContainer)){ 49 logger.warn("Invocation " + innerInvocation.getClass().getName() + " 's Container " + container.getClass().getName() + " is not a ClusterableContainer."); 50 return; 51 } 52 innerInvocation.setMethod(handler.getMethodByHash(innerInvocation.getMethodHash())); 53 54 55 58 ClassLoader oldCL = Thread.currentThread().getContextClassLoader(); 59 ClassLoader cl = handler.getClass().getClassLoader(); 60 try { 61 Thread.currentThread().setContextClassLoader(cl); 62 ((ClusterableContainer) container).syncInvocation(innerInvocation); 63 } 64 finally{ 65 Thread.currentThread().setContextClassLoader(oldCL); 66 } 67 68 } 69 70 public Class getHandlerClass() { 71 return this.getClass(); 72 } 73 74 } 75 | Popular Tags |