Package org.red5.server.api.service

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


  }

  /** {@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

                  }
                  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

    } 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

        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

    // 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

      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

    // ------------------------------------------------------------------------

    private void createPlayStream( IPendingServiceCallback callback ) {

        logger.debug( "create play stream" );
        IPendingServiceCallback wrapper = new CreatePlayStreamCallBack( callback );
        invoke( "createStream", null, wrapper );
    }
View Full Code Here

      if (stream.getStreamListeners() != null) {
       
        for (Iterator<IStreamListener> iter = stream.getStreamListeners().iterator();iter.hasNext();) {
         
          IStreamListener iStreamListener = iter.next();
         
          ListenerAdapter listenerAdapter = (ListenerAdapter) iStreamListener;
         
          log.debug("Stream Closing ?? "+listenerAdapter.getFlvRecordingMetaDataId()+ " " +flvRecordingMetaDataId);
         
View Full Code Here

            if ( !( event instanceof IRTMPEvent ) ) {
                logger.debug( "skipping non rtmp event: " + event );
                return;
            }

            IRTMPEvent rtmpEvent = (IRTMPEvent) event;

            if ( logger.isDebugEnabled() ) {
                // logger.debug("rtmp event: " + rtmpEvent.getHeader() + ", " +
                // rtmpEvent.getClass().getSimpleName());
            }

            if ( !( rtmpEvent instanceof IStreamData ) ) {
                logger.debug( "skipping non stream data" );
                return;
            }

            if ( rtmpEvent.getHeader().getSize() == 0 ) {
                logger.debug( "skipping event where size == 0" );
                return;
            }

            if ( rtmpEvent instanceof VideoData ) {
View Full Code Here

TOP

Related Classes of org.red5.server.api.service.IPendingServiceCall

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.