Package org.red5.server.api.persistence

Examples of org.red5.server.api.persistence.IPersistable


          }
          String scopeName = "hibernate";
          if (rcl.getRoom_id() != null) {
            scopeName = rcl.getRoom_id().toString();
          }
          IScope currentScope = this.scopeApplicationAdapter.getRoomScope(scopeName);
         
          HashMap<Integer,String> messageObj = new HashMap<Integer,String>();
          messageObj.put(0, "kick");
         
          this.scopeApplicationAdapter.sendMessageById(messageObj, rcl.getStreamid(), currentScope);
View Full Code Here


   * @param object           Object to attach to
   * @return                 Persistable object
   */
  private IPersistable doLoad(String name, IPersistable object) {
    log.debug("doLoad - name: {} object: {}", name, object);
    IPersistable result = object;
//    if (log.isTraceEnabled()) {
//      try {
//        log.trace("Relative #1: {}", (resources.getResource(name) != null ? resources.getResource(name).getFile().getAbsolutePath() : "Not found"));
//        log.trace("Absolute #2: {}", (resources.getResource("file://" + rootDir + '/' + name) != null ? resources.getResource("file://" + rootDir + '/' + name).getFile()
//            .getAbsolutePath() : "Not found"));
//      } catch (IOException e) {
//        log.warn("", e);
//      }
//    }
    Resource data = resources.getResource(name);
    if (data == null || !data.exists()) {
      // no such file
      log.debug("Resource / data was not found");
      // try again with full path
      data = resources.getResource("file://" + rootDir + '/' + name);
      if (data == null || !data.exists()) {
        log.debug("Resource / data was not found (full path)");
        return null;
      }
    }
    FileInputStream input;
    String filename;
    try {
      File fp = data.getFile();
      if (fp.length() == 0) {
        // File is empty
        log.error("The file at {} is empty", data.getFilename());
        return null;
      }
      filename = fp.getAbsolutePath();
      input = new FileInputStream(filename);
    } catch (FileNotFoundException e) {
      log.error("The file at {} does not exist", data.getFilename());
      return null;
    } catch (IOException e) {
      log.error("Could not load file from {}", data.getFilename(), e);
      return null;
    }

    try {
      IoBuffer buf = IoBuffer.allocate(input.available());
      try {
        ServletUtils.copy(input, buf.asOutputStream());
        buf.flip();
        Input in = new Input(buf);
        String className = Deserializer.deserialize(in, String.class);
        if (result == null) {
          // we need to create the object first
          try {
            Class<?> theClass = Class.forName(className);
            Constructor<?> constructor = null;
            try {
              // try to create object by calling constructor with Input stream as parameter
              for (Class<?> interfaceClass : in.getClass().getInterfaces()) {
                constructor = theClass.getConstructor(new Class[] { interfaceClass });
                if (constructor != null) {
                  break;
                }
              }
              if (constructor == null) {
                throw new NoSuchMethodException();
              }
              result = (IPersistable) constructor.newInstance(in);
            } catch (NoSuchMethodException err) {
              // no valid constructor found, use empty constructor
              result = (IPersistable) theClass.newInstance();
              result.deserialize(in);
            } catch (InvocationTargetException err) {
              // error while invoking found constructor, use empty constructor
              result = (IPersistable) theClass.newInstance();
              result.deserialize(in);
            }
          } catch (ClassNotFoundException cnfe) {
            log.error("Unknown class {}", className);
            return null;
          } catch (IllegalAccessException iae) {
            log.error("Illegal access", iae);
            return null;
          } catch (InstantiationException ie) {
            log.error("Could not instantiate class {}", className);
            return null;
          }
          // set object's properties
          log.debug("Name (after load): {}", result.getName());
          result.setPath(getObjectPath(name, result.getName()));
        } else {
          // Initialize existing object
          String resultClass = result.getClass().getName();
          if (!resultClass.equals(className)) {
            log.error("The classes differ: {} != {}", resultClass, className);
            return null;
          }
          result.deserialize(in);
        }
      } finally {
        buf.free();
        buf = null;
      }
      if (result.getStore() != this) {
        result.setStore(this);
      }
      super.save(result);
      log.debug("Loaded persistent object {} from {}", result, filename);
    } catch (IOException e) {
      log.error("Could not load file at {}", filename);
View Full Code Here

  /** {@inheritDoc} */
  @Override
  public IPersistable load(String name) {
    log.debug("load - name: {}", name);
    IPersistable result = super.load(name);
    if (result != null) {
      // Object has already been loaded
      return result;
    }
    return doLoad(path + '/' + name + extension);
View Full Code Here

    //
    super.notifyClose();
  }

  private void persist() {
    IPersistable persistable = null;
    while (!queue.isEmpty()) {
      try {
        persistable = queue.poll();
        if (!saveObject(persistable)) {
          log.warn("Object persist failed for: {}", persistable);
View Full Code Here

     * @param name             Resource name
     * @param object           Object to attach to
     * @return                 Persistable object
     */
    private IPersistable doLoad(String name, IPersistable object) {
    IPersistable result = object;
    Resource data = resources.getResource(name);
    if (data == null || !data.exists()) {
      // No such file
      return null;
    }

    FileInputStream input;
    String filename;
    try {
      File fp = data.getFile();
      if (fp.length() == 0) {
        // File is empty
        log.error("The file at " + data.getFilename() + " is empty.");
        return null;
      }

      filename = fp.getAbsolutePath();
      input = new FileInputStream(filename);
    } catch (FileNotFoundException e) {
      log.error("The file at " + data.getFilename() + " does not exist.");
      return null;
    } catch (IOException e) {
      log.error("Could not load file from " + data.getFilename() + '.', e);
      return null;
    }

    try {
      ByteBuffer buf = ByteBuffer.allocate(input.available());
      try {
        ServletUtils.copy(input, buf.asOutputStream());
        buf.flip();
        Input in = new Input(buf);
        Deserializer deserializer = new Deserializer();
        String className = deserializer.deserialize(in, String.class);
        if (result == null) {
          // We need to create the object first
          try {
            Class<?> theClass = Class.forName(className);
            Constructor<?> constructor = null;
            try {
              // Try to create object by calling constructor with Input stream as
              // parameter.
              for (Class<?> interfaceClass : in.getClass().getInterfaces()) {
                constructor = theClass.getConstructor(new Class[] { interfaceClass });
                if (constructor != null) {
                  break;
                }
              }
              if (constructor == null) {
                throw new NoSuchMethodException();
              }

              result = (IPersistable) constructor.newInstance(in);
            } catch (NoSuchMethodException err) {
              // No valid constructor found, use empty
              // constructor.
              result = (IPersistable) theClass.newInstance();
              result.deserialize(in);
            } catch (InvocationTargetException err) {
              // Error while invoking found constructor, use empty
              // constructor.
              result = (IPersistable) theClass.newInstance();
              result.deserialize(in);
            }
          } catch (ClassNotFoundException cnfe) {
            log.error("Unknown class " + className);
            return null;
          } catch (IllegalAccessException iae) {
            log.error("Illegal access.", iae);
            return null;
          } catch (InstantiationException ie) {
            log.error("Could not instantiate class " + className);
            return null;
          }

          // Set object's properties
          result.setName(getObjectName(name));
          result.setPath(getObjectPath(name, result.getName()));
        } else {
          // Initialize existing object
          String resultClass = result.getClass().getName();
          if (!resultClass.equals(className)) {
            log.error("The classes differ: " + resultClass + " != "
                + className);
            return null;
          }

          result.deserialize(in);
        }
      } finally {
        buf.release();
        buf = null;
      }
      if (result.getStore() != this) {
        result.setStore(this);
      }
      super.save(result);
      if (log.isDebugEnabled()) {
        log.debug("Loaded persistent object " + result + " from " + filename);
      }
View Full Code Here

  }

  /** {@inheritDoc} */
    @Override
  public IPersistable load(String name) {
    IPersistable result = super.load(name);
    if (result != null) {
      // Object has already been loaded
      return result;
    }

View Full Code Here

      synchronized (objects) {
      if (!objects.containsKey(name)) {
        return false;
      }
 
      IPersistable object = objects.remove(name);
      object.setPersistent(false);
      }
    return true;
  }
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.persistence.IPersistable

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.