Skip to content
This repository was archived by the owner on Sep 1, 2024. It is now read-only.

Commit 594044c

Browse files
committed
Scheduler API (initial specification)
1 parent 0abb3fb commit 594044c

18 files changed

Lines changed: 648 additions & 69 deletions

File tree

eu.dariolucia.reatmetric.api/src/main/java/eu/dariolucia/reatmetric/api/IReatmetricSystem.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import eu.dariolucia.reatmetric.api.model.ISystemModelProvisionService;
3131
import eu.dariolucia.reatmetric.api.parameters.IParameterDataProvisionService;
3232
import eu.dariolucia.reatmetric.api.rawdata.IRawDataProvisionService;
33+
import eu.dariolucia.reatmetric.api.scheduler.IScheduledActivityDataProvisionService;
34+
import eu.dariolucia.reatmetric.api.scheduler.IScheduler;
3335
import eu.dariolucia.reatmetric.api.transport.ITransportConnector;
3436

3537
import java.util.List;
@@ -67,5 +69,9 @@ public interface IReatmetricSystem extends IDebugInfoProvider {
6769

6870
IActivityExecutionService getActivityExecutionService() throws ReatmetricException;
6971

72+
IScheduler getScheduler() throws ReatmetricException;
73+
74+
IScheduledActivityDataProvisionService getScheduledActivityDataMonitorService() throws ReatmetricException;
75+
7076
List<ITransportConnector> getTransportConnectors() throws ReatmetricException;
7177
}

eu.dariolucia.reatmetric.api/src/main/java/eu/dariolucia/reatmetric/api/processing/input/AbstractInputDataItem.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package eu.dariolucia.reatmetric.api.processing.input;
1818

