Search in sources :

Example 11 with ScheduleOptions

use of org.apache.sling.commons.scheduler.ScheduleOptions in project sling by apache.

the class JcrResourceBundleProvider method scheduleReloadBundles.

private void scheduleReloadBundles(boolean withDelay) {
    // cancel all reload individual bundle jobs!
    synchronized (scheduledJobNames) {
        for (String scheduledJobName : scheduledJobNames) {
            scheduler.unschedule(scheduledJobName);
        }
    }
    scheduledJobNames.clear();
    // defer this job
    final ScheduleOptions options;
    if (withDelay) {
        options = scheduler.AT(new Date(System.currentTimeMillis() + invalidationDelay));
    } else {
        options = scheduler.NOW();
    }
    options.name("JcrResourceBundleProvider: reload all resource bundles");
    scheduler.schedule(new Runnable() {

        @Override
        public void run() {
            log.info("Reloading all resource bundles");
            clearCache();
            preloadBundles();
        }
    }, options);
}
Also used : ScheduleOptions(org.apache.sling.commons.scheduler.ScheduleOptions) Date(java.util.Date)

Example 12 with ScheduleOptions

use of org.apache.sling.commons.scheduler.ScheduleOptions in project sling by apache.

the class JcrResourceBundleProvider method scheduleReloadBundle.

private void scheduleReloadBundle(JcrResourceBundle bundle) {
    String baseName = bundle.getBaseName();
    Locale locale = bundle.getLocale();
    final Key key = new Key(baseName, locale);
    // defer this job
    ScheduleOptions options = scheduler.AT(new Date(System.currentTimeMillis() + invalidationDelay));
    final String jobName = "JcrResourceBundleProvider: reload bundle with key " + key.toString();
    scheduledJobNames.add(jobName);
    options.name(jobName);
    scheduler.schedule(new Runnable() {

        @Override
        public void run() {
            reloadBundle(key);
            scheduledJobNames.remove(jobName);
        }
    }, options);
}
Also used : Locale(java.util.Locale) ScheduleOptions(org.apache.sling.commons.scheduler.ScheduleOptions) Date(java.util.Date)

Example 13 with ScheduleOptions

use of org.apache.sling.commons.scheduler.ScheduleOptions in project sling by apache.

the class SimpleDistributionQueueProviderTest method testEnableQueueProcessingWithCheckpointRecovery.

@Test
public void testEnableQueueProcessingWithCheckpointRecovery() throws Exception {
    File checkpointDirectory = new File("dummy-agent-simple-queues-checkpoints");
    File file = new File(getClass().getResource("/dummy-agent-checkpoint").getFile());
    FileUtils.copyFileToDirectory(file, checkpointDirectory);
    Scheduler scheduler = mock(Scheduler.class);
    ScheduleOptions options = mock(ScheduleOptions.class);
    when(scheduler.NOW(-1, 1)).thenReturn(options);
    when(scheduler.NOW(-1, 15)).thenReturn(options);
    when(options.canRunConcurrently(false)).thenReturn(options);
    when(options.name(any(String.class))).thenReturn(options);
    String name = "dummy-agent";
    try {
        SimpleDistributionQueueProvider simpledistributionQueueProvider = new SimpleDistributionQueueProvider(scheduler, name, true);
        DistributionQueueProcessor processor = mock(DistributionQueueProcessor.class);
        simpledistributionQueueProvider.enableQueueProcessing(processor, name);
        DistributionQueue queue = simpledistributionQueueProvider.getQueue(name);
        assertNotNull(queue);
        assertEquals(1, queue.getStatus().getItemsCount());
        DistributionQueueEntry head = queue.getHead();
        assertNotNull(head);
        DistributionQueueItem item = head.getItem();
        assertNotNull(item);
        String packageId = item.getPackageId();
        assertNotNull(packageId);
        assertEquals("DSTRQ1", item.get("internal.request.id"));
        assertArrayEquals(new String[] { "/foo", "bar" }, (String[]) item.get("request.paths"));
        assertArrayEquals(new String[] { "/foo" }, (String[]) item.get("request.deepPaths"));
        assertEquals("admin", item.get("internal.request.user"));
        assertEquals("ADD", item.get("request.type"));
        assertEquals("default", item.get("package.type"));
        assertEquals("1464090250095", item.get("internal.request.startTime"));
    } finally {
        FileUtils.deleteDirectory(new File(name + "-simple-queues-checkpoints"));
    }
}
Also used : DistributionQueueProcessor(org.apache.sling.distribution.queue.DistributionQueueProcessor) ScheduleOptions(org.apache.sling.commons.scheduler.ScheduleOptions) DistributionQueue(org.apache.sling.distribution.queue.DistributionQueue) DistributionQueueEntry(org.apache.sling.distribution.queue.DistributionQueueEntry) Scheduler(org.apache.sling.commons.scheduler.Scheduler) File(java.io.File) DistributionQueueItem(org.apache.sling.distribution.queue.DistributionQueueItem) Test(org.junit.Test)

