http://git-wip-us.apache.org/repos/asf/zest-java/blob/8915dfaa/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 94e25b5..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.unitofwork.UnitOfWork; -import org.apache.zest.api.unitofwork.UnitOfWorkFactory; -import org.apache.zest.api.usecase.UsecaseBuilder; -import org.apache.zest.library.scheduler.Schedule; -import org.apache.zest.library.scheduler.Task; - -public class TaskRunner - implements Runnable -{ - private static ReentrantLock lock = new ReentrantLock(); - - @Structure - private UnitOfWorkFactory uowf; - - @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 = uowf.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 = uowf.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 = uowf.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/8915dfaa/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/internal/package.html ---------------------------------------------------------------------- diff --git a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/internal/package.html b/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/internal/package.html deleted file mode 100644 index 8ad4911..0000000 --- a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/internal/package.html +++ /dev/null @@ -1,24 +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 Internals.</h2> - </body> -</html> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/8915dfaa/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 88c9599..0000000 --- a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/package.html +++ /dev/null @@ -1,24 +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/8915dfaa/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 f65aa12..0000000 --- a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/schedule/package.html +++ /dev/null @@ -1,24 +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/8915dfaa/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 fac381d..0000000 --- a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/timeline/Timeline.java +++ /dev/null @@ -1,75 +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.timeline; - -import java.time.Instant; -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( Instant from, Instant to ); -} -// END SNIPPET: timeline http://git-wip-us.apache.org/repos/asf/zest-java/blob/8915dfaa/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 6c50651..0000000 --- a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/timeline/TimelineForScheduleConcern.java +++ /dev/null @@ -1,93 +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.timeline; - -import java.io.BufferedOutputStream; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.time.Instant; -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( Instant.now() ); - 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/8915dfaa/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 39108a9..0000000 --- a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/timeline/TimelineRecord.java +++ /dev/null @@ -1,81 +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.timeline; - -import java.time.Instant; -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<Instant> 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/8915dfaa/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 583a831..0000000 --- a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/timeline/TimelineRecordStep.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.timeline; - -public enum TimelineRecordStep -{ - STARTED, - SUCCESS, - FAILURE, - FUTURE -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/8915dfaa/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 9143bcf..0000000 --- a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/timeline/TimelineScheduleMixin.java +++ /dev/null @@ -1,141 +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.timeline; - -import java.time.Instant; -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<>(); - Instant time = Instant.now(); - 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(), to.toInstant() ); - } - - @Override - public Iterable<TimelineRecord> getRecords( Instant from, Instant to ) - { - Instant now = Instant.now(); - SortedSet<TimelineRecord> result = new TreeSet<>(); - result.addAll( getPastRecords( from ) ); - result.addAll( getFutureRecords( now, to ) ); - return result; - } - - private Collection<? extends TimelineRecord> getPastRecords( Instant from ) - { - SortedSet<TimelineRecord> result = new TreeSet<>(); - List<TimelineRecord> timelineRecords = state.history().get(); - for( TimelineRecord record : timelineRecords ) - { - Instant timestamp = record.timestamp().get(); - if( timestamp.isAfter( from ) ) - { - result.add( record ); - } - } - return result; - } - - private Collection<? extends TimelineRecord> getFutureRecords( Instant now, Instant to ) - { - if( now.isAfter( to ) ) - { - return Collections.emptyList(); - } - - SortedSet<TimelineRecord> result = new TreeSet<>(); - Instant time = Instant.now(); - while( time.isBefore(to) ) - { - time = me.nextRun( time ); - if( time.isBefore( to ) ) - { - result.add( createFutureRecord( time ) ); - } - } - return result; - } - - private TimelineRecord createFutureRecord( Instant 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/8915dfaa/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 981eb68..0000000 --- a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/timeline/TimelineScheduleState.java +++ /dev/null @@ -1,30 +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.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/8915dfaa/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 41d5a98..0000000 --- a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/timeline/TimelineSchedulerServiceMixin.java +++ /dev/null @@ -1,110 +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.timeline; - -import java.time.Instant; -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( Instant from, Instant 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/8915dfaa/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 765cabc..0000000 --- a/libraries/scheduler/src/main/java/org/apache/zest/library/scheduler/timeline/package.html +++ /dev/null @@ -1,24 +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 http://git-wip-us.apache.org/repos/asf/zest-java/blob/8915dfaa/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/AbstractSchedulerTest.java ---------------------------------------------------------------------- diff --git a/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/AbstractSchedulerTest.java b/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/AbstractSchedulerTest.java deleted file mode 100644 index f1ca8cc..0000000 --- a/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/AbstractSchedulerTest.java +++ /dev/null @@ -1,76 +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; - -import org.apache.zest.api.entity.EntityBuilder; -import org.apache.zest.api.entity.IdentityGenerator; -import org.apache.zest.api.unitofwork.UnitOfWork; -import org.apache.zest.api.value.ValueSerialization; -import org.apache.zest.bootstrap.AssemblyException; -import org.apache.zest.bootstrap.ModuleAssembly; -import org.apache.zest.bootstrap.ServiceDeclaration; -import org.apache.zest.entitystore.memory.MemoryEntityStoreService; -import org.apache.zest.index.rdf.assembly.RdfMemoryStoreAssembler; -import org.apache.zest.spi.uuid.UuidIdentityGeneratorService; -import org.apache.zest.test.AbstractZestTest; -import org.apache.zest.test.EntityTestAssembler; -import org.apache.zest.valueserialization.orgjson.OrgJsonValueSerializationService; - -public abstract class AbstractSchedulerTest - extends AbstractZestTest -{ - @Override - public final void assemble( ModuleAssembly assembly ) - throws AssemblyException - { - assembly.entities( FooTask.class ); - - assembly.services( MemoryEntityStoreService.class ); - assembly.services( UuidIdentityGeneratorService.class).withMixins( CountingIdentityGeneratorService.class ); - assembly.services( OrgJsonValueSerializationService.class ).taggedWith( ValueSerialization.Formats.JSON ); - new RdfMemoryStoreAssembler().assemble( assembly ); - - onAssembly( assembly ); - } - - protected abstract void onAssembly( ModuleAssembly module ) - throws AssemblyException; - - protected final FooTask createFooTask( UnitOfWork uow, String name, String input ) - { - EntityBuilder<FooTask> builder = uow.newEntityBuilder( FooTask.class ); - FooTask task = builder.instance(); - task.name().set( name ); - task.input().set( input ); - return builder.newInstance(); - } - - public static class CountingIdentityGeneratorService - implements IdentityGenerator - { - int counter = 0; - - @Override - public String generate( Class<?> compositeType ) - { - return compositeType.getSimpleName() + ":" + counter++; - } - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/8915dfaa/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/Constants.java ---------------------------------------------------------------------- diff --git a/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/Constants.java b/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/Constants.java deleted file mode 100644 index db61858..0000000 --- a/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/Constants.java +++ /dev/null @@ -1,27 +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; - -// TODO Rename to TestConstants -public interface Constants -{ - String BAR = "bar"; - String BAZAR = "bazar"; -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/8915dfaa/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/CronScheduleTest.java ---------------------------------------------------------------------- diff --git a/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/CronScheduleTest.java b/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/CronScheduleTest.java deleted file mode 100644 index a346f83..0000000 --- a/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/CronScheduleTest.java +++ /dev/null @@ -1,78 +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; - -import java.time.Instant; -import org.apache.zest.api.entity.EntityBuilder; -import org.apache.zest.api.unitofwork.UnitOfWork; -import org.apache.zest.bootstrap.AssemblyException; -import org.apache.zest.bootstrap.ModuleAssembly; -import org.apache.zest.test.AbstractZestTest; -import org.apache.zest.test.EntityTestAssembler; -import org.junit.Test; - -import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertThat; - -public class CronScheduleTest extends AbstractZestTest -{ - @Override - public void assemble( ModuleAssembly module ) - throws AssemblyException - { - new EntityTestAssembler().assemble( module ); - module.entities( CronSchedule.class ); - module.entities( Task.class ).withMixins( DummyTask.class ); - } - - @Test - public void given15SecondCronWhenRequestingNextExpectEvery15Seconds() - throws Exception - { - - UnitOfWork work = unitOfWorkFactory.newUnitOfWork(); - EntityBuilder<Task> builder1 = work.newEntityBuilder( Task.class ); - builder1.instance().name().set( "abc" ); - Task task = builder1.newInstance(); - EntityBuilder<CronSchedule> builder = work.newEntityBuilder( CronSchedule.class ); - builder.instance().start().set( Instant.now() ); - builder.instance().task().set( task ); - builder.instance().cronExpression().set( "*/15 * * * * *" ); - CronSchedule schedule = builder.newInstance(); - Instant nextRun = schedule.nextRun( Instant.now()); - for( int i = 0; i < 1000; i++ ) - { - Instant previousRun = nextRun; - nextRun = schedule.nextRun( previousRun ); - assertThat( "nextRun( previousRun + 1s ) @" + i, nextRun, equalTo( previousRun.plusSeconds( 15 )) ); - } - work.discard(); - } - - public static abstract class DummyTask implements Task - { - @Override - public void run() - { - System.out.println( "Dummy" ); - } - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/8915dfaa/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/FooTask.java ---------------------------------------------------------------------- diff --git a/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/FooTask.java b/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/FooTask.java deleted file mode 100644 index 8718dbd..0000000 --- a/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/FooTask.java +++ /dev/null @@ -1,77 +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; - -import org.apache.zest.api.common.Optional; -import org.apache.zest.api.common.UseDefaults; -import org.apache.zest.api.entity.Identity; -import org.apache.zest.api.injection.scope.This; -import org.apache.zest.api.mixin.Mixins; -import org.apache.zest.api.property.Property; -import org.apache.zest.api.unitofwork.concern.UnitOfWorkPropagation; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import static org.apache.zest.api.unitofwork.concern.UnitOfWorkPropagation.Propagation.REQUIRES_NEW; - -@Mixins( FooTask.Mixin.class ) -public interface FooTask - extends Task, Identity -{ - Property<String> input(); - - @Optional - Property<String> output(); - - @UseDefaults - Property<Integer> runCounter(); - - abstract class Mixin - implements Task - { - private static final Logger LOGGER = LoggerFactory.getLogger( FooTask.class ); - - @This - private FooTask me; - - @Override - public void run() - { - LOGGER.info( "FooTask.run({})", me.input().get() ); - synchronized( this ) - { - me.runCounter().set( me.runCounter().get() + 1 ); - LOGGER.info( "Identity: " + me.identity().get() ); - LOGGER.info( " Counter: " + me.runCounter().get() ); - } - if( me.input().get().equals( Constants.BAZAR ) ) - { - if( me.output().get() == null ) - { - me.output().set( Constants.BAR ); - } - else - { - me.output().set( me.output().get() + Constants.BAR ); - } - } - } - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/8915dfaa/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/SchedulerTest.java ---------------------------------------------------------------------- diff --git a/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/SchedulerTest.java b/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/SchedulerTest.java deleted file mode 100644 index 9f3eae6..0000000 --- a/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/SchedulerTest.java +++ /dev/null @@ -1,206 +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; - -import java.time.Duration; -import java.time.ZonedDateTime; -import java.util.concurrent.Callable; -import org.apache.zest.api.common.Visibility; -import org.apache.zest.api.unitofwork.UnitOfWork; -import org.apache.zest.api.unitofwork.UnitOfWorkCompletionException; -import org.apache.zest.api.usecase.Usecase; -import org.apache.zest.api.usecase.UsecaseBuilder; -import org.apache.zest.bootstrap.AssemblyException; -import org.apache.zest.bootstrap.ModuleAssembly; -import org.apache.zest.library.scheduler.bootstrap.SchedulerAssembler; -import org.apache.zest.library.scheduler.timeline.Timeline; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import static com.jayway.awaitility.Awaitility.await; -import static java.util.concurrent.TimeUnit.MILLISECONDS; -import static java.util.concurrent.TimeUnit.SECONDS; -import static org.apache.zest.functional.Iterables.count; -import static org.apache.zest.library.scheduler.Constants.BAR; -import static org.apache.zest.library.scheduler.Constants.BAZAR; -import static org.hamcrest.core.Is.is; -import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertThat; - -public class SchedulerTest - extends AbstractSchedulerTest -{ - private static final Logger LOGGER = LoggerFactory.getLogger( SchedulerTest.class ); - - @Override - protected void onAssembly( ModuleAssembly testAssembly ) - throws AssemblyException - { - @SuppressWarnings( "UnnecessaryLocalVariable" ) - ModuleAssembly moduleAssembly = testAssembly; - - @SuppressWarnings( "UnnecessaryLocalVariable" ) - ModuleAssembly configModuleAssembly = testAssembly; - - // START SNIPPET: assembly - new SchedulerAssembler().visibleIn( Visibility.application ) - .withConfig( configModuleAssembly, Visibility.layer ) - .withTimeline() - .assemble( moduleAssembly ); - // END SNIPPET: assembly - } - - @Test - public void testTaskWithoutScheduling() - throws UnitOfWorkCompletionException - { - Usecase usecase = UsecaseBuilder.newUsecase( "testTask" ); - String taskId; - try( UnitOfWork uow = unitOfWorkFactory.newUnitOfWork( usecase ) ) - { - FooTask task = createFooTask( uow, "TestTask", BAZAR ); - taskId = task.identity().get(); - task.run(); - uow.complete(); - } - try( UnitOfWork uow = unitOfWorkFactory.newUnitOfWork( usecase ) ) - { - FooTask task = uow.get( FooTask.class, taskId ); - assertThat( task.runCounter().get(), equalTo( 1 ) ); - assertThat( task.output().get(), equalTo( BAR ) ); - } - } - - @Test - public void testMinutely() - throws UnitOfWorkCompletionException - { - Usecase usecase = UsecaseBuilder.newUsecase( "TestMinutely" ); - ZonedDateTime start = ZonedDateTime.now(); - String taskIdentity; - long sleepMillis; - try( UnitOfWork uow = unitOfWorkFactory.newUnitOfWork( usecase ) ) - { - Scheduler scheduler = serviceFinder.findService( Scheduler.class ).get(); - - FooTask task = createFooTask( uow, usecase.name(), BAZAR ); - taskIdentity = task.identity().get(); - - ZonedDateTime expectedRun = start.withNano( 0 ).withSecond( 0 ).plusMinutes( 1 ); - scheduler.scheduleCron( task, "@minutely" ); - - uow.complete(); - - sleepMillis = Duration.between( start, expectedRun ).toMillis(); - LOGGER.info( "Task scheduled on {} to be run at {}", start.toLocalTime(), expectedRun.toLocalTime() ); - } - - await( usecase.name() ) - .atMost( sleepMillis + 5000, MILLISECONDS ) - .until( taskOutput( taskIdentity ), equalTo( 1 ) ); - - //noinspection unused - try( UnitOfWork uow = unitOfWorkFactory.newUnitOfWork( usecase ) ) - { - Timeline timeline = serviceFinder.findService( Timeline.class ).get(); - ZonedDateTime now = ZonedDateTime.now(); - - // Queries returning past records - assertThat( count( timeline.getLastRecords( 5 ) ), - is( 2L ) ); - assertThat( count( timeline.getRecords( start.toInstant(), now.toInstant() ) ), - is( 2L ) ); - - // Queries returning future records - assertThat( count( timeline.getNextRecords( 4 ) ), - is( 4L ) ); - assertThat( count( timeline.getRecords( now.plusNanos( 100000000L ), now.plusMinutes( 5 )) ), - is( 5L ) ); - - // Queries returning mixed past and future records - assertThat( count( timeline.getRecords( start, now.plusMinutes( 5 ) ) ), - is( 7L ) ); - } - } - - @Test - public void testOnce() - throws UnitOfWorkCompletionException, InterruptedException - { - System.setProperty( "zest.entity.print.state", Boolean.TRUE.toString() ); - final Usecase usecase = UsecaseBuilder.newUsecase( "TestOnce" ); - final String taskIdentity; - Scheduler scheduler = serviceFinder.findService( Scheduler.class ).get(); - - Schedule schedule1; - Schedule schedule2; - Schedule schedule3; - Schedule schedule4; - try( UnitOfWork uow = unitOfWorkFactory.newUnitOfWork( usecase ) ) - { - FooTask task = createFooTask( uow, usecase.name(), BAZAR ); - taskIdentity = task.identity().get(); - - schedule1 = scheduler.scheduleOnce( task, 1 ); - schedule2 = scheduler.scheduleOnce( task, 2 ); - schedule3 = scheduler.scheduleOnce( task, 3 ); - schedule4 = scheduler.scheduleOnce( task, 4 ); - - uow.complete(); - } - await( usecase.name() ) - .atMost( 6, SECONDS ) - .until( taskOutput( taskIdentity ), equalTo( 4 ) ); - - try( UnitOfWork uow = unitOfWorkFactory.newUnitOfWork( usecase ) ) - { - schedule1 = uow.get( schedule1 ); - schedule2 = uow.get( schedule2 ); - schedule3 = uow.get( schedule3 ); - schedule4 = uow.get( schedule4 ); - assertThat(schedule1.cancelled().get(), equalTo( false )); - assertThat(schedule2.cancelled().get(), equalTo( false )); - assertThat(schedule3.cancelled().get(), equalTo( false )); - assertThat(schedule4.cancelled().get(), equalTo( false )); - assertThat(schedule1.done().get(), equalTo( true )); - assertThat(schedule2.done().get(), equalTo( true )); - assertThat(schedule3.done().get(), equalTo( true )); - assertThat(schedule4.done().get(), equalTo( true )); - assertThat(schedule1.running().get(), equalTo( false )); - assertThat(schedule2.running().get(), equalTo( false )); - assertThat(schedule3.running().get(), equalTo( false )); - assertThat(schedule4.running().get(), equalTo( false )); - } - } - - private Callable<Integer> taskOutput( final String taskIdentity ) - { - return () -> { - try( UnitOfWork uow = unitOfWorkFactory.newUnitOfWork() ) - { - FooTask task = uow.get( FooTask.class, taskIdentity ); - Integer count = task.runCounter().get(); - uow.discard(); - return count; - } - }; - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/8915dfaa/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/docsupport/SchedulerDocs.java ---------------------------------------------------------------------- diff --git a/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/docsupport/SchedulerDocs.java b/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/docsupport/SchedulerDocs.java deleted file mode 100644 index 047e01e..0000000 --- a/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/docsupport/SchedulerDocs.java +++ /dev/null @@ -1,99 +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.docsupport; - -import org.apache.zest.api.association.Association; -import org.apache.zest.api.injection.scope.Service; -import org.apache.zest.api.injection.scope.This; -import org.apache.zest.api.property.Property; -import org.apache.zest.api.unitofwork.concern.UnitOfWorkDiscardOn; -import org.apache.zest.api.unitofwork.concern.UnitOfWorkPropagation; -import org.apache.zest.api.unitofwork.concern.UnitOfWorkRetry; -import org.apache.zest.library.scheduler.Scheduler; -import org.apache.zest.library.scheduler.Task; -import org.apache.zest.library.scheduler.Schedule; -import org.apache.zest.library.scheduler.timeline.Timeline; - -public class SchedulerDocs -{ - - // START SNIPPET: timeline - @Service - Timeline timeline; -// END SNIPPET: timeline - - // START SNIPPET: 2 - @Service - Scheduler scheduler; - - public void method() - { - MyTaskEntity myTask = todo(); - Schedule schedule = scheduler.scheduleOnce( myTask, 10 ); - // myTask will be run in 10 seconds from now - } - - // END SNIPPET: 2 - MyTaskEntity todo() - { - return null; - } - - // START SNIPPET: 1 - interface MyTaskEntity extends Task - { - Property<String> myTaskState(); - - Association<AnotherEntity> anotherEntity(); - } - - class MyTaskMixin implements Runnable - { - @This - MyTaskEntity me; - - @Override - public void run() - { - me.myTaskState().set( me.anotherEntity().get().doSomeStuff( me.myTaskState().get() ) ); - } - } - - // END SNIPPET: 1 - interface AnotherEntity - { - String doSomeStuff( String p ); - } - - public class MyTask implements Runnable - { - - // START SNIPPET: strategy - @Override - @UnitOfWorkRetry( retries = 3 ) - @UnitOfWorkDiscardOn( IllegalArgumentException.class ) - @UnitOfWorkPropagation( value = UnitOfWorkPropagation.Propagation.REQUIRES_NEW, usecase = "Load Data" ) - public void run() - { - // END SNIPPET: strategy - - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/8915dfaa/libraries/scheduler/src/test/resources/logback-test.xml ---------------------------------------------------------------------- diff --git a/libraries/scheduler/src/test/resources/logback-test.xml b/libraries/scheduler/src/test/resources/logback-test.xml deleted file mode 100644 index 41730a9..0000000 --- a/libraries/scheduler/src/test/resources/logback-test.xml +++ /dev/null @@ -1,35 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ 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. - ~ - ~ - --> -<configuration> - - <appender name="stdout" class="ch.qos.logback.core.ConsoleAppender"> - <layout class="ch.qos.logback.classic.PatternLayout"> - <Pattern>@%-10thread %-5level %logger{20} - %msg%n</Pattern> - </layout> - </appender> - - <root level="info"> - <appender-ref ref="stdout" /> - </root> - - <logger name="org.apache.zest.library.scheduler" level="trace"/> - -</configuration> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/8915dfaa/libraries/scheduler/test-repeatedly.sh ---------------------------------------------------------------------- diff --git a/libraries/scheduler/test-repeatedly.sh b/libraries/scheduler/test-repeatedly.sh deleted file mode 100755 index bb7516b..0000000 --- a/libraries/scheduler/test-repeatedly.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/sh - -# 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. - -# Run clean test once and test repeatedly -# Stop on first failure -# cat build/num-repeats to see how many times it ran -# Use time run-repeatedly.sh to get a time mesure -# -# Written because of milliseconds delays due to multithreading - -set -e - -../../gradlew clean test -Dversion=2.0-SNAPSHOT -echo "x "`date` > build/num-repeats - -while ( true ) ; do - ../../gradlew test -Dversion=2.0-SNAPSHOT - echo "x "`date` >> build/num-repeats -done - -exit 0 http://git-wip-us.apache.org/repos/asf/zest-java/blob/8915dfaa/manual/src/docs/userguide/libraries.txt ---------------------------------------------------------------------- diff --git a/manual/src/docs/userguide/libraries.txt b/manual/src/docs/userguide/libraries.txt index fcbace9..5da7c9e 100644 --- a/manual/src/docs/userguide/libraries.txt +++ b/manual/src/docs/userguide/libraries.txt @@ -115,10 +115,6 @@ include::../../../../libraries/restlet/src/docs/restlet.txt[] :leveloffset: 2 -include::../../../../libraries/scheduler/src/docs/scheduler.txt[] - -:leveloffset: 2 - include::../../../../libraries/servlet/src/docs/servlet.txt[] :leveloffset: 2 http://git-wip-us.apache.org/repos/asf/zest-java/blob/8915dfaa/settings.gradle ---------------------------------------------------------------------- diff --git a/settings.gradle b/settings.gradle index c865591..7cabe8b 100644 --- a/settings.gradle +++ b/settings.gradle @@ -48,7 +48,6 @@ include 'core:functional', 'libraries:rest-common', 'libraries:rest-server', 'libraries:restlet', - 'libraries:scheduler', 'libraries:scripting', 'libraries:servlet', 'libraries:shiro-core',
