Package com.gentics.cr.monitoring

Examples of com.gentics.cr.monitoring.UseCase


   * @param response - servlet responce to write back to
   * @throws IOException in case the container cannot process the request
   * @see #doService(HttpServletRequest, HttpServletResponse)
   */
  public void doServiceSafe(HttpServletRequest request, HttpServletResponse response) throws IOException {
    UseCase uc = MonitorFactory.startUseCase("RESTServlet(" + request.getServletPath() + ")");
    log.debug("Request:" + request.getQueryString());
    long starttime = new Date().getTime();
    try {
      doService(request, response);
    } finally {
      response.getOutputStream().flush();
      response.getOutputStream().close();
     
      long endtime = new Date().getTime();
      if (log.isInfoEnabled()) {
        StringBuilder requestID = new StringBuilder();
        requestID.append(request.getRequestURI());
        if (request.getQueryString() != null) {
          requestID.append('?');
          requestID.append(request.getQueryString());
        }
        log.info("Executiontime for " + requestID + ":" + (endtime - starttime));
      }
      uc.stop();
    }
  }
View Full Code Here


      this.container.finalize();
  }

  public void doService(HttpServletRequest request, HttpServletResponse response) throws ServletException,
      IOException {
    UseCase uc = MonitorFactory.startUseCase("RESTServlet(" + request.getServletPath() + ")");
    this.log.debug("Request:" + request.getQueryString());

    // starttime
    long s = new Date().getTime();
    HashMap<String, Resolvable> objects = new HashMap<String, Resolvable>();
    objects.put("request", new BeanWrapper(request));
    objects.put("session", new HttpSessionWrapper(request.getSession()));
    CRNavigationRequestBuilder requestBuilder = new CRNavigationRequestBuilder(request, crConf);
    container.processService(requestBuilder, objects, response.getOutputStream(), new ServletResponseTypeSetter(
        response));
    response.getOutputStream().flush();
    response.getOutputStream().close();
    // endtime
    long e = new Date().getTime();
    this.log.info("Executiontime for " + request.getQueryString() + ":" + (e - s));
    uc.stop();
  }
View Full Code Here

   * @return resulting objects
   * @throws CRException TODO javadoc
   */
  public final Collection<CRResolvableBean> getObjects(final CRRequest request, final boolean doNavigation)
      throws CRException {
    UseCase getObjectCase = MonitorFactory.startUseCase("CRRequestProcessor.getObjects(" + config.getName() + ")");
    Datasource ds = null;
    DatasourceFilter dsFilter;
    Vector<CRResolvableBean> collection = new Vector<CRResolvableBean>();
    if (request != null) {
      // Parse the given expression and create a datasource filter
      try {
        ds = this.config.getDatasource();
        if (ds == null) {
          throw (new DatasourceException("No Datasource available."));
        }

        dsFilter = request.getPreparedFilter(config, ds);
        // add base resolvables
        if (this.resolvables != null) {
          for (Iterator<String> it = this.resolvables.keySet().iterator(); it.hasNext();) {
            String name = it.next();
            dsFilter.addBaseResolvable(name, this.resolvables.get(name));
          }
        }

        String[] prefillAttributes = request.getAttributeArray();
        int first = request.getStart().intValue();
        int last = request.getCount().intValue();
        Sorting[] sorting = request.getSorting();
        // do the query
        Collection<Resolvable> col = getResult(ds, dsFilter, prefillAttributes, first, last, sorting);

        // convert all objects to serializeable beans
        if (col != null) {
          for (Iterator<Resolvable> it = col.iterator(); it.hasNext();) {
            CRResolvableBean crBean = new CRResolvableBean(it.next(), request.getAttributeArray());
            if (this.config.getFolderType().equals(crBean.getObj_type()) && doNavigation) {
              // Process child elements
              String fltr = "object.folder_id=='" + crBean.getContentid() + "'";
              if (request.getChildFilter() != null) {
                fltr += "AND (" + request.getChildFilter() + ")";
              }
              // If object is a folder => retrieve the childs of the object
              CRRequest childReq = request.Clone();
              childReq.setRequestFilter(fltr);
              crBean.fillChildRepository(this.getNavigation(childReq));
            }
            collection.add(this.replacePlinks(crBean, request));
          }
        }

      } catch (ParserException e) {
        e.printStackTrace();
        throw new CRException("ParserException", e.getMessage());
      } catch (ExpressionParserException e) {
        e.printStackTrace();
        throw new CRException("ExpressionParserException", e.getMessage());
      } catch (DatasourceException e) {
        e.printStackTrace();
        throw new CRException("DatasourceException", e.getMessage());
      } finally {
        CRDatabaseFactory.releaseDatasource(ds);
        getObjectCase.stop();
      }
    }
    return collection;
  }