Example 14 with ScheduleOptions

use of org.apache.sling.commons.scheduler.ScheduleOptions in project sling by apache.

the class RemoteEventDistributionTrigger method register.

public void register(@Nonnull DistributionRequestHandler requestHandler) throws DistributionException {
    try {
        log.info("applying remote event distribution trigger");
        ScheduleOptions options = scheduler.NOW();
        options.name(getJobName(requestHandler));
        options.canRunConcurrently(false);
        options.onLeaderOnly(true);
        scheduler.schedule(new EventBasedDistribution(requestHandler), options);
    } catch (Exception e) {
        throw new DistributionException("unable to register handler " + requestHandler, e);
    }
}
Also used : ScheduleOptions(org.apache.sling.commons.scheduler.ScheduleOptions) DistributionException(org.apache.sling.distribution.common.DistributionException) DistributionException(org.apache.sling.distribution.common.DistributionException) IOException(java.io.IOException)

Example 15 with ScheduleOptions

use of org.apache.sling.commons.scheduler.ScheduleOptions in project sling by apache.

the class SimpleDistributionQueueProviderTest method testDisableQueueProcessing.

@Test
public void testDisableQueueProcessing() throws Exception {
    Scheduler scheduler = mock(Scheduler.class);
    ScheduleOptions options = mock(ScheduleOptions.class);
    when(scheduler.NOW(-1, 10)).thenReturn(options);
    when(options.canRunConcurrently(false)).thenReturn(options);
    when(options.name(any(String.class))).thenReturn(options);
    SimpleDistributionQueueProvider simpledistributionQueueProvider = new SimpleDistributionQueueProvider(scheduler, "dummy-agent", false);
    simpledistributionQueueProvider.disableQueueProcessing();
}
Also used : ScheduleOptions(org.apache.sling.commons.scheduler.ScheduleOptions) Scheduler(org.apache.sling.commons.scheduler.Scheduler) Test(org.junit.Test)

Aggregations

ScheduleOptions (org.apache.sling.commons.scheduler.ScheduleOptions)21 Scheduler (org.apache.sling.commons.scheduler.Scheduler)8 Test (org.junit.Test)7 File (java.io.File)4 Date (java.util.Date)3 DistributionQueueProcessor (org.apache.sling.distribution.queue.DistributionQueueProcessor)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 LoginException (org.apache.sling.api.resource.LoginException)2 DistributionException (org.apache.sling.distribution.common.DistributionException)2 DistributionQueue (org.apache.sling.distribution.queue.DistributionQueue)2 DistributionQueueItem (org.apache.sling.distribution.queue.DistributionQueueItem)2 DistributionRequestHandler (org.apache.sling.distribution.trigger.DistributionRequestHandler)2 Workspace (com.adobe.acs.commons.workflow.bulk.execution.model.Workspace)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 FilenameFilter (java.io.FilenameFilter)1 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 StringReader (java.io.StringReader)1