private InvocationRequest createInvocationRequest(Object obj, SocketWrapper socketWrapper) { if(obj instanceof InvocationRequest) { return (InvocationRequest)obj; } else { // need to wrap request with invocation request SocketAddress remoteAddress = socketWrapper.getSocket().getRemoteSocketAddress(); return new InvocationRequest(remoteAddress.toString(), invoker.getSupportedSubsystems()[0], obj, new HashMap(), null, null); } }
private static boolean doCheckConnection(ClientInvoker clientInvoker) throws Throwable { boolean pingWorked = false; try { // Sending null client id as don't want to trigger lease on server side. This also means // that client connection validator will NOT impact client lease, so can not depend on it // to maintain client lease with the server. InvocationRequest ir = new InvocationRequest(null, Subsystem.SELF, "$PING$", null, null, null); if (trace) { log.trace("pinging, sending " + ir + " over " + clientInvoker); } clientInvoker.invoke(ir); if (trace) { log.trace("ConnectionValidator got successful ping using " + clientInvoker);} pingWorked = true; } catch (Throwable t) { log.debug("ConnectionValidator failed to ping via " + clientInvoker, t); } return pingWorked; }
private boolean doCheckConnectionWithLease() throws Throwable { boolean pingWorked = false; try { Map metadata = new HashMap(); metadata.put(ServerInvoker.INVOKER_SESSION_ID, this.invokerSessionId); InvocationRequest ir = new InvocationRequest(null, Subsystem.SELF, "$PING$", metadata, null, null); if (trace) { log.trace("pinging, sending " + ir + " over " + clientInvoker); } Object o = clientInvoker.invoke(ir); if (o instanceof Boolean && !((Boolean) o).booleanValue()) { // Server indicates lease has stopped. throw new Exception(); } if (trace) { log.trace("ConnectionValidator got successful ping using " + clientInvoker);} pingWorked = true; } catch (Throwable t) { log.debug("ConnectionValidator failed to ping via " + clientInvoker, t); } return pingWorked; }
private Object invoke(Object param, Map metadata, InvokerLocator callbackServerLocator) throws Throwable { if (isConnected()) { return invoker.invoke(new InvocationRequest(sessionId, subsystem, param, metadata, null, callbackServerLocator)); } else { throw new Exception("Can not make remoting client invocation " + "due to not being connected to server."); } }
InvokerLocator getSecondaryLocator() throws Throwable { InternalInvocation ii = new InternalInvocation(Bisocket.GET_SECONDARY_INVOKER_LOCATOR, null); InvocationRequest r = new InvocationRequest(null, null, ii, null, null, null); log.debug("getting secondary locator"); Exception savedException = null; for (int i = 0; i < maxRetries; i++) { try { Object o = invoke(r); log.debug("secondary locator: " + o); return (InvokerLocator) o; } catch (Exception e) { savedException = e; log.debug("unable to get secondary locator: trying again"); } } throw savedException; }
protected Home getUsableAddress(InvokerLocator locator) { List homes = getConnectHomes(); Iterator it = homes.iterator(); Home home = null; while (it.hasNext()) { try { home = (Home) it.next(); addr = InetAddress.getByName(home.host); address = createServerAddress(addr, home.port); invoke(new InvocationRequest(null, null, ServerInvoker.ECHO, null, null, null)); if (trace) log.trace(this + " able to contact server at: " + home); return home; } catch (Throwable e) { log.debug(this + " unable to contact server at: " + home); } } return null; }
new InvocationRequest(invokerSessionID, null, "$DISCONNECT$", metadata, null, null); invoker.invoke(ir);
new InvocationRequest(invokerSessionID, null, "$PING$", requestClients, null, null);
protected InvocationRequest createNewInvocationRequest(RequestMap requestMap, ResponseMap responseMap, Object payload) { // will try to use the same session id if possible to track String sessionId = getSessionId(requestMap); String subSystem = (String) requestMap.get(HEADER_SUBSYSTEM); InvocationRequest request = null; boolean isLeaseQueury = checkForLeaseQuery(requestMap); if(isLeaseQueury) { addLeaseInfo(responseMap); request = new InvocationRequest(sessionId, subSystem, "$PING$", null, responseMap, null); } else { request = new InvocationRequest(sessionId, subSystem, payload, requestMap, responseMap, null); } return request; }
clientMap.put(ServerInvoker.TIMEOUT, Integer.toString(disconnectTimeout)); InvocationRequest ir = new InvocationRequest(invokerSessionID, null, "$DISCONNECT$", clientMap, null, null); invoker.invoke(ir);
invoke(new InvocationRequest(null, null, ServerInvoker.ECHO, null, null, null)); if (log.isTraceEnabled()) log.trace(this + " able to contact server at: " + home); return home;
invoke(new InvocationRequest(null, null, ServerInvoker.ECHO, null, null, null)); if (log.isTraceEnabled()) log.trace(this + " able to contact server at: " + home); return home;
new InvocationRequest(invokerSessionID, null, "$PING$", null, new HashMap(), null);
/** * Takes an inputstream and wraps a server around. Then calls the target remoting server and * passes proxy for an inputstream to the server's handler. When the server handle calls on this * proxy, it will call back on this server wrapped around this inputstream. The InvokerLocator * passed is used to create the internal Connector used to receive the calls from the server * side. */ public Object invoke(InputStream inputStream, Object param, InvokerLocator streamServerLocator) throws Throwable { StreamServer streamServer = new StreamServer(inputStream, streamServerLocator); String locator = streamServer.getInvokerLocator(); // now call on target server and pass locator for stream callbacks InvocationRequest invocationRequest = new InvocationRequest(sessionId, subsystem, param, null, null, null); return invoke(new InternalInvocation(InternalInvocation.ADDSTREAMCALLBACK, new Object[]{locator, invocationRequest}), null); }
/** * Takes an inputstream and wraps a server around. Then calls the target remoting server and * passes a proxy for an inputstream to the server's handler. When the server handler calls on * this proxy, it will call back on this server wrapped around this inputstream. * * @param param - invocation payload. * * @return the return value from the invocation. * @throws Throwable */ public Object invoke(InputStream inputStream, Object param) throws Throwable { StreamServer streamServer = new StreamServer(inputStream); String locator = streamServer.getInvokerLocator(); // now call on target server and pass locator for stream callbacks InvocationRequest invocationRequest = new InvocationRequest(sessionId, subsystem, param, null, null, null); return invoke(new InternalInvocation(InternalInvocation.ADDSTREAMCALLBACK, new Object[]{locator, invocationRequest}), null); }
/** * Takes an inputstream and wraps a server around. Then calls the target remoting server and * passes a proxy for an inputstream to the server's handler. When the server handler calls on * this proxy, it will call back on this server wrapped around this inputstream. The Connector * passed is expected to have already been started and will have the stream handler added with * subsystem of 'stream'. Also note that the Connector passed will not be stopped when/if the * server calls to close the input stream. * * @param param - invocation payload. * * @return the return value from the invocation */ public Object invoke(InputStream inputStream, Object param, Connector streamConnector) throws Throwable { StreamServer streamServer = new StreamServer(inputStream, streamConnector); String locator = streamServer.getInvokerLocator(); // now call on target server and pass locator for stream callbacks InvocationRequest invocationRequest = new InvocationRequest(sessionId, subsystem, param, null, null, null); return invoke(new InternalInvocation(InternalInvocation.ADDSTREAMCALLBACK, new Object[]{locator, invocationRequest}), null); }
/** * Test setting a one-way invocation where there is a preexisting request * payload. */ public void testSetOneWayInvocationWithPreexistingRequestPayload() { Map requestPayload = new HashMap(); InvocationRequest invocation = new InvocationRequest("sessionId", "subsystem", null, requestPayload, null, null); // shouldn't be a one-way invocation yet assertFalse(TransportUtils.isOneWayInvocation(invocation)); TransportUtils.setOneWayInvocation(invocation); // check if it is now a one-way invocation assertTrue(TransportUtils.isOneWayInvocation(invocation)); }
/** * Test setting a one-way invocation where there is not a preexisting * request payload. */ public void testSetOneWayInvocationWithoutPreexistingRequestPayload() { Map requestPayload = null; InvocationRequest invocation = new InvocationRequest("sessionId", "subsystem", null, requestPayload, null, null); // shouldn't be a one-way invocation yet assertFalse(TransportUtils.isOneWayInvocation(invocation)); TransportUtils.setOneWayInvocation(invocation); // check if it is now a one-way invocation assertTrue(TransportUtils.isOneWayInvocation(invocation)); }