Simplify server auto-configuration

This simplifies the server-side auto-configuration as follows:

- delete svc discover abstraction (use ObjectProvider for now)
- use single AC class
This commit is contained in:
Chris Bono
2024-09-22 13:17:35 -05:00
committed by Dave Syer
parent 32286cfbed
commit bb60c8fcaa
5 changed files with 74 additions and 96 deletions

View File

@@ -28,6 +28,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.context.SmartLifecycle;
import org.springframework.grpc.server.GrpcServerFactory;
@@ -38,8 +39,9 @@ import io.grpc.Server;
*
* @author Michael (yidongnan@gmail.com)
* @author Dave Syer
* @author Chris Bono
*/
public class GrpcServerLifecycle implements SmartLifecycle {
public class GrpcServerLifecycle implements SmartLifecycle, ApplicationEventPublisherAware {
private static final Log logger = LogFactory.getLog(GrpcServerLifecycle.class);
@@ -49,7 +51,7 @@ public class GrpcServerLifecycle implements SmartLifecycle {
private final Duration shutdownGracePeriod;
private final ApplicationEventPublisher eventPublisher;
private ApplicationEventPublisher eventPublisher;
private Server server;
@@ -57,14 +59,10 @@ public class GrpcServerLifecycle implements SmartLifecycle {
* Creates a new GrpcServerLifecycle
* @param factory The server factory to use.
* @param shutdownGracePeriod The time to wait for the server to gracefully shut down.
* @param eventPublisher The event publisher to use.
*/
public GrpcServerLifecycle(final GrpcServerFactory factory, final Duration shutdownGracePeriod,
final ApplicationEventPublisher eventPublisher) {
public GrpcServerLifecycle(final GrpcServerFactory factory, final Duration shutdownGracePeriod) {
this.factory = requireNonNull(factory, "factory");
this.shutdownGracePeriod = requireNonNull(shutdownGracePeriod, "shutdownGracePeriod");
this.eventPublisher = eventPublisher;
}
@Override
@@ -107,6 +105,11 @@ public class GrpcServerLifecycle implements SmartLifecycle {
return this.server == null ? 0 : this.server.getPort();
}
@Override
public void setApplicationEventPublisher(ApplicationEventPublisher eventPublisher) {
this.eventPublisher = eventPublisher;
}
/**
* Creates and starts the grpc server.
* @throws IOException If the server is unable to bind the port.

View File

@@ -0,0 +1,30 @@
/*
* Copyright 2024-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.grpc.server;
import org.junit.jupiter.api.Test;
/**
* Tests for {@link DefaultGrpcServerFactory}/
*/
class DefaultGrpcServerFactoryTests {
@Test
void placeholderTest() {
}
}