Redkale 2.3.0 结束
This commit is contained in:
@@ -8,6 +8,7 @@ package org.redkale.source;
|
||||
import org.redkale.util.AutoLoad;
|
||||
import static org.redkale.source.FilterExpress.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.*;
|
||||
import javax.persistence.*;
|
||||
import org.redkale.convert.json.*;
|
||||
@@ -20,11 +21,11 @@ public class FilterNodeTest {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
final Properties props = new Properties();
|
||||
final BiFunction<DataSource, Class, List> fullloader = (s, t) -> new ArrayList();
|
||||
final BiFunction<DataSource, EntityInfo, CompletableFuture<List>> fullloader = (s, t) -> CompletableFuture.completedFuture(new ArrayList());
|
||||
final Function<Class, EntityInfo> func = (Class t) -> EntityInfo.load(t, false, props, null, fullloader);
|
||||
final EntityInfo<CarTestTable> carEntity = EntityInfo.load(CarTestTable.class, false, props, null, (s, t) -> CarTestTable.createList());
|
||||
final EntityInfo<UserTestTable> userEntity = EntityInfo.load(UserTestTable.class, false, props, null, (s, t) -> UserTestTable.createList());
|
||||
final EntityInfo<CarTypeTestTable> typeEntity = EntityInfo.load(CarTypeTestTable.class, false, props, null, (s, t) -> CarTypeTestTable.createList());
|
||||
final EntityInfo<CarTestTable> carEntity = EntityInfo.load(CarTestTable.class, false, props, null, (s, t) -> CompletableFuture.completedFuture(CarTestTable.createList()));
|
||||
final EntityInfo<UserTestTable> userEntity = EntityInfo.load(UserTestTable.class, false, props, null, (s, t) -> CompletableFuture.completedFuture(UserTestTable.createList()));
|
||||
final EntityInfo<CarTypeTestTable> typeEntity = EntityInfo.load(CarTypeTestTable.class, false, props, null, (s, t) -> CompletableFuture.completedFuture(CarTypeTestTable.createList()));
|
||||
|
||||
final CarTestBean bean = new CarTestBean();
|
||||
bean.carid = 70002;
|
||||
@@ -47,10 +48,10 @@ public class FilterNodeTest {
|
||||
System.out.println("node.sql = SELECT a.* FROM " + CarTestTable.class.getSimpleName().toLowerCase() + " a" + (nodeJoinsql == null ? "" : nodeJoinsql) + " WHERE " + nodeWhere);
|
||||
System.out.println("bean.sql = SELECT a.* FROM " + CarTestTable.class.getSimpleName().toLowerCase() + " a" + (beanJoinsql == null ? "" : beanJoinsql) + " WHERE " + beanWhere);
|
||||
boolean r1 = node.isCacheUseable(func);
|
||||
if(!r1) System.err.println("node.isCacheUseable 应该是true");
|
||||
if (!r1) System.err.println("node.isCacheUseable 应该是true");
|
||||
boolean r2 = beanNode.isCacheUseable(func);
|
||||
if(!r2) System.err.println("beanNode.isCacheUseable 应该是true");
|
||||
|
||||
if (!r2) System.err.println("beanNode.isCacheUseable 应该是true");
|
||||
|
||||
System.out.println("node.Predicate = " + node.createPredicate(carEntity.getCache()));
|
||||
System.out.println("bean.Predicate = " + beanNode.createPredicate(carEntity.getCache()));
|
||||
System.out.println("node.sheet = " + carEntity.getCache().querySheet(null, new Flipper(), node));
|
||||
|
||||
@@ -16,7 +16,7 @@ public class AsmCreator {
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
boolean realasm = false; //从http://forge.ow2.org/projects/asm/ 下载最新asm的src放在 srcasmroot 目录下
|
||||
File srcasmroot = new File("D:/JAVA/JDK源码/jdk/internal/org/objectweb/asm");
|
||||
File srcasmroot = new File("D:/JAVA/JDK源码/JDK11源码/java.base/jdk/internal/org/objectweb/asm");
|
||||
if (realasm) srcasmroot = new File("D:/JAVA/JDK源码/org/objectweb/asm");
|
||||
File destasmroot = new File("D:/Java-Projects/RedkaleProject/src/org/redkale/asm");
|
||||
String line = null;
|
||||
@@ -29,7 +29,9 @@ public class AsmCreator {
|
||||
File destfile = new File(destasmroot, line);
|
||||
String content = Utility.readThenClose(new FileInputStream(srcfile));
|
||||
FileOutputStream out = new FileOutputStream(destfile);
|
||||
out.write(content.replace("jdk.internal.org.objectweb", "org.redkale").replace("org.objectweb", "org.redkale").getBytes());
|
||||
out.write(content.replace("jdk.internal.org.objectweb", "org.redkale").replace("org.objectweb", "org.redkale")
|
||||
.replace("<tt>", "<tt>").replace("</tt>", "</tt>")
|
||||
.replace("{@link org.redkale.asm.tree.MethodNode#getLabelNode} method.", "").getBytes());
|
||||
out.close();
|
||||
}
|
||||
//需要屏蔽ClassReader中判断checks the class version的部分
|
||||
|
||||
56
test/org/redkale/test/convert/Fortune.java
Normal file
56
test/org/redkale/test/convert/Fortune.java
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package org.redkale.test.convert;
|
||||
|
||||
import javax.persistence.Id;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public class Fortune implements Comparable<Fortune> {
|
||||
|
||||
@Id
|
||||
private int id;
|
||||
|
||||
private String message = "";
|
||||
|
||||
public Fortune() {
|
||||
}
|
||||
|
||||
public Fortune(int id, String message) {
|
||||
this.id = id;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Fortune o) {
|
||||
return message.compareTo(o.message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonConvert.root().convertTo(this);
|
||||
}
|
||||
|
||||
}
|
||||
91
test/org/redkale/test/convert/Message.java
Normal file
91
test/org/redkale/test/convert/Message.java
Normal file
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package org.redkale.test.convert;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import org.redkale.convert.*;
|
||||
import org.redkale.convert.json.*;
|
||||
import org.redkale.util.ByteArray;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public final class Message {
|
||||
|
||||
protected boolean flag;
|
||||
|
||||
private int[] ints;
|
||||
|
||||
private List<Long> longs;
|
||||
|
||||
@ConvertSmallString
|
||||
private String message;
|
||||
|
||||
public Message() {
|
||||
}
|
||||
|
||||
public List<Long> getLongs() {
|
||||
return longs;
|
||||
}
|
||||
|
||||
public void setLongs(List<Long> longs) {
|
||||
this.longs = longs;
|
||||
}
|
||||
|
||||
public int[] getInts() {
|
||||
return ints;
|
||||
}
|
||||
|
||||
public void setInts(int[] ints) {
|
||||
this.ints = ints;
|
||||
}
|
||||
|
||||
public Message(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public boolean isFlag() {
|
||||
return flag;
|
||||
}
|
||||
|
||||
public void setFlag(boolean flag) {
|
||||
this.flag = flag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonConvert.root().convertTo(this);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
Message msg = new Message();
|
||||
msg.message = "dddd";
|
||||
List<Long> longs = new ArrayList<>();
|
||||
longs.add(2222L);
|
||||
longs.add(3333L);
|
||||
msg.longs = longs;
|
||||
msg.ints = new int[]{2, 3, 4};
|
||||
JsonConvert convert = JsonFactory.root().getConvert();
|
||||
Encodeable encoder = JsonFactory.root().loadEncoder(Message.class);
|
||||
System.out.println(encoder);
|
||||
ByteArray array = new ByteArray();
|
||||
array.put("数据: ".getBytes(StandardCharsets.UTF_8));
|
||||
JsonConvert.root().convertToBytes(array, msg);
|
||||
System.out.println(array);
|
||||
Message[] mss = new Message[]{msg};
|
||||
System.out.println(JsonConvert.root().convertTo(mss));
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,9 @@
|
||||
*/
|
||||
package org.redkale.test.convert;
|
||||
|
||||
import java.util.Arrays;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
import org.redkale.util.Utility;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -60,4 +62,28 @@ public class One {
|
||||
public String toString() {
|
||||
return JsonConvert.root().convertTo(this);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
int count = 100_0000;
|
||||
One one = new One(234);
|
||||
one.bytes = new byte[]{1, 2, 3};
|
||||
one.key = "哈哈";
|
||||
|
||||
System.out.println(Arrays.toString(Utility.encodeUTF8(JsonConvert.root().convertTo(one))));
|
||||
System.out.println(Arrays.toString(JsonConvert.root().convertToBytes(one)));
|
||||
long s = System.currentTimeMillis();
|
||||
for (int i = 0; i < count; i++) {
|
||||
JsonConvert.root().convertTo(one).getBytes();
|
||||
}
|
||||
long e = System.currentTimeMillis() - s;
|
||||
|
||||
long s2 = System.currentTimeMillis();
|
||||
for (int i = 0; i < count; i++) {
|
||||
JsonConvert.root().convertToBytes(one);
|
||||
}
|
||||
long e2 = System.currentTimeMillis() - s2;
|
||||
System.out.println(e);
|
||||
System.out.println(e2);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
57
test/org/redkale/test/convert/World.java
Normal file
57
test/org/redkale/test/convert/World.java
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package org.redkale.test.convert;
|
||||
|
||||
import javax.persistence.Id;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public class World implements Comparable<World> {
|
||||
|
||||
@Id
|
||||
private int id;
|
||||
|
||||
private int randomNumber;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getRandomNumber() {
|
||||
return randomNumber;
|
||||
}
|
||||
|
||||
public void setRandomNumber(int randomNumber) {
|
||||
this.randomNumber = randomNumber;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(World o) {
|
||||
return Integer.compare(id, o.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonConvert.root().convertTo(this);
|
||||
}
|
||||
public static void main(String[] args) throws Throwable {
|
||||
World[] worlds = new World[20];
|
||||
int index = 8866;
|
||||
for(int i =0;i<worlds.length;i++){
|
||||
worlds[i] = new World();
|
||||
worlds[i].setId(8866+i);
|
||||
worlds[i].setRandomNumber(9966+i);
|
||||
}
|
||||
System.out.println(JsonConvert.root().convertTo(worlds));
|
||||
}
|
||||
}
|
||||
49
test/org/redkale/test/convert/_DyncFortuneJsonEncoder.java
Normal file
49
test/org/redkale/test/convert/_DyncFortuneJsonEncoder.java
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package org.redkale.test.convert;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import org.redkale.convert.json.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public class _DyncFortuneJsonEncoder extends JsonDynEncoder<Fortune> {
|
||||
|
||||
protected final byte[] idFieldBytes = "\"id\":".getBytes();
|
||||
|
||||
protected final byte[] messageCommaFieldBytes = ",\"message\":".getBytes();
|
||||
|
||||
public _DyncFortuneJsonEncoder(JsonFactory factory, Type type) {
|
||||
super(factory, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void convertTo(JsonWriter out, Fortune value) {
|
||||
if (value == null) {
|
||||
out.writeObjectNull(null);
|
||||
return;
|
||||
}
|
||||
if (!out.isExtFuncEmpty()) {
|
||||
objectEncoder.convertTo(out, value);
|
||||
return;
|
||||
}
|
||||
|
||||
out.writeTo('{');
|
||||
|
||||
out.writeTo(idFieldBytes);
|
||||
out.writeInt(value.getId());
|
||||
|
||||
String message = value.getMessage();
|
||||
if (message != null) {
|
||||
out.writeTo(messageCommaFieldBytes);
|
||||
out.writeString(message);
|
||||
}
|
||||
|
||||
out.writeTo('}');
|
||||
}
|
||||
}
|
||||
51
test/org/redkale/test/convert/_DyncMessageJsonEncoder.java
Normal file
51
test/org/redkale/test/convert/_DyncMessageJsonEncoder.java
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package org.redkale.test.convert;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import org.redkale.convert.json.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public class _DyncMessageJsonEncoder extends JsonDynEncoder<Message> {
|
||||
|
||||
protected final byte[] messageFieldBytes = "\"message\":".getBytes();
|
||||
|
||||
protected final byte[] messageCommaFieldBytes = ",\"message\":".getBytes();
|
||||
|
||||
public _DyncMessageJsonEncoder(JsonFactory factory, Type type) {
|
||||
super(factory, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void convertTo(JsonWriter out, Message value) {
|
||||
if (value == null) {
|
||||
out.writeObjectNull(null);
|
||||
return;
|
||||
}
|
||||
if (!out.isExtFuncEmpty()) {
|
||||
objectEncoder.convertTo(out, value);
|
||||
return;
|
||||
}
|
||||
|
||||
out.writeTo('{');
|
||||
boolean comma = false;
|
||||
String message = value.getMessage();
|
||||
if (message != null) {
|
||||
if (comma) {
|
||||
out.writeTo(messageCommaFieldBytes);
|
||||
} else {
|
||||
out.writeTo(messageFieldBytes);
|
||||
comma = true;
|
||||
}
|
||||
out.writeLatin1To(true, message); //out.writeString(message);
|
||||
}
|
||||
out.writeTo('}');
|
||||
}
|
||||
|
||||
}
|
||||
47
test/org/redkale/test/convert/_DyncWorldJsonEncoder.java
Normal file
47
test/org/redkale/test/convert/_DyncWorldJsonEncoder.java
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package org.redkale.test.convert;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import org.redkale.convert.json.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public class _DyncWorldJsonEncoder extends JsonDynEncoder<World> {
|
||||
|
||||
protected final byte[] idFieldBytes = "\"id\":".getBytes();
|
||||
|
||||
protected final byte[] randomNumberFieldBytes = ",\"randomNumber\":".getBytes();
|
||||
|
||||
public _DyncWorldJsonEncoder(JsonFactory factory, Type type) {
|
||||
super(factory, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void convertTo(JsonWriter out, World value) {
|
||||
if (value == null) {
|
||||
out.writeObjectNull(null);
|
||||
return;
|
||||
}
|
||||
if (!out.isExtFuncEmpty()) {
|
||||
objectEncoder.convertTo(out, value);
|
||||
return;
|
||||
}
|
||||
|
||||
out.writeTo('{');
|
||||
boolean comma = false;
|
||||
|
||||
out.writeTo(idFieldBytes);
|
||||
out.writeInt(value.getId());
|
||||
|
||||
out.writeTo(randomNumberFieldBytes);
|
||||
out.writeInt(value.getRandomNumber());
|
||||
|
||||
out.writeTo('}');
|
||||
}
|
||||
}
|
||||
36
test/org/redkale/test/http/SocketMain.java
Normal file
36
test/org/redkale/test/http/SocketMain.java
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package org.redkale.test.http;
|
||||
|
||||
import java.net.Socket;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public class SocketMain {
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
Socket socket = new Socket("127.0.0.1", 6060);
|
||||
socket.getOutputStream().write("GET /json1 HTTP/1.1\r\nAccpet: aaa\r\nConnection: keep-alive\r\n\r\nGET /json2 HTTP/1.1\r\nAccpet: a".getBytes());
|
||||
socket.getOutputStream().flush();
|
||||
Thread.sleep(1000);
|
||||
socket.getOutputStream().write("aa\r\nConnection: keep-alive\r\n\r".getBytes());
|
||||
socket.getOutputStream().flush();
|
||||
Thread.sleep(1000);
|
||||
socket.getOutputStream().write("\nGET /json3 HTTP/1.1\r\nAccpet: aaa\r\nConnection: keep-alive\r\n\r".getBytes());
|
||||
socket.getOutputStream().flush();
|
||||
Thread.sleep(1000);
|
||||
socket.getOutputStream().write("\n".getBytes());
|
||||
socket.getOutputStream().flush();
|
||||
byte[] bs = new byte[10240];
|
||||
int rs = socket.getInputStream().read(bs);
|
||||
System.out.println(new String(bs, 0, rs));
|
||||
rs = socket.getInputStream().read(bs);
|
||||
System.out.println(new String(bs, 0, rs));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -33,11 +33,13 @@ public class TransportTest {
|
||||
HttpServer server = new HttpServer();
|
||||
DefaultAnyValue servconf = DefaultAnyValue.create("port", servaddr.getPort());
|
||||
server.init(servconf);
|
||||
server.start();
|
||||
server.start(null);
|
||||
}
|
||||
addrs.add(new InetSocketAddress("127.0.0.1", 22005));
|
||||
final AsyncIOGroup asyncGroup = new AsyncIOGroup(8192, 16);
|
||||
asyncGroup.start();
|
||||
Thread.sleep(1000);
|
||||
TransportFactory factory = TransportFactory.create(10);
|
||||
TransportFactory factory = TransportFactory.create(asyncGroup, 0, 0);
|
||||
DefaultAnyValue conf = DefaultAnyValue.create(TransportFactory.NAME_PINGINTERVAL, 5);
|
||||
factory.init(conf, Sncp.PING_BUFFER, Sncp.PONG_BUFFER.remaining());
|
||||
Transport transport = factory.createTransportTCP("", null, addrs);
|
||||
@@ -54,7 +56,7 @@ public class TransportTest {
|
||||
HttpServer server = new HttpServer();
|
||||
DefaultAnyValue servconf = DefaultAnyValue.create("port", 22005);
|
||||
server.init(servconf);
|
||||
server.start();
|
||||
server.start(null);
|
||||
Thread.sleep(4000);
|
||||
CountDownLatch cdl2 = new CountDownLatch(20);
|
||||
for (int i = 0; i < 20; i++) {
|
||||
|
||||
@@ -28,7 +28,7 @@ public class _DynHelloRestServlet1 extends SimpleRestServlet {
|
||||
|
||||
DefaultAnyValue conf = DefaultAnyValue.create("port", "" + port);
|
||||
server.init(conf);
|
||||
server.start();
|
||||
server.start(null);
|
||||
Thread.sleep(100);
|
||||
|
||||
HelloEntity entity = new HelloEntity();
|
||||
|
||||
@@ -15,7 +15,7 @@ import java.util.logging.*;
|
||||
import javax.annotation.Resource;
|
||||
import org.redkale.convert.bson.BsonConvert;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
import org.redkale.net.TransportFactory;
|
||||
import org.redkale.net.*;
|
||||
import org.redkale.net.http.*;
|
||||
import org.redkale.net.sncp.*;
|
||||
import org.redkale.service.Service;
|
||||
@@ -35,9 +35,11 @@ public class ABMainService implements Service {
|
||||
public static void remotemain(String[] args) throws Throwable {
|
||||
System.out.println("------------------- 远程模式调用 -----------------------------------");
|
||||
final int abport = 8888;
|
||||
final AsyncIOGroup asyncGroup = new AsyncIOGroup(8192, 16);
|
||||
asyncGroup.start();
|
||||
ResourceFactory resFactory = ResourceFactory.root();
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
final TransportFactory transFactory = TransportFactory.create(executor, newBufferPool(), newChannelGroup());
|
||||
final TransportFactory transFactory = TransportFactory.create(asyncGroup, 0, 0);
|
||||
transFactory.addGroupInfo("g77", new InetSocketAddress("127.0.0.1", 5577));
|
||||
transFactory.addGroupInfo("g88", new InetSocketAddress("127.0.0.1", 5588));
|
||||
transFactory.addGroupInfo("g99", new InetSocketAddress("127.0.0.1", 5599));
|
||||
@@ -51,7 +53,7 @@ public class ABMainService implements Service {
|
||||
cserver.getLogger().setLevel(Level.WARNING);
|
||||
cserver.addSncpServlet(cservice);
|
||||
cserver.init(DefaultAnyValue.create("port", 5577));
|
||||
cserver.start();
|
||||
cserver.start(null);
|
||||
|
||||
//------------------------ 初始化 BCService ------------------------------------
|
||||
BCService bcservice = Sncp.createSimpleLocalService(BCService.class, null, transFactory, new InetSocketAddress("127.0.0.1", 5588), "g88");
|
||||
@@ -62,7 +64,7 @@ public class ABMainService implements Service {
|
||||
bcserver.getLogger().setLevel(Level.WARNING);
|
||||
bcserver.addSncpServlet(bcservice);
|
||||
bcserver.init(DefaultAnyValue.create("port", 5588));
|
||||
bcserver.start();
|
||||
bcserver.start(null);
|
||||
|
||||
//------------------------ 初始化 ABMainService ------------------------------------
|
||||
ABMainService service = Sncp.createSimpleLocalService(ABMainService.class, null, transFactory, new InetSocketAddress("127.0.0.1", 5599), "g99");
|
||||
@@ -80,7 +82,7 @@ public class ABMainService implements Service {
|
||||
resFactory.inject(service);
|
||||
|
||||
server.init(DefaultAnyValue.create("port", abport));
|
||||
server.start();
|
||||
server.start(null);
|
||||
Thread.sleep(100);
|
||||
|
||||
//同步方法
|
||||
@@ -117,7 +119,7 @@ public class ABMainService implements Service {
|
||||
server.addRestServlet(null, service, null, HttpServlet.class, "/pipes");
|
||||
|
||||
server.init(DefaultAnyValue.create("port", "" + abport));
|
||||
server.start();
|
||||
server.start(null);
|
||||
Thread.sleep(100);
|
||||
|
||||
//同步方法
|
||||
|
||||
@@ -14,7 +14,7 @@ import java.util.concurrent.*;
|
||||
import java.util.concurrent.atomic.*;
|
||||
import java.util.logging.LogManager;
|
||||
import org.redkale.convert.bson.*;
|
||||
import org.redkale.net.TransportFactory;
|
||||
import org.redkale.net.*;
|
||||
import org.redkale.net.sncp.*;
|
||||
import org.redkale.service.Service;
|
||||
import org.redkale.util.*;
|
||||
@@ -33,6 +33,8 @@ public class SncpTest {
|
||||
|
||||
private static final int port2 = 4240;
|
||||
|
||||
private static final String protocol = "SNCP.UDP";
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
final PrintStream ps = new PrintStream(out);
|
||||
@@ -79,7 +81,9 @@ public class SncpTest {
|
||||
Set<InetSocketAddress> set = new LinkedHashSet<>();
|
||||
set.add(addr);
|
||||
if (port2 > 0) set.add(new InetSocketAddress(myhost, port2));
|
||||
final TransportFactory transFactory = TransportFactory.create(Executors.newSingleThreadExecutor(), newBufferPool(), newChannelGroup());
|
||||
final AsyncIOGroup asyncGroup = new AsyncIOGroup(8192, 16);
|
||||
asyncGroup.start();
|
||||
final TransportFactory transFactory = TransportFactory.create(asyncGroup, protocol.endsWith(".UDP") ? "UDP" : "TCP", 0, 0);
|
||||
transFactory.addGroupInfo("client", set);
|
||||
final SncpTestIService service = Sncp.createSimpleRemoteService(SncpTestIService.class, null, transFactory, addr, "client");
|
||||
ResourceFactory.root().inject(service);
|
||||
@@ -146,6 +150,8 @@ public class SncpTest {
|
||||
private static void runServer() throws Exception {
|
||||
InetSocketAddress addr = new InetSocketAddress(myhost, port);
|
||||
final CountDownLatch cdl = new CountDownLatch(1);
|
||||
final AsyncIOGroup asyncGroup = new AsyncIOGroup(8192, 16);
|
||||
asyncGroup.start();
|
||||
new Thread() {
|
||||
{
|
||||
setName("Thread-Server-01");
|
||||
@@ -154,20 +160,21 @@ public class SncpTest {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
SncpServer server = new SncpServer();
|
||||
AnyValue.DefaultAnyValue conf = new AnyValue.DefaultAnyValue();
|
||||
conf.addValue("host", "0.0.0.0");
|
||||
conf.addValue("port", "" + port);
|
||||
conf.addValue("protocol", protocol);
|
||||
SncpServer server = new SncpServer(null, System.currentTimeMillis(), conf, ResourceFactory.root());
|
||||
Set<InetSocketAddress> set = new LinkedHashSet<>();
|
||||
if (port2 > 0) set.add(new InetSocketAddress(myhost, port2));
|
||||
final TransportFactory transFactory = TransportFactory.create(Executors.newSingleThreadExecutor(), newBufferPool(), newChannelGroup());
|
||||
final TransportFactory transFactory = TransportFactory.create(asyncGroup, protocol.endsWith(".UDP") ? "UDP" : "TCP", 0, 0);
|
||||
transFactory.addGroupInfo("server", set);
|
||||
SncpTestIService service = Sncp.createSimpleLocalService(SncpTestServiceImpl.class, null, transFactory, addr, "server");
|
||||
ResourceFactory.root().inject(service);
|
||||
server.addSncpServlet(service);
|
||||
System.out.println(service);
|
||||
AnyValue.DefaultAnyValue conf = new AnyValue.DefaultAnyValue();
|
||||
conf.addValue("host", "0.0.0.0");
|
||||
conf.addValue("port", "" + port);
|
||||
server.init(conf);
|
||||
server.start();
|
||||
server.start(null);
|
||||
cdl.countDown();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@@ -180,6 +187,8 @@ public class SncpTest {
|
||||
private static void runServer2() throws Exception {
|
||||
InetSocketAddress addr = new InetSocketAddress(myhost, port2);
|
||||
final CountDownLatch cdl = new CountDownLatch(1);
|
||||
final AsyncIOGroup asyncGroup = new AsyncIOGroup(8192, 16);
|
||||
asyncGroup.start();
|
||||
new Thread() {
|
||||
{
|
||||
setName("Thread-Server-02");
|
||||
@@ -188,19 +197,20 @@ public class SncpTest {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
SncpServer server = new SncpServer();
|
||||
Set<InetSocketAddress> set = new LinkedHashSet<>();
|
||||
set.add(new InetSocketAddress(myhost, port));
|
||||
|
||||
final TransportFactory transFactory = TransportFactory.create(Executors.newSingleThreadExecutor(), newBufferPool(), newChannelGroup());
|
||||
transFactory.addGroupInfo("server", set);
|
||||
Service service = Sncp.createSimpleLocalService(SncpTestServiceImpl.class, null, transFactory, addr, "server");
|
||||
server.addSncpServlet(service);
|
||||
AnyValue.DefaultAnyValue conf = new AnyValue.DefaultAnyValue();
|
||||
conf.addValue("host", "0.0.0.0");
|
||||
conf.addValue("port", "" + port2);
|
||||
conf.addValue("protocol", protocol);
|
||||
SncpServer server = new SncpServer(null, System.currentTimeMillis(), conf, ResourceFactory.root());
|
||||
Set<InetSocketAddress> set = new LinkedHashSet<>();
|
||||
set.add(new InetSocketAddress(myhost, port));
|
||||
|
||||
final TransportFactory transFactory = TransportFactory.create(asyncGroup, protocol.endsWith(".UDP") ? "UDP" : "TCP", 0, 0);
|
||||
transFactory.addGroupInfo("server", set);
|
||||
Service service = Sncp.createSimpleLocalService(SncpTestServiceImpl.class, null, transFactory, addr, "server");
|
||||
server.addSncpServlet(service);
|
||||
server.init(conf);
|
||||
server.start();
|
||||
server.start(null);
|
||||
cdl.countDown();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -9,10 +9,9 @@ import java.lang.reflect.Method;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.channels.CompletionHandler;
|
||||
import java.util.concurrent.*;
|
||||
import org.redkale.net.TransportFactory;
|
||||
import org.redkale.net.*;
|
||||
import org.redkale.net.sncp.*;
|
||||
import org.redkale.service.*;
|
||||
import static org.redkale.test.sncp.SncpTest.*;
|
||||
import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
@@ -109,7 +108,9 @@ public class SncpTestServiceImpl implements SncpTestIService {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
final TransportFactory transFactory = TransportFactory.create(Executors.newSingleThreadExecutor(), newBufferPool(), newChannelGroup());
|
||||
final AsyncIOGroup asyncGroup = new AsyncIOGroup(8192, 16);
|
||||
asyncGroup.start();
|
||||
final TransportFactory transFactory = TransportFactory.create(asyncGroup, 0, 0);
|
||||
|
||||
transFactory.addGroupInfo("g70", new InetSocketAddress("127.0.0.1", 7070));
|
||||
Service service = Sncp.createSimpleLocalService(SncpTestServiceImpl.class, null, transFactory, new InetSocketAddress("127.0.0.1", 7070), "g70");
|
||||
|
||||
@@ -7,6 +7,7 @@ package org.redkale.test.source;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.BiFunction;
|
||||
import javax.persistence.Id;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
@@ -31,7 +32,7 @@ public class CacheTestBean {
|
||||
method.setAccessible(true);
|
||||
final EntityInfo<CacheTestBean> info = (EntityInfo<CacheTestBean>) method.invoke(null, CacheTestBean.class, true, new Properties(), null, new CacheTestBean.DefaultBeanLoader());
|
||||
EntityCache<CacheTestBean> cache = new EntityCache(info, null);
|
||||
cache.fullLoad();
|
||||
cache.fullLoadAsync();
|
||||
|
||||
System.out.println(cache.queryColumnMap("pkgid", FilterFunc.COUNT, "name", null));
|
||||
System.out.println(cache.queryColumnMap("pkgid", FilterFunc.DISTINCTCOUNT, "name", null));
|
||||
@@ -83,16 +84,16 @@ public class CacheTestBean {
|
||||
return JsonConvert.root().convertTo(this);
|
||||
}
|
||||
|
||||
public static class DefaultBeanLoader implements BiFunction<DataSource, Class, List> {
|
||||
public static class DefaultBeanLoader implements BiFunction<DataSource, EntityInfo, CompletableFuture<List>> {
|
||||
|
||||
@Override
|
||||
public List apply(DataSource t, Class u) {
|
||||
public CompletableFuture<List> apply(DataSource t, EntityInfo u) {
|
||||
final List<CacheTestBean> list = new ArrayList<>();
|
||||
list.add(new CacheTestBean(1, "a", 12));
|
||||
list.add(new CacheTestBean(1, "a", 18));
|
||||
list.add(new CacheTestBean(2, "b", 20));
|
||||
list.add(new CacheTestBean(2, "bb", 60));
|
||||
return list;
|
||||
return CompletableFuture.completedFuture(list);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ public class VideoWebSocketServlet extends WebSocketServlet {
|
||||
HttpServer server = new HttpServer();
|
||||
server.addHttpServlet("/pipes", new VideoWebSocketServlet(), "/listen/*");
|
||||
server.init(config);
|
||||
server.start();
|
||||
server.start(null);
|
||||
cdl.await();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user