Examples of IPersistable


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

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

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

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

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

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

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

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

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

  }

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

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

      synchronized (objects) {
      if (!objects.containsKey(name)) {
        return false;
      }
 
      IPersistable object = objects.remove(name);
      object.setPersistent(false);
      }
    return true;
  }
View Full Code Here

Examples of org.rssowl.core.persist.IPersistable

   */
  @Test
  public void testEquals() throws Exception {

    /* IExtendableType */
    IPersistable type1 = fFactory.createLabel(null, "name");
    IPersistable type2 = fFactory.createLabel(null, "name");

    IPersistable type3 = fFactory.createLabel(Long.valueOf(1), "name");
    IPersistable type4 = fFactory.createLabel(Long.valueOf(1), "name");

    IPersistable type5 = fFactory.createLabel(Long.valueOf(1), "name");
    IPersistable type6 = fFactory.createLabel(Long.valueOf(2), "name");

    assertFalse(type1.equals(type2));
    assertTrue(type3.equals(type4));
    assertFalse(type5.equals(type6));

View Full Code Here

Examples of org.rssowl.core.persist.IPersistable

   */
  @Test
  public void testHashCode() throws Exception {

    /* ExtendableType */
    IPersistable type1 = fFactory.createLabel(null, "name");
    IPersistable type2 = fFactory.createLabel(null, "name");

    IPersistable type3 = fFactory.createLabel(Long.valueOf(1), "name");
    IPersistable type4 = fFactory.createLabel(Long.valueOf(1), "name");

    IPersistable type5 = fFactory.createLabel(Long.valueOf(1), "name");
    IPersistable type6 = fFactory.createLabel(Long.valueOf(2), "name");

    assertFalse(type1.hashCode() == type2.hashCode());
    assertTrue(type3.hashCode() == type4.hashCode());
    assertFalse(type5.hashCode() == type6.hashCode());

    /* ISearchField */
    ISearchField fieldLabelName1 = fFactory.createSearchField(ILabel.NAME, ILabel.class.getName());
    ISearchField fieldLabelName2 = fFactory.createSearchField(ILabel.NAME, ILabel.class.getName());
    ISearchField fieldLabelAllFields = fFactory.createSearchField(IEntity.ALL_FIELDS, ILabel.class.getName());
View Full Code Here

Examples of org.rssowl.core.persist.IPersistable

    return new ArrayList<IEntity>(Arrays.asList(new IFolder[] { folder }));
  }

  private void processOutline(Element outline, IPersistable parent) {
    IPersistable type = null;
    String title = null;
    String link = null;
    String homepage = null;
    String description = null;
View Full Code Here

Examples of org.rssowl.core.persist.IPersistable

    return value;
  }

  private void processOutline(Element outline, IPersistable parent) {
    IPersistable type = null;
    String title = null;
    String link = null;
    String homepage = null;
    String description = null;
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.