Skip to content

Commit

Permalink
Fix init order
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbumenJ committed Nov 13, 2024
1 parent 7e4f8cf commit 9e4c85c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public abstract class AbstractPortUnificationServer extends AbstractServer {
/**
* extension name -> activate WireProtocol
*/
private final Map<String, WireProtocol> protocols;
private volatile Map<String, WireProtocol> protocols;

/*
protocol name --> URL object
Expand All @@ -50,21 +50,29 @@ public abstract class AbstractPortUnificationServer extends AbstractServer {

public AbstractPortUnificationServer(URL url, ChannelHandler handler) throws RemotingException {
super(url, handler);
ExtensionLoader<WireProtocol> extensionLoader =
url.getOrDefaultFrameworkModel().getExtensionLoader(WireProtocol.class);
this.protocols = extensionLoader.getActivateExtension(url, new String[0]).stream()
.collect(Collectors.toConcurrentMap(extensionLoader::getExtensionName, Function.identity()));
}

public Map<String, WireProtocol> getProtocols() {
return protocols;
}

@Override
protected final void doOpen() {
ExtensionLoader<WireProtocol> extensionLoader =
getUrl().getOrDefaultFrameworkModel().getExtensionLoader(WireProtocol.class);
this.protocols = extensionLoader.getActivateExtension(getUrl(), new String[0]).stream()
.collect(Collectors.toConcurrentMap(extensionLoader::getExtensionName, Function.identity()));

doOpen0();
}

protected abstract void doOpen0();

/*
This method registers URL object and corresponding channel handler to pu server.
In PuServerExchanger.bind, this method is called with ConcurrentHashMap.computeIfPresent to register messages to
this supportedUrls and supportedHandlers
*/
This method registers URL object and corresponding channel handler to pu server.
In PuServerExchanger.bind, this method is called with ConcurrentHashMap.computeIfPresent to register messages to
this supportedUrls and supportedHandlers
*/
public void addSupportedProtocol(URL url, ChannelHandler handler) {
this.supportedUrls.put(url.getProtocol(), url);
this.supportedHandlers.put(url.getProtocol(), handler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void bind() {
}

@Override
protected void doOpen() {
protected void doOpen0() {
NettyHelper.setNettyLoggerFactory();
ExecutorService boss = Executors.newCachedThreadPool(new NamedThreadFactory(EVENT_LOOP_BOSS_POOL_NAME, true));
ExecutorService worker =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void bind() throws Throwable {
}

@Override
public void doOpen() throws Throwable {
public void doOpen0() {
bootstrap = new ServerBootstrap();

bossGroup = NettyEventLoopFactory.eventLoopGroup(1, EVENT_LOOP_BOSS_POOL_NAME);
Expand Down

0 comments on commit 9e4c85c

Please sign in to comment.