/** {@inheritDoc} */
  public void onEvent(EventIterator eventIterator) {
    // waiting for Event.PROPERTY_ADDED, Event.PROPERTY_REMOVED,
    // Event.PROPERTY_CHANGED
    Session session = null;
    try {
      while (eventIterator.hasNext()) {
        Event event = eventIterator.nextEvent();
        String path = event.getPath();

        if (path.endsWith("/jcr:data")) {
          // jcr:data removed 'exo:groovyResourceContainer' then unbind resource
          if (event.getType() == Event.PROPERTY_REMOVED) {
            unloadScript(path.substring(0, path.lastIndexOf('/')));
          } else if (event.getType() == Event.PROPERTY_ADDED
              || event.getType() == Event.PROPERTY_CHANGED) {
            if (session == null) {
              session = repository.getSystemSession(workspaceName);
            }

            Node node = session.getItem(path).getParent();
            if (node.getProperty("exo:autoload").getBoolean()) loadScript(node);
          }
        }
      }
    } catch (Exception e) {
      LOG.error("Process event failed. ", e);
    } finally {
      if (session != null) {
        session.logout();
      }
    }
  }
예제 #2
0
    @SuppressWarnings("synthetic-access")
    @Override
    public void onEvent(EventIterator events) {
      while (events.hasNext()) {
        try {
          Event event = (Event) events.nextEvent();
          smokeCheckSequencingEvent(
              event,
              NODE_SEQUENCING_FAILURE,
              SEQUENCED_NODE_ID,
              SEQUENCED_NODE_PATH,
              Event.Sequencing.SEQUENCING_FAILURE_CAUSE,
              OUTPUT_PATH,
              SELECTED_PATH,
              SEQUENCER_NAME,
              USER_ID);
          String nodePath = event.getPath();

          sequencingEvents.putIfAbsent(nodePath, event);
          createWaitingLatchIfNecessary(nodePath, sequencingFailureLatches);
          sequencingFailureLatches.get(nodePath).countDown();
        } catch (Exception e) {
          throw new RuntimeException(e);
        }
      }
    }
