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