Skip to content

Commit

Permalink
fix: isolate stub.close change to another PR
Browse files Browse the repository at this point in the history
  • Loading branch information
miraleung committed Aug 2, 2021
1 parent 1c57844 commit 552af72
Show file tree
Hide file tree
Showing 21 changed files with 22 additions and 139 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
import com.google.api.generator.engine.ast.ScopeNode;
import com.google.api.generator.engine.ast.Statement;
import com.google.api.generator.engine.ast.ThisObjectValue;
import com.google.api.generator.engine.ast.ThrowExpr;
import com.google.api.generator.engine.ast.TryCatchStatement;
import com.google.api.generator.engine.ast.TypeNode;
import com.google.api.generator.engine.ast.ValueExpr;
import com.google.api.generator.engine.ast.Variable;
Expand Down Expand Up @@ -793,23 +791,6 @@ private List<MethodDefinition> createStubOverrideMethods(
.build())
.build();

// Generate the close() method:
// @Override
// public final void close() {
// try {
// backgroundResources.close();
// } catch (Exception e) {
// throw new IllegalStateException("Failed to close resource", e);
// }
// }
VariableExpr catchExceptionVarExpr =
VariableExpr.builder()
.setVariable(
Variable.builder()
.setType(TypeNode.withExceptionClazz(Exception.class))
.setName("e")
.build())
.build();
List<MethodDefinition> javaMethods = new ArrayList<>();
javaMethods.add(
methodMakerStarterFn
Expand All @@ -818,26 +799,8 @@ private List<MethodDefinition> createStubOverrideMethods(
.setReturnType(TypeNode.VOID)
.setBody(
Arrays.asList(
TryCatchStatement.builder()
.setTryBody(
Arrays.asList(
ExprStatement.withExpr(
MethodInvocationExpr.builder()
.setExprReferenceExpr(backgroundResourcesVarExpr)
.setMethodName("close")
.build())))
.addCatch(
catchExceptionVarExpr.toBuilder().setIsDecl(true).build(),
Arrays.asList(
ExprStatement.withExpr(
ThrowExpr.builder()
.setType(
TypeNode.withExceptionClazz(
IllegalStateException.class))
.setMessageExpr(String.format("Failed to close resource"))
.setCauseExpr(catchExceptionVarExpr)
.build())))
.build()))
ExprStatement.withExpr(
MethodInvocationExpr.builder().setMethodName("shutdown").build())))
.build());
javaMethods.add(voidMethodMakerFn.apply("shutdown"));
javaMethods.add(booleanMethodMakerFn.apply("isShutdown"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,7 @@ public class GrpcDeprecatedServiceStub extends DeprecatedServiceStub {

@Override
public final void close() {
try {
backgroundResources.close();
} catch (Exception e) {
throw new IllegalStateException("Failed to close resource", e);
}
shutdown();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,7 @@ public class GrpcEchoStub extends EchoStub {

@Override
public final void close() {
try {
backgroundResources.close();
} catch (Exception e) {
throw new IllegalStateException("Failed to close resource", e);
}
shutdown();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,11 +430,7 @@ public class GrpcPublisherStub extends PublisherStub {

@Override
public final void close() {
try {
backgroundResources.close();
} catch (Exception e) {
throw new IllegalStateException("Failed to close resource", e);
}
shutdown();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,7 @@ public class GrpcTestingStub extends TestingStub {

@Override
public final void close() {
try {
backgroundResources.close();
} catch (Exception e) {
throw new IllegalStateException("Failed to close resource", e);
}
shutdown();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,11 +484,7 @@ public class HttpJsonComplianceStub extends ComplianceStub {

@Override
public final void close() {
try {
backgroundResources.close();
} catch (Exception e) {
throw new IllegalStateException("Failed to close resource", e);
}
shutdown();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,11 +598,7 @@ public UnaryCallable<DeleteFeedRequest, Empty> deleteFeedCallable() {

@Override
public final void close() {
try {
backgroundResources.close();
} catch (Exception e) {
throw new IllegalStateException("Failed to close resource", e);
}
shutdown();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,11 +403,7 @@ public UnaryCallable<ListAddressesRequest, ListPagedResponse> listPagedCallable(

@Override
public final void close() {
try {
backgroundResources.close();
} catch (Exception e) {
throw new IllegalStateException("Failed to close resource", e);
}
shutdown();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,7 @@ public UnaryCallable<GetRegionOperationRequest, Operation> getCallable() {

@Override
public final void close() {
try {
backgroundResources.close();
} catch (Exception e) {
throw new IllegalStateException("Failed to close resource", e);
}
shutdown();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,7 @@ public UnaryCallable<SignJwtRequest, SignJwtResponse> signJwtCallable() {

@Override
public final void close() {
try {
backgroundResources.close();
} catch (Exception e) {
throw new IllegalStateException("Failed to close resource", e);
}
shutdown();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,7 @@ public UnaryCallable<GetIamPolicyRequest, Policy> getIamPolicyCallable() {

@Override
public final void close() {
try {
backgroundResources.close();
} catch (Exception e) {
throw new IllegalStateException("Failed to close resource", e);
}
shutdown();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1119,11 +1119,7 @@ public UnaryCallable<GetLocationRequest, Location> getLocationCallable() {

@Override
public final void close() {
try {
backgroundResources.close();
} catch (Exception e) {
throw new IllegalStateException("Failed to close resource", e);
}
shutdown();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,11 +450,7 @@ public UnaryCallable<MoveBookRequest, Book> moveBookCallable() {

@Override
public final void close() {
try {
backgroundResources.close();
} catch (Exception e) {
throw new IllegalStateException("Failed to close resource", e);
}
shutdown();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -889,11 +889,7 @@ public UnaryCallable<UpdateCmekSettingsRequest, CmekSettings> updateCmekSettings

@Override
public final void close() {
try {
backgroundResources.close();
} catch (Exception e) {
throw new IllegalStateException("Failed to close resource", e);
}
shutdown();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,7 @@ public UnaryCallable<ListLogsRequest, ListLogsPagedResponse> listLogsPagedCallab

@Override
public final void close() {
try {
backgroundResources.close();
} catch (Exception e) {
throw new IllegalStateException("Failed to close resource", e);
}
shutdown();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,7 @@ public UnaryCallable<DeleteLogMetricRequest, Empty> deleteLogMetricCallable() {

@Override
public final void close() {
try {
backgroundResources.close();
} catch (Exception e) {
throw new IllegalStateException("Failed to close resource", e);
}
shutdown();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,11 +549,7 @@ public UnaryCallable<GetIamPolicyRequest, Policy> getIamPolicyCallable() {

@Override
public final void close() {
try {
backgroundResources.close();
} catch (Exception e) {
throw new IllegalStateException("Failed to close resource", e);
}
shutdown();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,11 +412,7 @@ public UnaryCallable<GetIamPolicyRequest, Policy> getIamPolicyCallable() {

@Override
public final void close() {
try {
backgroundResources.close();
} catch (Exception e) {
throw new IllegalStateException("Failed to close resource", e);
}
shutdown();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -762,11 +762,7 @@ public UnaryCallable<GetIamPolicyRequest, Policy> getIamPolicyCallable() {

@Override
public final void close() {
try {
backgroundResources.close();
} catch (Exception e) {
throw new IllegalStateException("Failed to close resource", e);
}
shutdown();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,11 +505,7 @@ public OperationCallable<DeleteInstanceRequest, Empty, Any> deleteInstanceOperat

@Override
public final void close() {
try {
backgroundResources.close();
} catch (Exception e) {
throw new IllegalStateException("Failed to close resource", e);
}
shutdown();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,7 @@ public ClientStreamingCallable<WriteObjectRequest, WriteObjectResponse> writeObj

@Override
public final void close() {
try {
backgroundResources.close();
} catch (Exception e) {
throw new IllegalStateException("Failed to close resource", e);
}
shutdown();
}

@Override
Expand Down

0 comments on commit 552af72

Please sign in to comment.