Package org.exist.storage

Examples of org.exist.storage.BrokerPool$StatusReporter


   
   
    /** Creates a new instance */
    public GrammarTooling(XQueryContext context, FunctionSignature signature) {
        super(context, signature);
        final BrokerPool brokerPool = context.getBroker().getBrokerPool();
        config = brokerPool.getConfiguration();
    }
View Full Code Here


            response.setContentType(mediaType + "; charset=" + encoding);
        }
       
        Serializer serializer = null;
       
        BrokerPool db = null;
        DBBroker broker = null;
        try {
          db = BrokerPool.getInstance();
          broker = db.get(null);
         
            serializer = broker.getSerializer();
            serializer.reset();
           
            final OutputStream sout = response.getOutputStream();
            final PrintWriter output = new PrintWriter(new OutputStreamWriter(sout, encoding));

          final SerializerPool serializerPool = SerializerPool.getInstance();

          final SAXSerializer sax = (SAXSerializer) serializerPool.borrowObject(SAXSerializer.class);
          try {
            sax.setOutput(output, serializeOptions);

            serializer.setProperties(serializeOptions);
            serializer.setSAXHandlers(sax, sax);
              serializer.toSAX(inputNode, 1, inputNode.getItemCount(), false, false);
             
          } catch (final SAXException e) {
            e.printStackTrace();
            throw new IOException(e);
          } finally {
            serializerPool.returnObject(sax);
          }
          output.flush();
          output.close();
           
            //commit the response
            response.flushBuffer();
        } catch (final IOException e) {
            throw new XPathException(this, "IO exception while streaming node: " + e.getMessage(), e);
        } catch (final EXistException e) {
            throw new XPathException(this, "Exception while streaming node: " + e.getMessage(), e);
    } finally {
      if (db != null)
        {db.release(broker);}
    }
        return Sequence.EMPTY_SEQUENCE;
  }
View Full Code Here

     */
    public void stream(XmldbURL xmldbURL, File tmp, Subject user) throws IOException {
        LOG.debug("Begin document upload");
       
        Collection collection = null;
        BrokerPool pool =null;
        DBBroker broker =null;
        TransactionManager transact = null;
        Txn txn = null;
       
        boolean collectionLocked = true;
       
       
        try {
            pool = BrokerPool.getInstance();
           
            if(user==null) {
                if(xmldbURL.hasUserInfo()){
                    user=EmbeddedUser.authenticate(xmldbURL, pool);
                    if(user==null){
                        LOG.debug("Unauthorized user "+xmldbURL.getUsername());
                        throw new IOException("Unauthorized user "+xmldbURL.getUsername());
                    }
                } else {
                    user=EmbeddedUser.getUserGuest(pool);
                }
            }
           
            broker = pool.get(user);
           
            final XmldbURI collectionUri = XmldbURI.create(xmldbURL.getCollection());
            final XmldbURI documentUri = XmldbURI.create(xmldbURL.getDocumentName());
           
            collection = broker.openCollection(collectionUri, Lock.READ_LOCK);
           
            if(collection == null)
                {throw new IOException("Resource "+collectionUri.toString()+" is not a collection.");}
           
            if(collection.hasChildCollection(broker, documentUri))
                {throw new IOException("Resource "+documentUri.toString()+" is a collection.");}
           
            MimeType mime = MimeTable.getInstance().getContentTypeFor(documentUri);
            String contentType=null;
            if (mime != null){
                contentType = mime.getName();
            } else {
                mime = MimeType.BINARY_TYPE;
            }
           
            transact = pool.getTransactionManager();
            txn = transact.beginTransaction();
           
            if(mime.isXMLType()) {
                LOG.debug("storing XML resource");
                final InputSource inputsource = new InputSource(tmp.toURI().toASCIIString());
                final IndexInfo info = collection.validateXMLResource(txn, broker, documentUri, inputsource);
                final DocumentImpl doc = info.getDocument();
                doc.getMetadata().setMimeType(contentType);
                collection.release(Lock.READ_LOCK);
                collectionLocked = false;
                collection.store(txn, broker, info, inputsource, false);
                LOG.debug("done");
               
            } else {
                LOG.debug("storing Binary resource");
                final InputStream is = new FileInputStream(tmp);
                try {
                  collection.addBinaryResource(txn, broker, documentUri, is, contentType, tmp.length());
                } finally {
                  is.close();
                }
                LOG.debug("done");
            }
           
            LOG.debug("commit");
            transact.commit(txn);
           
        } catch (final IOException ex) {
            try {
              // is it still actual? -shabanovd
                // Throws an exception when the user is unknown!
              if (transact != null)
                {transact.abort(txn);}
            } catch (final Exception abex) {
                LOG.debug(abex);
            }
            //ex.printStackTrace();
            LOG.debug(ex);
            throw ex;
           
        } catch (final Exception ex) {
            try {
              // is it still actual? -shabanovd
                // Throws an exception when the user is unknown!
              if (transact != null)
                {transact.abort(txn);}
            } catch (final Exception abex) {
                LOG.debug(abex);
            }
            //ex.printStackTrace();
            LOG.debug(ex);
            throw new IOException(ex.getMessage(), ex);
           
        } finally {
            if (transact != null) {
                transact.close(txn);
            }
            LOG.debug("Done.");
            if(collectionLocked && collection != null){
                collection.release(Lock.READ_LOCK);
            }
           
            pool.release(broker);
        }
       
    }
