Merge "Allow callers to synchronously block for shutdown"
am: 9121322ce7
Change-Id: Ic0293bf12688e785f4942f0985a8470155fe062b
This commit is contained in:
@@ -72,6 +72,7 @@ import java.util.Objects;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.StringJoiner;
|
import java.util.StringJoiner;
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@@ -100,6 +101,11 @@ public class IpClient extends StateMachine {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Callbacks for handling IpClient events.
|
* Callbacks for handling IpClient events.
|
||||||
|
*
|
||||||
|
* These methods are called by IpClient on its own thread. Implementations
|
||||||
|
* of this class MUST NOT carry out long-running computations or hold locks
|
||||||
|
* for which there might be contention with other code calling public
|
||||||
|
* methods of the same IpClient instance.
|
||||||
*/
|
*/
|
||||||
public static class Callback {
|
public static class Callback {
|
||||||
// In order to receive onPreDhcpAction(), call #withPreDhcpAction()
|
// In order to receive onPreDhcpAction(), call #withPreDhcpAction()
|
||||||
@@ -545,6 +551,7 @@ public class IpClient extends StateMachine {
|
|||||||
private final String mClatInterfaceName;
|
private final String mClatInterfaceName;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
protected final Callback mCallback;
|
protected final Callback mCallback;
|
||||||
|
private final CountDownLatch mShutdownLatch;
|
||||||
private final INetworkManagementService mNwService;
|
private final INetworkManagementService mNwService;
|
||||||
private final NetlinkTracker mNetlinkTracker;
|
private final NetlinkTracker mNetlinkTracker;
|
||||||
private final WakeupMessage mProvisioningTimeoutAlarm;
|
private final WakeupMessage mProvisioningTimeoutAlarm;
|
||||||
@@ -597,6 +604,7 @@ public class IpClient extends StateMachine {
|
|||||||
mInterfaceName = ifName;
|
mInterfaceName = ifName;
|
||||||
mClatInterfaceName = CLAT_PREFIX + ifName;
|
mClatInterfaceName = CLAT_PREFIX + ifName;
|
||||||
mCallback = new LoggingCallbackWrapper(callback);
|
mCallback = new LoggingCallbackWrapper(callback);
|
||||||
|
mShutdownLatch = new CountDownLatch(1);
|
||||||
mNwService = nwService;
|
mNwService = nwService;
|
||||||
|
|
||||||
mLog = new SharedLog(MAX_LOG_RECORDS, mTag);
|
mLog = new SharedLog(MAX_LOG_RECORDS, mTag);
|
||||||
@@ -704,6 +712,7 @@ public class IpClient extends StateMachine {
|
|||||||
@Override
|
@Override
|
||||||
protected void onQuitting() {
|
protected void onQuitting() {
|
||||||
mCallback.onQuit();
|
mCallback.onQuit();
|
||||||
|
mShutdownLatch.countDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shut down this IpClient instance altogether.
|
// Shut down this IpClient instance altogether.
|
||||||
@@ -712,6 +721,17 @@ public class IpClient extends StateMachine {
|
|||||||
sendMessage(CMD_TERMINATE_AFTER_STOP);
|
sendMessage(CMD_TERMINATE_AFTER_STOP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// In order to avoid deadlock, this method MUST NOT be called on the
|
||||||
|
// IpClient instance's thread. This prohibition includes code executed by
|
||||||
|
// when methods on the passed-in IpClient.Callback instance are called.
|
||||||
|
public void awaitShutdown() {
|
||||||
|
try {
|
||||||
|
mShutdownLatch.await();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
mLog.e("Interrupted while awaiting shutdown: " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static ProvisioningConfiguration.Builder buildProvisioningConfiguration() {
|
public static ProvisioningConfiguration.Builder buildProvisioningConfiguration() {
|
||||||
return new ProvisioningConfiguration.Builder();
|
return new ProvisioningConfiguration.Builder();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user