Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ language: java
sudo: false

notifications:
email: false
email: false

env:
- TEST_DIR=ThreadPool
script: cd $TEST_DIR && ./gradlew clean check
15 changes: 15 additions & 0 deletions ThreadPool/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
group 'ru.spbau.dkaznacheev'
version '1.0-SNAPSHOT'

apply plugin: 'java'

sourceCompatibility = 1.8

repositories {
mavenCentral()
}

dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile group: 'org.jetbrains', name: 'annotations', version: '13.0'
}
Binary file added ThreadPool/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions ThreadPool/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Fri Mar 09 02:05:00 MSK 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-rc-2-all.zip
172 changes: 172 additions & 0 deletions ThreadPool/gradlew

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

84 changes: 84 additions & 0 deletions ThreadPool/gradlew.bat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions ThreadPool/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
rootProject.name = 'ThreadPool'
rootProject.name = 'ThreadPool'

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package ru.spbau.dkaznacheev.threadpool;

import java.util.function.Function;

public interface LightFuture<T> {

/**
* Returns whether a computation is completed.
* @return whether a computation is completed
*/
boolean isReady();

/**
* Returns the result of the computation, if it is not completed, this method blocks the execution.
* @return result of the computation
* @throws LightFutureException if an exception occurred during a computation
*/
T get() throws LightFutureException;

/**
* Applies the result of current computation to another and returns another computation's LightFuture.
* @param function the function to compute with this LightFuture's result
* @param <U> type that the function returns
* @return the result of the function
*/
<U> LightFuture<U> thenApply(Function<T, U> function);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ru.spbau.dkaznacheev.threadpool;

/**
* An Exception that is thrown when a computation in ThreadPool throws an Exception.
*/
public class LightFutureException extends RuntimeException {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package ru.spbau.dkaznacheev.threadpool;

import java.util.function.Supplier;

/**
* ThreadPool interface. It is capable of adding tasks to it and shutting down all of current workers.
*/
public interface ThreadPool {
/**
* Adds a task to the pool, returning a LightFuture object.
* @param supplier supplier for the computation
* @param <T> type of the result
* @return LightFuture object that will contain the result of computation
*/
<T> LightFuture<T> addTask(Supplier<T> supplier);

/**
* Shuts down all of its current workers.
*/
void shutdown() throws InterruptedException;
}
Loading