top.yqingyu.trans$client.main.TransClient Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of TransClient Show documentation
Show all versions of TransClient Show documentation
Qy's Client based on QyMsg transport protocol
package top.yqingyu.trans$client.main;
import lombok.extern.slf4j.Slf4j;
import top.yqingyu.common.qymsg.*;
import top.yqingyu.common.utils.YamlUtil;
import top.yqingyu.trans$client.api.Connection;
import top.yqingyu.trans$client.api.ConnectionConfig;
import top.yqingyu.trans$client.api.ConnectionFactory;
import java.net.Socket;
import java.util.Scanner;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.ReentrantLock;
/**
* @author YYJ
* @version 1.0.0
* @date 2022/4/22 4:19
* @description
* @modified by
*/
@Slf4j
public class TransClient {
public ConnectionConfig clientConf;
public ConnectionFactory factory;
TransClient(ConnectionConfig config) throws Exception {
clientConf = config;
this.factory = new ConnectionFactory(config);
}
public final LinkedBlockingQueue Main_PartitionMsgQueue = new LinkedBlockingQueue<>();
public final LinkedBlockingQueue CI_PartitionMsgQueue = new LinkedBlockingQueue<>();
public final LinkedBlockingQueue REQ_MSG_QUEUE = new LinkedBlockingQueue<>();
public final LinkedBlockingQueue RSP_MSG_QUEUE = new LinkedBlockingQueue<>();
public final ConcurrentHashMap RCV_MSG_CONTAINER = new ConcurrentHashMap<>();
public final AtomicBoolean running = new AtomicBoolean(true);
public final ReentrantLock readMsgLock = new ReentrantLock();
public static void main(String[] args) throws Exception {
ConnectionConfig build = ConnectionConfig.build(ConnectionConfig.Type.FILE);
build.pool_max = build.pool_min = 1;
build.pooling = true;
TransClient client = new TransClient(build);
HeartBeatThread.init(client);
SendMsgThread.init(client);
ReadMsgThread.init(client);
PrintMsgThread.init(client);
ClientInteractionThread.init(client);
Scanner scanner = new Scanner(System.in);
while (client.running.get()) {
try {
System.out.print("$>");
String msg = scanner.nextLine();
QyMsg clone = client.clientConf.NORMAL_MSG.clone();
clone.putMsg(msg);
client.REQ_MSG_QUEUE.add(clone);
} catch (Exception e) {
log.error("", e);
}
}
}
public Connection getConnection() throws Exception {
return factory.getConnection();
}
}