Package net.sf.lipermi.call

Examples of net.sf.lipermi.call.RemoteReturn


  public RemoteReturn delegateCall(RemoteCall remoteCall) throws LipeRMIException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException {
    Object implementator = exportedObjects.get(remoteCall.getRemoteInstance());
    if (implementator == null)
      throw new LipeRMIException(String.format("Class %s doesn't have implementation", remoteCall.getRemoteInstance().getClassName())); //$NON-NLS-1$

    RemoteReturn remoteReturn;

    Method implementationMethod = null;
   
    for (Method method : implementator.getClass().getMethods()) {
      String implementationMethodId = method.toString();
      implementationMethodId = implementationMethodId.replace(implementator.getClass().getName(), remoteCall.getRemoteInstance().getClassName());
     
      if (implementationMethodId.endsWith(remoteCall.getMethodId())) {
        implementationMethod = method;
        break;
      }
    }
   
    if (implementationMethod == null)
      throw new NoSuchMethodException(remoteCall.getMethodId());
   
    try {
      Object methodReturn = null;
      implementationMethod.setAccessible(true);
      methodReturn = implementationMethod.invoke(implementator, remoteCall.getArgs());
      if (exportedObjects.containsValue(methodReturn))
        methodReturn = getRemoteReference(methodReturn);
     
      remoteReturn = new RemoteReturn(false, methodReturn, remoteCall.getCallId());
    } catch (InvocationTargetException e) {
      remoteReturn = new RemoteReturn(true, e, remoteCall.getCallId());
    }
   
    return remoteReturn;
  }
View Full Code Here


         
          Thread delegator = new Thread(new Runnable() {
            public void run() {
              CallLookup.handlingMe(ConnectionHandler.this);
             
              RemoteReturn remoteReturn;
              try {
//                System.out.println("remoteCall: " + remoteCall.getCallId() + " - " + remoteCall.getRemoteInstance().getInstanceId());
//                System.out.println("(" + remoteCall.getCallId() + ") " + remoteCall.getArgs()[0]);
                remoteReturn = callHandler.delegateCall(remoteCall);
//                System.out.println("(" + remoteCall.getCallId() + ") " + remoteReturn.getRet());
                sendMessage(remoteReturn);
              } catch (Exception e) {
                e.printStackTrace();
              }
             
              CallLookup.forgetMe();
            }
          }, "Delegator"); //$NON-NLS-1$
          delegator.setDaemon(true);
          delegator.start();
        }
        else if (remoteMessage instanceof RemoteReturn) {
          RemoteReturn remoteReturn = (RemoteReturn) remoteMessage;
          synchronized (remoteReturns) {
            remoteReturns.add(remoteReturn);
            remoteReturns.notifyAll();
          }
        }
View Full Code Here

    String methodId = method.toString().substring(15);
   
    IRemoteMessage remoteCall = new RemoteCall(remoteInstance, methodId, args, id);
    sendMessage(remoteCall);
   
    RemoteReturn remoteReturn = null;
   
    boolean bReturned = false;
    do {
      synchronized (remoteReturns) {
        for (RemoteReturn ret : remoteReturns) {
          if (ret.getCallId().equals(id)) {
            bReturned = true;
            remoteReturn = ret;
            break;
          }
        }
        if (bReturned)
          remoteReturns.remove(remoteReturn);
        else {
          try {
            remoteReturns.wait();
          }
          catch (InterruptedException ie) {}
        }
      }
    }
    while (socket.isConnected() && !bReturned);
   
    if (!socket.isConnected() && !bReturned)
      throw new LipeRMIException("Connection aborted"); //$NON-NLS-1$
   
    if (remoteReturn.isThrowing() && remoteReturn.getRet() instanceof Throwable)
      throw ((Throwable) remoteReturn.getRet()).getCause();
   
    if (remoteReturn.getRet() instanceof RemoteInstance) {
      RemoteInstance remoteInstanceReturn = (RemoteInstance) remoteReturn.getRet();
      Object proxyReturn = remoteInstanceProxys.get(remoteInstanceReturn);
      if (proxyReturn == null) {
        proxyReturn = CallProxy.buildProxy(remoteInstanceReturn, this);
        remoteInstanceProxys.put(remoteInstanceReturn, proxyReturn);
      }
      return proxyReturn;
    }   
   
    return remoteReturn.getRet();
  }
View Full Code Here

TOP

Related Classes of net.sf.lipermi.call.RemoteReturn

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.