public BackgroundJob run( RunnableThatMayFail runnable ) { final ParallelJobRunner jobRunner = new ParallelJobRunner(runnable, onError); return run( jobRunner ); }
@Override public V get(Object key) { return containsKey( key ) ? value : null; }
@Override public void close() { shutdown(); }
public static <K,V> ChainedMap<K,V> with( K key, V value ) { return new ChainedMap<K,V>().and( key, value ); } }
static String readFileAsString( String fileName, String encoding) { try ( InputStream file = openFile( fileName ) ) { if ( file == null ) throw new IllegalStateException( "File not found: " + fileName ); return readFileAsString( file, encoding ); } catch ( IOException cause ) { throw new IllegalStateException( cause ); } }
static Tuple<String, String> fixContentType( String contentType, String defaultEncoding ){ if ( contentType == null ) return Tuple.empty(); final StringCursor cursor = new StringCursor(contentType); if ( cursor.shiftCursorToNextChar( ';' ) ) { contentType = cursor.substringFromLastMark( 1 ); cursor.mark(1); cursor.end(); defaultEncoding = cursor.substringFromLastMark(); } return Tuple.of( contentType, defaultEncoding ); } }
public <R> BackgroundJob<R> computeInBackground( Class<R> responseType ) { return new BackgroundJob<> (); }
@Override public void close() { await(); }
default void runInBackgroundWithParallelism(final EndpointInboxConsumer consumer, final int parallelism, Threads threads){ for ( int i=0; i<parallelism; i++ ) threads.submit( consumer ); }
public static <K,V> Tuple<K,V> empty(){ return new Tuple<>(null, null); }
public ChainedMap<K,V> and( K key, V value ) { return set( key, value ); }
public void await() { awaitResponses(); } }
default Object call() throws Exception { run(); return null; }
@Override public void putAll(Map<? extends K, ? extends V> m) { if ( m!= null ) m.forEach((key1, value1) -> put(key1, value1)); }
static byte[] readFileAsBytes(InputStream inputStream) { return readFile(inputStream).toByteArray(); }
public static Threads elasticPool() { return new Threads( Executors.newCachedThreadPool() ); }
public <T> BackgroundJob<R> compute( Callable<T> callable ) { final ParallelJobRunner jobRunner = new ParallelJobRunner(callable, onError); return run( jobRunner ); }
@Override public void unload() { isShutdown.set( true ); threads.shutdown(); } }
public <R> BackgroundJob<R> background() { return new BackgroundJob<> (); }