Package com.google.apphosting.runtime
Class BackgroundRequestCoordinator
- java.lang.Object
-
- com.google.apphosting.runtime.BackgroundRequestCoordinator
-
public class BackgroundRequestCoordinator extends Object
BackgroundRequestCoordinator facilitates the exchange of two pieces of data between the backgroundThreadFactoryand theJavaRuntimecode that processes the fake request.Background threads are backed by a "fake" request, which is initiated using the System API. The System API will return a request identifier and also initiate a "fake" request with this identifier stored in a header. The runtime must match each fake request up with the original API call and pass the user's
Runnableto the thread so it can be executed, and pass theThreadback to the user's code so it can be joined and referenced.Unfortunately there is a race between these two threads. We don't know whether the System API RPC will return first or whether the background request will be received first.
-
-
Constructor Summary
Constructors Constructor Description BackgroundRequestCoordinator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ThreadwaitForThreadStart(String requestId, Runnable runnable, long deadlineInMillis)Wait for the fake request with the specifiedrequestIdto callwaitForUserRunnable(java.lang.String, java.lang.Thread, long)and then exchangerunnablefor the specifiedThread.RunnablewaitForUserRunnable(String requestId, Thread thread, long deadLineInMillis)Wait for the system API call with the specifiedrequestIdto callwaitForThreadStart(java.lang.String, java.lang.Runnable, long)and then exchangethreadfor the specifiedRunnable.
-
-
-
Method Detail
-
waitForThreadStart
public Thread waitForThreadStart(String requestId, Runnable runnable, long deadlineInMillis) throws InterruptedException, TimeoutException
Wait for the fake request with the specifiedrequestIdto callwaitForUserRunnable(java.lang.String, java.lang.Thread, long)and then exchangerunnablefor the specifiedThread.- Throws:
InterruptedExceptionTimeoutException
-
waitForUserRunnable
public Runnable waitForUserRunnable(String requestId, Thread thread, long deadLineInMillis) throws InterruptedException, TimeoutException
Wait for the system API call with the specifiedrequestIdto callwaitForThreadStart(java.lang.String, java.lang.Runnable, long)and then exchangethreadfor the specifiedRunnable.- Throws:
InterruptedExceptionTimeoutException
-
-