Package org.red5.server.api.scope

Examples of org.red5.server.api.scope.IScope


   *
   * @param conn  RTMP connection
   * @param call  Service call
   */
  protected void invokeCall(RTMPConnection conn, IServiceCall call) {
    final IScope scope = conn.getScope();
    if (scope != null) {
        if (scope.hasHandler()) {
          final IScopeHandler handler = scope.getHandler();
          log.debug("Scope: {} handler: {}", scope, handler);
          if (!handler.serviceCall(conn, call)) {
            // XXX: What to do here? Return an error?
            log.warn("Scope: {} handler failed on service call", scope.getName(), new Exception("Service call failed"));
            return;
          }
        }
        final IContext context = scope.getContext();
        log.debug("Context: {}", context);
        context.getServiceInvoker().invoke(call, scope);
    } else {
      log.warn("Scope was null for invoke: {} connection state: {}", call.getServiceMethodName(), conn.getStateCode());
    }
View Full Code Here


   *            Server-side service object
   * @return <code>true</code> if the call was performed, otherwise
   *         <code>false</code>
   */
  private boolean invokeCall(RTMPConnection conn, IServiceCall call, Object service) {
    final IScope scope = conn.getScope();
    final IContext context = scope.getContext();
    if (log.isTraceEnabled()) {
      log.trace("Scope: {} context: {} service: {}", scope, context, service);
    }
    return context.getServiceInvoker().invoke(call, service);
  }
View Full Code Here

          // Lookup server scope when connected using host and application name
          IGlobalScope global = server.lookupGlobal(host, path);
          log.trace("Global lookup result: {}", global);
          if (global != null) {
            final IContext context = global.getContext();
            IScope scope = null;
            try {
              // TODO optimize this to use Scope instead of Context
              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 {
View Full Code Here

    log.debug("-----------------------------------------------------------------connectionHandler");
    TestConnection conn = new TestConnection(host, "/", null);
    // add the connection to thread local
    Red5.setConnectionLocal(conn);
    // resolve root
    IScope scope = context.resolveScope("/");
    IClientRegistry reg = context.getClientRegistry();
    IClient client = reg.newClient(null);
    assertNotNull(client);
    conn.initialize(client);
    if (conn.connect(scope)) {
View Full Code Here

  @Override
  protected void onSharedObject(RTMPConnection conn, Channel channel, Header source, SharedObjectMessage message) {
    if (log.isDebugEnabled()) {
      log.debug("onSharedObject - conn: {} channel: {} so message: {}", new Object[] { conn.getSessionId(), channel.getId(), message });
    }
    final IScope scope = conn.getScope();
    if (scope != null) {
      // so name
      String name = message.getName();
      // whether or not the incoming so is persistent
      boolean persistent = message.isPersistent();
      // shared object service
      ISharedObjectService sharedObjectService = (ISharedObjectService) ScopeUtils.getScopeService(scope, ISharedObjectService.class, SharedObjectService.class, false);
      if (!sharedObjectService.hasSharedObject(scope, name)) {
        log.debug("Shared object service doesnt have requested object, creation will be attempted");
        ISharedObjectSecurityService security = (ISharedObjectSecurityService) ScopeUtils.getScopeService(scope, ISharedObjectSecurityService.class);
        if (security != null) {
          // Check handlers to see if creation is allowed
          for (ISharedObjectSecurity handler : security.getSharedObjectSecurity()) {
            if (!handler.isCreationAllowed(scope, name, persistent)) {
              log.debug("Shared object create failed, creation is not allowed");
              sendSOCreationFailed(conn, message);
              return;
            }
          }
        }
        if (!sharedObjectService.createSharedObject(scope, name, persistent)) {
          log.debug("Shared object create failed");
          sendSOCreationFailed(conn, message);
          return;
        }
      }
      ISharedObject so = sharedObjectService.getSharedObject(scope, name);
      if (so != null) {
        if (so.isPersistent() == persistent) {
          log.debug("Dispatch persistent shared object");
          so.dispatchEvent(message);
        } else {
          log.warn("Shared object persistence mismatch - current: {} incoming: {}", so.isPersistent(), persistent);
          // reset the object so we can re-use it
          message.reset();
          // add the error event
          message.addEvent(new SharedObjectEvent(ISharedObjectEvent.Type.CLIENT_STATUS, "error", SO_PERSISTENCE_MISMATCH));
          conn.getChannel(3).write(message);
        }
      } else {
        log.warn("Shared object lookup returned null for {} in {}", name, scope.getName());
        // reset the object so we can re-use it
        message.reset();
        // add the error event
        message.addEvent(new SharedObjectEvent(ISharedObjectEvent.Type.CLIENT_STATUS, "error", NC_CALL_FAILED));
        conn.getChannel(3).write(message);
View Full Code Here

  }

  @Test
  public void context() {
    log.debug("-----------------------------------------------------------------context");
    IScope testRoom = context.resolveScope(roomPath);
    IContext context = testRoom.getContext();
    assertTrue("context should not be null", context != null);
    log.debug("{}", testRoom.getContext().getResource(""));
    log.debug("{}", testRoom.getResource(""));
    log.debug("{}", testRoom.getParent().getResource(""));
  }
View Full Code Here

   *
   * @throws InterruptedException
   */
  public void handler() throws InterruptedException {
    log.debug("-----------------------------------------------------------------handler");
    IScope testApp = context.resolveScope(appPath);
    assertTrue("should have a handler", testApp.hasHandler());
    log.debug("App: {}", testApp);

    TestConnection conn = new TestConnection(host, "/junit", null);
    Red5.setConnectionLocal(conn);

    IClientRegistry reg = context.getClientRegistry();
    IClient client = reg.newClient(null);
    assertTrue("client should not be null", client != null);
    log.debug("{}", client);
    String key = "key";
    String value = "value";
    client.setAttribute(key, value);
    assertTrue("attributes not working", client.getAttribute(key) == value);

    conn.initialize(client);

    if (conn.connect(testApp)) {
      // give connect a moment to settle
      Thread.sleep(100L);
      assertTrue("Should have a scope", conn.getScope() != null);
      assertTrue("app should have 1 client", ((Scope) testApp).getActiveClients() == 1);
      assertTrue("host should have 1 client", testApp.getParent().getClients().size() == 1);
      conn.close();
      assertTrue("Should not be connected", !conn.isConnected());
      assertTrue("app should have 0 client", ((Scope) testApp).getActiveClients() == 0);
      assertTrue("host should have 0 client", testApp.getParent().getClients().size() == 0);
    } else {
      fail("Didnt connect");
    }
    //client.disconnect();
    Red5.setConnectionLocal(null);
View Full Code Here

  @Test
  public void scopeResolver() {
    log.debug("-----------------------------------------------------------------scopeResolver");
    // Global
    IScope global = context.getGlobalScope();
    assertNotNull("global scope should be set", global);
    assertTrue("should be global", ScopeUtils.isGlobal(global));
    log.debug("{}", global);
    // Test App
    IScope testApp = context.resolveScope(appPath);
    assertTrue("testApp scope not null", testApp != null);
    log.debug("{}", testApp);
    // Test Room
    IScope testRoom = context.resolveScope(roomPath);
    log.debug("{}", testRoom);
    // Test App Not Found
    try {
      IScope notFoundApp = context.resolveScope(appPath + "notfound");
      log.debug("{}", notFoundApp);
      assertTrue("should have thrown an exception", false);
    } catch (RuntimeException e) {
    }
  }
View Full Code Here

  @Test
  public void testScopeConnection() {
    log.debug("-----------------------------------------------------------------testScopeConnection");
    setupScopes();
    IScope room5 = ScopeUtils.resolveScope(appScope, "/junit/room1/room4/room5");
    log.debug("Room 5 scope: {}", room5);
    // test section for issue #259
    // a little pre-setup is needed first
    IClientRegistry reg = context.getClientRegistry();
    IClient client = reg.newClient(null);
    TestConnection conn = new TestConnection(host, appPath, client.getId());
    conn.initialize(client);
    Red5.setConnectionLocal(conn);
    assertTrue(conn.connect(room5));
    // their code
    IScope scope = Red5.getConnectionLocal().getScope();
    for (IConnection tempConn : scope.getClientConnections()) {
      if (tempConn instanceof IServiceCapableConnection) {
        try {
          @SuppressWarnings("unused")
          IServiceCapableConnection sc = (IServiceCapableConnection) tempConn;
          //sc.invoke(methodName, objArrays);
View Full Code Here

  @Test
  public void testGetScopeNames() throws Exception {
    log.debug("-----------------------------------------------------------------testGetScopeNames");
    setupScopes();
    IScope room1 = ScopeUtils.resolveScope(appScope, "/junit/room1");
    log.debug("Room 1 scope: {}", room1);
    assertTrue(room1.getDepth() == 2);
    Set<String> names = room1.getScopeNames();
    log.debug("Scope: {}", names);
    IScope room5 = ScopeUtils.resolveScope(appScope, "/junit/room1/room4/room5");
    if (room5 != null) {
      log.debug("Room 5 scope: {}", room5);
      assertTrue(room5.getDepth() == 4);
      names = room1.getScopeNames();
      log.debug("Scope: {}", names);
    } else {
      log.warn("Room 5 scope was not found");
    }
View Full Code Here

TOP

Related Classes of org.red5.server.api.scope.IScope

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.