public class Remoter
extends cn.xnatural.aio.AioBase
AioServer, AioClient| 限定符和类型 | 字段和说明 |
|---|---|
protected cn.xnatural.remoter.Lazier<Charset> |
_charset
数据编码
|
protected cn.xnatural.remoter.Lazier<Boolean> |
_master
是否为master
true: 则向同为master的应用同步集群应用信息, false: 只向 masterHps 指向的服务同步集群应用信息
|
protected cn.xnatural.remoter.Lazier<String> |
_masterHps
集群的服务中心地址 [host1]:port1,[host2]:port2.
|
protected cn.xnatural.aio.AioClient |
aioClient
tcp数据发送端
|
protected cn.xnatural.aio.AioServer |
aioServer
tcp数据接收端
|
protected String |
appId
应用实例id
|
protected String |
appName
应用名
|
protected Map<String,Object> |
attrs
属性集
|
protected Map<String,DataVersion> |
dataVersionMap
集群数据版本管理
|
protected Map<String,cn.xnatural.enet.event.EC> |
ecMap
远程事件临时持有
ecId ->
EC |
protected cn.xnatural.enet.event.EP |
ep
事件中心
https://gitee.com/xnat/enet
|
protected ExecutorService |
exec
线程池
|
protected static org.slf4j.Logger |
log |
protected Map<String,cn.xnatural.remoter.SafeList<cn.xnatural.remoter.Node>> |
nodeMap
保存集群中的应用节点信息
name -> Node
|
protected cn.xnatural.sched.Sched |
sched
定时任务
https://gitee.com/xnat/sched
|
| 构造器和说明 |
|---|
Remoter(String appName,
String appId,
Map<String,Object> attrs)
|
Remoter(String appName,
String appId,
Map<String,Object> attrs,
ExecutorService exec,
cn.xnatural.enet.event.EP ep,
cn.xnatural.sched.Sched sched)
创建
Remoter |
| 限定符和类型 | 方法和说明 |
|---|---|
protected void |
appUp(Map data,
cn.xnatural.aio.AioStream se)
client -> master
接收集群应用的数据上传, 应用上线通知
NOTE: 此方法线程已安全
id 和 tcp 必须唯一
|
Remoter |
autoHeartbeat()
开始自动心跳
|
DataVersion |
dataVersion(String key)
获取数据集的数据版本集群同步器
|
protected void |
doFire(cn.xnatural.enet.event.EC ec,
String appName,
String eName,
List remoteMethodArgs)
调用远程事件
执行流程: 1.
|
Object |
fire(String appName,
String eName,
List remoteMethodArgs)
同步远程事件调用
|
void |
fireAsync(String appName,
String eName,
Consumer callback,
List remoteMethodArgs)
异步远程事件调用
|
cn.xnatural.aio.AioClient |
getAioClient()
getter
|
cn.xnatural.aio.AioServer |
getAioServer()
getter
|
Map<String,Object> |
getAppInfo()
应用自己的信息
例: {"id":"gy_GRLD5JhT4g", "name":"rc", "tcp":"192.168.2.104:8001", "http":"192.168.2.104:8000", "master": true}
|
cn.xnatural.enet.event.EP |
getEp()
事件中心
|
boolean |
isMaster()
是否为master
|
protected void |
receiveDataVersion(String key,
String dataKey,
Long version,
Object data)
接收远程远程应用的数据同步
|
protected void |
receiveEventReq(com.alibaba.fastjson.JSONObject data,
com.alibaba.fastjson.JSONObject source,
cn.xnatural.aio.AioStream se)
接收远程事件的执行请求
|
protected void |
receiveEventResp(com.alibaba.fastjson.JSONObject data)
接收远程事件返回的数据.
|
protected void |
receiveMsg(String msg,
cn.xnatural.aio.AioStream stream)
接收远程发送的消息
|
protected void |
receiveReply(String reply,
cn.xnatural.aio.AioStream se)
接收远程回响的消息
|
String |
resolveHttp(String appName) |
protected void |
sendMsg(String appName,
String msg,
String target)
发送消息
|
Remoter |
sendMsgToAll(String appName,
String msg)
向不应用的所有实例发送消息
|
Remoter |
sendMsgToAny(String appName,
String msg)
向应用其中一个实例发送数据
|
void |
stop()
stop
|
void |
sync()
集群应用同步函数
|
protected void |
updateAppInfo(com.alibaba.fastjson.JSONObject data)
master -> client
更新 app 信息
|
protected static final org.slf4j.Logger log
protected ExecutorService exec
protected cn.xnatural.enet.event.EP ep
protected cn.xnatural.sched.Sched sched
protected String appName
protected String appId
protected final Map<String,cn.xnatural.remoter.SafeList<cn.xnatural.remoter.Node>> nodeMap
protected final Map<String,DataVersion> dataVersionMap
protected cn.xnatural.aio.AioClient aioClient
protected cn.xnatural.aio.AioServer aioServer
protected final cn.xnatural.remoter.Lazier<String> _masterHps
protected final cn.xnatural.remoter.Lazier<Boolean> _master
protected final cn.xnatural.remoter.Lazier<Charset> _charset
public Remoter(String appName, String appId, Map<String,Object> attrs, ExecutorService exec, cn.xnatural.enet.event.EP ep, cn.xnatural.sched.Sched sched)
RemoterappName - 当前应用名appId - 当前应用实例idattrs - 属性集exec - 线程池ep - 事件中心sched - 定时任务调度public void stop()
public Object fire(String appName, String eName, List remoteMethodArgs)
appName - 应用名eName - 远程应用中的事件名remoteMethodArgs - 远程事件监听方法的参数public void fireAsync(String appName, String eName, Consumer callback, List remoteMethodArgs)
appName - 应用名eName - 远程应用中的事件名callback - 回调函数. 1. 正常结果, 2. ExceptionremoteMethodArgs - 远程事件监听方法的参数public Remoter sendMsgToAny(String appName, String msg)
appName - 应用名msg - 消息Remoterpublic Remoter sendMsgToAll(String appName, String msg)
appName - 应用名msg - 消息Remoterprotected void sendMsg(String appName, String msg, String target)
appName - 应用名msg - 消息内容target - 可用值: 'any', 'all'public DataVersion dataVersion(String key)
key - 同步器的keyDataVersion@EL(name="dataVersion") protected void receiveDataVersion(String key, String dataKey, Long version, Object data)
key - 同步KeydataKey - 数据keyversion - 数据版本data - 数据public Remoter autoHeartbeat()
public void sync()
@EL(name="remote")
protected void doFire(cn.xnatural.enet.event.EC ec,
String appName,
String eName,
List remoteMethodArgs)
doFire(EC, String, String, List)
2. 服务端接收到事件: receiveEventReq(JSONObject, JSONObject, AioStream)
3. 客户端接收到返回: receiveEventResp(com.alibaba.fastjson.JSONObject)ec - appName - 应用名eName - 远程应用中的事件名remoteMethodArgs - 远程事件监听方法的参数protected void receiveMsg(String msg, cn.xnatural.aio.AioStream stream)
msg - 消息内容stream - AioStreamprotected void receiveReply(String reply, cn.xnatural.aio.AioStream se)
reply - 回应消息se - AioSessionprotected void receiveEventResp(com.alibaba.fastjson.JSONObject data)
doFire(EC, String, String, List) 对应data - protected void receiveEventReq(com.alibaba.fastjson.JSONObject data,
com.alibaba.fastjson.JSONObject source,
cn.xnatural.aio.AioStream se)
data - 数据source - 来源se - AioStreamprotected void appUp(Map data, cn.xnatural.aio.AioStream se)
data - 节点应用上传的数据 {"name": "应用名", "id": "应用实例id", "tcp":"host:port", "http":"host:port", "udp": "host:port"}se - AioStream@EL(name="updateAppInfo") protected void updateAppInfo(com.alibaba.fastjson.JSONObject data)
data - app node信息
例: {"name":"rc", "id":"rc_b70d18d52269451291ea6380325e2a84", "tcp":"192.168.56.1:8001","http":"localhost:8000"}
属性不为空: name, id, tcppublic Map<String,Object> getAppInfo()
public cn.xnatural.aio.AioClient getAioClient()
AioClientpublic cn.xnatural.aio.AioServer getAioServer()
AioServerpublic cn.xnatural.enet.event.EP getEp()
EPpublic boolean isMaster()
Copyright © 2021. All rights reserved.