예제 #3
0
    @SuppressWarnings("synthetic-access")
    @Override
    public void onEvent(EventIterator events) {
      while (events.hasNext()) {
        try {
          Event event = (Event) events.nextEvent();
          smokeCheckSequencingEvent(
              event,
              NODE_SEQUENCED,
              SEQUENCED_NODE_ID,
              SEQUENCED_NODE_PATH,
              OUTPUT_PATH,
              SELECTED_PATH,
              SEQUENCER_NAME,
              USER_ID);
          sequencingEvents.putIfAbsent((String) event.getInfo().get(SEQUENCED_NODE_PATH), event);

          String nodePath = event.getPath();
          logger.debug("New sequenced node at: " + nodePath);
          sequencedNodes.put(nodePath, session.getNode(nodePath));

          // signal the node is available
          createWaitingLatchIfNecessary(nodePath, nodeSequencedLatches);
          nodeSequencedLatches.get(nodePath).countDown();
        } catch (Exception e) {
          throw new RuntimeException(e);
        }
      }
    }
  @Override
  public void onEvent(EventIterator eventIterator) {
    while (eventIterator.hasNext()) {
      try {
        Event currentEvent = eventIterator.nextEvent();

        if (currentEvent.getType() == Event.PROPERTY_ADDED
            || currentEvent.getType() == Event.PROPERTY_CHANGED
            || currentEvent.getType() == Event.PROPERTY_REMOVED) {
          clientLibraryCacheManager.invalidateCache(
              currentEvent.getPath().substring(0, currentEvent.getPath().lastIndexOf("/")));
        } else if (currentEvent.getType() == Event.NODE_REMOVED) {
          clientLibraryCacheManager.invalidateCache(currentEvent.getPath());
        } else if (currentEvent.getType() == Event.NODE_MOVED) {
          if (currentEvent.getInfo().containsKey("srcAbsPath")) {
            clientLibraryCacheManager.invalidateCache(
                (String) currentEvent.getInfo().get("srcAbsPath"));
          }
          clientLibraryCacheManager.invalidateCache(currentEvent.getPath());
        }
      } catch (RepositoryException e) {
        LOG.error("Repository Exception", e);
      } catch (ClientLibraryCachingException e) {
        LOG.error(
            "Client Library Caching Exception encountered while processing page content events", e);
      }
    }
  }
 /** @see javax.jcr.observation.EventListener#onEvent(javax.jcr.observation.EventIterator) */
 public void onEvent(EventIterator iterator) {
   System.out.println("received events: ");
   for (; iterator.hasNext(); ) {
     try {
       System.out.println(toStringEvent(iterator.nextEvent()));
     } catch (RepositoryException e) {
       System.err.println(
           "exception while listnening " + SessionFactoryUtils.translateException(e));
     }
   }
 }
  /**
   * This method is called when a bundle of events is dispatched.
   *
   * @param events The event set received.
   */
  public void onEvent(EventIterator events) {
    final Cache depCache = cacheProvider.getDependenciesCache();
    final Cache regexpDepCache = cacheProvider.getRegexpDependenciesCache();
    final Set<String> flushed = new HashSet<String>();
    while (events.hasNext()) {
      Event event = (Event) events.next();
      boolean propageToOtherClusterNodes = !isExternal(event);
      try {
        String path = event.getPath();
        if (!path.startsWith("/jcr:system")) {
          boolean flushParent = false;
          boolean flushRoles = false;
          if (path.contains("j:view")) {
            flushParent = true;
          }
          final int type = event.getType();
          if (type == Event.PROPERTY_ADDED
              || type == Event.PROPERTY_CHANGED
              || type == Event.PROPERTY_REMOVED) {
            if (path.endsWith("/j:published")) {
              flushParent = true;
            }
            if (path.endsWith("j:roles")) {
              flushRoles = true;
            }
            path = path.substring(0, path.lastIndexOf("/"));
          } else if (type == Event.NODE_ADDED
              || type == Event.NODE_MOVED
              || type == Event.NODE_REMOVED) {
            flushParent = true;
          }
          if (path.contains("vanityUrlMapping")) {
            flushParent = true;
          }
          if (path.contains("j:acl")
              || path.contains("jnt:group")
              || flushRoles
              || type == Event.NODE_MOVED) {
            // Flushing cache of acl key for users as a group or an acl has been updated
            CacheKeyGenerator cacheKeyGenerator = cacheProvider.getKeyGenerator();
            if (cacheKeyGenerator instanceof DefaultCacheKeyGenerator) {
              DefaultCacheKeyGenerator generator = (DefaultCacheKeyGenerator) cacheKeyGenerator;
              generator.flushUsersGroupsKey(propageToOtherClusterNodes);
            }
            flushParent = true;
          }
          path =
              StringUtils.substringBeforeLast(
                  StringUtils.substringBeforeLast(path, "/j:translation"), "/j:acl");
          flushDependenciesOfPath(depCache, flushed, path, propageToOtherClusterNodes);
          try {
            flushDependenciesOfPath(
                depCache,
                flushed,
                ((JCREventIterator) events).getSession().getNode(path).getIdentifier(),
                propageToOtherClusterNodes);
          } catch (PathNotFoundException e) {
            if (event instanceof EventImpl && (((EventImpl) event).getChildId() != null)) {
              flushDependenciesOfPath(
                  depCache,
                  flushed,
                  ((EventImpl) event).getChildId().toString(),
                  propageToOtherClusterNodes);
            }
          }
          flushRegexpDependenciesOfPath(regexpDepCache, path, propageToOtherClusterNodes);
          if (flushParent) {
            path = StringUtils.substringBeforeLast(path, "/");
            flushDependenciesOfPath(depCache, flushed, path, propageToOtherClusterNodes);
            try {
              flushDependenciesOfPath(
                  depCache,
                  flushed,
                  ((JCREventIterator) events).getSession().getNode(path).getIdentifier(),
                  propageToOtherClusterNodes);
            } catch (PathNotFoundException e) {
              if (event instanceof EventImpl && (((EventImpl) event).getParentId() != null)) {
                flushDependenciesOfPath(
                    depCache,
                    flushed,
                    ((EventImpl) event).getParentId().toString(),
                    propageToOtherClusterNodes);
              }
            }
            flushRegexpDependenciesOfPath(regexpDepCache, path, propageToOtherClusterNodes);
          }
        }

      } catch (RepositoryException e) {
        logger.error(e.getMessage(), e);
      }
    }
  }