View Full Code Here

    public EmbeddedDownloadThread(XmldbURL url, OutputStream bos) {
        xmldbURL = url;
        this.bos = bos;
       
        try {
            BrokerPool pool = BrokerPool.getInstance(url.getInstanceName());
            subject = pool.getSubject();
        } catch (Throwable e) {
            //e.printStackTrace();
        }
    }
View Full Code Here

    }

    private void executeXQuery(String xqueryResourcePath) {
        if (xqueryResourcePath != null && xqueryResourcePath.length() > 0) {
            xqueryResourcePath = xqueryResourcePath.trim();
            BrokerPool pool = null;
            DBBroker broker = null;
            Subject subject = null;

            try {
                DocumentImpl resource = null;
                Source source = null;

                pool = BrokerPool.getInstance();
                subject = pool.getSecurityManager().getSystemSubject();

                broker = pool.get(subject);
                if (broker == null) {
                    LOG.error("Unable to retrieve DBBroker for " + subject.getName());
                    return;
                }

                final XmldbURI pathUri = XmldbURI.create(xqueryResourcePath);


                resource = broker.getXMLResource(pathUri, Lock.READ_LOCK);

                if(resource != null) {
                    LOG.info("Resource [" + xqueryResourcePath + "] exists.");
                    source = new DBSource(broker, (BinaryDocument)resource, true);
                } else {
                    LOG.error("Resource [" + xqueryResourcePath + "] does not exist.");
                    return;
                }


                final XQuery xquery = broker.getXQueryService();

                if (xquery == null) {
                    LOG.error("broker unable to retrieve XQueryService");
                    return;
                }

                final XQueryPool xqpool = xquery.getXQueryPool();
                CompiledXQuery compiled = xqpool.borrowCompiledXQuery(broker, source);
                XQueryContext context;
                if (compiled == null)
                    {context = xquery.newContext(AccessContext.REST);}
                else
                    {context = compiled.getContext();}
                context.setStaticallyKnownDocuments(new XmldbURI[] { pathUri });
                context.setBaseURI(new AnyURIValue(pathUri.toString()));

                if (compiled == null)
                    {compiled = xquery.compile(context, source);}
                else {
                    compiled.getContext().updateContext(context);
                    context.getWatchDog().reset();
                }

                final Properties outputProperties = new Properties();
                Sequence result = null;

                try {
                    final long startTime = System.currentTimeMillis();
                    result = xquery.execute(compiled, null, outputProperties);
                    final long queryTime = System.currentTimeMillis() - startTime;
                    LOG.info("XQuery execution results: " + result.toString()  + " in " + queryTime + "ms.");
                } finally {
                    xqpool.returnCompiledXQuery(source, compiled);
                }

            } catch (final Exception e) {
                LOG.error("Exception while executing [" + xqueryResourcePath + "] script for " + subject.getName(), e);
            }
            finally {
                if (pool != null)
                    {pool.release(broker);}
            }
        }
    }
View Full Code Here

    public EmbeddedUploadThread(XmldbURL url, BlockingInputStream bis) {
        xmldbURL=url;
        this.bis=bis;
       
        try {
            BrokerPool pool = BrokerPool.getInstance(url.getInstanceName());
            subject = pool.getSubject();
        } catch (Throwable e) {
            //e.printStackTrace();
        }
    }
