All Downloads are FREE. Search and download functionalities are using the official Maven repository.

webpiecesxxxxxpackage.service.RemoteServiceImpl Maven / Gradle / Ivy

Go to download

Someone forgot to fill this in. See http://stackoverflow.com/questions/38272550/how-to-fail-the-gradle-build-if-subproject-is-missing-a-property

There is a newer version: 2.1.28
Show newest version
package webpiecesxxxxxpackage.service;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class RemoteServiceImpl implements RemoteService {

	private ExecutorService pool = Executors.newFixedThreadPool(1);
	
	@Override
	public CompletableFuture fetchRemoteValue(String s, int i)  {
		//Here a remote service usually returns an uncompleted future and completes it when the remote
		//service returns it's value unblocking this thread for others to use.
		//we simulate that with a threadpool that is not needed in real situations
	
		//create not yet resolved future..
		CompletableFuture future = new CompletableFuture();
		
		pool.execute(new Runnable() {
			@Override
			public void run() {
				try {
					Thread.sleep(1000);
				} catch (InterruptedException e) {
					future.completeExceptionally(e);
					return;
				}
				
				//sleep 1 second to make sure other thread has returned back to platform
				//resolve futuere now
				future.complete(33);
				
			}
		});
		
		return future;
	}

	@Override
	public void sendData(int num) {
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy