1 2 9 10 package org.jboss.remoting; 11 12 import org.jboss.logging.Logger; 13 import org.jboss.remoting.invocation.InternalInvocation; 14 import org.jboss.remoting.transport.ClientInvoker; 15 import org.jboss.util.id.GUID; 16 17 import java.io.Serializable ; 18 import java.util.List ; 19 20 21 22 41 public class ClientInvokerAdapter 42 implements ClientInterceptor, Serializable 43 { 44 static final long serialVersionUID = -1795129092816780782L; 45 private static Logger log = Logger.getLogger(ClientInvokerAdapter.class); 46 transient ClassLoader cl; 47 String internalSessionId = new GUID().toString(); 48 49 public ClientInvokerAdapter() 50 { 51 this(Thread.currentThread().getContextClassLoader()); 52 } 54 public ClientInvokerAdapter(ClassLoader cl) 55 { 56 this.cl = cl; 57 } 59 60 62 70 public void addListener(InvokerLocator locator, String subsystem, InvokerCallbackHandler callbackHandler) throws Throwable 71 { 72 ClientInvoker invoker = getClientInvoker(locator); 73 InvokerLocator clientLocator = invoker.getClientLocator(); 75 if(clientLocator != null) { 77 connect(clientLocator); 78 invoke(new InvocationRequest(internalSessionId, 79 subsystem, 80 new InternalInvocation(InternalInvocation.ADDCLIENTLISTENER, 81 new Object []{callbackHandler}), 82 null, 83 null, 84 clientLocator)); 85 86 disconnect(clientLocator); } 88 invoke(new InvocationRequest(internalSessionId, subsystem, new InternalInvocation(InternalInvocation.ADDLISTENER, null), null, null, locator)); 90 91 92 } 93 94 102 public void removeListener(InvokerLocator locator, String subsystem, InvokerCallbackHandler callbackHandler) throws Throwable 103 { 104 ClientInvoker invoker = getClientInvoker(locator); 105 InvokerLocator clientLocator = invoker.getClientLocator(); 107 if(clientLocator != null) { 109 connect(clientLocator); 110 invoke(new InvocationRequest(internalSessionId, 111 subsystem, 112 new InternalInvocation(InternalInvocation.REMOVECLIENTLISTENER, 113 new Object []{callbackHandler}), 114 null, 115 null, 116 clientLocator)); 117 118 disconnect(clientLocator); 119 } 120 invoke(new InvocationRequest(internalSessionId, subsystem, new InternalInvocation(InternalInvocation.REMOVELISTENER, null), null, null, locator)); 122 } 123 124 132 public List getCallbacks(InvokerLocator locator, String subsystem) throws Throwable 133 { 134 return (List )invoke(new InvocationRequest(internalSessionId, subsystem, new InternalInvocation(InternalInvocation.GETCALLBACKS, null), null, null, locator)); 135 136 } 137 138 149 public Object invoke(InvocationRequest invocation) 150 throws Throwable 151 { 152 ClientInvoker invoker = getClientInvoker(invocation.getLocator()); 153 if (invoker.isConnected()==false) 154 { 155 if (log.isDebugEnabled()) 156 { 157 log.debug("invoke called, but our invoker is disconnected, discarding and fetching another fresh invoker for: "+invoker.getLocator()); 158 } 159 invoker.connect(); 160 } 161 return invoker.invoke(invocation); 162 } 163 164 170 public void connect(InvokerLocator locator) throws Exception 171 { 172 ClientInvoker invoker = getClientInvoker(locator); 173 invoker.connect(); 174 } 175 176 182 public boolean isConnected(InvokerLocator locator) throws Exception 183 { 184 ClientInvoker invoker = getClientInvoker(locator); 185 return invoker.isConnected(); 186 } 187 188 193 public void disconnect(InvokerLocator locator) throws Exception 194 { 195 ClientInvoker invoker = getClientInvoker(locator); 196 invoker.disconnect(); 197 } 198 199 protected ClientInvoker getClientInvoker(InvokerLocator locator) throws Exception 200 { 201 return InvokerRegistry.createClientInvoker(locator); 202 } 203 204 } | Popular Tags |