Package com.google.apphosting.runtime
Class BackgroundRequestCoordinator
java.lang.Object
com.google.apphosting.runtime.BackgroundRequestCoordinator
BackgroundRequestCoordinator facilitates the exchange of two pieces
of data between the background
ThreadFactory and the
JavaRuntime code 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
Runnable to the thread so it can be executed, and pass the
Thread back 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 -
Method Summary
Modifier and TypeMethodDescriptionwaitForThreadStart(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.waitForUserRunnable(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.
-
Constructor Details
-
BackgroundRequestCoordinator
public BackgroundRequestCoordinator()
-
-
Method Details
-
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
-