Context.updateServerAddress
This commit is contained in:
@@ -167,6 +167,10 @@ public class Context {
|
||||
conn.updateWriteIOThread(ioWriteThread);
|
||||
}
|
||||
|
||||
protected void updateServerAddress(InetSocketAddress addr) {
|
||||
this.serverAddress = addr;
|
||||
}
|
||||
|
||||
public ResourceFactory getResourceFactory() {
|
||||
return resourceFactory;
|
||||
}
|
||||
|
||||
@@ -329,7 +329,7 @@ public abstract class Server<K extends Serializable, C extends Context, R extend
|
||||
Objects.requireNonNull(addr);
|
||||
final InetSocketAddress oldAddress = context.serverAddress;
|
||||
final ProtocolServer oldServerChannel = this.serverChannel;
|
||||
context.serverAddress = addr;
|
||||
context.updateServerAddress(addr);
|
||||
ProtocolServer newServerChannel = null;
|
||||
try {
|
||||
newServerChannel = ProtocolServer.create(this.netprotocol, context, this.serverClassLoader);
|
||||
@@ -337,7 +337,7 @@ public abstract class Server<K extends Serializable, C extends Context, R extend
|
||||
newServerChannel.bind(addr, backlog);
|
||||
newServerChannel.accept(application, this);
|
||||
} catch (IOException e) {
|
||||
context.serverAddress = oldAddress;
|
||||
context.updateServerAddress(oldAddress);
|
||||
throw e;
|
||||
}
|
||||
this.address = context.serverAddress;
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
*/
|
||||
package org.redkale.net.sncp;
|
||||
|
||||
import org.redkale.net.*;
|
||||
import java.net.InetSocketAddress;
|
||||
import org.redkale.net.Context;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -15,8 +16,21 @@ import org.redkale.net.*;
|
||||
*/
|
||||
public class SncpContext extends Context {
|
||||
|
||||
protected byte[] serverAddressBytes;
|
||||
|
||||
protected int serverAddressPort;
|
||||
|
||||
public SncpContext(SncpContextConfig config) {
|
||||
super(config);
|
||||
this.serverAddressBytes = serverAddress.getAddress().getAddress();
|
||||
this.serverAddressPort = serverAddress.getPort();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateServerAddress(InetSocketAddress addr) {
|
||||
super.updateServerAddress(addr);
|
||||
this.serverAddressBytes = addr.getAddress().getAddress();
|
||||
this.serverAddressPort = addr.getPort();
|
||||
}
|
||||
|
||||
public static class SncpContextConfig extends ContextConfig {
|
||||
|
||||
Reference in New Issue
Block a user