Examples of IPendingServiceCall


Examples of org.red5.server.api.service.IPendingServiceCall

          //if the conversion fails and the endpoint is not a ServiceAdapter
          //just drop the object directly into an array
          args = new Object[]{msg.body};
        }
       
        IPendingServiceCall call = new PendingCall(operation, args);
        try {
          if (!serviceInvoker.invoke(call, endpoint)) {
            if (call.getException() != null) {
              // Use regular exception handling
              Throwable err = call.getException();
              return returnError(msg, "Server.Invoke.Error", err.getMessage(), err);
            }
            return returnError(msg, "Server.Invoke.Error", "Can't invoke method.", "");
          }
        } catch (Throwable err) {
          log.error("Error while invoking method.", err);
          return returnError(msg, "Server.Invoke.Error", err.getMessage(), err);
        }
   
        //we got a valid result from the method call.
        result.body = call.getResult();
    }
   
    return result;
  }
View Full Code Here

Examples of org.red5.server.api.service.IPendingServiceCall

          onSharedObject(conn, channel, header, (SharedObjectMessage) message);
          break;
        case TYPE_INVOKE:
        case TYPE_FLEX_MESSAGE:
          onCommand(conn, channel, header, (Invoke) message);
          IPendingServiceCall call = ((Invoke) message).getCall();
          if (message.getHeader().getStreamId() != 0 && call.getServiceName() == null && StreamAction.PUBLISH.equals(call.getServiceMethodName())) {
            if (stream != null) {
              // Only dispatch if stream really was created
              ((IEventDispatcher) stream).dispatchEvent(message);
            }
          }
View Full Code Here

