Package nux.xom.pool

Examples of nux.xom.pool.PoolConfig


        }
      };

      // prepare XQuery pool
      XQueryPool queryPool = new XQueryPool(
          new PoolConfig(), new XQueryFactory(null, resolver));
     
      ResultSequenceSerializer serializer = new ResultSequenceSerializer();
      serializer.setAlgorithm(algorithm);
      serializer.setEncoding(encoding);
      serializer.setIndent(indent);
View Full Code Here


    }
  }

  private DocumentPool createDocumentPool(final boolean isBench) {
    // prepare BuilderPool
    PoolConfig config = new PoolConfig();
    if (noBuilderPool) config.setMaxEntries(0);
    final BuilderPool builderPool;
   
    if (filter == null) {
      builderPool = new BuilderPool(config, new BuilderFactory());
    } else {
      BuilderFactory builderFactory = new BuilderFactory() {
        protected Builder newBuilder(XMLReader parser, boolean validate) {
          StreamingTransform myTransform = new StreamingTransform() {
            public Nodes transform(Element subtree) {
              return XQueryUtil.xquery(subtree, filterQuery);
            }
          };
          return new Builder(parser, validate, filter.createNodeFactory(null, myTransform));    
        }
      };
      builderPool = new BuilderPool(config, builderFactory);
    }

    // prepare DocumentFactory and DocumentPool
    DocumentFactory docFactory = new DocumentFactory() {
      public Document createDocument(InputStream input, URI baseURI)
          throws ParsingException, IOException {
        long start = System.currentTimeMillis();
        Document doc;
        if (baseURI != null && baseURI.getPath().endsWith(".bnux")) {
          if (filter == null) {
            doc = getBinaryXMLFactory().createDocument(input, baseURI);
          } else {
            StreamingTransform myTransform = new StreamingTransform() {
              public Nodes transform(Element subtree) {
                return XQueryUtil.xquery(subtree, filterQuery);
              }
            };
 
            if (input == null && baseURI == null)
              throw new IllegalArgumentException("input and baseURI must not both be null");
            if (input == null) input = baseURI.toURL().openStream();
            try {
              doc = new BinaryXMLCodec().deserialize(input, filter.createNodeFactory(null, myTransform));
              if (baseURI != null) doc.setBaseURI(baseURI.toASCIIString());
            } finally {
              input.close(); // do what SAX XML parsers do
            }
          }
        } else {
          doc = super.createDocument(input, baseURI);
        }
        if (xinclude) {
          try {
            XIncluder.resolveInPlace(doc, newBuilder());
          } catch (XIncludeException e) {
            throw new ParsingException(e.getMessage(), e);
          }
        }
        if (stripWhitespace) XOMUtil.Normalizer.STRIP.normalize(doc);
        long end = System.currentTimeMillis();
        if (isBench || explain) System.out.println(baseURI + " parse [ms]=" + (end-start));
        return doc;
      }
     
      protected Builder newBuilder() {
        if (validate.equals("wf")) {
          return builderPool.getBuilder(false);
        } else if (validate.equals("dtd")) {
          if (schema == null) return builderPool.getBuilder(true);
          EntityResolver resolver;
          try {
            resolver = new BuilderFactory().createResolver(
                  new FileInputStream(schema));
          } catch (IOException e) {
            throw new UsageException(e);
          }
          return builderPool.getDTDBuilder(resolver);
        } else if (validate.equals("schema")) {
          HashMap map = new HashMap();
          if (schema != null) map.put(schema, namespace);
//          return new BuilderFactory().createW3CBuilder(map);
          return builderPool.getW3CBuilder(map);
        } else if (validate.equals("relaxng")) {
          if (schema == null) throw new UsageException(
              "Missing required argument --schema");
          return builderPool.getMSVBuilder(schema.toURI());
        } else if (validate.equals("html")) {
          XMLReader parser;
          try {
            parser = (XMLReader) Class.forName("org.ccil.cowan.tagsoup.Parser").newInstance();
          } catch (Exception e) {
            throw new UsageException(e);
          }
          return new Builder(parser);
        } else {
          throw new UsageException("Illegal validate option: " + validate);
        }
      }
    };
   
    return new DocumentPool(
      new DocumentMap(
        new PoolConfig().
          setCompressionLevel(docPoolCompression).
          setCapacity(docPoolCapacity)),
        docFactory);
  }
