Пример #1
0
 protected void addSequencingListeners(JcrSession session) throws RepositoryException {
   observationManager = ((Workspace) session.getWorkspace()).getObservationManager();
   observationManager.addEventListener(
       new SequencingListener(), NODE_SEQUENCED, null, true, null, null, false);
   observationManager.addEventListener(
       new SequencingFailureListener(), NODE_SEQUENCING_FAILURE, null, true, null, null, false);
 }
Пример #2
0
  @Override
  public void doStart() throws JBIException {
    if (repository == null) {
      throw new JBIException("No repository configured, unable to start JCR auditor");
    }
    if (strategy == null) {
      throw new JBIException("No JcrAuditorStrategy configure, unable to start JCR auditor");
    }

    try {
      marshaler = getMarshaler();
    } catch (LoginException e) {
      throw new JBIException("Login exception, unable to get Auditor Marshaler", e);
    } catch (RepositoryException e1) {
      throw new JBIException("Repository exception, unable to get Auditor Marshaler", e1);
    }

    try {
      ObservationManager observationManager = getSession().getWorkspace().getObservationManager();

      observationManager.addEventListener(
          eventListener, Event.PROPERTY_CHANGED, CONFIG_TYPE, false, null, null, false);

    } catch (UnsupportedRepositoryOperationException e) {
      throw new JBIException(
          "Unsupported repository operation exception, unable to add Event Listener", e);
    } catch (RepositoryException e1) {
      throw new JBIException("Repository exception, unable to add Event Listener", e1);
    }

    super.doStart();
  }
Пример #3
0
  /** Register an event listener: reload cache configuration when something changes. */
  private static void registerEventListener() {

    log.info("Registering event listener for Listeners"); // $NON-NLS-1$

    try {
      ObservationManager observationManager =
          ContentRepository.getHierarchyManager(ContentRepository.CONFIG)
              .getWorkspace()
              .getObservationManager();

      observationManager.addEventListener(
          new EventListener() {

            public void onEvent(EventIterator iterator) {
              // reload everything
              reload();
            }
          },
          Event.NODE_ADDED
              | Event.NODE_REMOVED
              | Event.PROPERTY_ADDED
              | Event.PROPERTY_CHANGED
              | Event.PROPERTY_REMOVED,
          "/" + CONFIG_PAGE + "/" + "IPConfig",
          true,
          null,
          null,
          false); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    } catch (RepositoryException e) {
      log.error("Unable to add event listeners for Listeners", e); // $NON-NLS-1$
    }
  }
Пример #4
0
 @Override
 public void afterEach() throws Exception {
   for (EventListenerIterator it = observationManager.getRegisteredEventListeners();
       it.hasNext(); ) {
     observationManager.removeEventListener(it.nextEventListener());
   }
   super.afterEach();
   cleanupData();
 }
  /**
   * This method registers the listener <code> org.apache.jackrabbit.demo.blog.model.AlertManager
   * </code> with the default workspace. This listener listens to events of adding new comments to
   * blog entries.
   *
   * @throws RepositoryException if an error occur in the repository
   */
  private void registerListeners() throws RepositoryException {

    Workspace ws = session.getWorkspace();
    ObservationManager observationMgr = ws.getObservationManager();
    AlertManager alertMgr = new AlertManager(repository);
    observationMgr.addEventListener(
        alertMgr, Event.NODE_ADDED, "/blogRoot", true, null, null, false);

    log("JACKRABBIT-JCR-DEMO: Listeners registered ...");
  }
Пример #6
0
 /**
  * This method will observes the specification node by giving the following param : listener, node
  * Its add an event listener to this node to observes anything that changes to this
  *
  * @param node Specify the node to observe
  * @param listener The object of EventListener
  * @see EventListener
  * @see Node
  * @throws Exception
  */
 private void observeNode(Node node, EventListener listener) throws Exception {
   String workspace = node.getSession().getWorkspace().getName();
   Session systemSession = repoService_.getCurrentRepository().getSystemSession(workspace);
   List<String> list = getDocumentNodeTypes(node);
   String[] observedNodeTypeNames = list.toArray(new String[list.size()]);
   ObservationManager observationManager = systemSession.getWorkspace().getObservationManager();
   observationManager.addEventListener(
       listener, Event.PROPERTY_CHANGED, node.getPath(), true, null, observedNodeTypeNames, false);
   systemSession.logout();
 }
Пример #7
0
 /**
  * This method will re-observer all nodes that have been ever observed with all repositories.
  *
  * @throws Exception
  */
 private void reInitObserver() throws Exception {
   RepositoryEntry repo = repoService_.getCurrentRepository().getConfiguration();
   ManageableRepository repository = repoService_.getCurrentRepository();
   String[] workspaceNames = repository.getWorkspaceNames();
   for (String workspace : workspaceNames) {
     Session session = repository.getSystemSession(workspace);
     QueryManager queryManager = null;
     try {
       queryManager = session.getWorkspace().getQueryManager();
     } catch (Exception e) {
       if (LOG.isErrorEnabled()) {
         LOG.error("Unexpected error", e);
       }
     }
     if (queryManager == null) {
       session.logout();
       continue;
     }
     try {
       Query query = queryManager.createQuery(WATCHABLE_MIXIN_QUERY, Query.XPATH);
       QueryResult queryResult = query.execute();
       for (NodeIterator iter = queryResult.getNodes(); iter.hasNext(); ) {
         Node observedNode = iter.nextNode();
         EmailNotifyListener emailNotifyListener = new EmailNotifyListener(observedNode);
         ObservationManager manager = session.getWorkspace().getObservationManager();
         List<String> list = getDocumentNodeTypes(observedNode);
         String[] observedNodeTypeNames = list.toArray(new String[list.size()]);
         manager.addEventListener(
             emailNotifyListener,
             Event.PROPERTY_CHANGED,
             observedNode.getPath(),
             true,
             null,
             observedNodeTypeNames,
             false);
       }
       session.logout();
     } catch (Exception e) {
       if (LOG.isWarnEnabled()) {
         LOG.warn(
             "==>>> Cannot init observer for node: "
                 + e.getLocalizedMessage()
                 + " in '"
                 + repo.getName()
                 + "' repository");
       }
       if (LOG.isErrorEnabled()) {
         LOG.error("Unexpected error", e);
       }
     }
   }
 }