@@ -253,7 +253,7 @@ public void uncaughtException(Thread t, Throwable e) {
253
253
// Must only be mutated and read from syncContext
254
254
private boolean shutdownNowed ;
255
255
// Must only be mutated from syncContext
256
- private volatile boolean terminating ;
256
+ private boolean terminating ;
257
257
// Must be mutated from syncContext
258
258
private volatile boolean terminated ;
259
259
private final CountDownLatch terminatedLatch = new CountDownLatch (1 );
@@ -1399,9 +1399,9 @@ public AbstractSubchannel createSubchannel(CreateSubchannelArgs args) {
1399
1399
@ Override
1400
1400
public void updateBalancingState (
1401
1401
final ConnectivityState newState , final SubchannelPicker newPicker ) {
1402
+ syncContext .throwIfNotInThisSynchronizationContext ();
1402
1403
checkNotNull (newState , "newState" );
1403
1404
checkNotNull (newPicker , "newPicker" );
1404
- logWarningIfNotInSyncContext ("updateBalancingState()" );
1405
1405
final class UpdateBalancingState implements Runnable {
1406
1406
@ Override
1407
1407
public void run () {
@@ -1424,7 +1424,7 @@ public void run() {
1424
1424
1425
1425
@ Override
1426
1426
public void refreshNameResolution () {
1427
- logWarningIfNotInSyncContext ( "refreshNameResolution()" );
1427
+ syncContext . throwIfNotInThisSynchronizationContext ( );
1428
1428
final class LoadBalancerRefreshNameResolution implements Runnable {
1429
1429
@ Override
1430
1430
public void run () {
@@ -1814,9 +1814,9 @@ private final class SubchannelImpl extends AbstractSubchannel {
1814
1814
subchannelLogger = new ChannelLoggerImpl (subchannelTracer , timeProvider );
1815
1815
}
1816
1816
1817
- // This can be called either in or outside of syncContext
1818
- // TODO(zhangkun83): merge it back into start() once the caller createSubchannel() is deleted.
1819
- private void internalStart ( final SubchannelStateListener listener ) {
1817
+ @ Override
1818
+ public void start (final SubchannelStateListener listener ) {
1819
+ syncContext . throwIfNotInThisSynchronizationContext ();
1820
1820
checkState (!started , "already started" );
1821
1821
checkState (!shutdown , "already shutdown" );
1822
1822
checkState (!terminating , "Channel is being terminated" );
@@ -1872,21 +1872,8 @@ void onNotInUse(InternalSubchannel is) {
1872
1872
.build ());
1873
1873
1874
1874
this .subchannel = internalSubchannel ;
1875
- // TODO(zhangkun83): no need to schedule on syncContext when this whole method is required
1876
- // to be called from syncContext
1877
- syncContext .execute (new Runnable () {
1878
- @ Override
1879
- public void run () {
1880
- channelz .addSubchannel (internalSubchannel );
1881
- subchannels .add (internalSubchannel );
1882
- }
1883
- });
1884
- }
1885
-
1886
- @ Override
1887
- public void start (SubchannelStateListener listener ) {
1888
- syncContext .throwIfNotInThisSynchronizationContext ();
1889
- internalStart (listener );
1875
+ channelz .addSubchannel (internalSubchannel );
1876
+ subchannels .add (internalSubchannel );
1890
1877
}
1891
1878
1892
1879
@ Override
@@ -1897,18 +1884,6 @@ InternalInstrumented<ChannelStats> getInstrumentedInternalSubchannel() {
1897
1884
1898
1885
@ Override
1899
1886
public void shutdown () {
1900
- // TODO(zhangkun83): replace shutdown() with internalShutdown() to turn the warning into an
1901
- // exception.
1902
- logWarningIfNotInSyncContext ("Subchannel.shutdown()" );
1903
- syncContext .execute (new Runnable () {
1904
- @ Override
1905
- public void run () {
1906
- internalShutdown ();
1907
- }
1908
- });
1909
- }
1910
-
1911
- private void internalShutdown () {
1912
1887
syncContext .throwIfNotInThisSynchronizationContext ();
1913
1888
if (subchannel == null ) {
1914
1889
// start() was not successful
@@ -1957,14 +1932,14 @@ public void run() {
1957
1932
1958
1933
@ Override
1959
1934
public void requestConnection () {
1960
- logWarningIfNotInSyncContext ( "Subchannel.requestConnection()" );
1935
+ syncContext . throwIfNotInThisSynchronizationContext ( );
1961
1936
checkState (started , "not started" );
1962
1937
subchannel .obtainActiveTransport ();
1963
1938
}
1964
1939
1965
1940
@ Override
1966
1941
public List <EquivalentAddressGroup > getAllAddresses () {
1967
- logWarningIfNotInSyncContext ( "Subchannel.getAllAddresses()" );
1942
+ syncContext . throwIfNotInThisSynchronizationContext ( );
1968
1943
checkState (started , "not started" );
1969
1944
return subchannel .getAddressGroups ();
1970
1945
}
@@ -2238,17 +2213,6 @@ public ConfigOrError parseServiceConfig(Map<String, ?> rawServiceConfig) {
2238
2213
}
2239
2214
}
2240
2215
2241
- private void logWarningIfNotInSyncContext (String method ) {
2242
- try {
2243
- syncContext .throwIfNotInThisSynchronizationContext ();
2244
- } catch (IllegalStateException e ) {
2245
- logger .log (Level .WARNING ,
2246
- method + " should be called from SynchronizationContext. "
2247
- + "This warning will become an exception in a future release. "
2248
- + "See https://github.com/grpc/grpc-java/issues/5015 for more details" , e );
2249
- }
2250
- }
2251
-
2252
2216
/**
2253
2217
* A ResolutionState indicates the status of last name resolution.
2254
2218
*/
0 commit comments