View Full Code Here

  public static void main(String[] args) throws Exception {
    System.setProperty("nux.xom.pool.Pool.debug", "true"); // watch evictions
//    System.setProperty("nux.xom.pool.PoolConfig.invalidationPeriod", "5000");
   
    final PoolConfig config = new PoolConfig();
    int k = -1;
   
    int numFiles = 1000;
    if (args.length > ++k) numFiles = Math.max(1, Integer.parseInt(args[k]));

    int threads = 1;
    if (args.length > ++k) threads = Math.max(1, Integer.parseInt(args[k]));
   
    if (args.length > ++k) config.setCompressionLevel(Integer.parseInt(args[k]));
   
    if (args.length > ++k) config.setMaxEntries(Integer.parseInt(args[k]));
   
    if (args.length > ++k) config.setFileMonitoring(new Boolean(args[k]).booleanValue());
   
    if (args.length > ++k) config.setCapacity(Long.parseLong(args[k]));
   
    if (args.length > ++k) config.setMaxIdleTime(Long.parseLong(args[k]));
   
    if (args.length > ++k) config.setMaxLifeTime(Long.parseLong(args[k]));
   
    final DocumentMap pool = new DocumentMap(config);
   
    final File[] files = new File[numFiles];
    new File("tmp").mkdir();
View Full Code Here

   
    byte[] b = new byte[0];
    if (memory && !fileName.equals("nofile")) b = FileUtil.toByteArray(new FileInputStream(fileName));
    final byte[] bytes = b;
   
    final BuilderPool pool = !nullNodeFactory ? BuilderPool.GLOBAL_POOL : new BuilderPool(new PoolConfig(),
        new BuilderFactory() {
          protected NodeFactory createNodeFactory() {
            return XOMUtil.getNullNodeFactory();
          }
        }
View Full Code Here

  public static void main(String[] args) throws Exception {
    System.setProperty("nux.xom.pool.Pool.debug", "true"); // watch evictions
//    System.setProperty("nux.xom.pool.PoolConfig.invalidationPeriod", "1000");
   
    final PoolConfig config = new PoolConfig();
    int k = -1;
   
    Document doc = null;
    if (args.length > ++k && !args[k].equals("-"))
      doc = new Builder().build(args[k]);
   
    int threads = 1;
    if (args.length > ++k) threads = Math.max(1, Integer.parseInt(args[k]));
   
    if (args.length > ++k) config.setCompressionLevel(Integer.parseInt(args[k]));
   
    if (args.length > ++k) config.setMaxEntries(Integer.parseInt(args[k]));
   
    if (args.length > ++k) config.setFileMonitoring(new Boolean(args[k]).booleanValue());
   
    if (args.length > ++k) config.setCapacity(Long.parseLong(args[k]));
   
    if (args.length > ++k) config.setMaxIdleTime(Long.parseLong(args[k]));
   
    if (args.length > ++k) config.setMaxLifeTime(Long.parseLong(args[k]));
   
    int printStep = 10;
    if (args.length > ++k) printStep = Math.max(1, Integer.parseInt(args[k]));
   
    final DocumentMap pool = new DocumentMap(config);
   
    for (int j=0; j < threads; j++) {
      final int t = j;
      final Document xmlDoc = doc;
      final int step = printStep;
      Runnable runner = new Runnable() {
        public void run() {
          try {
            int i = 0;
            while (true) {
              if (i % step == 0) System.out.println("t="+ t + ", index=" + i);
              Document doc;
              if (xmlDoc == null) {
                Element root = new Element("root");
                Element child = new Element("child");
                root.appendChild(child);
                for (int j=0; j < 10000; j++) child.appendChild("xxxxxxxxxxxxxxxxxx" + j);
                doc = new Document(root);
              }
              else {
                doc = xmlDoc;
                if (config.getCompressionLevel() == -1) doc = new Document(doc);
              }
             
              Object key = new Integer(i + t*100);
//              Object key = new Integer(-1);
              pool.putDocument(key, doc);
View Full Code Here

TOP

Related Classes of nux.xom.pool.PoolConfig

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.