Server.changeAddress
This commit is contained in:
@@ -307,8 +307,9 @@ public abstract class Server<K extends Serializable, C extends Context, R extend
|
|||||||
this.serverChannel.open(config);
|
this.serverChannel.open(config);
|
||||||
serverChannel.bind(address, backlog);
|
serverChannel.bind(address, backlog);
|
||||||
SocketAddress localAddress = serverChannel.getLocalAddress();
|
SocketAddress localAddress = serverChannel.getLocalAddress();
|
||||||
if (localAddress instanceof InetSocketAddress) {
|
if (localAddress instanceof InetSocketAddress && !Objects.equals(localAddress, this.address)) {
|
||||||
this.address = (InetSocketAddress) localAddress;
|
this.address = (InetSocketAddress) localAddress;
|
||||||
|
this.context.updateServerAddress(this.address);
|
||||||
}
|
}
|
||||||
serverChannel.accept(application, this);
|
serverChannel.accept(application, this);
|
||||||
postStart();
|
postStart();
|
||||||
@@ -327,19 +328,23 @@ public abstract class Server<K extends Serializable, C extends Context, R extend
|
|||||||
public void changeAddress(Application application, final InetSocketAddress addr) throws IOException {
|
public void changeAddress(Application application, final InetSocketAddress addr) throws IOException {
|
||||||
long s = System.currentTimeMillis();
|
long s = System.currentTimeMillis();
|
||||||
Objects.requireNonNull(addr);
|
Objects.requireNonNull(addr);
|
||||||
final InetSocketAddress oldAddress = context.serverAddress;
|
|
||||||
final ProtocolServer oldServerChannel = this.serverChannel;
|
final ProtocolServer oldServerChannel = this.serverChannel;
|
||||||
context.updateServerAddress(addr);
|
|
||||||
ProtocolServer newServerChannel = null;
|
ProtocolServer newServerChannel = null;
|
||||||
|
InetSocketAddress addr0 = addr;
|
||||||
try {
|
try {
|
||||||
newServerChannel = ProtocolServer.create(this.netprotocol, context, this.serverClassLoader);
|
newServerChannel = ProtocolServer.create(this.netprotocol, context, this.serverClassLoader);
|
||||||
|
this.resourceFactory.inject(newServerChannel);
|
||||||
newServerChannel.open(config);
|
newServerChannel.open(config);
|
||||||
newServerChannel.bind(addr, backlog);
|
newServerChannel.bind(addr, backlog);
|
||||||
|
SocketAddress localAddress = newServerChannel.getLocalAddress();
|
||||||
|
if (localAddress instanceof InetSocketAddress) {
|
||||||
|
addr0 = (InetSocketAddress) localAddress;
|
||||||
|
}
|
||||||
newServerChannel.accept(application, this);
|
newServerChannel.accept(application, this);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
context.updateServerAddress(oldAddress);
|
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
context.updateServerAddress(addr0);
|
||||||
this.address = context.serverAddress;
|
this.address = context.serverAddress;
|
||||||
this.serverChannel = newServerChannel;
|
this.serverChannel = newServerChannel;
|
||||||
logger.info(this.getClass().getSimpleName() + ("TCP".equalsIgnoreCase(netprotocol) ? "" : ("." + netprotocol))
|
logger.info(this.getClass().getSimpleName() + ("TCP".equalsIgnoreCase(netprotocol) ? "" : ("." + netprotocol))
|
||||||
|
|||||||
Reference in New Issue
Block a user