Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract inner classes out of the JobScheduler interface, and into top…
…-level.
- Loading branch information
Showing
52 changed files
with
262 additions
and
157 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
community/common/src/main/java/org/neo4j/scheduler/CancelListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,33 @@ | |||
/* | |||
* Copyright (c) 2002-2018 "Neo4j," | |||
* Neo4j Sweden AB [http://neo4j.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.scheduler; | |||
|
|||
/** | |||
* Gets notified about calls to {@link JobHandle#cancel(boolean)}. | |||
*/ | |||
public interface CancelListener | |||
{ | |||
/** | |||
* Notification that {@link JobHandle#cancel(boolean)} was called. | |||
* | |||
* @param mayInterruptIfRunning argument from {@link JobHandle#cancel(boolean)} call. | |||
*/ | |||
void cancelled( boolean mayInterruptIfRunning ); | |||
} |
75 changes: 75 additions & 0 deletions
75
community/common/src/main/java/org/neo4j/scheduler/Group.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,75 @@ | |||
/* | |||
* Copyright (c) 2002-2018 "Neo4j," | |||
* Neo4j Sweden AB [http://neo4j.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.scheduler; | |||
|
|||
import java.util.Objects; | |||
import java.util.concurrent.atomic.AtomicInteger; | |||
|
|||
/** | |||
* Represents a common group of jobs, defining how they should be scheduled. | |||
*/ | |||
public final class Group | |||
{ | |||
private final AtomicInteger threadCounter = new AtomicInteger(); | |||
private final String name; | |||
|
|||
Group( String name ) | |||
{ | |||
Objects.requireNonNull( name, "Group name cannot be null." ); | |||
this.name = name; | |||
} | |||
|
|||
public String name() | |||
{ | |||
return name; | |||
} | |||
|
|||
/** | |||
* Name a new thread. This method may or may not be used, it is up to the scheduling strategy to decide | |||
* to honor this. | |||
*/ | |||
public String threadName() | |||
{ | |||
return "neo4j." + name() + "-" + threadCounter.incrementAndGet(); | |||
} | |||
|
|||
@Override | |||
public boolean equals( Object o ) | |||
{ | |||
if ( this == o ) | |||
{ | |||
return true; | |||
} | |||
if ( o == null || getClass() != o.getClass() ) | |||
{ | |||
return false; | |||
} | |||
|
|||
Group group = (Group) o; | |||
|
|||
return name.equals( group.name ); | |||
} | |||
|
|||
@Override | |||
public int hashCode() | |||
{ | |||
return name.hashCode(); | |||
} | |||
} |
35 changes: 35 additions & 0 deletions
35
community/common/src/main/java/org/neo4j/scheduler/JobHandle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,35 @@ | |||
/* | |||
* Copyright (c) 2002-2018 "Neo4j," | |||
* Neo4j Sweden AB [http://neo4j.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.scheduler; | |||
|
|||
import java.util.concurrent.CancellationException; | |||
import java.util.concurrent.ExecutionException; | |||
|
|||
public interface JobHandle | |||
{ | |||
void cancel( boolean mayInterruptIfRunning ); | |||
|
|||
void waitTermination() throws InterruptedException, ExecutionException, CancellationException; | |||
|
|||
default void registerCancelListener( CancelListener listener ) | |||
{ | |||
throw new UnsupportedOperationException( "Unsupported in this implementation" ); | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.