Committed by
Gerrit Code Review
[Emu] MutexExecutionService for running tasks that need to run only on a single instance.
Change-Id: Idf9fedbbf15c014e97c77db25aa608cd1db53b27
Showing
3 changed files
with
73 additions
and
0 deletions
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
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 | +package org.onosproject.store.service; | ||
17 | + | ||
18 | +import java.util.concurrent.CompletableFuture; | ||
19 | +import java.util.concurrent.Executor; | ||
20 | + | ||
21 | +/** | ||
22 | + * Service for mutually exclusive job execution. | ||
23 | + */ | ||
24 | +public interface MutexExecutionService { | ||
25 | + | ||
26 | + /** | ||
27 | + * Runs the specified task in a mutually exclusive fashion. | ||
28 | + * @param task task to run | ||
29 | + * @param exclusionPath path on which different instances synchronize | ||
30 | + * @param executor executor to use for running the task | ||
31 | + * @return future that is completed when the task execution completes. | ||
32 | + */ | ||
33 | + CompletableFuture<Void> execute(MutexTask task, String exclusionPath, Executor executor); | ||
34 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
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 | +package org.onosproject.store.service; | ||
17 | + | ||
18 | +/** | ||
19 | + * The MutexTask interface should be implemented by any class whose | ||
20 | + * instances distributed across controllers are intended to be executed | ||
21 | + * in a mutually exclusive fashion. | ||
22 | + */ | ||
23 | +public interface MutexTask { | ||
24 | + | ||
25 | + /** | ||
26 | + * Begins the execution of a mutually exclusive task. | ||
27 | + * The start method will be called once the "lock" is acquired. | ||
28 | + * After the start method returns the lock is released and some other | ||
29 | + * instance can take over execution. | ||
30 | + */ | ||
31 | + void start(); | ||
32 | + | ||
33 | + /** | ||
34 | + * This method will be called when exclusivity of task execution | ||
35 | + * can no longer be guaranteed. The implementation should take necessary steps | ||
36 | + * to halt task execution in order to ensure correctness. | ||
37 | + */ | ||
38 | + void stop(); | ||
39 | +} |
core/store/dist/src/main/java/org/onosproject/store/consistent/impl/MutexExecutionManager.java
0 → 100644
This diff is collapsed. Click to expand it.
-
Please register or login to post a comment