19-
public abstract class AbstractInputDataItem {
19+
import java.io.Serializable;
20+
21+
public abstract class AbstractInputDataItem implements Serializable {
2022
// Marker class
2123
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package eu.dariolucia.reatmetric.api.scheduler;
22

3-
public abstract class AbstractSchedulingTrigger {
3+
import java.io.Serializable;
4+
5+
public abstract class AbstractSchedulingTrigger implements Serializable {
46

57
}

eu.dariolucia.reatmetric.api/src/main/java/eu/dariolucia/reatmetric/api/scheduler/IScheduler.java

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,31 @@
22

33
import eu.dariolucia.reatmetric.api.common.IUniqueId;
44
import eu.dariolucia.reatmetric.api.scheduler.exceptions.SchedulingException;
5+
import eu.dariolucia.reatmetric.api.scheduler.input.SchedulingRequest;
56

67
import java.time.Instant;
78
import java.util.List;
89

9-
public interface IScheduler {
10+
/**
11+
* Interface implemented by a ReatMetric scheduler, allowing the change in the scheduler state as well as
12+
* the capability to create, update and remove scheduled activities.
13+
*/
14+
public interface IScheduler extends IScheduledActivityDataProvisionService {
1015

16+
void initialise() throws SchedulingException;
17+
18+
/**
19+
* Subscribe the provided subscriber to the scheduler, to know the current scheduler state.
20+
*
21+
* @param subscriber the subscriber
22+
*/
1123
void subscribe(ISchedulerSubscriber subscriber);
1224

25+
/**
26+
* Unsubscribe the provided subscriber.
27+
*
28+
* @param subscriber the subscriber
29+
*/
1330
void unsubscribe(ISchedulerSubscriber subscriber);
1431

1532
void enable() throws SchedulingException;
@@ -22,6 +39,26 @@ public interface IScheduler {
2239

2340
List<ScheduledActivityData> schedule(List<SchedulingRequest> request, CreationConflictStrategy conflictStrategy) throws SchedulingException;
2441

42+
/**
43+
* Return the list of the activities currently in the state {@link SchedulingState#SCHEDULED}.
44+
*
45+
* @return the list of the activities currently in the state {@link SchedulingState#SCHEDULED}
46+
* @throws SchedulingException in case of issues when executing the method
47+
*/
48+
List<ScheduledActivityData> getCurrentScheduledActivities() throws SchedulingException;
49+
50+
/**
51+
* Update the scheduled activity indicated by originalId with the new data coming from the provided {@link SchedulingRequest}.
52+
*
53+
* The scheduled activity can be updated only if it is in the {@link SchedulingState#SCHEDULED} state.
54+
*
55+
* @param originalId the original scheduled activity to update
56+
* @param newRequest the new request
57+
* @param conflictStrategy the creation conflict strategy to be used in case of resource conflict
58+
* @return the updated scheduled activity data
59+
* @throws SchedulingException in case the conflict strategy does not allow proper resolution or in case the scheduled activity is not
60+
* in the expected state
61+
*/
2562
ScheduledActivityData update(IUniqueId originalId, SchedulingRequest newRequest, CreationConflictStrategy conflictStrategy) throws SchedulingException;
2663

2764
boolean remove(IUniqueId scheduledId) throws SchedulingException;
@@ -33,7 +70,7 @@ public interface IScheduler {
3370
* and adds the new scheduling requests. This is effectively the operation needed to replace schedule increments belonging to
3471
* a given source.
3572
*
36-
* If a merge is requested, method {@link IScheduler#schedule(List, CreationConflictStrategy)} should be used.
73+
* If a merge is instead requested, method {@link IScheduler#schedule(List, CreationConflictStrategy)} should be used.
3774
*
3875
* @param startTime the start of the schedule increment
3976
* @param endTime the end of the schedule increments
@@ -42,7 +79,7 @@ public interface IScheduler {
4279
* @param conflictStrategy the conflict strategy to use with respect to resources
4380
* @return the list of scheduled operations
4481
*/
45-
List<ScheduledActivityData> reload(Instant startTime, Instant endTime, List<SchedulingRequest> requests, String source, CreationConflictStrategy conflictStrategy);
82+
List<ScheduledActivityData> load(Instant startTime, Instant endTime, List<SchedulingRequest> requests, String source, CreationConflictStrategy conflictStrategy);
4683

4784

4885

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) 2020 Dario Lucia (https://www.dariolucia.eu)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package eu.dariolucia.reatmetric.api.scheduler;
18+
19+
import eu.dariolucia.reatmetric.api.archive.IArchive;
20+
import eu.dariolucia.reatmetric.api.archive.exceptions.ArchiveException;
21+
import eu.dariolucia.reatmetric.api.scheduler.exceptions.SchedulingException;
22+
23+
/**
24+
* This interface is the service interface representing the scheduling service in a ReatMetric system. It contains
25+
* a single factory method that can be used to instantiate an implementation of the {@link IScheduler} interface.
26+
*/
27+
public interface ISchedulerFactory {
28+
29+
/**
30+
* Return an implementation of the {@link IScheduler} interface supplied by the provider of the service. The
31+
* archive argument allows the implementation to restore the current status from the archive.
32+
*
33+
* The returned {@link IScheduler} object is not required to be a different new object: {@link ISchedulerFactory}
34+
* implementations are allowed to cache objects or use a singleton-based design.
35+
*
36+
* @param archive the archive system, can be null: in such case, nothing is restored
37+
* @return an implementation of {@link IScheduler} interface
38+
* @throws SchedulingException in case of problems arising from the construction of the specific {@link IScheduler} object
39+
*/
40+
IScheduler buildScheduler(IArchive archive) throws SchedulingException;
41+
42+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
package eu.dariolucia.reatmetric.api.scheduler;
22

3+
/**
4+
* Interface subscriber for the scheduler state.
5+
*/
36
public interface ISchedulerSubscriber {
47

8+
/**
9+
* Report the enablement status of the scheduler when it changes.
10+
*
11+
* @param enabled true if the scheduler is enabled
12+
*/
513
void schedulerEnablementChanged(boolean enabled);
614

715
}

eu.dariolucia.reatmetric.api/src/main/java/eu/dariolucia/reatmetric/api/scheduler/ScheduledActivityData.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import eu.dariolucia.reatmetric.api.processing.input.ActivityRequest;
66

77
import java.time.Instant;
8+
import java.util.Collection;
89
import java.util.Set;
910

1011
public final class ScheduledActivityData extends AbstractDataItem {
@@ -27,11 +28,36 @@ public final class ScheduledActivityData extends AbstractDataItem {
2728

2829
private final SchedulingState state;
2930

30-
public ScheduledActivityData(IUniqueId internalId, Instant generationTime, ActivityRequest request, IUniqueId activityOccurrence, Set<String> resources, String source, long externalId, AbstractSchedulingTrigger trigger, Instant latestInvocationTime, ConflictStrategy conflictStrategy, SchedulingState state, Object extension) {
31+
/**
32+
*
33+
* @param internalId
34+
* @param generationTime
35+
* @param request
36+
* @param activityOccurrence
37+
* @param resources the resources required by this activity: not null, each string can contain any characters except whitespaces
38+
* @param source
39+
* @param externalId
40+
* @param trigger
41+
* @param latestInvocationTime
42+
* @param conflictStrategy
43+
* @param state
44+
* @param extension
45+
*/
46+
public ScheduledActivityData(IUniqueId internalId, Instant generationTime, ActivityRequest request, IUniqueId activityOccurrence, Collection<String> resources, String source, long externalId, AbstractSchedulingTrigger trigger, Instant latestInvocationTime, ConflictStrategy conflictStrategy, SchedulingState state, Object extension) {
3147
super(internalId, generationTime, extension);
48+
if(resources == null) {
49+
throw new NullPointerException("Resources cannot be null");
50+
}
51+
for(String res : resources) {
52+
if(res.isBlank()) {
53+
throw new IllegalArgumentException("Resource '" + res + "' is blank");
54+
} else if(res.indexOf(' ') != -1) {
55+
throw new IllegalArgumentException("Resource '" + res + "' contains whitespaces (forbidden)");
56+
}
57+
}
3258
this.request = request;
3359
this.activityOccurrence = activityOccurrence;
34-
this.resources = resources;
60+
this.resources = Set.copyOf(resources);
3561
this.source = source;
3662
this.externalId = externalId;
3763
this.trigger = trigger;

eu.dariolucia.reatmetric.api/src/main/java/eu/dariolucia/reatmetric/api/scheduler/SchedulingRequest.java

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package eu.dariolucia.reatmetric.api.scheduler.input;
2+
3+
import eu.dariolucia.reatmetric.api.processing.input.AbstractInputDataItem;
4+
import eu.dariolucia.reatmetric.api.processing.input.ActivityRequest;
5+
import eu.dariolucia.reatmetric.api.scheduler.AbstractSchedulingTrigger;
6+
import eu.dariolucia.reatmetric.api.scheduler.ConflictStrategy;
7+
8+
import java.time.Instant;
9+
import java.util.Set;
10+
11+
public final class SchedulingRequest extends AbstractInputDataItem {
12+
13+
private final ActivityRequest request;
14+
15+
private final Set<String> resources;
16+
17+
private final String source;
18+
19+
private final long externalId;
20+
21+
private final AbstractSchedulingTrigger trigger;
22+
23+
private final Instant latestInvocationTime;
24+
25+
private final ConflictStrategy conflictStrategy;
26+
27+
public SchedulingRequest(ActivityRequest request, Set<String> resources, String source, long externalId, AbstractSchedulingTrigger trigger, Instant latestInvocationTime, ConflictStrategy conflictStrategy) {
28+
this.request = request;
29+
this.resources = resources;
30+
this.source = source;
31+
this.externalId = externalId;
32+
this.trigger = trigger;
33+
this.latestInvocationTime = latestInvocationTime;
34+
this.conflictStrategy = conflictStrategy;
35+
}
36+
37+
public ActivityRequest getRequest() {
38+
return request;
39+
}
40+
41+
public Set<String> getResources() {
42+
return resources;
43+
}
44+
45+
public String getSource() {
46+
return source;
47+
}
48+
49+
public long getExternalId() {
50+
return externalId;
51+
}
52+
53+
public AbstractSchedulingTrigger getTrigger() {
54+
return trigger;
55+
}
56+
57+
public Instant getLatestInvocationTime() {
58+
return latestInvocationTime;
59+
}
60+
61+
public ConflictStrategy getConflictStrategy() {
62+
return conflictStrategy;
63+
}
64+
}
65+

eu.dariolucia.reatmetric.api/src/main/java/module-info.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
exports eu.dariolucia.reatmetric.api.processing.exceptions;
2121
exports eu.dariolucia.reatmetric.api.processing.input;
2222
exports eu.dariolucia.reatmetric.api.processing.scripting;
23+
exports eu.dariolucia.reatmetric.api.scheduler;
24+
exports eu.dariolucia.reatmetric.api.scheduler.exceptions;
25+
exports eu.dariolucia.reatmetric.api.scheduler.input;
2326
exports eu.dariolucia.reatmetric.api.transport;
2427
exports eu.dariolucia.reatmetric.api.transport.exceptions;
2528
}

0 commit comments

Comments
 (0)