@@ -55,6 +55,7 @@ public final class InternalConnectorRegistry {
5555 private static final String version = getVersion ();
5656 private static final long MIN_REFRESH_DELAY_MS = 30000 ; // Minimum 30 seconds between refresh.
5757 private static InternalConnectorRegistry internalConnectorRegistry ;
58+ private static boolean shutdown = false ;
5859 private final ListenableFuture <KeyPair > localKeyPair ;
5960 private final ConcurrentHashMap <ConnectorConfig , Connector > unnamedConnectors =
6061 new ConcurrentHashMap <>();
@@ -91,6 +92,10 @@ public final class InternalConnectorRegistry {
9192
9293 /** Returns the {@link InternalConnectorRegistry} singleton. */
9394 public static synchronized InternalConnectorRegistry getInstance () {
95+ if (shutdown ) {
96+ throw new IllegalStateException ("ConnectorRegistry was shut down." );
97+ }
98+
9499 if (internalConnectorRegistry == null ) {
95100 logger .debug ("First Cloud SQL connection, generating RSA key pair." );
96101
@@ -114,14 +119,24 @@ public static synchronized InternalConnectorRegistry getInstance() {
114119 * Calls shutdown on the singleton and removes the singleton. After calling shutdownInstance(),
115120 * the next call to getInstance() will start a new singleton instance.
116121 */
117- public static synchronized void shutdownInstance () {
122+ public static synchronized void resetInstance () {
118123 if (internalConnectorRegistry != null ) {
119124 InternalConnectorRegistry old = internalConnectorRegistry ;
120125 internalConnectorRegistry = null ;
121126 old .shutdown ();
127+ resetUserAgent ();
122128 }
123129 }
124130
131+ /**
132+ * Calls shutdown on the singleton and removes the singleton. After calling shutdownInstance(),
133+ * the next call to getInstance() will start a new singleton instance.
134+ */
135+ public static synchronized void shutdownInstance () {
136+ shutdown = true ;
137+ resetInstance ();
138+ }
139+
125140 // TODO(kvg): Figure out better executor to use for testing
126141 @ VisibleForTesting
127142 // Returns a listenable, scheduled executor that exits upon shutdown.
0 commit comments