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:
@@ -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.
|
||||
|
||||
@@ -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() {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user