-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d1ab3a1
commit c5a569c
Showing
5 changed files
with
80 additions
and
7 deletions.
There are no files selected for viewing
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
39 changes: 39 additions & 0 deletions
39
smoothcloud-node/src/main/java/eu/smoothcloud/node/util/ThreadBound.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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package eu.smoothcloud.node.util; | ||
|
||
import java.util.concurrent.Future; | ||
|
||
public class ThreadBound<T> { | ||
|
||
private final String taskName; | ||
private final ThreadManager threadManager; | ||
private final T instance; | ||
|
||
public ThreadBound(ThreadManager manager, String taskName, T instance) { | ||
this.taskName = taskName; | ||
this.threadManager = manager; | ||
this.instance = instance; | ||
} | ||
|
||
public <R> Future<R> callOnThread(CallableInstance<T, R> callable) { | ||
return threadManager.submitTask(taskName, () -> callable.call(instance)); | ||
} | ||
|
||
public void runOnThread(ConsumerInstance<T> consumer) { | ||
threadManager.startTask(taskName, () -> consumer.accept(instance)); | ||
} | ||
|
||
public T getInstance() { | ||
return instance; | ||
} | ||
|
||
@FunctionalInterface | ||
public interface CallableInstance<T, R> { | ||
R call(T instance); | ||
} | ||
|
||
@FunctionalInterface | ||
public interface ConsumerInstance<T> { | ||
void accept(T instance); | ||
} | ||
|
||
} |
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