Package org.apache.sling.commons.scheduler

Examples of org.apache.sling.commons.scheduler.ScheduleOptions


    protected void deleteQueue(ReplicationQueue queue) {
        // do nothing as queues just exist in the cache
    }

    public void enableQueueProcessing(@Nonnull String agentName, @Nonnull ReplicationQueueProcessor queueProcessor) {
        ScheduleOptions options = scheduler.NOW(-1, 10)
                .canRunConcurrently(false)
                .name(getJobName(agentName));
        scheduler.schedule(new ScheduledReplicationQueueProcessorTask(this, queueProcessor), options);
    }
View Full Code Here


    }

    @Test
    public void testEnableQueueProcessing() 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);
        SimpleReplicationQueueProvider simpleReplicationQueueProvider = new SimpleReplicationQueueProvider(scheduler);
        ReplicationQueueProcessor processor = mock(ReplicationQueueProcessor.class);
        simpleReplicationQueueProvider.enableQueueProcessing("dummy-agent", processor);
    }
View Full Code Here

    }

    @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);
        SimpleReplicationQueueProvider simpleReplicationQueueProvider = new SimpleReplicationQueueProvider(scheduler);
        simpleReplicationQueueProvider.disableQueueProcessing("dummy-agent");
    }
View Full Code Here

        this.scheduler = scheduler;
    }

    public void register(@Nonnull ReplicationRequestHandler requestHandler) throws ReplicationTriggerException {
        try {
            ScheduleOptions options = scheduler.NOW(-1, secondsInterval);
            options.name(requestHandler.toString());
            scheduler.schedule(new ScheduledReplication(requestHandler), options);
        } catch (Exception e) {
            throw new ReplicationTriggerException("unable to register handler " + requestHandler, e);
        }
    }
View Full Code Here

    public void register(@Nonnull ReplicationRequestHandler requestHandler) throws ReplicationTriggerException {
        try {
            log.info("applying remote event replication trigger");

            ScheduleOptions options = scheduler.NOW();
            options.name(requestHandler.toString());
            scheduler.schedule(new EventBasedReplication(requestHandler), options);
        } catch (Exception e) {
            throw new ReplicationTriggerException("unable to register handler " + requestHandler, e);
        }
    }
View Full Code Here

        for (ReplicationActionType action : ReplicationActionType.values()) {
            String path = "/path/to/somewhere";
            int interval = 10;
            ReplicationRequestHandler handler = mock(ReplicationRequestHandler.class);
            Scheduler scheduler = mock(Scheduler.class);
            ScheduleOptions options = mock(ScheduleOptions.class);
            when(scheduler.NOW(-1, interval)).thenReturn(options);
            when(options.name(handler.toString())).thenReturn(options);
            ScheduledReplicationTrigger scheduledReplicationTrigger = new ScheduledReplicationTrigger(action.name(), path, interval, scheduler);
            scheduledReplicationTrigger.register(handler);
        }
    }
View Full Code Here

        ReplicationRequestHandler handler = mock(ReplicationRequestHandler.class);
        String endpoint = "";
        TransportAuthenticationProvider<CredentialsProvider, CredentialsProvider> authProvider = mock(TransportAuthenticationProvider.class);
        when(authProvider.canAuthenticate(CredentialsProvider.class)).thenReturn(true);
        Scheduler scheduler = mock(Scheduler.class);
        ScheduleOptions options = mock(ScheduleOptions.class);
        when(options.name(handler.toString())).thenReturn(options);
        when(scheduler.NOW()).thenReturn(options);
        RemoteEventReplicationTrigger remoteEventReplicationTrigger = new RemoteEventReplicationTrigger(
                endpoint, authProvider, scheduler);
        remoteEventReplicationTrigger.register(handler);
    }
View Full Code Here

                }
            }
            config.put(JOB_CONFIG, properties);
            config.put(JOB_SCHEDULE_INFO, scheduleInfo);

            final ScheduleOptions options;
            if ( scheduleInfo.expression != null ) {
                if ( this.logger.isDebugEnabled() ) {
                    this.logger.debug("Adding timed event " + config.get(JOB_TOPIC) + "(" + scheduleInfo.jobId + ")" + " with cron expression " + scheduleInfo.expression);
                }
                options = localScheduler.EXPR(scheduleInfo.expression);
            } else if ( scheduleInfo.period != null ) {
                if ( this.logger.isDebugEnabled() ) {
                    this.logger.debug("Adding timed event " + config.get(JOB_TOPIC) + "(" + scheduleInfo.jobId + ")" + " with period " + scheduleInfo.period);
                }
                final Date startDate = new Date(System.currentTimeMillis() + scheduleInfo.period * 1000);
                options = localScheduler.AT(startDate, -1, scheduleInfo.period);
            } else {
                // then it must be date
                if ( this.logger.isDebugEnabled() ) {
                    this.logger.debug("Adding timed event " + config.get(JOB_TOPIC) + "(" + scheduleInfo.jobId + ")" + " with date " + scheduleInfo.date);
                }
                options = localScheduler.AT(scheduleInfo.date);
            }
            localScheduler.schedule(this, options.canRunConcurrently(false).name(scheduleInfo.jobId).config(config));
            this.startedSchedulerJobs.add(scheduleInfo.jobId);
            return true;
        } else {
            this.logger.error("No scheduler available to start timed event " + event);
        }
View Full Code Here

        if ( !info.isSuspended() ) {
            logger.debug("Adding scheduled job: {}", info.getName());
            int index = 0;
            for(final ScheduleInfo si : info.getSchedules()) {
                final String name = info.getSchedulerJobId() + "-" + String.valueOf(index);
                ScheduleOptions options = null;
                switch ( si.getType() ) {
                    case DAILY:
                    case WEEKLY:
                    case HOURLY:
                    case MONTHLY:
                    case YEARLY:
                    case CRON:
                        options = this.scheduler.EXPR(((ScheduleInfoImpl)si).getCronExpression());

                        break;
                    case DATE:
                        options = this.scheduler.AT(((ScheduleInfoImpl)si).getNextScheduledExecution());
                        break;
                }
                // Create configuration for scheduled job
                final Map<String, Serializable> config = new HashMap<String, Serializable>();
                config.put(PROPERTY_READ_JOB, info);
                config.put(PROPERTY_SCHEDULE_INDEX, index);
                this.scheduler.schedule(this, options.name(name).config(config).canRunConcurrently(false));
                index++;
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.sling.commons.scheduler.ScheduleOptions

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.