View Full Code Here

   * @param sorting {@link Sorting} that should be used.
   * @return {@link Collection} of {@link Resolvable}s described by the filter.
   */
  private Collection<Resolvable> getResult(final Datasource ds, final DatasourceFilter dsFilter,
      final String[] prefillAttributes, final int first, final int last, final Sorting[] sorting) {
    UseCase getResultCase = MonitorFactory.startUseCase("CRRequestProcessor.getResult(" + config.getName() + ")");
    Collection<?> result;
    Collection<Resolvable> checkCacheResult;
    Collection<Resolvable> collection = null;
    Collection<Resolvable> cachedResult;
    String cacheKey = config.getName() + "-" + dsFilter.getExpressionString();

    try {
      UseCase getResultFastCase = MonitorFactory.startUseCase("CRRequestProcessor.getResult(" + config.getName()
          + ")#fastResult");
      checkCacheResult = toResolvableCollection(ds.getResult(dsFilter, new String[] {}, first, last, sorting));
      getResultFastCase.stop();

      UseCase getResultCacheCase = MonitorFactory.startUseCase("CRRequestProcessor.getResult(" + config.getName()
          + ")#cache");
      cachedResult = getCachedResult(cacheKey);
      getResultCacheCase.stop();

      boolean up2date = compare(cachedResult, checkCacheResult);

      if (up2date) {
        collection = cachedResult;
      } else {
        UseCase getResultUncachedCase = MonitorFactory.startUseCase("CRRequestProcessor.getResult("
            + config.getName() + ")#uncached");
        result = ds.getResult(dsFilter, prefillAttributes, first, last, sorting);
        collection = toResolvableCollection(result);
        saveResult(cacheKey, collection);
        getResultUncachedCase.stop();
      }
    } catch (DatasourceException e) {
      logger.error("Cannot get the result from the Datasource.", e);
    }
    getResultCase.stop();
View Full Code Here

   * @param left first Resolvable
   * @param right second Resolvable
   * @return returns false if they are not equal
   */
  public static boolean compare(final Collection<Resolvable> left, final Collection<Resolvable> right) {
    UseCase getResultVerifyCase = MonitorFactory.startUseCase("CRRequestProcessor.compare()#verify");
    if (left.size() != right.size()) {
      return false;
    } else {
      int leftUpdatetime = 0;
      for (Resolvable leftResolvable : left) {
        leftUpdatetime = checkUpdatetime(leftResolvable, leftUpdatetime);
      }
      int rightUpdatetime = 0;
      for (Resolvable rightResolvable : right) {
        rightUpdatetime = checkUpdatetime(rightResolvable, rightUpdatetime);
      }
      getResultVerifyCase.stop();
      if (rightUpdatetime != leftUpdatetime) {
        return false;
      }
    }
    return true;
View Full Code Here

   * Process the specified bean with monitoring.
   * @param bean
   * @throws CRException
   */
  public void processBeanWithMonitoring(CRResolvableBean bean) throws CRException {
    UseCase pcase = MonitorFactory.startUseCase("Transformer:" + this.getClass());
    try {
      processBean(bean);
    } finally {
      pcase.stop();
    }
  }
View Full Code Here

   * Process the specified bean with monitoring.
   * @param bean
   * @throws CRException
   */
  public void processBeanWithMonitoring(CRResolvableBean bean, IndexWriter writer) throws CRException {
    UseCase pcase = MonitorFactory.startUseCase("Transformer:" + this.getClass());
    try {
      processBean(bean, writer);
    } finally {
      pcase.stop();
    }
  }
View Full Code Here

        if (!interrupted) {
          // Only Optimize the Index if the thread
          // has not been interrupted
          if (optimize) {
            log.debug("Executing optimize command.");
            UseCase uc = MonitorFactory.startUseCase("optimize(" + crid + ")");
            try {
              indexWriter.optimize();
            } finally {
              uc.stop();
            }
          } else if (maxSegmentsString != null) {
            log.debug("Executing optimize command with max" + " segments: " + maxSegmentsString);
            int maxs = Integer.parseInt(maxSegmentsString);
            UseCase uc = MonitorFactory.startUseCase("optimize(" + crid + ")");
            try {
              indexWriter.optimize(maxs);
            } finally {
              uc.stop();
            }
          }
        } else {
          log.debug("Job has been interrupted and will now be closed." + " Missing objects " + "will be reindexed next run.");
        }
        finishedIndexJobSuccessfull = true;
      } catch (Exception ex) {
        log.error("Could not complete index run... indexed Objects: " + status.getObjectsDone()
            + ", trying to close index and remove lock.", ex);
        finishedIndexJobWithError = true;
        status.setError("Could not complete index run... indexed " + "Objects: " + status.getObjectsDone()
            + ", trying to close index and remove lock.");
      } finally {
        if (!finishedIndexJobSuccessfull && !finishedIndexJobWithError) {
          log.fatal("There seems to be a run time exception from this" + " index job.\nLast slice was: " + slice);
        }
        //Set status for job if it was not locked
        status.setCurrentStatusString("Finished job.");
        int objectCount = status.getObjectsDone();
        log.debug("Indexed " + objectCount + " objects...");

        if (taxonomyAccessor != null && taxonomyWriter != null) {
          taxonomyAccessor.release(taxonomyWriter);
        }

        if (indexAccessor != null && indexWriter != null) {
          indexAccessor.release(indexWriter);
        }
        if (indexAccessor != null && indexReader != null) {
          indexAccessor.release(indexReader, false);
        }

        if (objectCount > 0) {
          indexLocation.createReopenFile();
        }
        UseCase ucFireEvent = MonitorFactory.startUseCase("indexCR(" + crid + ") fire IndexingFinishedEvent");
        EventManager.getInstance().fireEvent(new IndexingFinishedEvent(indexLocation));
        ucFireEvent.stop();
      }
    } catch (LockedIndexException ex) {
      log.debug("LOCKED INDEX DETECTED. TRYING AGAIN IN NEXT JOB.");
      if (this.indexLocation != null && !this.indexLocation.hasLockDetection()) {
        log.error("IT SEEMS THAT THE INDEX HAS UNEXPECTEDLY BEEN " + "LOCKED. TRYING TO REMOVE THE LOCK", ex);
View Full Code Here

      final Collection<CRResolvableBean> slice, final Map<String, Boolean> attributes, final RequestProcessor rp,
      final boolean create, final CRConfigUtil config, final List<ContentTransformer> transformerlist,
      final List<String> reverseattributes, final TaxonomyWriter taxonomyWriter, final TaxonomyAccessor taxonomyAccessor)
      throws CRException, IOException {
    // prefill all needed attributes
    UseCase uc = MonitorFactory.startUseCase("indexSlice(" + crid + ")");
    try {
      CRRequest req = new CRRequest();
      String[] prefillAttributes = attributes.keySet().toArray(new String[0]);
      req.setAttributeArray(prefillAttributes);
      UseCase prefillCase = MonitorFactory.startUseCase("indexSlice(" + crid + ").prefillAttributes");
      rp.fillAttributes(slice, req, idAttribute);
      prefillCase.stop();
      for (Resolvable objectToIndex : slice) {
        CRResolvableBean bean = new CRResolvableBean(objectToIndex, prefillAttributes);
        UseCase bcase = MonitorFactory.startUseCase("indexSlice(" + crid + ").indexBean");
        try {
          //CALL PRE INDEX PROCESSORS/TRANSFORMERS
          //TODO This could be optimized for multicore servers with
          //a map/reduce algorithm
          if (transformerlist != null) {
            for (ContentTransformer transformer : transformerlist) {
              try {

                if (transformer.match(bean)) {
                  String msg = "TRANSFORMER: " + transformer.getTransformerKey() + "; BEAN: " + bean.get(idAttribute);
                  status.setCurrentStatusString(msg);
                  ContentTransformer.getLogger().debug(msg);
                  if (transformer instanceof AbstractLuceneMonitoringTransformer) {
                    ((AbstractLuceneMonitoringTransformer) transformer).processBeanWithMonitoring(bean, indexWriter);
                  } else {
                    transformer.processBeanWithMonitoring(bean);
                  }
                }
              } catch (Exception e) {
                //TODO Remember broken files
                log.error("Error while Transforming Contentbean" + "with id: " + bean.get(idAttribute) + " Transformer: "
                    + transformer.getTransformerKey() + " " + transformer.getClass().getName(), e);
              }
            }
          }
          Term idTerm = new Term(idAttribute, bean.getString(idAttribute));
          Document docToUpdate = getUniqueDocument(indexReader, idTerm, crid);

          // get the category paths for the facets
          CategoryDocumentBuilder categoryDocBuilder = null;
          if (useFacets && taxonomyAccessor != null && taxonomyWriter != null) {
            List<CategoryPath> categories = getCategoryAttributeMapping(bean, taxonomyAccessor.getTaxonomyMappings());
            if (categories.size() > 0) {
              categoryDocBuilder = new CategoryDocumentBuilder(taxonomyWriter).setCategoryPaths(categories);
            }
          }
          if (!create && docToUpdate != null) {
            Document doc = getDocument(docToUpdate, bean, attributes, config, reverseattributes);
            // add facets to document
            if (categoryDocBuilder != null) {
              categoryDocBuilder.build(doc);
            }
            indexWriter.updateDocument(idTerm, doc);
          } else {
            Document doc = getDocument(null, bean, attributes, config, reverseattributes);
            // add facets to document
            if (categoryDocBuilder != null) {
              categoryDocBuilder.build(doc);
            }
            indexWriter.addDocument(doc);
          }
        } finally {
          bcase.stop();
        }
        //Stop Indexing when thread has been interrupted
        if (Thread.currentThread().isInterrupted()) {
          break;
        }
View Full Code Here

  @Override
  public void deleteStaleObjects() {
    log.debug(checkedDocuments.size() + " objects checked, " + docs.size() + " objects already in the index.");
    IndexReader writeReader = null;
    boolean readerNeedsWrite = true;
    UseCase deleteStale = MonitorFactory.startUseCase("LuceneIndexUpdateChecker.deleteStaleObjects(" + indexLocation.getName() + ")");
    try {
      boolean objectsDeleted = false;
      for (String contentId : docs.keySet()) {
        if (!checkedDocuments.contains(contentId)) {
          log.debug("Object " + contentId + " wasn't checked in the last run. So i will delete it.");
          if (writeReader == null) {
            writeReader = indexAccessor.getReader(readerNeedsWrite);
          }
          writeReader.deleteDocument(docs.get(contentId));
          objectsDeleted = true;
        }
      }
      if (objectsDeleted) {
        indexLocation.createReopenFile();
      }
    } catch (IOException e) {
      log.error("Cannot delete objects from index.", e);
    } finally {
      //always release writeReader it blocks other threads if you don't
      if (writeReader != null) {
        indexAccessor.release(writeReader, readerNeedsWrite);
      }
      log.debug("Finished cleaning stale documents");
      deleteStale.stop();
    }
    checkedDocuments.clear();
  }
View Full Code Here

TOP

Related Classes of com.gentics.cr.monitoring.UseCase

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.