-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
TaskExecutor.java
68 lines (61 loc) · 2.58 KB
/
TaskExecutor.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* Copyright (c) 2002-2016 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.unsafe.impl.batchimport.executor;
import java.util.concurrent.ExecutorService;
import org.neo4j.unsafe.impl.batchimport.Parallelizable;
/**
* Like an {@link ExecutorService} with additional absolute control of the current processor count,
* i.e. the number of threads executing the tasks in parallel.
*
* @param <LOCAL> object/state local to each thread, that submitted {@link Task tasks} can get access to
* when {@link Task#run(Object) running}.
*/
public interface TaskExecutor<LOCAL> extends Parallelizable
{
int SF_AWAIT_ALL_COMPLETED = 0x1;
int SF_ABORT_QUEUED = 0x2;
/**
* Submits a task to be executed by one of the processors in this {@link TaskExecutor}. Tasks will be
* executed in the order of which they arrive.
*
* @param task a {@link Runnable} defining the task to be executed.
*/
void submit( Task<LOCAL> task );
/**
* Shuts down this {@link TaskExecutor}, disallowing new tasks to be {@link #submit(Task) submitted}.
*
* @param flags {@link #SF_AWAIT_ALL_COMPLETED} will wait for all queued or already executing tasks to be
* executed and completed, before returning from this method. {@link #SF_ABORT_QUEUED} will have
* submitted tasks which haven't started executing yet cancelled, never to be executed.
*/
void shutdown( int flags );
/**
* @return {@code true} if {@link #shutdown(int)} has been called, otherwise {@code false}.
*/
boolean isShutdown();
/**
* Asserts that this {@link TaskExecutor} is healthy. Useful to call when deciding to wait on a condition
* this executor is expected to fulfill.
*
* @throws RuntimeException of some sort if this executor is in a bad stage, the original error that
* made this executor fail.
*/
void assertHealthy();
}