Skip to content

Commit

Permalink
fix(proxy): fix wrong nums of StartAndShutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoma20082008 committed Oct 23, 2024
1 parent 221d9a0 commit 230eb02
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public GrpcServer build() {
int port = ConfigurationManager.getProxyConfig().getGrpcServerPort();
//
ThreadPoolExecutor executor = createServerExecutor();
initializer.getStartAndShutdowns().add(new StartAndShutdown() {
appendStartAndShutdown(new StartAndShutdown() {
@Override
public void shutdown() throws Exception {
executor.shutdown();
Expand All @@ -61,7 +61,7 @@ public void start() throws Exception {
});
//
GrpcMessagingApplication application = GrpcMessagingApplication.create(initializer.getMessagingProcessor());
initializer.getStartAndShutdowns().add(application);
appendStartAndShutdown(application);
//
NettyServerBuilder serverBuilder = NettyServerBuilder.forPort(port);
serverBuilder.addService(application)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@
package org.apache.rocketmq.proxy.spi;

import org.apache.rocketmq.acl.AccessValidator;
import org.apache.rocketmq.common.utils.StartAndShutdown;

import java.util.ArrayList;
import java.util.List;

public abstract class ProxyServerFactoryBase implements ProxyServerFactory {

protected List<AccessValidator> validators;
protected ProxyServerInitializer initializer;
protected final List<StartAndShutdown> startAndShutdowns = new ArrayList<StartAndShutdown>();

@Override
public ProxyServerFactory withAccessValidators(List<AccessValidator> accessValidators) {
Expand All @@ -41,11 +44,18 @@ public ProxyServerFactory withInitializer(ProxyServerInitializer proxyServerInit
@Override
public final ProxyServerBase get() {
ProxyServerBase serverBase = build();
this.initializer.getStartAndShutdowns().forEach(this::appendStartAndShutdown);
serverBase.setBrokerController(this.initializer.getBrokerController());
serverBase.setStartAndShutdowns(this.initializer.getStartAndShutdowns());
serverBase.setStartAndShutdowns(this.startAndShutdowns);
serverBase.setMessagingProcessor(this.initializer.getMessagingProcessor());
return serverBase;
}

protected void appendStartAndShutdown(StartAndShutdown sas) {
if (sas != null && !this.startAndShutdowns.contains(sas)) {
this.startAndShutdowns.add(sas);
}
}

protected abstract ProxyServerBase build();
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private void initializeConfiguration() throws Exception {

private void validateConfiguration() throws Exception {
String proxyModeStr = ConfigurationManager.getProxyConfig().getProxyMode();
if (!ProxyMode.isClusterMode(proxyModeStr) || !ProxyMode.isLocalMode(proxyModeStr)) {
if (!ProxyMode.isClusterMode(proxyModeStr) && !ProxyMode.isLocalMode(proxyModeStr)) {
throw new IllegalArgumentException("try to start proxy server with wrong mode, use 'local' or 'cluster'");
}
}
Expand Down

0 comments on commit 230eb02

Please sign in to comment.