// Executed after the complete execution of doInBackground() method
    @Override
    protected void onPostExecute(String result) {
      ParserTask parserTask = new ParserTask();

      // Start parsing the Google places in JSON format
      // Invokes the "doInBackground()" method of the class ParseTask
      parserTask.execute(result);
    }
    // executes in UI thread after doInBackground
    @Override
    protected void onPostExecute(String result) {
      super.onPostExecute(result);

      // invokes thread for parsing json data
      ParserTask parserTask = new ParserTask();
      parserTask.execute(result);
    }
Пример #3
0
    // Executes in UI thread, after the execution of
    // doInBackground()
    @Override
    protected void onPostExecute(String result) {
      super.onPostExecute(result);

      ParserTask parserTask = new ParserTask();

      // Invokes the thread for parsing the JSON data
      parserTask.execute(result);
    }
  /**
   * Scan jars in WEB-INF/lib
   *
   * @param context
   * @param parser
   * @throws Exception
   */
  public void parseWebInfLib(final WebAppContext context, final AnnotationParser parser)
      throws Exception {
    List<FragmentDescriptor> frags = context.getMetaData().getFragments();

    // email from Rajiv Mordani jsrs 315 7 April 2010
    // jars that do not have a web-fragment.xml are still considered fragments
    // they have to participate in the ordering
    ArrayList<URI> webInfUris = new ArrayList<URI>();

    List<Resource> jars = context.getMetaData().getOrderedWebInfJars();

    // No ordering just use the jars in any order
    if (jars == null || jars.isEmpty()) jars = context.getMetaData().getWebInfJars();

    _webInfLibStats = new CounterStatistic();

    for (Resource r : jars) {
      // for each jar, we decide which set of annotations we need to parse for
      final Set<Handler> handlers = new HashSet<Handler>();

      FragmentDescriptor f = getFragmentFromJar(r, frags);

      // if its from a fragment jar that is metadata complete, we should skip scanning for
      // @webservlet etc
      // but yet we still need to do the scanning for the classes on behalf of  the
      // servletcontainerinitializers
      // if a jar has no web-fragment.xml we scan it (because it is not excluded by the ordering)
      // or if it has a fragment we scan it if it is not metadata complete
      if (f == null
          || !isMetaDataComplete(f)
          || _classInheritanceHandler != null
          || !_containerInitializerAnnotationHandlers.isEmpty()) {
        // register the classinheritance handler if there is one
        if (_classInheritanceHandler != null) handlers.add(_classInheritanceHandler);

        // register the handlers for the @HandlesTypes values that are themselves annotations if
        // there are any
        handlers.addAll(_containerInitializerAnnotationHandlers);

        // only register the discoverable annotation handlers if this fragment is not metadata
        // complete, or has no fragment descriptor
        if (f == null || !isMetaDataComplete(f)) handlers.addAll(_discoverableAnnotationHandlers);

        if (_parserTasks != null) {
          ParserTask task = new ParserTask(parser, handlers, r, _webAppClassNameResolver);
          _parserTasks.add(task);
          _webInfLibStats.increment();
          if (LOG.isDebugEnabled()) task.setStatistic(new TimeStatistic());
        }
      }
    }
  }
 @Override
 public void onDestroy() {
   super.onDestroy();
   if (task != null) {
     task.cancel(true);
   }
 }
 public void init() {
   XmlResourceParser xrp = getActivity().getResources().getXml(R.xml.search_widget_config);
   if (task == null) {
     task = new ParserTask();
   }
   task.execute(xrp);
 }
  /**
   * Scan classes in WEB-INF/classes
   *
   * @param context
   * @param parser
   * @throws Exception
   */
  public void parseWebInfClasses(final WebAppContext context, final AnnotationParser parser)
      throws Exception {
    Set<Handler> handlers = new HashSet<Handler>();
    handlers.addAll(_discoverableAnnotationHandlers);
    if (_classInheritanceHandler != null) handlers.add(_classInheritanceHandler);
    handlers.addAll(_containerInitializerAnnotationHandlers);

    _webInfClassesStats = new CounterStatistic();

    for (Resource dir : context.getMetaData().getWebInfClassesDirs()) {
      if (_parserTasks != null) {
        ParserTask task = new ParserTask(parser, handlers, dir, _webAppClassNameResolver);
        _parserTasks.add(task);
        _webInfClassesStats.increment();
        if (LOG.isDebugEnabled()) task.setStatistic(new TimeStatistic());
      }
    }
  }
  // ----------------------------------------------------------------------------------------------------
  public synchronized void parseHtmlText(final String baseURL, final String htmlText) {

    // Si es la primera tarea del trabajo, actualiza el contador
    if (m_numTasksForJob == 0) {
      m_numTasksForJob++;
    }

    ParserTask task = new ParserTask();
    task.jobID = getCurrentJobID();
    task.htmlText = htmlText;
    task.baseURL = baseURL;
    try {
      m_tasksQueue.add(task);
      this.notifyAll();
    } catch (Exception ex) {
      Tracer._error("Error putting a new ParserTask in the queue", ex);
    }
  }
 public void parseContainerPath(final WebAppContext context, final AnnotationParser parser)
     throws Exception {
   final Set<Handler> handlers = new HashSet<Handler>();
   handlers.addAll(_discoverableAnnotationHandlers);
   handlers.addAll(_containerInitializerAnnotationHandlers);
   if (_classInheritanceHandler != null) {
     handlers.add(_classInheritanceHandler);
   }
   _containerPathStats = new CounterStatistic();
   List<Resource> _resources = getResources(getClass().getClassLoader());
   for (Resource r : _resources) {
     if (_parserTasks != null) {
       ParserTask task = new ParserTask(parser, handlers, r, _containerClassNameResolver);
       _parserTasks.add(task);
       _containerPathStats.increment();
       if (LOG.isDebugEnabled()) {
         task.setStatistic(new TimeStatistic());
       }
     }
   }
 }
  /**
   * Scan jars on container path.
   *
   * @param context
   * @param parser
   * @throws Exception
   */
  public void parseContainerPath(final WebAppContext context, final AnnotationParser parser)
      throws Exception {
    // always parse for discoverable annotations as well as class hierarchy and
    // servletcontainerinitializer related annotations
    final Set<Handler> handlers = new HashSet<Handler>();
    handlers.addAll(_discoverableAnnotationHandlers);
    handlers.addAll(_containerInitializerAnnotationHandlers);
    if (_classInheritanceHandler != null) handlers.add(_classInheritanceHandler);

    _containerPathStats = new CounterStatistic();

    for (Resource r : context.getMetaData().getContainerResources()) {
      // queue it up for scanning if using multithreaded mode
      if (_parserTasks != null) {
        ParserTask task = new ParserTask(parser, handlers, r, _containerClassNameResolver);
        _parserTasks.add(task);
        _containerPathStats.increment();
        if (LOG.isDebugEnabled()) task.setStatistic(new TimeStatistic());
      }
    }
  }
  /**
   * Perform scanning of classes for annotations
   *
   * @param context
   * @throws Exception
   */
  protected void scanForAnnotations(WebAppContext context) throws Exception {
    AnnotationParser parser = createAnnotationParser();
    _parserTasks = new ArrayList<ParserTask>();

    long start = 0;

    if (LOG.isDebugEnabled())
      LOG.debug(
          "Annotation scanning commencing: webxml={}, metadatacomplete={}, configurationDiscovered={}, multiThreaded={}, maxScanWait={}",
          context.getServletContext().getEffectiveMajorVersion(),
          context.getMetaData().isMetaDataComplete(),
          context.isConfigurationDiscovered(),
          isUseMultiThreading(context),
          getMaxScanWait(context));

    parseContainerPath(context, parser);
    // email from Rajiv Mordani jsrs 315 7 April 2010
    //    If there is a <others/> then the ordering should be
    //          WEB-INF/classes the order of the declared elements + others.
    //    In case there is no others then it is
    //          WEB-INF/classes + order of the elements.
    parseWebInfClasses(context, parser);
    parseWebInfLib(context, parser);

    start = System.nanoTime();

    // execute scan, either effectively synchronously (1 thread only), or asynchronously (limited by
    // number of processors available)
    final Semaphore task_limit =
        (isUseMultiThreading(context)
            ? new Semaphore(Runtime.getRuntime().availableProcessors())
            : new Semaphore(1));
    final CountDownLatch latch = new CountDownLatch(_parserTasks.size());
    final MultiException me = new MultiException();

    for (final ParserTask p : _parserTasks) {
      task_limit.acquire();
      context
          .getServer()
          .getThreadPool()
          .execute(
              new Runnable() {
                @Override
                public void run() {
                  try {
                    p.call();
                  } catch (Exception e) {
                    me.add(e);
                  } finally {
                    task_limit.release();
                    latch.countDown();
                  }
                }
              });
    }

    boolean timeout = !latch.await(getMaxScanWait(context), TimeUnit.SECONDS);

    if (LOG.isDebugEnabled()) {
      for (ParserTask p : _parserTasks)
        LOG.debug(
            "Scanned {} in {}ms",
            p.getResource(),
            TimeUnit.MILLISECONDS.convert(p.getStatistic().getElapsed(), TimeUnit.NANOSECONDS));

      LOG.debug(
          "Scanned {} container path jars, {} WEB-INF/lib jars, {} WEB-INF/classes dirs in {}ms for context {}",
          _containerPathStats.getTotal(),
          _webInfLibStats.getTotal(),
          _webInfClassesStats.getTotal(),
          (TimeUnit.MILLISECONDS.convert(System.nanoTime() - start, TimeUnit.NANOSECONDS)),
          context);
    }

    if (timeout) me.add(new Exception("Timeout scanning annotations"));
    me.ifExceptionThrow();
  }
Пример #12
0
 @Override
 public void onSuccess(int statusCode, Header[] headers, byte[] responseBytes) {
   BaseApplication.putToLastRefreshTime(getCacheKey(), StringUtils.getCurTimeStr());
   mParserTask = new ParserTask(responseBytes);
   mParserTask.execute();
 }
 private void cacelParserTask() {
   if (mParserTask != null) {
     mParserTask.cancel(true);
     mParserTask = null;
   }
 }
 private void executeParseTask(byte[] data, boolean fromCache) {
   cacelParserTask();
   mParserTask = new ParserTask(this, data, fromCache);
   mParserTask.execute();
 }