javax.jcr.observation.EventIterator Java Examples

The following examples show how to use javax.jcr.observation.EventIterator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConfirmedOrdersObserver.java    From sling-samples with Apache License 2.0 6 votes vote down vote up
public void onEvent(EventIterator it) {
    while (it.hasNext()) {
        // Just accumulate the changed paths - we'll do the actual work in 
        // a separate non-event method, as this should return quickly.
        try {
            final String path = it.nextEvent().getPath();
            if(path.endsWith(SlingbucksConstants.CONFIRMED_ORDER_PROPERTY_NAME)) {
                synchronized (changedPropertyPaths) {
                    log.debug("onEvent: property {} changed", path);
                    changedPropertyPaths.add(path);
                }
            }
        } catch(Exception e) {
            log.warn(e.getClass().getName() + " in onEvent", e);
        }
    }
}
 
Example #2
Source File: CatalogDataResourceProviderManagerImpl.java    From commerce-cif-connector with Apache License 2.0 5 votes vote down vote up
@Activate
protected synchronized void activate(final ComponentContext ctx) throws LoginException, RepositoryException {
    // check enabled state
    if (resolver == null) {
        bundleContext = ctx.getBundleContext();
        final Map<String, Object> map = new HashMap<>();
        map.put(ResourceResolverFactory.SUBSERVICE, VIRTUAL_PRODUCTS_SERVICE);
        resolver = resolverFactory.getServiceResourceResolver(map);

        // Watch for events on the root to register/deregister virtual catalogs data roots at runtime
        // For each observed path create an event listener object which redirects the event to the main class
        final Session session = resolver.adaptTo(Session.class);
        if (session != null) {
            this.observationEventListeners = new EventListener[this.observationPaths.length];
            for (int i = 0; i < this.observationPaths.length; i++) {
                this.observationEventListeners[i] = new EventListener() {
                    public void onEvent(EventIterator events) {
                        CatalogDataResourceProviderManagerImpl.this.onEvent(events);
                    }
                };
                session.getWorkspace()
                    .getObservationManager()
                    .addEventListener(this.observationEventListeners[i],
                        Event.NODE_ADDED | Event.NODE_REMOVED | Event.PROPERTY_ADDED | Event.PROPERTY_CHANGED | Event.PROPERTY_REMOVED,
                        this.observationPaths[i],
                        // absolute path
                        true,
                        // isDeep
                        null,
                        // uuids
                        null,
                        // node types
                        true); // noLocal
            }
        }

        // register all virtual catalog data definitions that already exist
        registerDataRoots();
    }
}
 
Example #3
Source File: ProductsSuggestionOmniSearchHandler.java    From commerce-cif-connector with Apache License 2.0 5 votes vote down vote up
@Override
public void onEvent(EventIterator eventIterator) {
    if (resolver == null) {
        try {
            resolver = getResourceResolver();
            init(resolver);
            jsonMapper = new ObjectMapper();
        } catch (LoginException e) {
            LOGGER.error("Error initializing!", e);
        }
    }
}
 
Example #4
Source File: ThumbnailGenerator.java    From sling-samples with Apache License 2.0 5 votes vote down vote up
public void onEvent(EventIterator it) {
    while (it.hasNext()) {
        Event event = it.nextEvent();
        try {
            if (event.getType() == Event.NODE_ADDED && !(event.getPath().contains("thumbnails"))) {
                log.info("new upload: {}", event.getPath());
                Node addedNode = session.getRootNode().getNode(event.getPath().substring(1));
                processNewNode(addedNode);
                log.info("finished processing of {}", event.getPath());
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
}
 
Example #5
Source File: CatalogDataResourceProviderManagerImpl.java    From commerce-cif-connector with Apache License 2.0 4 votes vote down vote up
/**
 * Handle resource events to add or remove virtual catalog data registrations.
 */
public void onEvent(EventIterator events) {
    try {
        // collect all actions to be performed for this event

        final Map<String, Boolean> actions = new HashMap<>();
        boolean nodeAdded = false;
        boolean nodeRemoved = false;
        while (events.hasNext()) {
            final Event event = events.nextEvent();
            final String path = event.getPath();
            final int eventType = event.getType();
            if (eventType == Event.NODE_ADDED) {
                nodeAdded = true;
                Session session = resolver.adaptTo(Session.class);
                final Node node = session.getNode(path);
                if (node != null && node.isNodeType(JcrResourceConstants.NT_SLING_FOLDER) && node.hasProperty(
                    CatalogDataResourceProviderFactory.PROPERTY_FACTORY_ID) || node.hasProperty(CONF_ROOT)) {
                    actions.put(path, true);
                }
            } else if (eventType == Event.NODE_REMOVED && providers.containsKey(path)) {
                nodeRemoved = true;
                actions.put(path, false);
            } else if ((eventType == Event.PROPERTY_CHANGED || eventType == Event.PROPERTY_ADDED || eventType == Event.PROPERTY_REMOVED)
                && isRelevantPath(path)) {
                // narrow down the properties to be watched.
                // force re-registering
                nodeAdded = true;
                nodeRemoved = true;
            }
        }

        for (Map.Entry<String, Boolean> action : actions.entrySet()) {
            if (action.getValue()) {
                final Resource rootResource = resolver.getResource(action.getKey());
                if (rootResource != null) {
                    registerDataRoot(rootResource);
                }
            } else {
                final ResourceProvider provider = providers.remove(action.getKey());
                if (provider != null) {
                    unregisterService(provider);
                }
            }
        }

        if (nodeAdded && nodeRemoved) {
            // maybe a virtual catalog was moved, re-register all virtual catalogs
            // (existing ones will be skipped)
            registerDataRoots();
        }
    } catch (RepositoryException e) {
        log.error("Unexpected repository exception during event processing.", e);
    }
}
 
Example #6
Source File: LongResourceResolverEvenListenerError.java    From AEM-Rules-for-SonarQube with Apache License 2.0 4 votes vote down vote up
@Override
public void onEvent(final EventIterator events) {
}
 
Example #7
Source File: LongSessionEventListenerError.java    From AEM-Rules-for-SonarQube with Apache License 2.0 4 votes vote down vote up
@Override
public void onEvent(final EventIterator events) {
}
 
Example #8
Source File: LongSessionService.java    From AEM-Rules-for-SonarQube with Apache License 2.0 4 votes vote down vote up
@Override
public void onEvent(EventIterator events) {
    throw new UnsupportedOperationException("Not supported yet.");
}
 
Example #9
Source File: LongSessionEventListener.java    From AEM-Rules-for-SonarQube with Apache License 2.0 4 votes vote down vote up
@Override
public void onEvent(final EventIterator events) {
}