Examples of org.red5.server.api.service.IPendingServiceCall

   * @param invoke
   *            Pending call result event context
   */
  protected void handlePendingCallResult(RTMPConnection conn, Invoke invoke) {
    final IServiceCall call = invoke.getCall();
    final IPendingServiceCall pendingCall = conn.retrievePendingCall(invoke.getTransactionId());
    if (pendingCall != null) {
      // The client sent a response to a previously made call.
      Object[] args = call.getArguments();
      if (args != null && args.length > 0) {
        // TODO: can a client return multiple results?
        pendingCall.setResult(args[0]);
      }
      Set<IPendingServiceCallback> callbacks = pendingCall.getCallbacks();
      if (!callbacks.isEmpty()) {
        HashSet<IPendingServiceCallback> tmp = new HashSet<IPendingServiceCallback>();
        tmp.addAll(callbacks);
        for (IPendingServiceCallback callback : tmp) {
          try {
View Full Code Here

Examples of org.red5.server.api.service.IPendingServiceCall

    invoke(method, null, callback);
  }

  /** {@inheritDoc} */
  public void invoke(String method, Object[] params, IPendingServiceCallback callback) {
    IPendingServiceCall call = new PendingCall(method, params);
    if (callback != null) {
      call.registerCallback(callback);
    }
    invoke(call);
  }
View Full Code Here

Examples of org.red5.server.api.service.IPendingServiceCall

      } else {
        output = new org.red5.io.amf.Output(out);
      }
    }
    if (!isPending && (command instanceof Invoke)) {
      IPendingServiceCall pendingCall = (IPendingServiceCall) call;
      if (!call.isSuccess()) {
        log.debug("Call was not successful");
        StatusObject status = generateErrorResult(StatusCodes.NC_CALL_FAILED, call.getException());
        pendingCall.setResult(status);
      }
      Object res = pendingCall.getResult();
      log.debug("Writing result: {}", res);
      Serializer.serialize(output, res);
    } else {
      log.debug("Writing params");
      final Object[] args = call.getArguments();
View Full Code Here

Examples of org.red5.server.api.service.IPendingServiceCall

              scope = context.resolveScope(global, path);
              // if global scope connection is not allowed, reject
              if (scope.getDepth() < 1 && !globalScopeConnectionAllowed) {
                call.setStatus(Call.STATUS_ACCESS_DENIED);
                if (call instanceof IPendingServiceCall) {
                  IPendingServiceCall pc = (IPendingServiceCall) call;
                  StatusObject status = getStatus(NC_CONNECT_REJECTED);
                  status.setDescription("Global scope connection disallowed on this server.");
                  pc.setResult(status);
                }
                disconnectOnReturn = true;
              }
              if (scope != null) {
                if (log.isTraceEnabled()) {
                  log.trace("Connecting to: {}", scope);
                }
                if (log.isDebugEnabled()) {
                  log.debug("Connecting to: {}", scope.getName());
                  log.debug("Conn {}, scope {}, call {}", new Object[] { conn, scope, call });
                  log.debug("Call args {}", call.getArguments());
                }
                boolean okayToConnect;
                try {
                  if (call.getArguments() != null) {
                    okayToConnect = conn.connect(scope, call.getArguments());
                  } else {
                    okayToConnect = conn.connect(scope);
                  }
                  if (okayToConnect) {
                    log.debug("Connected - {}", conn.getClient());
                    call.setStatus(Call.STATUS_SUCCESS_RESULT);
                    if (call instanceof IPendingServiceCall) {
                      IPendingServiceCall pc = (IPendingServiceCall) call;
                      //send fmsver and capabilities
                      StatusObject result = getStatus(NC_CONNECT_SUCCESS);
                      result.setAdditional("fmsVer", Red5.getFMSVersion());
                      result.setAdditional("capabilities", Integer.valueOf(31));
                      result.setAdditional("mode", Integer.valueOf(1));
                      result.setAdditional("data", Red5.getDataVersion());
                      pc.setResult(result);
                    }
                    // Measure initial roundtrip time after connecting
                    conn.ping(new Ping(Ping.STREAM_BEGIN, 0, -1));
                    disconnectOnReturn = false;
                  } else {
                    log.debug("Connect failed");
                    call.setStatus(Call.STATUS_ACCESS_DENIED);
                    if (call instanceof IPendingServiceCall) {
                      IPendingServiceCall pc = (IPendingServiceCall) call;
                      pc.setResult(getStatus(NC_CONNECT_REJECTED));
                    }
                    disconnectOnReturn = true;
                  }
                } catch (ClientRejectedException rejected) {
                  log.debug("Connect rejected");
                  call.setStatus(Call.STATUS_ACCESS_DENIED);
                  if (call instanceof IPendingServiceCall) {
                    IPendingServiceCall pc = (IPendingServiceCall) call;
                    StatusObject status = getStatus(NC_CONNECT_REJECTED);
                    Object reason = rejected.getReason();
                    if (reason != null) {
                      status.setApplication(reason);
                      //should we set description?
                      status.setDescription(reason.toString());
                    }
                    pc.setResult(status);
                  }
                  disconnectOnReturn = true;
                }
              }
            } catch (ScopeNotFoundException err) {
              log.warn("Scope not found", err);
              call.setStatus(Call.STATUS_SERVICE_NOT_FOUND);
              if (call instanceof IPendingServiceCall) {
                StatusObject status = getStatus(NC_CONNECT_REJECTED);
                status.setDescription(String.format("No scope '%s' on this server.", path));
                ((IPendingServiceCall) call).setResult(status);
              }
              log.info("Scope {} not found on {}", path, host);
              disconnectOnReturn = true;
            } catch (ScopeShuttingDownException err) {
              log.warn("Scope shutting down", err);
              call.setStatus(Call.STATUS_APP_SHUTTING_DOWN);
              if (call instanceof IPendingServiceCall) {
                StatusObject status = getStatus(NC_CONNECT_APPSHUTDOWN);
                status.setDescription(String.format("Application at '%s' is currently shutting down.", path));
                ((IPendingServiceCall) call).setResult(status);
              }
              log.info("Application at {} currently shutting down on {}", path, host);
              disconnectOnReturn = true;
            }
          } else {
            log.warn("Scope {} not found", path);
            call.setStatus(Call.STATUS_SERVICE_NOT_FOUND);
            if (call instanceof IPendingServiceCall) {
              StatusObject status = getStatus(NC_CONNECT_INVALID_APPLICATION);
              status.setDescription(String.format("No scope '%s' on this server.", path));
              ((IPendingServiceCall) call).setResult(status);
            }
            log.info("No application scope found for {} on host {}", path, host);
            disconnectOnReturn = true;
          }
        } catch (RuntimeException e) {
          call.setStatus(Call.STATUS_GENERAL_EXCEPTION);
          if (call instanceof IPendingServiceCall) {
            IPendingServiceCall pc = (IPendingServiceCall) call;
            pc.setResult(getStatus(NC_CONNECT_FAILED));
          }
          log.error("Error connecting {}", e);
          disconnectOnReturn = true;
        }
        // Evaluate request for AMF3 encoding
        if (Integer.valueOf(3).equals(params.get("objectEncoding"))) {
          if (call instanceof IPendingServiceCall) {
            Object pcResult = ((IPendingServiceCall) call).getResult();
            Map<String, Object> result;
            if (pcResult instanceof Map) {
              result = (Map<String, Object>) pcResult;
              result.put("objectEncoding", 3);
            } else if (pcResult instanceof StatusObject) {
              result = new HashMap<String, Object>();
              StatusObject status = (StatusObject) pcResult;
              result.put("code", status.getCode());
              result.put("description", status.getDescription());
              result.put("application", status.getApplication());
              result.put("level", status.getLevel());
              result.put("objectEncoding", 3);
              ((IPendingServiceCall) call).setResult(result);
            }
          }
          conn.getState().setEncoding(Encoding.AMF3);
        }
      } else {
        // not connected and attempting to send an invoke
        log.warn("Not connected, closing connection");
        conn.close();
      }
    }
    if (command instanceof Invoke) {
      if ((source.getStreamId() != 0) && (call.getStatus() == Call.STATUS_SUCCESS_VOID || call.getStatus() == Call.STATUS_SUCCESS_NULL)) {
        // This fixes a bug in the FP on Intel Macs.
        log.debug("Method does not have return value, do not reply");
        return;
      }
      boolean sendResult = true;
      if (call instanceof IPendingServiceCall) {
        IPendingServiceCall psc = (IPendingServiceCall) call;
        Object result = psc.getResult();
        if (result instanceof DeferredResult) {
          // Remember the deferred result to be sent later
          DeferredResult dr = (DeferredResult) result;
          dr.setServiceCall(psc);
          dr.setChannel(channel);
View Full Code Here

Examples of org.red5.server.api.service.IPendingServiceCall

  @Test
  public void simpletest() {
    if (context.hasBean("echoService")) {
        EchoService service = (EchoService) context.getBean("echoService");
        IPendingServiceCall call = new PendingCall("echoService", "echoString",
            new Object[] { "My String" });
        context.getServiceInvoker().invoke(call, service);
        assertTrue("result null", call.getResult() != null);
    } else {
      System.out.println("No echo service found");
      assertTrue(false);
    }
  }
View Full Code Here

Examples of org.red5.server.api.service.IPendingServiceCall

  @Override
  public void invoke(String name, Object[] params, IPendingServiceCallback callback) {
    if ("echo".equals(name)) {
      echo(params);
    }   
    IPendingServiceCall call = new PendingCall(null, name, params);
    call.setResult(Boolean.TRUE);
    callback.resultReceived(call);
  }
View Full Code Here

Examples of org.red5.server.api.service.IPendingServiceCall

     * @param conn         Connection
     * @param invoke       Pending call result event context
     */
    protected void handlePendingCallResult(RTMPConnection conn, Notify invoke) {
    final IServiceCall call = invoke.getCall();
    final IPendingServiceCall pendingCall = conn.getPendingCall(invoke
        .getInvokeId());
    if (pendingCall != null) {
      // The client sent a response to a previously made call.
      Object[] args = call.getArguments();
      if ((args != null) && (args.length > 0)) {
        // TODO: can a client return multiple results?
        pendingCall.setResult(args[0]);
      }

      Set<IPendingServiceCallback> callbacks = pendingCall
          .getCallbacks();
      if (!callbacks.isEmpty()) {
        HashSet<IPendingServiceCallback> tmp = new HashSet<IPendingServiceCallback>();
        tmp.addAll(callbacks);
              for (IPendingServiceCallback callback : tmp) {
View Full Code Here

Examples of org.red5.server.api.service.IPendingServiceCall

  }

  /** {@inheritDoc} */
  public void invoke(String method, Object[] params,
      IPendingServiceCallback callback) {
    IPendingServiceCall call = new PendingCall(method, params);
    if (callback != null) {
      call.registerCallback(callback);
    }
    invoke(call);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.