TransportStrategy增加offerConnection方法
This commit is contained in:
@@ -294,6 +294,7 @@ public final class Transport {
|
||||
}
|
||||
|
||||
public void offerConnection(final boolean forceClose, AsyncConnection conn) {
|
||||
if (this.strategy != null && strategy.offerConnection(forceClose, conn)) return;
|
||||
if (!forceClose && conn.isTCP()) {
|
||||
if (conn.isOpen()) {
|
||||
TransportAddress taddr = findTransportAddress(conn.getRemoteAddress());
|
||||
@@ -350,6 +351,8 @@ public final class Transport {
|
||||
|
||||
protected final BlockingQueue<AsyncConnection> conns = new ArrayBlockingQueue<>(MAX_POOL_LIMIT);
|
||||
|
||||
protected final ConcurrentHashMap<String, Object> attributes = new ConcurrentHashMap<>();
|
||||
|
||||
public TransportAddress(InetSocketAddress address) {
|
||||
this.address = address;
|
||||
this.enable = true;
|
||||
@@ -361,6 +364,35 @@ public final class Transport {
|
||||
this.enable = enable;
|
||||
}
|
||||
|
||||
public <T> T setAttribute(String name, T value) {
|
||||
attributes.put(name, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T getAttribute(String name) {
|
||||
return (T) attributes.get(name);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T removeAttribute(String name) {
|
||||
return (T) attributes.remove(name);
|
||||
}
|
||||
|
||||
public TransportAddress clearAttributes() {
|
||||
attributes.clear();
|
||||
return this;
|
||||
}
|
||||
|
||||
public ConcurrentHashMap<String, Object> getAttributes() {
|
||||
return attributes;
|
||||
}
|
||||
|
||||
public void setAttributes(ConcurrentHashMap<String, Object> map) {
|
||||
attributes.clear();
|
||||
if (map != null) attributes.putAll(map);
|
||||
}
|
||||
|
||||
public InetSocketAddress getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
@@ -18,5 +18,25 @@ import java.util.concurrent.CompletableFuture;
|
||||
*/
|
||||
public interface TransportStrategy {
|
||||
|
||||
/**
|
||||
* 创建AsyncConnection
|
||||
*
|
||||
* @param addr 服务器地址
|
||||
* @param transport Transport
|
||||
*
|
||||
* @return AsyncConnection
|
||||
*/
|
||||
public CompletableFuture<AsyncConnection> pollConnection(SocketAddress addr, Transport transport);
|
||||
|
||||
/**
|
||||
* 回收AsyncConnection,返回false表示使用Transport默认的回收实现, 返回true表示自定义回收实现
|
||||
*
|
||||
* @param forceClose 是否强制关闭
|
||||
* @param conn AsyncConnection
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
default boolean offerConnection(final boolean forceClose, AsyncConnection conn) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user