@Override public void run() { // create service registration properties final Dictionary<String, Object> props = new Hashtable<String, Object>(); props.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation"); // listen for all resource added OSGi events in the DEA area props.put(ResourceChangeListener.CHANGES, ResourceChange.ChangeType.ADDED.name()); props.put(ResourceChangeListener.PATHS, rootPath); final ServiceRegistration<ResourceChangeListener> reg = bundleContext.registerService(ResourceChangeListener.class, DistributedEventSender.this, props); DistributedEventSender.this.serviceRegistration = reg; try { runInBackground(); } catch (Throwable t) { //NOSONAR logger.error("Background thread stopped with exception: " + t.getMessage(), t); running = false; } } });
@Override public void onChange(@NotNull List<ResourceChange> changes) { for (ResourceChange change : changes) { String path = change.getPath(); ResourceChange.ChangeType changeType = change.getType(); switch (changeType) { case CHANGED: if (slyJavaUseMap.containsKey(path)) { slyJavaUseMap.put(path, System.currentTimeMillis()); } break; case REMOVED: if (slyJavaUseMap.containsKey(path)) { slyJavaUseMap.remove(path); } break; default: break; } LOG.debug("Java Use Object {} was {}.", path, changeType.toString()); } } }
private int compareChangeTypes(final Set<ChangeType> t, final Set<ChangeType> o) { int result = t.size() - o.size(); if ( result == 0 ) { final Iterator<ChangeType> tIter = t.iterator(); final Iterator<ChangeType> oIter = o.iterator(); while ( result == 0 && tIter.hasNext() ) { result = tIter.next().compareTo(oIter.next()); } } return result; }
/** * Activate this component. * @param props Configuration properties */ @Activate protected void activate(final BundleContext ctx, final Map<String, Object> props) throws LoginException { this.jobScheduler = new org.apache.sling.event.impl.jobs.scheduling.JobSchedulerImpl(this.configuration, this.scheduler, this); this.maintenanceTask = new CleanUpTask(this.configuration, this.jobScheduler); final Dictionary<String, Object> regProps = new Hashtable<>(); regProps.put(ResourceChangeListener.PATHS, this.configuration.getScheduledJobsPath(false)); regProps.put(ResourceChangeListener.CHANGES, new String[] { ResourceChange.ChangeType.ADDED.name(), ResourceChange.ChangeType.CHANGED.name(), ResourceChange.ChangeType.REMOVED.name() }); regProps.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation"); regProps.put(Constants.SERVICE_DESCRIPTION, "Resource change listener for scheduled jobs"); this.changeListenerReg = ctx.registerService(ResourceChangeListener.class, this.jobScheduler, regProps); logger.info("Apache Sling Job Manager started on instance {}", Environment.APPLICATION_ID); }
private boolean scriptAdded(ResourceChange change) { return ResourceChange.ChangeType.ADDED.equals(change.getType()) && scriptVerified(change); }
private boolean scriptAdded(ResourceChange change) { return ResourceChange.ChangeType.ADDED.equals(change.getType()) && scriptVerified(change); }
private boolean scriptChanged(ResourceChange change) { return ResourceChange.ChangeType.CHANGED.equals(change.getType()) && (fileReplaced(change)); }
private boolean scriptChanged(ResourceChange change) { return ResourceChange.ChangeType.CHANGED.equals(change.getType()) && (fileReplaced(change)); }
/** * Activate this component. * Register an event handler. */ @Activate protected void activate(final BundleContext bundleContext) { final Dictionary<String, Object> properties = new Hashtable<>(); properties.put(Constants.SERVICE_DESCRIPTION, "Apache Sling Job Topic Manager Event Handler"); properties.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation"); properties.put(ResourceChangeListener.CHANGES, ChangeType.ADDED.toString()); properties.put(ResourceChangeListener.PATHS, this.configuration.getLocalJobsPath()); this.listenerRegistration = bundleContext.registerService(ResourceChangeListener.class, this, properties); }