Examples of IPendingServiceCall


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

                  }
                  if (okayToConnect) {
                    log.debug("Connected - Client: {}", conn.getClient());
                    call.setStatus(Call.STATUS_SUCCESS_RESULT);
                    if (call instanceof IPendingServiceCall) {
                      IPendingServiceCall pc = (IPendingServiceCall) call;
                      pc.setResult(getStatus(NC_CONNECT_SUCCESS));
                    }
                    // Measure initial roundtrip time after
                    // connecting
                    conn.getChannel(2).write(
                        new Ping(Ping.STREAM_CLEAR, 0,
                            -1));
                    conn.startRoundTripMeasurement();
                  } 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);
                    if (rejected.getReason() != null)
                      status.setApplication(rejected
                          .getReason());
                    pc.setResult(status);
                  }
                  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"))
              && call instanceof IPendingServiceCall) {
            Object pcResult = ((IPendingServiceCall) call)
                .getResult();
            Map<String, Object> result;
            if (pcResult instanceof Map) {
              result = (Map) 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);
            }

            rtmp.setEncoding(Encoding.AMF3);
          }
        }
      } else if (action.equals(ACTION_DISCONNECT)) {
        conn.close();
      } else if (action.equals(ACTION_CREATE_STREAM)
          || action.equals(ACTION_DELETE_STREAM)
          || action.equals(ACTION_RELEASE_STREAM)
          || action.equals(ACTION_PUBLISH)
          || action.equals(ACTION_PLAY) || action.equals(ACTION_SEEK)
          || action.equals(ACTION_PAUSE)
          || action.equals(ACTION_CLOSE_STREAM)
          || action.equals(ACTION_RECEIVE_VIDEO)
          || action.equals(ACTION_RECEIVE_AUDIO)) {
        IStreamService streamService = (IStreamService) getScopeService(
            conn.getScope(), IStreamService.class,
            StreamService.class);
        Status status = null;
        try {
          if (!invokeCall(conn, call, streamService)) {
            status = getStatus(NS_INVALID_ARGUMENT).asStatus();
            status.setDescription("Failed to " + action
                + " (stream ID: " + source.getStreamId() + ")");
          }
        } catch (Throwable err) {
          log.error("Error while invoking " + action
              + " on stream service.", err);
          status = getStatus(NS_FAILED).asStatus();
          status.setDescription("Error while invoking " + action
              + " (stream ID: " + source.getStreamId() + ")");
          status.setDetails(err.getMessage());
        }
        if (status != null) {
          channel.sendStatus(status);
        }
      } else {
        invokeCall(conn, call);
      }
    } else if (conn.isConnected()) {
      // Service calls, must be connected.
      invokeCall(conn, call);
    } else {
      // Warn user attemps to call service without being connected
      log.warn("Not connected, closing connection");
      conn.close();
    }

    if (invoke 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.
        if (log.isDebugEnabled()) {
          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

    } else {
      serviceInvoker.invoke(call, serviceProvider);
    }
   
    if (call instanceof IPendingServiceCall) {
      IPendingServiceCall psc = (IPendingServiceCall) call;
      Object result = psc.getResult();
      if (result instanceof DeferredResult) {
        DeferredResult dr = (DeferredResult) result;
        dr.setInvokeId(invoke.getInvokeId());
        dr.setServiceCall(psc);
        dr.setChannel(channel);
View Full Code Here

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

        output = new org.red5.io.amf.Output(out);
      }
    }

    if (!isPending && (invoke instanceof Invoke)) {
      IPendingServiceCall pendingCall = (IPendingServiceCall) call;
      if (!call.isSuccess()) {
        StatusObject status = generateErrorResult(StatusCodes.NC_CALL_FAILED, call.getException());
        pendingCall.setResult(status);
      }
      if (log.isDebugEnabled()) {
        log.debug("Writing result: " + pendingCall.getResult());
      }
      serializer.serialize(output, pendingCall.getResult());
    } else {
      if (log.isDebugEnabled()) {
        log.debug("Writing params");
      }
      final Object[] args = invoke.getCall().getArguments();
View Full Code Here

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

    // check the security constraints
    // send back "ConnectionRejected" if fails.
    if (!checkPermission(conn)) {
      call.setStatus(Call.STATUS_ACCESS_DENIED);
      if (call instanceof IPendingServiceCall) {
        IPendingServiceCall pc = (IPendingServiceCall) call;
        pc.setResult(getStatus(NC_CONNECT_REJECTED));
      }
      Invoke reply = new Invoke();
      reply.setCall(call);
      reply.setInvokeId(invoke.getInvokeId());
      channel.write(reply);
View Full Code Here

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

      log.error("Endpoint " + msg.destination + " doesn't exist (" + msg + ")");
      return returnError(msg, "Server.Invoke.Error", "Endpoint " + msg.destination + " doesn't exist.", "Endpoint " + msg.destination + " doesn't exist.");
    }
   
    Object[] args = (Object[]) ConversionUtils.convert(msg.body, Object[].class);
    IPendingServiceCall call = new PendingCall(msg.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.
    AcknowledgeMessage result = new AcknowledgeMessage();
    result.body = call.getResult();
    result.headers = msg.headers;
    result.clientId = msg.clientId;
    result.correlationId = msg.messageId;
    return result;
  }
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.