http://git-wip-us.apache.org/repos/asf/zest-java/blob/551c04d5/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/TriggerWrapper.java ---------------------------------------------------------------------- diff --git a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/TriggerWrapper.java b/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/TriggerWrapper.java new file mode 100644 index 0000000..47ec9f5 --- /dev/null +++ b/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/TriggerWrapper.java @@ -0,0 +1,178 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package org.apache.zest.library.scheduler; + +import java.util.Date; +import org.apache.zest.api.mixin.Mixins; +import org.apache.zest.api.property.Property; +import org.quartz.Calendar; +import org.quartz.JobDataMap; +import org.quartz.JobExecutionContext; +import org.quartz.JobExecutionException; +import org.quartz.JobKey; +import org.quartz.SchedulerException; +import org.quartz.Trigger; +import org.quartz.TriggerKey; +import org.quartz.spi.OperableTrigger; + +@Mixins( TriggerWrapper.OperableMixin.class) +public interface TriggerWrapper extends OperableTrigger +{ + enum State {waiting, aquired } + Property<Trigger> trigger(); + + Property<Long> nextTime(); + + Property<State> state(); + + abstract class OperableMixin + implements OperableTrigger{ + + @Override + public void triggered( Calendar calendar ) + { + + } + + @Override + public Date computeFirstFireTime( Calendar calendar ) + { + return null; + } + + @Override + public CompletedExecutionInstruction executionComplete( JobExecutionContext context, + JobExecutionException result + ) + { + return null; + } + + @Override + public void updateAfterMisfire( Calendar cal ) + { + + } + + @Override + public void updateWithNewCalendar( Calendar cal, long misfireThreshold ) + { + + } + + @Override + public void validate() + throws SchedulerException + { + + } + + @Override + public void setFireInstanceId( String id ) + { + + } + + @Override + public String getFireInstanceId() + { + return null; + } + + @Override + public void setNextFireTime( Date nextFireTime ) + { + + } + + @Override + public void setPreviousFireTime( Date previousFireTime ) + { + + } + + @Override + public void setKey( TriggerKey key ) + { + + } + + @Override + public void setJobKey( JobKey key ) + { + + } + + @Override + public void setDescription( String description ) + { + + } + + @Override + public void setCalendarName( String calendarName ) + { + + } + + @Override + public void setJobDataMap( JobDataMap jobDataMap ) + { + + } + + @Override + public void setPriority( int priority ) + { + + } + + @Override + public void setStartTime( Date startTime ) + { + + } + + @Override + public void setEndTime( Date endTime ) + { + + } + + @Override + public void setMisfireInstruction( int misfireInstruction ) + { + + } + + @Override + public int compareTo( Trigger other ) + { + return -1; + } + + @Override + public Object clone() + { + throw new UnsupportedOperationException( "This operation is not supported." ); + } + } +}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/551c04d5/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/TriggersGroup.java ---------------------------------------------------------------------- diff --git a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/TriggersGroup.java b/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/TriggersGroup.java new file mode 100644 index 0000000..79e98d1 --- /dev/null +++ b/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/TriggersGroup.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package org.apache.zest.library.scheduler; + +import org.apache.zest.api.association.NamedAssociation; +import org.apache.zest.api.entity.EntityComposite; + +public interface TriggersGroup extends EntityComposite +{ + NamedAssociation<TriggerWrapper> triggers(); +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/551c04d5/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/TriggersGroups.java ---------------------------------------------------------------------- diff --git a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/TriggersGroups.java b/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/TriggersGroups.java new file mode 100644 index 0000000..e89f773 --- /dev/null +++ b/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/TriggersGroups.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package org.apache.zest.library.scheduler; + +import org.apache.zest.api.association.NamedAssociation; +import org.apache.zest.api.entity.EntityComposite; + +public interface TriggersGroups extends EntityComposite +{ + NamedAssociation<TriggersGroup> groups(); +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/551c04d5/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/ZestJob.java ---------------------------------------------------------------------- diff --git a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/ZestJob.java b/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/ZestJob.java new file mode 100644 index 0000000..927df41 --- /dev/null +++ b/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/ZestJob.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package org.apache.zest.library.scheduler; + +import org.apache.zest.api.common.Optional; +import org.apache.zest.api.entity.EntityComposite; +import org.apache.zest.api.property.Property; +import org.apache.zest.library.constraints.annotation.Matches; +import org.quartz.Job; + +public interface ZestJob extends Job, EntityComposite +{ +// @Matches( "job://[a-zA-Z0-9_]+\\.[a-zA-Z0-9_]+" ) +// Property<String> identity(); + + @Optional + Property<String> description(); +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/551c04d5/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/ZestJobDetail.java ---------------------------------------------------------------------- diff --git a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/ZestJobDetail.java b/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/ZestJobDetail.java new file mode 100644 index 0000000..5324dd0 --- /dev/null +++ b/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/ZestJobDetail.java @@ -0,0 +1,128 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package org.apache.zest.library.scheduler; + +import java.lang.reflect.UndeclaredThrowableException; +import org.apache.zest.api.common.Optional; +import org.apache.zest.api.injection.scope.This; +import org.apache.zest.api.mixin.Mixins; +import org.apache.zest.api.property.Property; +import org.quartz.Job; +import org.quartz.JobBuilder; +import org.quartz.JobDataMap; +import org.quartz.JobDetail; +import org.quartz.JobKey; + +@Mixins( ZestJobDetail.ZestJobDetailMixin.class ) +public interface ZestJobDetail extends JobDetail +{ + + interface State + { + Property<String> jobIdentity(); + + @Optional + Property<String> description(); + + Property<String> jobClass(); + } + + class ZestJobDetailMixin implements JobDetail + { + + @This + State state; + + @Override + public JobKey getKey() + { + String id = state.jobIdentity().get(); + id = id.substring( "job://".length() ); + String[] split = id.split( "\\." ); + return JobKey.jobKey( split[ 1 ], split[ 0 ] ); + } + + @Override + public String getDescription() + { + return state.description().get(); + } + + @Override + public Class<? extends Job> getJobClass() + { + String classname = state.jobClass().get(); + try + { + @SuppressWarnings( "unchecked" ) + Class<? extends Job> jobClass = (Class<? extends Job>) getClass().getClassLoader() + .loadClass( classname ); + return jobClass; + } + catch( ClassNotFoundException e ) + { + throw new UndeclaredThrowableException( e ); + } + } + + @Override + public JobDataMap getJobDataMap() + { + return null; + } + + @Override + public boolean isDurable() + { + return true; + } + + @Override + public boolean isPersistJobDataAfterExecution() + { + return false; + } + + @Override + public boolean isConcurrentExectionDisallowed() + { + return false; + } + + @Override + public boolean requestsRecovery() + { + return false; + } + + @Override + public JobBuilder getJobBuilder() + { + throw new UnsupportedOperationException( "Quartz JobBuilder is not supported in Apache Zest. Use EntityBuilders." ); + } + + @Override + public Object clone() + { + throw new UnsupportedOperationException( "clone() should not be needed as JobDetail is a ValueComposite." ); + } + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/551c04d5/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/ZestJobFactory.java ---------------------------------------------------------------------- diff --git a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/ZestJobFactory.java b/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/ZestJobFactory.java new file mode 100644 index 0000000..312d707 --- /dev/null +++ b/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/ZestJobFactory.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package org.apache.zest.library.scheduler; + +import org.apache.zest.api.injection.scope.Structure; +import org.apache.zest.api.unitofwork.UnitOfWork; +import org.apache.zest.api.unitofwork.UnitOfWorkFactory; +import org.quartz.Job; +import org.quartz.JobDetail; +import org.quartz.JobKey; +import org.quartz.Scheduler; +import org.quartz.SchedulerException; +import org.quartz.spi.JobFactory; +import org.quartz.spi.TriggerFiredBundle; + +public class ZestJobFactory + implements JobFactory +{ + @Structure + private UnitOfWorkFactory uowf; + + @Override + public Job newJob( TriggerFiredBundle bundle, Scheduler scheduler ) + throws SchedulerException + { + JobDetail jobDetail = bundle.getJobDetail(); + Class<? extends Job> jobType = jobDetail.getJobClass(); + if( ZestJob.class.isAssignableFrom( jobType ) ) + { + JobKey jobKey = jobDetail.getKey(); + String jobId = "job://" + jobKey.getGroup() + "." + jobKey.getName(); + + @SuppressWarnings( "unchecked" ) + ZestJob job = createJob( (Class<? extends ZestJob>) jobType, jobId ); + return job; + } + return null; + } + + private <T extends ZestJob> T createJob( Class<T> jobType, String jobId ) + { + UnitOfWork uow = uowf.currentUnitOfWork(); + return uow.get( jobType, jobId ); + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/551c04d5/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/bootstrap/SchedulerAssembler.java ---------------------------------------------------------------------- diff --git a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/bootstrap/SchedulerAssembler.java b/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/bootstrap/SchedulerAssembler.java deleted file mode 100644 index 317abd1..0000000 --- a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/bootstrap/SchedulerAssembler.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (c) 2010-2012, Paul Merlin. - * Copyright (c) 2012, Niclas Hedhman. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - * implied. - * - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.zest.library.scheduler.bootstrap; - -import org.apache.zest.api.unitofwork.concern.UnitOfWorkConcern; -import org.apache.zest.bootstrap.Assemblers; -import org.apache.zest.bootstrap.AssemblyException; -import org.apache.zest.bootstrap.EntityDeclaration; -import org.apache.zest.bootstrap.ModuleAssembly; -import org.apache.zest.bootstrap.ServiceDeclaration; -import org.apache.zest.bootstrap.ValueDeclaration; -import org.apache.zest.library.scheduler.SchedulerConfiguration; -import org.apache.zest.library.scheduler.SchedulerService; -import org.apache.zest.library.scheduler.internal.TaskRunner; -import org.apache.zest.library.scheduler.ScheduleFactory; -import org.apache.zest.library.scheduler.internal.Schedules; -import org.apache.zest.library.scheduler.CronSchedule; -import org.apache.zest.library.scheduler.OnceSchedule; -import org.apache.zest.library.scheduler.timeline.Timeline; -import org.apache.zest.library.scheduler.timeline.TimelineForScheduleConcern; -import org.apache.zest.library.scheduler.timeline.TimelineRecord; -import org.apache.zest.library.scheduler.timeline.TimelineScheduleMixin; -import org.apache.zest.library.scheduler.timeline.TimelineSchedulerServiceMixin; - -/** - * Assembler for Scheduler. - * - * Use this Assembler to add the Scheduler service to your application. - * This Assembler provide a fluent api to programmatically configure configuration defaults and - * activate the Timeline service assembly that allow to browse in past and future Task runs. - * - * Here is a full example: - * <pre> - * new SchedulerAssembler(). - * visibleIn( Visibility.layer ). - * withConfig( configModuleAssembly, Visibility.application ). - * withTimeline(). - * assemble( module ); - * </pre> - */ -public class SchedulerAssembler - extends Assemblers.VisibilityConfig<SchedulerAssembler> -{ - - private static final int DEFAULT_WORKERS_COUNT = Runtime.getRuntime().availableProcessors() + 1; - private static final int DEFAULT_WORKQUEUE_SIZE = 10; - - private boolean timeline; - - /** - * Activate the assembly of Timeline related services. - * - * @return SchedulerAssembler - */ - public SchedulerAssembler withTimeline() - { - timeline = true; - return this; - } - - @Override - public void assemble( ModuleAssembly assembly ) - throws AssemblyException - { - assembly.services( ScheduleFactory.class ); - assembly.entities( Schedules.class ); - EntityDeclaration scheduleEntities = assembly.entities( CronSchedule.class, OnceSchedule.class ); - - ValueDeclaration scheduleValues = assembly.values( CronSchedule.class, OnceSchedule.class ); - - ServiceDeclaration schedulerDeclaration = assembly.services( SchedulerService.class ) - .visibleIn( visibility() ) - .instantiateOnStartup(); - - assembly.transients( Runnable.class ).withMixins( TaskRunner.class ).withConcerns( UnitOfWorkConcern.class ); - - if( timeline ) - { - scheduleEntities.withTypes( Timeline.class ) - .withMixins( TimelineScheduleMixin.class ) - .withConcerns( TimelineForScheduleConcern.class ); - - scheduleValues.withTypes( Timeline.class ) - .withMixins( TimelineScheduleMixin.class ) - .withConcerns( TimelineForScheduleConcern.class ); - - // Internal - assembly.values( TimelineRecord.class ); - schedulerDeclaration.withTypes( Timeline.class ).withMixins( TimelineSchedulerServiceMixin.class ); - } - - if( hasConfig() ) - { - configModule().entities( SchedulerConfiguration.class ) - .visibleIn( configVisibility() ); - SchedulerConfiguration defaults = assembly.forMixin( SchedulerConfiguration.class ).declareDefaults(); - defaults.workersCount().set( DEFAULT_WORKERS_COUNT ); - defaults.workQueueSize().set( DEFAULT_WORKQUEUE_SIZE ); - } - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/551c04d5/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/bootstrap/package.html ---------------------------------------------------------------------- diff --git a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/bootstrap/package.html b/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/bootstrap/package.html deleted file mode 100644 index b9a2ef1..0000000 --- a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/bootstrap/package.html +++ /dev/null @@ -1,21 +0,0 @@ -<!-- -Licensed to the Apache Software Foundation (ASF) under one or more -contributor license agreements. See the NOTICE file distributed with -this work for additional information regarding copyright ownership. -The ASF licenses this file to You under the Apache License, Version 2.0 -(the "License"); you may not use this file except in compliance with -the License. You may obtain a copy of the License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. ---> -<html> - <body> - <h2>Scheduler Assembly.</h2> - </body> -</html> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/551c04d5/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/defaults/DefaultRejectionHandler.java ---------------------------------------------------------------------- diff --git a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/defaults/DefaultRejectionHandler.java b/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/defaults/DefaultRejectionHandler.java deleted file mode 100644 index 9a8e631..0000000 --- a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/defaults/DefaultRejectionHandler.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -package org.apache.zest.library.scheduler.defaults; - -import java.util.concurrent.RejectedExecutionHandler; -import java.util.concurrent.ThreadPoolExecutor; -import org.apache.zest.library.scheduler.SchedulerService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class DefaultRejectionHandler - implements RejectedExecutionHandler -{ - private static final Logger LOGGER = LoggerFactory.getLogger( SchedulerService.class ); - - @Override - public void rejectedExecution( Runnable r, ThreadPoolExecutor executor ) - { - LOGGER.error( "Runnable [" + r + "] was rejected by executor [" + executor + "]" ); - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/551c04d5/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/defaults/DefaultScheduleFactoryMixin.java ---------------------------------------------------------------------- diff --git a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/defaults/DefaultScheduleFactoryMixin.java b/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/defaults/DefaultScheduleFactoryMixin.java deleted file mode 100644 index 27c7125..0000000 --- a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/defaults/DefaultScheduleFactoryMixin.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -package org.apache.zest.library.scheduler.defaults; - -import org.apache.zest.api.entity.EntityBuilder; -import org.apache.zest.api.injection.scope.Service; -import org.apache.zest.api.injection.scope.Structure; -import org.apache.zest.api.structure.Module; -import org.apache.zest.api.unitofwork.UnitOfWork; -import org.apache.zest.library.scheduler.SchedulerService; -import org.apache.zest.library.scheduler.Task; -import org.apache.zest.library.scheduler.Schedule; -import org.apache.zest.library.scheduler.ScheduleFactory; -import org.apache.zest.library.scheduler.CronSchedule; -import org.apache.zest.library.scheduler.OnceSchedule; -import org.apache.zest.spi.uuid.UuidIdentityGeneratorService; -import org.joda.time.DateTime; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class DefaultScheduleFactoryMixin - implements ScheduleFactory -{ - private static final Logger logger = LoggerFactory.getLogger( ScheduleFactory.class ); - - @Structure - private Module module; - - @Service - private SchedulerService scheduler; - - @Service - private UuidIdentityGeneratorService uuid; - - @Override - public CronSchedule newCronSchedule( Task task, String cronExpression, DateTime start ) - { - return newPersistentCronSchedule( task, cronExpression, start ); - } - - @Override - public Schedule newOnceSchedule( Task task, DateTime runAt ) - { - return newPersistentOnceSchedule( task, runAt ); - } - - private CronSchedule newPersistentCronSchedule( Task task, String cronExpression, DateTime start ) - { - UnitOfWork uow = module.currentUnitOfWork(); - EntityBuilder<CronSchedule> builder = uow.newEntityBuilder( CronSchedule.class ); - CronSchedule instance = builder.instance(); - instance.task().set( task ); - instance.start().set( start ); - instance.identity().set( uuid.generate( CronSchedule.class ) ); - instance.cronExpression().set( cronExpression ); - CronSchedule schedule = builder.newInstance(); - logger.info( "Schedule {} created: {}", schedule.presentationString(), schedule.identity().get() ); - return schedule; - } - - private Schedule newPersistentOnceSchedule( Task task, DateTime runAt ) - { - UnitOfWork uow = module.currentUnitOfWork(); - EntityBuilder<OnceSchedule> builder = uow.newEntityBuilder( OnceSchedule.class ); - OnceSchedule builderInstance = builder.instance(); - builderInstance.task().set( task ); - builderInstance.start().set( runAt ); - builderInstance.identity().set( uuid.generate( OnceSchedule.class ) ); - OnceSchedule schedule = builder.newInstance(); - logger.info( "Schedule {} created: {}", schedule.presentationString(), schedule.identity().get() ); - return schedule; - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/551c04d5/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/defaults/DefaultThreadFactory.java ---------------------------------------------------------------------- diff --git a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/defaults/DefaultThreadFactory.java b/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/defaults/DefaultThreadFactory.java deleted file mode 100644 index 43520bd..0000000 --- a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/defaults/DefaultThreadFactory.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -package org.apache.zest.library.scheduler.defaults; - -import java.util.concurrent.atomic.AtomicInteger; -import org.apache.zest.api.injection.scope.This; -import org.apache.zest.library.scheduler.internal.Execution; -import org.apache.zest.library.scheduler.SchedulerService; - -public class DefaultThreadFactory - implements java.util.concurrent.ThreadFactory -{ - private static final AtomicInteger POOL_NUMBER = new AtomicInteger( 1 ); - private final ThreadGroup group; - private final AtomicInteger threadNumber = new AtomicInteger( 1 ); - private final String namePrefix; - - protected DefaultThreadFactory( @This SchedulerService me ) - { - SecurityManager sm = System.getSecurityManager(); - group = ( sm != null ) ? sm.getThreadGroup() : Execution.ExecutionMixin.TG; - namePrefix = me.identity().get() + "-P" + POOL_NUMBER.getAndIncrement() + "W"; - } - - @Override - public Thread newThread( Runnable runnable ) - { - Thread thread = new Thread( group, runnable, namePrefix + threadNumber.getAndIncrement(), 0 ); - if( thread.isDaemon() ) - { - thread.setDaemon( false ); - } - if( thread.getPriority() != Thread.NORM_PRIORITY ) - { - thread.setPriority( Thread.NORM_PRIORITY ); - } - return thread; - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/551c04d5/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/internal/Execution.java ---------------------------------------------------------------------- diff --git a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/internal/Execution.java b/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/internal/Execution.java deleted file mode 100644 index 08eb627..0000000 --- a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/internal/Execution.java +++ /dev/null @@ -1,275 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -package org.apache.zest.library.scheduler.internal; - -import java.util.SortedSet; -import java.util.TreeSet; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.RejectedExecutionHandler; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; -import org.apache.zest.api.concern.Concerns; -import org.apache.zest.api.configuration.Configuration; -import org.apache.zest.api.injection.scope.Structure; -import org.apache.zest.api.injection.scope.This; -import org.apache.zest.api.mixin.Mixins; -import org.apache.zest.api.structure.Module; -import org.apache.zest.api.unitofwork.NoSuchEntityException; -import org.apache.zest.api.unitofwork.UnitOfWork; -import org.apache.zest.api.unitofwork.concern.UnitOfWorkConcern; -import org.apache.zest.library.scheduler.Schedule; -import org.apache.zest.library.scheduler.Scheduler; -import org.apache.zest.library.scheduler.SchedulerConfiguration; - -/** - * This composite handles the Execution of Schedules. - * - * The composite is internal and should never be used by clients. - */ -@Mixins( Execution.ExecutionMixin.class ) -public interface Execution -{ - void dispatchForExecution( Schedule schedule ); - - void start() - throws Exception; - - void stop() - throws Exception; - - void updateNextTime( ScheduleTime schedule ); // This method is public, only because the UnitOfWorkConcern is wanted. - - class ExecutionMixin - implements Execution, Runnable - { - public static final ThreadGroup TG = new ThreadGroup( "Zest Scheduling" ); - - private final Object lock = new Object(); - - @Structure - private Module module; - - @This - private Scheduler scheduler; - - @This - private Configuration<SchedulerConfiguration> config; - - @This - private ThreadFactory threadFactory; - - @This - private RejectedExecutionHandler rejectionHandler; - - private final SortedSet<ScheduleTime> timingQueue = new TreeSet<>(); - private volatile boolean running; - private ThreadPoolExecutor taskExecutor; - private volatile Thread scheduleThread; - - @Override - public void run() - { - running = true; - while( running ) - { - try - { - ScheduleTime scheduleTime = timing(); - if( scheduleTime != null ) - { - waitFor( scheduleTime ); - - if( isTime( scheduleTime ) ) // We might have been awakened to reschedule - { - updateNextTime( scheduleTime ); - } - } - else - { - waitFor( 100 ); - } - } - catch( Throwable e ) - { - e.printStackTrace(); - } - } - } - - private ScheduleTime timing() - { - synchronized( lock ) - { - if( timingQueue.size() == 0 ) - { - return null; - } - return timingQueue.first(); - } - } - - private boolean isTime( ScheduleTime scheduleTime ) - { - long now = System.currentTimeMillis(); - return scheduleTime.nextTime() <= now; - } - - private void waitFor( ScheduleTime scheduleTime ) - throws InterruptedException - { - long now = System.currentTimeMillis(); - long waitingTime = scheduleTime.nextTime() - now; - waitFor( waitingTime ); - } - - private void waitFor( long waitingTime ) - { - if( waitingTime > 0 ) - { - synchronized( lock ) - { - try - { - lock.wait( waitingTime ); - } - catch( InterruptedException e ) - { - // should be ignored. - } - } - } - } - - @Override - public void updateNextTime( ScheduleTime oldScheduleTime ) - { - long now = System.currentTimeMillis(); - - try (UnitOfWork uow = module.newUnitOfWork()) // This will discard() the UoW when block is exited. We are only doing reads, so fine. - { - submitTaskForExecution( oldScheduleTime ); - Schedule schedule = uow.get( Schedule.class, oldScheduleTime.scheduleIdentity() ); - long nextTime = schedule.nextRun( now + 1000 ); - if( nextTime != Long.MIN_VALUE ) - { - ScheduleTime newScheduleTime = new ScheduleTime( oldScheduleTime.scheduleIdentity(), nextTime ); - synchronized( lock ) - { - // Re-add to the Timing Queue, to re-position the sorting. - timingQueue.remove( oldScheduleTime ); - timingQueue.add( newScheduleTime ); - } - } - else - { - synchronized( lock ) - { - timingQueue.remove( oldScheduleTime ); - } - } - } - catch( NoSuchEntityException e ) - { - e.printStackTrace(); -// scheduler.cancelSchedule( oldScheduleTime.scheduleIdentity() ); - } - } - - private void submitTaskForExecution( ScheduleTime scheduleTime ) - { - Runnable taskRunner = module.newTransient( Runnable.class, scheduleTime ); - this.taskExecutor.submit( taskRunner ); - } - - public void dispatchForExecution( Schedule schedule ) - { - long now = System.currentTimeMillis(); - long nextRun = schedule.nextRun( now + 1000 ); - if( nextRun > 0 ) - { - synchronized( lock ) - { - timingQueue.add( new ScheduleTime( schedule.identity().get(), nextRun ) ); - lock.notifyAll(); - } - } - } - - @Override - public void start() - throws Exception - { - SchedulerConfiguration configuration = config.get(); - Integer workersCount = configuration.workersCount().get(); - Integer workQueueSize = configuration.workQueueSize().get(); - createThreadPoolExecutor( workersCount, workQueueSize ); - taskExecutor.prestartAllCoreThreads(); - - SecurityManager sm = System.getSecurityManager(); - ThreadGroup threadGroup = sm != null ? sm.getThreadGroup() : TG; - scheduleThread = new Thread( threadGroup, this, "Scheduler" ); - scheduleThread.start(); - } - - private void createThreadPoolExecutor( Integer workersCount, Integer workQueueSize ) - { - int corePoolSize = 2; - if( workersCount > 4 ) - { - corePoolSize = workersCount / 4 + 1; - } - if( corePoolSize > 50 ) - { - corePoolSize = 20; - } - if( workersCount > 200 ) - { - workersCount = 200; - } - taskExecutor = new ThreadPoolExecutor( corePoolSize, workersCount, - 0, TimeUnit.MILLISECONDS, - new LinkedBlockingQueue<>( workQueueSize ), - threadFactory, rejectionHandler ); - } - - @Override - public void stop() - throws Exception - { - running = false; - synchronized( this ) - { - scheduleThread.interrupt(); - } - taskExecutor.shutdown(); - try - { - taskExecutor.awaitTermination( 5, TimeUnit.SECONDS ); - } - catch( InterruptedException e ) - { - e.printStackTrace(); - } - taskExecutor.shutdownNow(); - } - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/551c04d5/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/internal/ScheduleTime.java ---------------------------------------------------------------------- diff --git a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/internal/ScheduleTime.java b/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/internal/ScheduleTime.java deleted file mode 100644 index b008de7..0000000 --- a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/internal/ScheduleTime.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.zest.library.scheduler.internal; - -import org.apache.zest.api.util.NullArgumentException; - -public final class ScheduleTime - implements Comparable<ScheduleTime> -{ - private String scheduleIdentity; - private long nextTime; - - public ScheduleTime( String scheduleIdentity, long nextTime ) - { - NullArgumentException.validateNotEmpty( "scheduleIdentity", scheduleIdentity ); - this.scheduleIdentity = scheduleIdentity; - this.nextTime = nextTime; - } - - public long nextTime() - { - return nextTime; - } - - public String scheduleIdentity() - { - return scheduleIdentity; - } - - @Override - public int compareTo( ScheduleTime another ) - { - if( this.scheduleIdentity.equals( another.scheduleIdentity ) ) - { - return 0; - } - - if( this.nextTime < another.nextTime ) - { - return -1; - } - return 1; - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/551c04d5/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/internal/SchedulerMixin.java ---------------------------------------------------------------------- diff --git a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/internal/SchedulerMixin.java b/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/internal/SchedulerMixin.java deleted file mode 100644 index 3afafa5..0000000 --- a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/internal/SchedulerMixin.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.zest.library.scheduler.internal; - -import org.apache.zest.api.configuration.Configuration; -import org.apache.zest.api.injection.scope.Service; -import org.apache.zest.api.injection.scope.Structure; -import org.apache.zest.api.injection.scope.This; -import org.apache.zest.api.service.ServiceActivation; -import org.apache.zest.api.structure.Module; -import org.apache.zest.api.unitofwork.NoSuchEntityException; -import org.apache.zest.api.unitofwork.UnitOfWork; -import org.apache.zest.api.unitofwork.UnitOfWorkCompletionException; -import org.apache.zest.api.usecase.UsecaseBuilder; -import org.apache.zest.library.scheduler.Scheduler; -import org.apache.zest.library.scheduler.SchedulerConfiguration; -import org.apache.zest.library.scheduler.SchedulerService; -import org.apache.zest.library.scheduler.SchedulesHandler; -import org.apache.zest.library.scheduler.Task; -import org.apache.zest.library.scheduler.CronSchedule; -import org.apache.zest.library.scheduler.Schedule; -import org.apache.zest.library.scheduler.ScheduleFactory; -import org.joda.time.DateTime; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class SchedulerMixin - implements Scheduler, ServiceActivation -{ - private static final Logger LOGGER = LoggerFactory.getLogger( Scheduler.class ); - - @Service - private ScheduleFactory scheduleFactory; - - @Structure - private Module module; - - @This - private SchedulerService me; - - @This - private SchedulesHandler schedulesHandler; - - @This - private Execution execution; - - @This - private Configuration<SchedulerConfiguration> config; - - public SchedulerMixin() - { - } - - @Override - public Schedule scheduleOnce( Task task, int initialSecondsDelay ) - { - long now = System.currentTimeMillis(); - Schedule schedule = scheduleFactory.newOnceSchedule( task, new DateTime( now + initialSecondsDelay * 1000 ) ); - saveAndDispatch( schedule ); - return schedule; - } - - @Override - public Schedule scheduleOnce( Task task, DateTime runAt ) - { - Schedule schedule = scheduleFactory.newOnceSchedule( task, runAt ); - saveAndDispatch( schedule ); - return schedule; - } - - @Override - public Schedule scheduleCron( Task task, String cronExpression ) - { - DateTime now = new DateTime(); - Schedule schedule = scheduleFactory.newCronSchedule( task, cronExpression, now ); - saveAndDispatch( schedule ); - return schedule; - } - - @Override - public Schedule scheduleCron( Task task, @CronSchedule.CronExpression String cronExpression, DateTime start ) - { - Schedule schedule = scheduleFactory.newCronSchedule( task, cronExpression, start ); - saveAndDispatch( schedule ); - return schedule; - } - - @Override - public void scheduleCron( Schedule schedule ) - { - saveAndDispatch( schedule ); - } - - @Override - public Schedule scheduleCron( Task task, String cronExpression, long initialDelay ) - { - DateTime start = new DateTime( System.currentTimeMillis() + initialDelay ); - Schedule schedule = scheduleFactory.newCronSchedule( task, cronExpression, start ); - saveAndDispatch( schedule ); - return schedule; - } - - @Override - public void cancelSchedule( String scheduleId ) - { - UnitOfWork uow = module.currentUnitOfWork(); - Schedule schedule = null; - try - { - schedule = uow.get( Schedule.class, scheduleId ); - } - catch( NoSuchEntityException e ) - { - return; - } - cancelSchedule( schedule ); - } - - @Override - public void cancelSchedule( Schedule schedule ) - { - Schedules active = schedulesHandler.getActiveSchedules(); - if( active.schedules().remove( schedule ) ) - { - schedule.cancelled().set( true ); - } - } - - private void saveAndDispatch( Schedule schedule ) - { - Schedules schedules = schedulesHandler.getActiveSchedules(); - schedules.schedules().add( schedule ); - execution.dispatchForExecution( schedule ); - } - - private void loadSchedules() - throws UnitOfWorkCompletionException - { - try (UnitOfWork ignored = module.newUnitOfWork( UsecaseBuilder.newUsecase( "Initialize Schedules" ) )) - { - Schedules schedules = schedulesHandler.getActiveSchedules(); - for( Schedule schedule : schedules.schedules() ) - { - dispatch( schedule ); - } - } - } - - private void dispatch( Schedule schedule ) - { - try - { - if( !schedule.cancelled().get() && !schedule.done().get() ) - { - execution.dispatchForExecution( schedule ); - } - } catch( Exception e ) - { - e.printStackTrace(); - } - } - - @Override - public void activateService() - throws Exception - { - // Throws IllegalArgument if corePoolSize or keepAliveTime less than zero, - // or if workersCount less than or equal to zero, - // or if corePoolSize greater than workersCount. - execution.start(); - loadSchedules(); - LOGGER.debug( "Activated" ); - } - - @Override - public void passivateService() - throws Exception - { - execution.stop(); - LOGGER.debug( "Passivated" ); - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/551c04d5/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/internal/Schedules.java ---------------------------------------------------------------------- diff --git a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/internal/Schedules.java b/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/internal/Schedules.java deleted file mode 100644 index 95563c1..0000000 --- a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/internal/Schedules.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.zest.library.scheduler.internal; - -import org.apache.zest.api.association.ManyAssociation; -import org.apache.zest.library.scheduler.Schedule; - -public interface Schedules -{ - ManyAssociation<Schedule> schedules(); -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/551c04d5/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/internal/TaskRunner.java ---------------------------------------------------------------------- diff --git a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/internal/TaskRunner.java b/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/internal/TaskRunner.java deleted file mode 100644 index fa52d73..0000000 --- a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/internal/TaskRunner.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -package org.apache.zest.library.scheduler.internal; - -import java.lang.reflect.UndeclaredThrowableException; -import java.util.concurrent.locks.ReentrantLock; -import org.apache.zest.api.injection.scope.Structure; -import org.apache.zest.api.injection.scope.Uses; -import org.apache.zest.api.structure.Module; -import org.apache.zest.api.unitofwork.UnitOfWork; -import org.apache.zest.api.usecase.UsecaseBuilder; -import org.apache.zest.library.scheduler.Task; -import org.apache.zest.library.scheduler.Schedule; - -public class TaskRunner - implements Runnable -{ - private static ReentrantLock lock = new ReentrantLock(); - - @Structure - private Module module; - - @Uses - private ScheduleTime schedule; - - @Override - public void run() - { - // TODO: (niclas) I am NOT happy with this implementation, requiring 3 UnitOfWorks to be created. 15-20 milliseconds on my MacBook. If there is a better way to detect overrun, two of those might not be needed. - UnitOfWork uow = module.newUnitOfWork( UsecaseBuilder.newUsecase( "Task Runner initialize" ) ); - try - { - lock.lock(); - Schedule schedule = uow.get( Schedule.class, this.schedule.scheduleIdentity() ); - if( !schedule.running().get() ) // check for overrun. - { - try - { - schedule.taskStarting(); - schedule.running().set( true ); - uow.complete(); // This completion is needed to detect overrun - - uow = module.newUnitOfWork( UsecaseBuilder.newUsecase( "Task Runner" ) ); - schedule = uow.get( schedule ); // re-attach the entity to the new UnitOfWork - Task task = schedule.task().get(); - lock.unlock(); - task.run(); - lock.lock(); - uow.complete(); - uow = module.newUnitOfWork( UsecaseBuilder.newUsecase( "Task Runner conclude" ) ); - schedule = uow.get( schedule ); // re-attach the entity to the new UnitOfWork - schedule.running().set( false ); - schedule.taskCompletedSuccessfully(); - schedule.executionCounter().set( schedule.executionCounter().get() + 1 ); - } - catch( RuntimeException ex ) - { - schedule.running().set( false ); - processException( schedule, ex ); - } - } - else - { - schedule.overrun().set( schedule.overrun().get() + 1 ); - } - uow.complete(); - } - catch( Exception e ) - { - e.printStackTrace(); - throw new UndeclaredThrowableException( e ); - } - finally - { - uow.discard(); - try - { - lock.unlock(); - } - catch( IllegalMonitorStateException e ) - { - // ignore, as it may happen on certain exceptions. - } - } - } - - private void processException( Schedule schedule, RuntimeException ex ) - { - Throwable exception = ex; - while( exception instanceof UndeclaredThrowableException ) - { - exception = ( (UndeclaredThrowableException) ex ).getUndeclaredThrowable(); - } - schedule.taskCompletedWithException( exception ); - schedule.exceptionCounter().set( schedule.exceptionCounter().get() + 1 ); - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/551c04d5/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/package.html ---------------------------------------------------------------------- diff --git a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/package.html b/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/package.html deleted file mode 100644 index a796ce1..0000000 --- a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/package.html +++ /dev/null @@ -1,21 +0,0 @@ -<!-- -Licensed to the Apache Software Foundation (ASF) under one or more -contributor license agreements. See the NOTICE file distributed with -this work for additional information regarding copyright ownership. -The ASF licenses this file to You under the Apache License, Version 2.0 -(the "License"); you may not use this file except in compliance with -the License. You may obtain a copy of the License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. ---> -<html> - <body> - <h2>Scheduler Library.</h2> - </body> -</html> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/551c04d5/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/schedule/package.html ---------------------------------------------------------------------- diff --git a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/schedule/package.html b/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/schedule/package.html deleted file mode 100644 index 7c74250..0000000 --- a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/schedule/package.html +++ /dev/null @@ -1,21 +0,0 @@ -<!-- -Licensed to the Apache Software Foundation (ASF) under one or more -contributor license agreements. See the NOTICE file distributed with -this work for additional information regarding copyright ownership. -The ASF licenses this file to You under the Apache License, Version 2.0 -(the "License"); you may not use this file except in compliance with -the License. You may obtain a copy of the License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. ---> -<html> - <body> - <h2>Scheduler Schedules.</h2> - </body> -</html> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/551c04d5/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/timeline/Timeline.java ---------------------------------------------------------------------- diff --git a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/timeline/Timeline.java b/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/timeline/Timeline.java deleted file mode 100644 index 1c2e7e7..0000000 --- a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/timeline/Timeline.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2010-2012, Paul Merlin. - * Copyright (c) 2012, Niclas Hedhman. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - * implied. - * - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.zest.library.scheduler.timeline; - -import java.time.ZonedDateTime; -import org.apache.zest.api.unitofwork.concern.UnitOfWorkPropagation; - -/** - * Timeline allow to browse in past and future Task runs. - */ -// START SNIPPET: timeline -public interface Timeline -{ -// END SNIPPET: timeline - - /** - * @param maxResults Maximum number of TimelineRecord to compute - * - * @return Last past records - */ - @UnitOfWorkPropagation( UnitOfWorkPropagation.Propagation.MANDATORY ) -// START SNIPPET: timeline - Iterable<TimelineRecord> getLastRecords( int maxResults ); -// END SNIPPET: timeline - - /** - * @param maxResults Maximum number of TimelineRecord to compute - * - * @return Next running or future records - */ - @UnitOfWorkPropagation( UnitOfWorkPropagation.Propagation.MANDATORY ) -// START SNIPPET: timeline - Iterable<TimelineRecord> getNextRecords( int maxResults ); -// END SNIPPET: timeline - - /** - * @param from Lower limit - * @param to Upper limit - * - * @return Records between the given dates - */ - @UnitOfWorkPropagation( UnitOfWorkPropagation.Propagation.MANDATORY ) -// START SNIPPET: timeline - Iterable<TimelineRecord> getRecords( ZonedDateTime from, ZonedDateTime to ); -// END SNIPPET: timeline - - /** - * @param from Lower limit - * @param to Upper limit - * - * @return Records between the given dates - */ - @UnitOfWorkPropagation( UnitOfWorkPropagation.Propagation.MANDATORY ) -// START SNIPPET: timeline - Iterable<TimelineRecord> getRecords( long from, long to ); -} -// END SNIPPET: timeline http://git-wip-us.apache.org/repos/asf/zest-java/blob/551c04d5/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/timeline/TimelineForScheduleConcern.java ---------------------------------------------------------------------- diff --git a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/timeline/TimelineForScheduleConcern.java b/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/timeline/TimelineForScheduleConcern.java deleted file mode 100644 index 2ec856d..0000000 --- a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/timeline/TimelineForScheduleConcern.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 2012, Niclas Hedhman. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - * implied. - * - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.zest.library.scheduler.timeline; - -import java.io.BufferedOutputStream; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.List; -import org.apache.zest.api.concern.ConcernOf; -import org.apache.zest.api.injection.scope.Structure; -import org.apache.zest.api.injection.scope.This; -import org.apache.zest.api.structure.Module; -import org.apache.zest.api.value.ValueBuilder; -import org.apache.zest.library.scheduler.Schedule; - -public abstract class TimelineForScheduleConcern - extends ConcernOf<Schedule> - implements Schedule -{ - @This - private TimelineScheduleState state; - - @Structure - private Module module; - - @Override - public void taskStarting() - { - addRecord( TimelineRecordStep.STARTED, "" ); - next.taskStarting(); - } - - @Override - public void taskCompletedSuccessfully() - { - addRecord( TimelineRecordStep.SUCCESS, "" ); - next.taskCompletedSuccessfully(); - } - - @Override - public void taskCompletedWithException( Throwable ex ) - { - TimelineRecordStep step = TimelineRecordStep.FAILURE; - String details = "Exception occurred:" + getStackTrace( ex ); - addRecord( step, details ); - next.taskCompletedWithException( ex ); - } - - private void addRecord( TimelineRecordStep step, String details ) - { - ValueBuilder<TimelineRecord> builder = module.newValueBuilder( TimelineRecord.class ); - TimelineRecord prototype = builder.prototype(); - prototype.step().set( step ); - prototype.taskName().set( task().get().name().get() ); - List<String> tags = task().get().tags().get(); - prototype.taskTags().set( tags ); - prototype.timestamp().set( System.currentTimeMillis() ); - prototype.scheduleIdentity().set( this.identity().get() ); - prototype.details().set( details ); - TimelineRecord record = builder.newInstance(); - List<TimelineRecord> timelineRecords = state.history().get(); - timelineRecords.add( record ); - state.history().set( timelineRecords ); - } - - private String getStackTrace( Throwable ex ) - { - ByteArrayOutputStream baos = new ByteArrayOutputStream( 1000 ); - BufferedOutputStream out = new BufferedOutputStream( baos ); - PrintStream print = new PrintStream( out ); - ex.printStackTrace( print ); - print.flush(); - return baos.toString(); - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/551c04d5/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/timeline/TimelineRecord.java ---------------------------------------------------------------------- diff --git a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/timeline/TimelineRecord.java b/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/timeline/TimelineRecord.java deleted file mode 100644 index 1c7c304..0000000 --- a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/timeline/TimelineRecord.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2010-2012, Paul Merlin. - * Copyright (c) 2012, Niclas Hedhman. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - * implied. - * - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.zest.library.scheduler.timeline; - -import java.util.List; -import org.apache.zest.api.common.UseDefaults; -import org.apache.zest.api.entity.Queryable; -import org.apache.zest.api.mixin.Mixins; -import org.apache.zest.api.property.Property; -import org.apache.zest.api.value.ValueComposite; -import org.apache.zest.library.scheduler.Scheduler; - -/** - * Record in {@link Scheduler}'s {@link Timeline}. - * - * {@link TimelineRecord}s are {@link Comparable} regarding their {@link TimelineRecord#timestamp()}. - */ -@Mixins( TimelineRecord.Mixin.class ) -public interface TimelineRecord - extends Comparable<TimelineRecord>, ValueComposite -{ - /** - * @return Identity of the associated {@link Scheduler} - */ - Property<String> scheduleIdentity(); - - /** - * @return Timestamp of this record - */ - Property<Long> timestamp(); - - /** - * @return Name of the associated {@link org.apache.zest.library.scheduler.Task} - */ - Property<String> taskName(); - - /** - * @return Tags of the associated {@link org.apache.zest.library.scheduler.Task} - */ - @UseDefaults - Property<List<String>> taskTags(); - - Property<TimelineRecordStep> step(); - - /** - * @return Details text of this record - */ - @Queryable( false ) - @UseDefaults - Property<String> details(); - - abstract class Mixin - implements TimelineRecord - { - - @Override - public int compareTo( TimelineRecord o ) - { - return timestamp().get().compareTo( o.timestamp().get() ); - } - } - -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/551c04d5/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/timeline/TimelineRecordStep.java ---------------------------------------------------------------------- diff --git a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/timeline/TimelineRecordStep.java b/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/timeline/TimelineRecordStep.java deleted file mode 100644 index e1110ce..0000000 --- a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/timeline/TimelineRecordStep.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2010-2012, Paul Merlin. - * Copyright (c) 2012, Niclas Hedhman. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - * implied. - * - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.zest.library.scheduler.timeline; - -public enum TimelineRecordStep -{ - STARTED, - SUCCESS, - FAILURE, - FUTURE -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/551c04d5/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/timeline/TimelineScheduleMixin.java ---------------------------------------------------------------------- diff --git a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/timeline/TimelineScheduleMixin.java b/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/timeline/TimelineScheduleMixin.java deleted file mode 100644 index 01d9628..0000000 --- a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/timeline/TimelineScheduleMixin.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright (c) 2012, Niclas Hedhman. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.zest.library.scheduler.timeline; - -import java.time.ZonedDateTime; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.SortedSet; -import java.util.TreeSet; -import org.apache.zest.api.injection.scope.Structure; -import org.apache.zest.api.injection.scope.This; -import org.apache.zest.api.structure.Module; -import org.apache.zest.api.value.ValueBuilder; -import org.apache.zest.library.scheduler.Schedule; - -public class TimelineScheduleMixin - implements Timeline -{ - @Structure - private Module module; - - @This - private TimelineScheduleState state; - - @This - private Schedule me; - - @Override - public Iterable<TimelineRecord> getLastRecords( int maxResults ) - { - List<TimelineRecord> timelineRecords = state.history().get(); - int size = timelineRecords.size(); - if( size < maxResults ) - { - return Collections.unmodifiableCollection( timelineRecords ); - } - SortedSet<TimelineRecord> result = new TreeSet<>(); - for( int i = size - maxResults; i < size; i++ ) - { - result.add( timelineRecords.get( i ) ); - } - return result; - } - - @Override - public Iterable<TimelineRecord> getNextRecords( int maxResults ) - { - SortedSet<TimelineRecord> result = new TreeSet<>(); - long time = System.currentTimeMillis(); - for( int i = 0; i < maxResults; i++ ) - { - time = me.nextRun( time ); - result.add( createFutureRecord( time ) ); - } - return result; - } - - @Override - public Iterable<TimelineRecord> getRecords( ZonedDateTime from, ZonedDateTime to ) - { - return getRecords( from.toInstant().toEpochMilli(), to.toInstant().toEpochMilli() ); - } - - @Override - public Iterable<TimelineRecord> getRecords( long from, long to ) - { - long now = System.currentTimeMillis(); - SortedSet<TimelineRecord> result = new TreeSet<>(); - result.addAll( getPastRecords( from ) ); - result.addAll( getFutureRecords( now, to ) ); - return result; - } - - private Collection<? extends TimelineRecord> getPastRecords( long from ) - { - SortedSet<TimelineRecord> result = new TreeSet<>(); - List<TimelineRecord> timelineRecords = state.history().get(); - for( TimelineRecord record : timelineRecords ) - { - Long timestamp = record.timestamp().get(); - if( timestamp >= from ) - { - result.add( record ); - } - } - return result; - } - - private Collection<? extends TimelineRecord> getFutureRecords( long now, long to ) - { - if( now > to ) - { - return Collections.emptyList(); - } - - SortedSet<TimelineRecord> result = new TreeSet<>(); - long time = now; - while( time <= to ) - { - time = me.nextRun( time ); - if( time <= to ) - { - result.add( createFutureRecord( time ) ); - } - } - return result; - } - - private TimelineRecord createFutureRecord( long when ) - { - ValueBuilder<TimelineRecord> builder = module.newValueBuilder( TimelineRecord.class ); - TimelineRecord prototype = builder.prototype(); - prototype.step().set( TimelineRecordStep.FUTURE ); - prototype.taskName().set( me.task().get().name().get() ); - List<String> tags = me.task().get().tags().get(); - prototype.taskTags().set( tags ); - prototype.timestamp().set( when ); - prototype.scheduleIdentity().set( me.identity().get() ); - prototype.details().set( "" ); - return builder.newInstance(); - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/551c04d5/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/timeline/TimelineScheduleState.java ---------------------------------------------------------------------- diff --git a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/timeline/TimelineScheduleState.java b/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/timeline/TimelineScheduleState.java deleted file mode 100644 index c6ff172..0000000 --- a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/timeline/TimelineScheduleState.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2012, Niclas Hedhman. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.zest.library.scheduler.timeline; - -import java.util.List; -import org.apache.zest.api.common.UseDefaults; -import org.apache.zest.api.property.Property; - -public interface TimelineScheduleState -{ - @UseDefaults - Property<List<TimelineRecord>> history(); -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/551c04d5/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/timeline/TimelineSchedulerServiceMixin.java ---------------------------------------------------------------------- diff --git a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/timeline/TimelineSchedulerServiceMixin.java b/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/timeline/TimelineSchedulerServiceMixin.java deleted file mode 100644 index d04934c..0000000 --- a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/timeline/TimelineSchedulerServiceMixin.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2012, Niclas Hedhman. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.zest.library.scheduler.timeline; - -import java.time.ZonedDateTime; -import java.util.SortedSet; -import java.util.TreeSet; -import org.apache.zest.api.injection.scope.Structure; -import org.apache.zest.api.injection.scope.This; -import org.apache.zest.api.service.ServiceComposite; -import org.apache.zest.api.structure.Module; -import org.apache.zest.functional.Iterables; -import org.apache.zest.library.scheduler.SchedulerService; -import org.apache.zest.library.scheduler.SchedulesHandler; -import org.apache.zest.library.scheduler.Schedule; -import org.apache.zest.library.scheduler.internal.Schedules; - -/** - * WARN TimelineService Mixin use SortedSets to keep records ordered and repeatedly search for the next run. - * Could be greedy with large intervals - */ -public abstract class TimelineSchedulerServiceMixin - implements Timeline, ServiceComposite -{ - @Structure - private Module module; - - @This - private SchedulerService scheduler; - - @This - private SchedulesHandler schedulesHandler; - - @Override - public Iterable<TimelineRecord> getLastRecords( int maxResults ) - { - SortedSet<TimelineRecord> result = new TreeSet<>(); - - Schedules schedules = schedulesHandler.getActiveSchedules(); - for( Schedule schedule : schedules.schedules() ) - { - Timeline timeline = (Timeline) schedule; - Iterable<TimelineRecord> lastRecords = timeline.getLastRecords( maxResults ); - Iterables.addAll( result, lastRecords ); - } - return Iterables.limit( maxResults, Iterables.reverse( result ) ); - } - - @Override - public Iterable<TimelineRecord> getNextRecords( int maxResults ) - { - SortedSet<TimelineRecord> result = new TreeSet<>(); - Schedules schedules = schedulesHandler.getActiveSchedules(); - for( Schedule schedule : schedules.schedules() ) - { - Timeline timeline = (Timeline) schedule; - Iterable<TimelineRecord> lastRecords = timeline.getNextRecords( maxResults ); - Iterables.addAll( result, lastRecords ); - } - return Iterables.limit( maxResults, result ); - } - - @Override - public Iterable<TimelineRecord> getRecords( ZonedDateTime from, ZonedDateTime to ) - { - SortedSet<TimelineRecord> result = new TreeSet<>(); - - Schedules schedules = schedulesHandler.getActiveSchedules(); - for( Schedule schedule : schedules.schedules() ) - { - Timeline timeline = (Timeline) schedule; - Iterable<TimelineRecord> lastRecords = timeline.getRecords( from, to ); - Iterables.addAll( result, lastRecords ); - } - return result; - } - - @Override - public Iterable<TimelineRecord> getRecords( long from, long to ) - { - SortedSet<TimelineRecord> result = new TreeSet<>(); - - Schedules schedules = schedulesHandler.getActiveSchedules(); - for( Schedule schedule : schedules.schedules() ) - { - Timeline timeline = (Timeline) schedule; - Iterable<TimelineRecord> lastRecords = timeline.getRecords( from, to ); - Iterables.addAll( result, lastRecords ); - } - return result; - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/551c04d5/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/timeline/package.html ---------------------------------------------------------------------- diff --git a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/timeline/package.html b/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/timeline/package.html deleted file mode 100644 index 1b757d2..0000000 --- a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/timeline/package.html +++ /dev/null @@ -1,21 +0,0 @@ -<!-- -Licensed to the Apache Software Foundation (ASF) under one or more -contributor license agreements. See the NOTICE file distributed with -this work for additional information regarding copyright ownership. -The ASF licenses this file to You under the Apache License, Version 2.0 -(the "License"); you may not use this file except in compliance with -the License. You may obtain a copy of the License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. ---> -<html> - <body> - <h2>Scheduler Timeline.</h2> - </body> -</html> \ No newline at end of file