View Full Code Here

    String query =
      "xmldb:document()//p[. = '\u4ED6\u4E3A\u8FD9\u9879\u5DE5\u7A0B\u6295"
        + "\u5165\u4E86\u5341\u4E09\u5E74\u65F6\u95F4\u3002']";

    // get a BrokerPool for access to the database engine
    BrokerPool pool = null;
    try {
      pool = BrokerPool.getInstance();
    } catch (EXistException e1) {
      e1.printStackTrace();
      fail(e1.getMessage());
    }
    DBBroker broker = null;
    TransactionManager transact = null;
    Txn transaction = null;
    try {
      broker = pool.get(pool.getSecurityManager().getSystemSubject());
      try {
        // parse the xml source
        transact = pool.getTransactionManager();
              assertNotNull(transact);
              transaction = transact.beginTransaction();
              assertNotNull(transaction);
              Collection collection = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI);
              broker.saveCollection(transaction, collection);
 
              IndexInfo info = collection.validateXMLResource(transaction, broker, XmldbURI.create("test.xml"), xml);
              //TODO : unlock the collection here ?
              collection.store(transaction, broker, info, xml, false);
              transact.commit(transaction);
      } catch (Exception e) {
        transact.abort(transaction);
              e.printStackTrace();
              fail(e.getMessage());
      }

      try {
              // parse the query into the internal syntax tree
        XQueryContext context = new XQueryContext(broker.getBrokerPool(), AccessContext.TEST);
        XQueryLexer lexer = new XQueryLexer(context, new StringReader(query));
        XQueryParser xparser = new XQueryParser(lexer);
        XQueryTreeParser treeParser = new XQueryTreeParser(context);
        xparser.xpath();
        if (xparser.foundErrors()) {
          System.err.println(xparser.getErrorMessage());
          return;
        }
 
        AST ast = xparser.getAST();
        System.out.println("generated AST: " + ast.toStringTree());
 
        PathExpr expr = new PathExpr(context);
        treeParser.xpath(ast, expr);
        if (treeParser.foundErrors()) {
          System.err.println(treeParser.getErrorMessage());
          return;
        }
        expr.analyze(new AnalyzeContextInfo());
        // execute the query
        Sequence result = expr.eval(null, null);
 
        // check results
        System.out.println("----------------------------------");
        System.out.println("found: " + result.getItemCount());
      } catch (Exception e) {
              e.printStackTrace();
              fail(e.getMessage());
      }
    } catch (EXistException e) {
            e.printStackTrace();
            fail(e.getMessage());
    } finally {
      pool.release(broker);
    }
    if (localDb)
      try {
        BrokerPool.stop();
      } catch (EXistException e2) {
View Full Code Here

            stopItem.setEnabled(false);
        }
    }

    private void checkInstalledApps() {
        BrokerPool pool = null;
        DBBroker broker = null;
        try {
            pool = BrokerPool.getInstance();
            broker = pool.get(pool.getSecurityManager().getSystemSubject());
            final XQuery xquery = broker.getXQueryService();
            final Sequence pkgs = xquery.execute("repo:list()", null, AccessContext.INITIALIZE);
            for (final SequenceIterator i = pkgs.iterate(); i.hasNext(); ) {
                final ExistRepository.Notification notification = new ExistRepository.Notification(ExistRepository.Action.INSTALL, i.nextItem().getStringValue());
                update(pool.getExpathRepo(), notification);
                utilityPanel.update(pool.getExpathRepo(), notification);
            }
        } catch (final EXistException e) {
            System.err.println("Failed to check installed packages: " + e.getMessage());
            e.printStackTrace();
        } catch (final XPathException e) {
            System.err.println("Failed to check installed packages: " + e.getMessage());
            e.printStackTrace();
        } catch (final PermissionDeniedException e) {
            System.err.println("Failed to check installed packages: " + e.getMessage());
            e.printStackTrace();
        } finally {
            if (pool != null)
                {pool.release(broker);}
        }
    }
View Full Code Here

        }
    }

    private void registerObserver() {
        try {
            final BrokerPool pool = BrokerPool.getInstance();
            pool.getExpathRepo().addObserver(this);
            pool.getExpathRepo().addObserver(utilityPanel);
        } catch (final EXistException e) {
            System.err.println("Failed to register as observer for package manager events");
            e.printStackTrace();
        }
    }
View Full Code Here

  }
  public void init(PolicyFinder finder) {}

  public PolicyFinderResult findPolicy(EvaluationCtx context)
  {
    final BrokerPool pool = pdp.getBrokerPool();
    DBBroker broker = null;
    try
    {
      broker = pool.get(pool.getSecurityManager().getSystemSubject());
      return findPolicy(broker, context);
    }
                catch(final PermissionDeniedException pde) {
                      return XACMLUtil.errorResult("Error while finding policy: " + pde.getMessage(), pde);
                }
    catch(final EXistException ee)
    {
      return XACMLUtil.errorResult("Error while finding policy: " + ee.getMessage(), ee);
    }
    finally
    {
      pool.release(broker);
    }
  }
View Full Code Here

TOP

Related Classes of org.exist.storage.BrokerPool$StatusReporter

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.