public void run()

in slingbucks/src/main/java/org/apache/sling/slingbucks/server/ConfirmedOrdersObserver.java [119:164]


    public void run() {
        if(changedPropertyPaths.isEmpty()) {
            return;
        }
        
        final List<String> paths = new ArrayList<String>();
        final List<String> toRetry = new ArrayList<String>();
        synchronized (changedPropertyPaths) {
            paths.addAll(changedPropertyPaths);
            changedPropertyPaths.clear();
        }
        
        try {
            while(!paths.isEmpty()) {
                final String path = paths.remove(0);
                if(session.itemExists(path)) {
                    final Item it = session.getItem(path);
                    if(!it.isNode()) {
                        final Property p = (Property)it;
                        final Node n = p.getParent();
                        if(!n.hasProperty(SlingbucksConstants.LAST_MODIFIED_PROPERTY_NAME)) {
                            log.debug("Node {} doesn't have property {}, ignored", n.getPath(), SlingbucksConstants.LAST_MODIFIED_PROPERTY_NAME);
                        } else {
                            Calendar lastMod = n.getProperty(SlingbucksConstants.LAST_MODIFIED_PROPERTY_NAME).getDate();
                            if(System.currentTimeMillis() - lastMod.getTime().getTime() < WAIT_AFTER_LAST_CHANGE_MSEC) {
                                log.debug("Node {} modified more recently than {} msec, ignored", n.getPath(), WAIT_AFTER_LAST_CHANGE_MSEC);
                                toRetry.add(path);
                            } else {
                                final String targetPath = SlingbucksConstants.CONFIRMED_ORDERS_PATH + "/" + n.getName();
                                session.getWorkspace().move(n.getPath(), targetPath);
                                log.info("Confirmed order node {} moved to {}", n.getPath(), targetPath);
                            }
                        }
                    }
                }
            }
        } catch(Exception e){
            log.error("Exception in run()", e);
        } finally {
            // Re-add any paths that we didn't process
            synchronized (changedPropertyPaths) {
                changedPropertyPaths.addAll(paths);
                changedPropertyPaths.addAll(toRetry);
            }
        }
    }