10 changed files with 212 additions and 20 deletions
@ -0,0 +1,43 @@ |
|||||||
|
package net.sopod.soim.router.datasync.server.session; |
||||||
|
|
||||||
|
import net.sopod.soim.router.datasync.server.SyncClient; |
||||||
|
|
||||||
|
import java.util.concurrent.ConcurrentHashMap; |
||||||
|
|
||||||
|
/** |
||||||
|
* SyncClientSession |
||||||
|
* |
||||||
|
* @author tmy |
||||||
|
* @date 2022-05-09 17:45 |
||||||
|
*/ |
||||||
|
public class SyncClientSession { |
||||||
|
|
||||||
|
private static final SyncClientSession INSTANCE = new SyncClientSession(); |
||||||
|
|
||||||
|
public static SyncClientSession getInstance() { |
||||||
|
return INSTANCE; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 服务端addr,连接 channel |
||||||
|
*/ |
||||||
|
public final ConcurrentHashMap<String, SyncClient> serverChannel = new ConcurrentHashMap<>(); |
||||||
|
|
||||||
|
public void connect(String host, int port) { |
||||||
|
SyncClient client = new SyncClient(); |
||||||
|
try { |
||||||
|
client.connect(host, port); |
||||||
|
serverChannel.put(host + ":" + port, client); |
||||||
|
} catch (InterruptedException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void close(String addr) { |
||||||
|
SyncClient syncClient = serverChannel.get(addr); |
||||||
|
if (syncClient != null) { |
||||||
|
syncClient.close(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,45 @@ |
|||||||
|
package net.sopod.soim.router.datasync.server.session; |
||||||
|
|
||||||
|
import org.apache.dubbo.common.utils.ConcurrentHashSet; |
||||||
|
|
||||||
|
import java.nio.channels.Channel; |
||||||
|
import java.util.Set; |
||||||
|
|
||||||
|
/** |
||||||
|
* SyncServerSession |
||||||
|
* |
||||||
|
* @author tmy |
||||||
|
* @date 2022-05-09 14:49 |
||||||
|
*/ |
||||||
|
public class SyncServerSession { |
||||||
|
|
||||||
|
private static final SyncServerSession INSTANCE = new SyncServerSession(); |
||||||
|
|
||||||
|
public static SyncServerSession getInstance() { |
||||||
|
return INSTANCE; |
||||||
|
} |
||||||
|
|
||||||
|
/** 已连接客户端 */ |
||||||
|
public final Set<Channel> clients = new ConcurrentHashSet<>(); |
||||||
|
|
||||||
|
/** 备份数据节点 */ |
||||||
|
public final Set<Channel> backupClients = new ConcurrentHashSet<>(); |
||||||
|
|
||||||
|
/** 新增节点发送 Sync 命令后添加到该连接集合 */ |
||||||
|
public final Set<Channel> newNodeClients = new ConcurrentHashSet<>(); |
||||||
|
|
||||||
|
public void addClient(Channel channel) { |
||||||
|
clients.add(channel); |
||||||
|
} |
||||||
|
|
||||||
|
public void addBackupClient() { |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public void removeClient(Channel channel) { |
||||||
|
clients.remove(channel); |
||||||
|
backupClients.remove(channel); |
||||||
|
newNodeClients.remove(channel); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
Loading…
Reference in new issue