Full Code Format
This commit is contained in:
@@ -8,14 +8,11 @@ package org.redkale.test.asm;
|
||||
import java.io.*;
|
||||
import org.redkale.util.Utility;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class AsmCreator {
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
boolean realasm = false; //从http://forge.ow2.org/projects/asm/ 下载最新asm的src放在 srcasmroot 目录下
|
||||
boolean realasm = false; // 从http://forge.ow2.org/projects/asm/ 下载最新asm的src放在 srcasmroot 目录下
|
||||
File srcasmroot = new File("D:/JAVA/JDK源码/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/main/java/org/redkale/asm");
|
||||
@@ -29,11 +26,14 @@ 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")
|
||||
.replace("<tt>", "<tt>").replace("</tt>", "</tt>")
|
||||
.replace("{@link org.redkale.asm.tree.MethodNode#getLabelNode} method.", "").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的部分
|
||||
// 需要屏蔽ClassReader中判断checks the class version的部分
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,16 +17,13 @@ import org.redkale.service.Service;
|
||||
import org.redkale.source.Range;
|
||||
import org.redkale.util.RedkaleException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class CacheInstance implements Service {
|
||||
|
||||
@Resource
|
||||
private CacheManager cacheManager;
|
||||
|
||||
//修改远程缓存的key值
|
||||
// 修改远程缓存的key值
|
||||
public void updateName(String code, Map<String, Long> map) {
|
||||
cacheManager.remoteSetString(code, code + "_" + map.get("id"), Duration.ofMillis(60));
|
||||
}
|
||||
@@ -66,9 +63,14 @@ public class CacheInstance implements Service {
|
||||
return CompletableFuture.completedFuture(new File("aa.txt"));
|
||||
}
|
||||
|
||||
@Cached(key = "info_#{id}_file#{files.one}", localExpire = "30", remoteExpire = "60", timeUnit = TimeUnit.MILLISECONDS)
|
||||
public CompletableFuture<Map<String, Integer>> getInfo2Async(ParamBean bean,
|
||||
int id, List<String> idList, Map<String, File> files) throws IOException, InstantiationException {
|
||||
@Cached(
|
||||
key = "info_#{id}_file#{files.one}",
|
||||
localExpire = "30",
|
||||
remoteExpire = "60",
|
||||
timeUnit = TimeUnit.MILLISECONDS)
|
||||
public CompletableFuture<Map<String, Integer>> getInfo2Async(
|
||||
ParamBean bean, int id, List<String> idList, Map<String, File> files)
|
||||
throws IOException, InstantiationException {
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
@@ -113,6 +115,5 @@ public class CacheInstance implements Service {
|
||||
public void setRange(Range.IntRange range) {
|
||||
this.range = range;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,10 +19,7 @@ import org.redkale.source.CacheMemorySource;
|
||||
import org.redkale.util.Environment;
|
||||
import org.redkale.util.Utility;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class CacheInstanceTest {
|
||||
|
||||
private static ResourceFactory resourceFactory;
|
||||
@@ -53,14 +50,13 @@ public class CacheInstanceTest {
|
||||
CacheAsmMethodBoost boost = new CacheAsmMethodBoost(false, serviceClass);
|
||||
SncpRpcGroups grous = new SncpRpcGroups();
|
||||
AsyncGroup iGroup = AsyncGroup.create("", Utility.newScheduledExecutor(1), 0, 0);
|
||||
SncpClient client = new SncpClient("", iGroup, "0", new InetSocketAddress("127.0.0.1", 8080), new ClientAddress(), "TCP", 1, 16);
|
||||
CacheInstance instance = Sncp.createLocalService(null, "", serviceClass, boost, resourceFactory,
|
||||
grous, client, null, null, null);
|
||||
//System.out.println(instance.getName());
|
||||
SncpClient client = new SncpClient(
|
||||
"", iGroup, "0", new InetSocketAddress("127.0.0.1", 8080), new ClientAddress(), "TCP", 1, 16);
|
||||
CacheInstance instance = Sncp.createLocalService(
|
||||
null, "", serviceClass, boost, resourceFactory, grous, client, null, null, null);
|
||||
// System.out.println(instance.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void run2() throws Exception {
|
||||
|
||||
}
|
||||
public void run2() throws Exception {}
|
||||
}
|
||||
|
||||
@@ -12,10 +12,7 @@ import org.redkale.convert.json.JsonConvert;
|
||||
import org.redkale.source.CacheMemorySource;
|
||||
import org.redkale.util.Utility;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class CacheManagerTest {
|
||||
|
||||
private static CacheManagerService manager;
|
||||
@@ -49,9 +46,11 @@ public class CacheManagerTest {
|
||||
|
||||
String json = bean.toString();
|
||||
manager.localSet("user", bean.getName(), CachingBean.class, bean, expire);
|
||||
Assertions.assertEquals(manager.localGet("user", bean.getName(), CachingBean.class).toString(), json);
|
||||
Assertions.assertEquals(
|
||||
manager.localGet("user", bean.getName(), CachingBean.class).toString(), json);
|
||||
bean.setRemark(bean.getRemark() + "-新备注");
|
||||
Assertions.assertEquals(manager.localGet("user", bean.getName(), CachingBean.class).toString(), json);
|
||||
Assertions.assertEquals(
|
||||
manager.localGet("user", bean.getName(), CachingBean.class).toString(), json);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -64,29 +63,45 @@ public class CacheManagerTest {
|
||||
CountDownLatch cdl = new CountDownLatch(count);
|
||||
for (int i = 0; i < count; i++) {
|
||||
new Thread(() -> {
|
||||
manager.bothGetSet("ParallelBean", "name", String.class, false, localExpire, remoteExpire, () -> bean.getName());
|
||||
cdl.countDown();
|
||||
}).start();
|
||||
manager.bothGetSet(
|
||||
"ParallelBean",
|
||||
"name",
|
||||
String.class,
|
||||
false,
|
||||
localExpire,
|
||||
remoteExpire,
|
||||
() -> bean.getName());
|
||||
cdl.countDown();
|
||||
})
|
||||
.start();
|
||||
}
|
||||
cdl.await();
|
||||
}
|
||||
Assertions.assertEquals(1, ParallelBean.c1.get());
|
||||
Utility.sleep(200);
|
||||
manager.bothGetSet("ParallelBean", "name", String.class, false, localExpire, remoteExpire, () -> bean.getName());
|
||||
manager.bothGetSet(
|
||||
"ParallelBean", "name", String.class, false, localExpire, remoteExpire, () -> bean.getName());
|
||||
Assertions.assertEquals(1, ParallelBean.c1.get());
|
||||
Utility.sleep(200);
|
||||
{
|
||||
CountDownLatch cdl = new CountDownLatch(count);
|
||||
for (int i = 0; i < count; i++) {
|
||||
new Thread(() -> {
|
||||
manager.bothGetSet("ParallelBean", "name", String.class, false, localExpire, remoteExpire, () -> bean.getName());
|
||||
cdl.countDown();
|
||||
}).start();
|
||||
manager.bothGetSet(
|
||||
"ParallelBean",
|
||||
"name",
|
||||
String.class,
|
||||
false,
|
||||
localExpire,
|
||||
remoteExpire,
|
||||
() -> bean.getName());
|
||||
cdl.countDown();
|
||||
})
|
||||
.start();
|
||||
}
|
||||
cdl.await();
|
||||
}
|
||||
Assertions.assertEquals(2, ParallelBean.c1.get());
|
||||
|
||||
}
|
||||
|
||||
public static class ParallelBean {
|
||||
|
||||
@@ -18,13 +18,8 @@ import org.redkale.util.AnyValue;
|
||||
import org.redkale.util.RedkaleException;
|
||||
import org.redkale.util.ThrowSupplier;
|
||||
|
||||
@Resource(
|
||||
name = ""
|
||||
)
|
||||
@SncpDyn(
|
||||
remote = false,
|
||||
type = CacheInstance.class
|
||||
)
|
||||
@Resource(name = "")
|
||||
@SncpDyn(remote = false, type = CacheInstance.class)
|
||||
@ResourceType(CacheInstance.class)
|
||||
public class _DynLocalCacheInstance extends CacheInstance {
|
||||
|
||||
@@ -46,11 +41,16 @@ public class _DynLocalCacheInstance extends CacheInstance {
|
||||
|
||||
private CacheAction _redkale_getName2CacheAction7;
|
||||
|
||||
public _DynLocalCacheInstance() {
|
||||
}
|
||||
public _DynLocalCacheInstance() {}
|
||||
|
||||
@DynForCache(dynField = "_redkale_getNameCacheAction1", hash = "", key = "name", nullable = false, timeUnit = TimeUnit.SECONDS, remoteExpire = "-1", localExpire = "30"
|
||||
)
|
||||
@DynForCache(
|
||||
dynField = "_redkale_getNameCacheAction1",
|
||||
hash = "",
|
||||
key = "name",
|
||||
nullable = false,
|
||||
timeUnit = TimeUnit.SECONDS,
|
||||
remoteExpire = "-1",
|
||||
localExpire = "30")
|
||||
public String getName() {
|
||||
ThrowSupplier<String> supplier = () -> this.getName_afterCache();
|
||||
return _redkale_getNameCacheAction1.get(supplier);
|
||||
@@ -60,17 +60,32 @@ public class _DynLocalCacheInstance extends CacheInstance {
|
||||
return super.getName();
|
||||
}
|
||||
|
||||
@DynForCache(dynField = "_redkale_getInfoCacheAction2", hash = "", key = "info_#{id}_file#{files.one}", nullable = false, timeUnit = TimeUnit.SECONDS, remoteExpire = "60", localExpire = "30")
|
||||
@DynForCache(
|
||||
dynField = "_redkale_getInfoCacheAction2",
|
||||
hash = "",
|
||||
key = "info_#{id}_file#{files.one}",
|
||||
nullable = false,
|
||||
timeUnit = TimeUnit.SECONDS,
|
||||
remoteExpire = "60",
|
||||
localExpire = "30")
|
||||
public File getInfo(CacheInstance.ParamBean bean, int id, List<String> idList, Map<String, File> files) {
|
||||
ThrowSupplier<File> supplier = () -> this.getInfo_afterCache(bean, id, idList, files);
|
||||
return _redkale_getInfoCacheAction2.get(supplier);
|
||||
}
|
||||
|
||||
private File getInfo_afterCache(CacheInstance.ParamBean bean, int id, List<String> idList, Map<String, File> files) {
|
||||
private File getInfo_afterCache(
|
||||
CacheInstance.ParamBean bean, int id, List<String> idList, Map<String, File> files) {
|
||||
return super.getInfo(bean, id, idList, files);
|
||||
}
|
||||
|
||||
@DynForCache(dynField = "_redkale_getNameAsyncCacheAction3", hash = "", key = "name", nullable = false, timeUnit = TimeUnit.SECONDS, remoteExpire = "-1", localExpire = "30")
|
||||
@DynForCache(
|
||||
dynField = "_redkale_getNameAsyncCacheAction3",
|
||||
hash = "",
|
||||
key = "name",
|
||||
nullable = false,
|
||||
timeUnit = TimeUnit.SECONDS,
|
||||
remoteExpire = "-1",
|
||||
localExpire = "30")
|
||||
public CompletableFuture<String> getNameAsync() {
|
||||
ThrowSupplier<CompletableFuture<String>> supplier = () -> this.getNameAsync_afterCache();
|
||||
return _redkale_getNameAsyncCacheAction3.get(supplier);
|
||||
@@ -80,19 +95,36 @@ public class _DynLocalCacheInstance extends CacheInstance {
|
||||
return super.getNameAsync();
|
||||
}
|
||||
|
||||
@DynForCache(dynField = "_redkale_getInfo2AsyncCacheAction4", hash = "", key = "info_#{id}_file#{files.one}", nullable = false, timeUnit = TimeUnit.SECONDS, remoteExpire = "60", localExpire = "30")
|
||||
public CompletableFuture<Map<String, Integer>> getInfo2Async(CacheInstance.ParamBean bean, int id,
|
||||
List<String> idList, Map<String, File> files) throws IOException, InstantiationException {
|
||||
ThrowSupplier<CompletableFuture<Map<String, Integer>>> supplier = () -> this.getInfo2Async_afterCache(bean, id, idList, files);
|
||||
@DynForCache(
|
||||
dynField = "_redkale_getInfo2AsyncCacheAction4",
|
||||
hash = "",
|
||||
key = "info_#{id}_file#{files.one}",
|
||||
nullable = false,
|
||||
timeUnit = TimeUnit.SECONDS,
|
||||
remoteExpire = "60",
|
||||
localExpire = "30")
|
||||
public CompletableFuture<Map<String, Integer>> getInfo2Async(
|
||||
CacheInstance.ParamBean bean, int id, List<String> idList, Map<String, File> files)
|
||||
throws IOException, InstantiationException {
|
||||
ThrowSupplier<CompletableFuture<Map<String, Integer>>> supplier =
|
||||
() -> this.getInfo2Async_afterCache(bean, id, idList, files);
|
||||
return _redkale_getInfo2AsyncCacheAction4.get(supplier, bean, id, idList, files);
|
||||
}
|
||||
|
||||
private CompletableFuture<Map<String, Integer>> getInfo2Async_afterCache(CacheInstance.ParamBean bean, int id,
|
||||
List<String> idList, Map<String, File> files) throws IOException, InstantiationException {
|
||||
private CompletableFuture<Map<String, Integer>> getInfo2Async_afterCache(
|
||||
CacheInstance.ParamBean bean, int id, List<String> idList, Map<String, File> files)
|
||||
throws IOException, InstantiationException {
|
||||
return super.getInfo2Async(bean, id, idList, files);
|
||||
}
|
||||
|
||||
@DynForCache(dynField = "_redkale_getName2AsyncCacheAction5", hash = "", key = "name", nullable = false, timeUnit = TimeUnit.SECONDS, remoteExpire = "60", localExpire = "30")
|
||||
@DynForCache(
|
||||
dynField = "_redkale_getName2AsyncCacheAction5",
|
||||
hash = "",
|
||||
key = "name",
|
||||
nullable = false,
|
||||
timeUnit = TimeUnit.SECONDS,
|
||||
remoteExpire = "60",
|
||||
localExpire = "30")
|
||||
public CompletableFuture<String> getName2Async() throws IOException, InstantiationException {
|
||||
ThrowSupplier<CompletableFuture<String>> supplier = () -> this.getName2Async_afterCache();
|
||||
return _redkale_getName2AsyncCacheAction5.get(supplier);
|
||||
@@ -102,17 +134,33 @@ public class _DynLocalCacheInstance extends CacheInstance {
|
||||
return super.getName2Async();
|
||||
}
|
||||
|
||||
@DynForCache(dynField = "_redkale_getInfoAsyncCacheAction6", hash = "", key = "info_#{id}_file#{files.one}", nullable = false, timeUnit = TimeUnit.SECONDS, remoteExpire = "60", localExpire = "30")
|
||||
public CompletableFuture<File> getInfoAsync(CacheInstance.ParamBean bean, int id, List<String> idList, Map<String, File> files) {
|
||||
@DynForCache(
|
||||
dynField = "_redkale_getInfoAsyncCacheAction6",
|
||||
hash = "",
|
||||
key = "info_#{id}_file#{files.one}",
|
||||
nullable = false,
|
||||
timeUnit = TimeUnit.SECONDS,
|
||||
remoteExpire = "60",
|
||||
localExpire = "30")
|
||||
public CompletableFuture<File> getInfoAsync(
|
||||
CacheInstance.ParamBean bean, int id, List<String> idList, Map<String, File> files) {
|
||||
ThrowSupplier<CompletableFuture<File>> supplier = () -> this.getInfoAsync_afterCache(bean, id, idList, files);
|
||||
return _redkale_getInfoAsyncCacheAction6.get(supplier, bean, id, idList, files);
|
||||
}
|
||||
|
||||
private CompletableFuture<File> getInfoAsync_afterCache(CacheInstance.ParamBean bean, int id, List<String> idList, Map<String, File> files) {
|
||||
private CompletableFuture<File> getInfoAsync_afterCache(
|
||||
CacheInstance.ParamBean bean, int id, List<String> idList, Map<String, File> files) {
|
||||
return super.getInfoAsync(bean, id, idList, files);
|
||||
}
|
||||
|
||||
@DynForCache(dynField = "_redkale_getName2CacheAction7", hash = "", key = "name", nullable = false, timeUnit = TimeUnit.SECONDS, remoteExpire = "60", localExpire = "30")
|
||||
@DynForCache(
|
||||
dynField = "_redkale_getName2CacheAction7",
|
||||
hash = "",
|
||||
key = "name",
|
||||
nullable = false,
|
||||
timeUnit = TimeUnit.SECONDS,
|
||||
remoteExpire = "60",
|
||||
localExpire = "30")
|
||||
public String getName2() throws RedkaleException {
|
||||
ThrowSupplier<String> supplier = () -> this.getName2_afterCache();
|
||||
return _redkale_getName2CacheAction7.get(supplier);
|
||||
|
||||
@@ -11,9 +11,7 @@ import org.redkale.convert.ConvertField;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
import org.redkale.util.Attribute;
|
||||
|
||||
/**
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class BiFunctionConvertTest {
|
||||
|
||||
public static class GamePlayer {
|
||||
@@ -37,36 +35,39 @@ public class BiFunctionConvertTest {
|
||||
GamePlayer player1 = new GamePlayer();
|
||||
player1.userid = 1;
|
||||
player1.username = "玩家1";
|
||||
player1.cards = new int[]{11, 12, 13, 14, 15};
|
||||
player1.cards = new int[] {11, 12, 13, 14, 15};
|
||||
GamePlayer player2 = new GamePlayer();
|
||||
player2.userid = 2;
|
||||
player2.username = "玩家2";
|
||||
player2.cards = new int[]{21, 22, 23, 24, 25};
|
||||
player2.cards = new int[] {21, 22, 23, 24, 25};
|
||||
GamePlayer player3 = new GamePlayer();
|
||||
player3.userid = 3;
|
||||
player3.username = "玩家3";
|
||||
player3.cards = new int[]{31, 32, 33, 34, 35};
|
||||
player3.cards = new int[] {31, 32, 33, 34, 35};
|
||||
GameTable table = new GameTable();
|
||||
table.tableid = 100;
|
||||
table.players = new GamePlayer[]{player1, player2, player3};
|
||||
table.players = new GamePlayer[] {player1, player2, player3};
|
||||
JsonConvert convert1 = JsonConvert.root();
|
||||
System.out.println(convert1.convertTo(table));
|
||||
JsonConvert convert2 = convert1.newConvert((Attribute t, Object u) -> {
|
||||
if (t.field().equals("cards") && u instanceof GamePlayer) {
|
||||
int userid = ((GamePlayer) u).userid;
|
||||
if (userid == 3) return null; //玩家3的cards不输出
|
||||
return t.get(u);
|
||||
}
|
||||
return t.get(u);
|
||||
}, (Object u) -> {
|
||||
if (table != u) return null;
|
||||
//return new ConvertField[]{new ConvertField("extcol1", 30), new ConvertField("extcol2", "扩展字段值")};
|
||||
return ConvertField.ofArray("extcol1", 30, "extcol2", "扩展字段值");
|
||||
});
|
||||
JsonConvert convert2 = convert1.newConvert(
|
||||
(Attribute t, Object u) -> {
|
||||
if (t.field().equals("cards") && u instanceof GamePlayer) {
|
||||
int userid = ((GamePlayer) u).userid;
|
||||
if (userid == 3) return null; // 玩家3的cards不输出
|
||||
return t.get(u);
|
||||
}
|
||||
return t.get(u);
|
||||
},
|
||||
(Object u) -> {
|
||||
if (table != u) return null;
|
||||
// return new ConvertField[]{new ConvertField("extcol1", 30), new ConvertField("extcol2", "扩展字段值")};
|
||||
return ConvertField.ofArray("extcol1", 30, "extcol2", "扩展字段值");
|
||||
});
|
||||
System.out.println(convert2.convertTo(table));
|
||||
Assertions.assertEquals("{\"players\":[{\"cards\":[11,12,13,14,15],\"userid\":1,\"username\":\"玩家1\"},{\"cards\":[21,22,23,24,25],\"userid\":2,\"username\":\"玩家2\"},{\"userid\":3,\"username\":\"玩家3\"}],\"tableid\":100,\"extcol1\":30,\"extcol2\":\"扩展字段值\"}",
|
||||
convert2.convertTo(table));
|
||||
//{"players":[{"cards":[11,12,13,14,15],"userid":1,"username":"玩家1"},{"cards":[21,22,23,24,25],"userid":2,"username":"玩家2"},{"cards":[31,32,33,34,35],"userid":3,"username":"玩家3"}],"tableid":100}
|
||||
//{"players":[{"cards":[11,12,13,14,15],"userid":1,"username":"玩家1"},{"cards":[21,22,23,24,25],"userid":2,"username":"玩家2"},{"userid":3,"username":"玩家3"}],"tableid":100,"extcol1":30,"extcol2":"扩展字段值"}
|
||||
Assertions.assertEquals(
|
||||
"{\"players\":[{\"cards\":[11,12,13,14,15],\"userid\":1,\"username\":\"玩家1\"},{\"cards\":[21,22,23,24,25],\"userid\":2,\"username\":\"玩家2\"},{\"userid\":3,\"username\":\"玩家3\"}],\"tableid\":100,\"extcol1\":30,\"extcol2\":\"扩展字段值\"}",
|
||||
convert2.convertTo(table));
|
||||
// {"players":[{"cards":[11,12,13,14,15],"userid":1,"username":"玩家1"},{"cards":[21,22,23,24,25],"userid":2,"username":"玩家2"},{"cards":[31,32,33,34,35],"userid":3,"username":"玩家3"}],"tableid":100}
|
||||
// {"players":[{"cards":[11,12,13,14,15],"userid":1,"username":"玩家1"},{"cards":[21,22,23,24,25],"userid":2,"username":"玩家2"},{"userid":3,"username":"玩家3"}],"tableid":100,"extcol1":30,"extcol2":"扩展字段值"}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,12 +15,9 @@ import org.redkale.convert.json.JsonConvert;
|
||||
import org.redkale.persistence.*;
|
||||
import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class BsonMainTest {
|
||||
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
BsonMainTest test = new BsonMainTest();
|
||||
test.run1();
|
||||
@@ -35,11 +32,14 @@ public class BsonMainTest {
|
||||
|
||||
@Test
|
||||
public void run1() throws Throwable {
|
||||
Serializable[] sers = new Serializable[]{"aaa", 4};
|
||||
Serializable[] sers = new Serializable[] {"aaa", 4};
|
||||
final BsonConvert convert = BsonFactory.root().getConvert();
|
||||
byte[] bytes = convert.convertTo(sers);
|
||||
Utility.println("---", bytes);
|
||||
byte[] checks = new byte[]{0x00, 0x00, 0x00, 0x02, 0x7f, 0x01, 0x41, 0x00, 0x00, 0x00, 0x03, 0x61, 0x61, 0x61, 0x01, 0x69, 0x00, 0x00, 0x00, 0x04};
|
||||
byte[] checks = new byte[] {
|
||||
0x00, 0x00, 0x00, 0x02, 0x7f, 0x01, 0x41, 0x00, 0x00, 0x00, 0x03, 0x61, 0x61, 0x61, 0x01, 0x69, 0x00, 0x00,
|
||||
0x00, 0x04
|
||||
};
|
||||
Assertions.assertArrayEquals(checks, bytes);
|
||||
Serializable[] a = convert.convertFrom(Serializable[].class, bytes);
|
||||
Assertions.assertEquals("[aaa, 4]", Arrays.toString(a));
|
||||
@@ -88,7 +88,9 @@ public class BsonMainTest {
|
||||
convert.convertTo(writer, bean);
|
||||
bytes2 = writer.toArray();
|
||||
System.out.println(convert.convertFrom(ComplextEntity.class, bytes2).toString());
|
||||
Assertions.assertEquals("{\"chname\":\"\",\"flag\":true,\"userid\":0}", convert.convertFrom(ComplextEntity.class, bytes2).toString());
|
||||
Assertions.assertEquals(
|
||||
"{\"chname\":\"\",\"flag\":true,\"userid\":0}",
|
||||
convert.convertFrom(ComplextEntity.class, bytes2).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -129,10 +131,8 @@ public class BsonMainTest {
|
||||
bs = convert.convertTo(Object.class, val);
|
||||
obj = convert.convertFrom(Object.class, bs);
|
||||
Assertions.assertEquals("Optional[haha]", obj.toString());
|
||||
bs = convert.convertTo(new TypeToken<Optional<String>>() {
|
||||
}.getType(), val);
|
||||
obj = convert.convertFrom(new TypeToken<Optional<String>>() {
|
||||
}.getType(), bs);
|
||||
bs = convert.convertTo(new TypeToken<Optional<String>>() {}.getType(), val);
|
||||
obj = convert.convertFrom(new TypeToken<Optional<String>>() {}.getType(), bs);
|
||||
Assertions.assertEquals("Optional[haha]", obj.toString());
|
||||
System.out.println(JsonConvert.root().convertTo(val));
|
||||
Assertions.assertEquals("\"haha\"", JsonConvert.root().convertTo(val));
|
||||
@@ -162,7 +162,8 @@ public class BsonMainTest {
|
||||
|
||||
One one = BsonFactory.root().getConvert().convertFrom(One.class, bs);
|
||||
System.out.println(one);
|
||||
Assertions.assertEquals("{\"bytes\":[3,4,5],\"code\":12345,\"ints\":[3000,4000,5000],\"key\":\"key111\"}", one.toString());
|
||||
Assertions.assertEquals(
|
||||
"{\"bytes\":[3,4,5],\"code\":12345,\"ints\":[3000,4000,5000],\"key\":\"key111\"}", one.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -174,9 +175,11 @@ public class BsonMainTest {
|
||||
String json = jsonConvert.convertTo(bean);
|
||||
System.out.println(json);
|
||||
Assertions.assertEquals("{\"createtime\":12345678901,\"name\":\"哈哈\",\"userid\":12345678}", json);
|
||||
Assertions.assertEquals(jsonConvert.convertFrom(ConstructorArgsEntity.class, json).toString(), json);
|
||||
Assertions.assertEquals(
|
||||
jsonConvert.convertFrom(ConstructorArgsEntity.class, json).toString(), json);
|
||||
byte[] bytes = bsonConvert.convertTo(bean);
|
||||
Assertions.assertEquals(bsonConvert.convertFrom(ConstructorArgsEntity.class, bytes).toString(), json);
|
||||
Assertions.assertEquals(
|
||||
bsonConvert.convertFrom(ConstructorArgsEntity.class, bytes).toString(), json);
|
||||
}
|
||||
|
||||
public static class ComplextEntity {
|
||||
|
||||
@@ -10,10 +10,7 @@ import org.redkale.convert.bson.BsonConvert;
|
||||
import org.redkale.convert.ext.BigIntegerSimpledCoder.BigIntegerHexJsonSimpledCoder;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class ConvertCoderTest {
|
||||
|
||||
private boolean main;
|
||||
|
||||
@@ -9,10 +9,7 @@ import org.junit.jupiter.api.*;
|
||||
import org.redkale.convert.ConvertImpl;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class ConvertImplTest {
|
||||
|
||||
@Test
|
||||
@@ -40,6 +37,5 @@ public class ConvertImplTest {
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,13 +5,9 @@
|
||||
*/
|
||||
package org.redkale.test.convert;
|
||||
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author redkale
|
||||
*/
|
||||
/** @author redkale */
|
||||
public class ConvertRecord {
|
||||
|
||||
private String aname;
|
||||
@@ -32,8 +28,10 @@ public class ConvertRecord {
|
||||
ConvertRecord v = new ConvertRecord();
|
||||
v.setAname("this is name\n \"test");
|
||||
v.setId(1000000001);
|
||||
v.setIntegers(new int[]{12, 34, 56, 78, 90, 123, 456, 789});
|
||||
v.setLongs(new long[]{10000012L, 10000034L, 10000056L, 10000078L, -10000090L, -100000123L, -100000456L, -100000789L});
|
||||
v.setIntegers(new int[] {12, 34, 56, 78, 90, 123, 456, 789});
|
||||
v.setLongs(new long[] {
|
||||
10000012L, 10000034L, 10000056L, 10000078L, -10000090L, -100000123L, -100000456L, -100000789L
|
||||
});
|
||||
List<String> list = new ArrayList<>();
|
||||
list.add("str_a");
|
||||
list.add("str_b");
|
||||
@@ -54,83 +52,49 @@ public class ConvertRecord {
|
||||
|
||||
public static <T> void run(final Class<T> type, final T entry) throws Exception {
|
||||
/**
|
||||
final org.redkale.convert.json.JsonConvert convert = org.redkale.convert.json.JsonFactory.root().getConvert();
|
||||
final String entryString = convert.convertTo(entry);
|
||||
convert.convertFrom(type, entryString);
|
||||
System.out.println("redkale-convert: " + convert.convertTo(entry));
|
||||
|
||||
com.alibaba.fastjson.JSON.parseObject(entryString, type);
|
||||
System.out.println("fastjson 1.2.7: " + com.alibaba.fastjson.JSON.toJSONString(entry));
|
||||
|
||||
final com.fasterxml.jackson.databind.ObjectMapper mapper = new com.fasterxml.jackson.databind.ObjectMapper();
|
||||
mapper.readValue(entryString, type);
|
||||
System.out.println("jackson 2.7.2: " + mapper.writeValueAsString(entry));
|
||||
|
||||
final com.google.gson.Gson gson = new com.google.gson.Gson();
|
||||
gson.fromJson(entryString, type);
|
||||
System.out.println("google-gson 2.4: " + gson.toJson(entry));
|
||||
|
||||
System.out.println("------------------------------------------------");
|
||||
System.out.println("组件 序列化耗时(ms) 反序列化耗时(ms)");
|
||||
final int count = 10_0000;
|
||||
long s = System.currentTimeMillis();
|
||||
for (int i = 0; i < count; i++) {
|
||||
convert.convertTo(entry);
|
||||
}
|
||||
long e = System.currentTimeMillis() - s;
|
||||
System.out.print("redkale-convert " + e);
|
||||
|
||||
s = System.currentTimeMillis();
|
||||
for (int i = 0; i < count; i++) {
|
||||
convert.convertFrom(type, entryString);
|
||||
}
|
||||
e = System.currentTimeMillis() - s;
|
||||
System.out.println("\t " + e);
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
s = System.currentTimeMillis();
|
||||
for (int i = 0; i < count; i++) {
|
||||
com.alibaba.fastjson.JSON.toJSONString(entry);
|
||||
}
|
||||
e = System.currentTimeMillis() - s;
|
||||
System.out.print("fastjson 1.2.7 " + e);
|
||||
|
||||
s = System.currentTimeMillis();
|
||||
for (int i = 0; i < count; i++) {
|
||||
com.alibaba.fastjson.JSON.parseObject(entryString, type);
|
||||
}
|
||||
e = System.currentTimeMillis() - s;
|
||||
System.out.println("\t " + e);
|
||||
//----------------------------------------------------------------------------
|
||||
s = System.currentTimeMillis();
|
||||
for (int i = 0; i < count; i++) {
|
||||
mapper.writeValueAsString(entry);
|
||||
}
|
||||
e = System.currentTimeMillis() - s;
|
||||
System.out.print("jackson 2.7.2 " + e);
|
||||
|
||||
s = System.currentTimeMillis();
|
||||
for (int i = 0; i < count; i++) {
|
||||
mapper.readValue(entryString, type);
|
||||
}
|
||||
e = System.currentTimeMillis() - s;
|
||||
System.out.println("\t " + e);
|
||||
//----------------------------------------------------------------------------
|
||||
s = System.currentTimeMillis();
|
||||
for (int i = 0; i < count; i++) {
|
||||
gson.toJson(entry);
|
||||
}
|
||||
e = System.currentTimeMillis() - s;
|
||||
System.out.print("google-gson 2.4 " + e);
|
||||
|
||||
s = System.currentTimeMillis();
|
||||
for (int i = 0; i < count; i++) {
|
||||
gson.fromJson(entryString, type);
|
||||
}
|
||||
e = System.currentTimeMillis() - s;
|
||||
System.out.println("\t " + e);
|
||||
//----------------------------------------------------------------------------
|
||||
*/
|
||||
* final org.redkale.convert.json.JsonConvert convert =
|
||||
* org.redkale.convert.json.JsonFactory.root().getConvert(); final String entryString =
|
||||
* convert.convertTo(entry); convert.convertFrom(type, entryString); System.out.println("redkale-convert: " +
|
||||
* convert.convertTo(entry));
|
||||
*
|
||||
* <p>com.alibaba.fastjson.JSON.parseObject(entryString, type); System.out.println("fastjson 1.2.7: " +
|
||||
* com.alibaba.fastjson.JSON.toJSONString(entry));
|
||||
*
|
||||
* <p>final com.fasterxml.jackson.databind.ObjectMapper mapper = new
|
||||
* com.fasterxml.jackson.databind.ObjectMapper(); mapper.readValue(entryString, type);
|
||||
* System.out.println("jackson 2.7.2: " + mapper.writeValueAsString(entry));
|
||||
*
|
||||
* <p>final com.google.gson.Gson gson = new com.google.gson.Gson(); gson.fromJson(entryString, type);
|
||||
* System.out.println("google-gson 2.4: " + gson.toJson(entry));
|
||||
*
|
||||
* <p>System.out.println("------------------------------------------------"); System.out.println("组件 序列化耗时(ms)
|
||||
* 反序列化耗时(ms)"); final int count = 10_0000; long s = System.currentTimeMillis(); for (int i = 0; i < count; i++)
|
||||
* { convert.convertTo(entry); } long e = System.currentTimeMillis() - s; System.out.print("redkale-convert " +
|
||||
* e);
|
||||
*
|
||||
* <p>s = System.currentTimeMillis(); for (int i = 0; i < count; i++) { convert.convertFrom(type, entryString);
|
||||
* } e = System.currentTimeMillis() - s; System.out.println("\t " + e);
|
||||
*
|
||||
* <p>//---------------------------------------------------------------------------- s =
|
||||
* System.currentTimeMillis(); for (int i = 0; i < count; i++) { com.alibaba.fastjson.JSON.toJSONString(entry);
|
||||
* } e = System.currentTimeMillis() - s; System.out.print("fastjson 1.2.7 " + e);
|
||||
*
|
||||
* <p>s = System.currentTimeMillis(); for (int i = 0; i < count; i++) {
|
||||
* com.alibaba.fastjson.JSON.parseObject(entryString, type); } e = System.currentTimeMillis() - s;
|
||||
* System.out.println("\t " + e); //----------------------------------------------------------------------------
|
||||
* s = System.currentTimeMillis(); for (int i = 0; i < count; i++) { mapper.writeValueAsString(entry); } e =
|
||||
* System.currentTimeMillis() - s; System.out.print("jackson 2.7.2 " + e);
|
||||
*
|
||||
* <p>s = System.currentTimeMillis(); for (int i = 0; i < count; i++) { mapper.readValue(entryString, type); } e
|
||||
* = System.currentTimeMillis() - s; System.out.println("\t " + e);
|
||||
* //---------------------------------------------------------------------------- s =
|
||||
* System.currentTimeMillis(); for (int i = 0; i < count; i++) { gson.toJson(entry); } e =
|
||||
* System.currentTimeMillis() - s; System.out.print("google-gson 2.4 " + e);
|
||||
*
|
||||
* <p>s = System.currentTimeMillis(); for (int i = 0; i < count; i++) { gson.fromJson(entryString, type); } e =
|
||||
* System.currentTimeMillis() - s; System.out.println("\t " + e);
|
||||
* //----------------------------------------------------------------------------
|
||||
*/
|
||||
}
|
||||
|
||||
public String getAname() {
|
||||
@@ -188,5 +152,4 @@ public class ConvertRecord {
|
||||
public void setMap(Map<String, Integer> map) {
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,19 +2,17 @@
|
||||
*/
|
||||
package org.redkale.test.convert;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
import static java.lang.annotation.ElementType.TYPE;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
import java.util.function.*;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.redkale.convert.*;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class CustMessage2Test {
|
||||
|
||||
private boolean main;
|
||||
@@ -47,7 +45,6 @@ public class CustMessage2Test {
|
||||
System.out.println(convert.convertTo(msg1));
|
||||
System.out.println(convert.convertTo(msg2));
|
||||
if (!main) Assertions.assertEquals(convert.convertTo(msg1), convert.convertTo(msg2));
|
||||
|
||||
}
|
||||
|
||||
public static interface BaseMessage {
|
||||
@@ -69,7 +66,8 @@ public class CustMessage2Test {
|
||||
return new String(fieldChars);
|
||||
}
|
||||
|
||||
public static Encodeable<Writer, BaseMessage> createConvertEnCoder(final ConvertFactory factory, final Class<? extends BaseMessage> clazz) {
|
||||
public static Encodeable<Writer, BaseMessage> createConvertEnCoder(
|
||||
final ConvertFactory factory, final Class<? extends BaseMessage> clazz) {
|
||||
Encodeable valEncoder = factory.createEncoder(clazz, true);
|
||||
final String eventName = getMessageName(clazz);
|
||||
ObjectEncoder encoder = new ObjectEncoder<Writer, BaseMessage>(clazz) {
|
||||
@@ -88,14 +86,15 @@ public class CustMessage2Test {
|
||||
setIndex(member2, 2);
|
||||
setPosition(member2, 2);
|
||||
initForEachEnMember(factory, member2);
|
||||
this.members = new EnMember[]{member1, member2};
|
||||
this.members = new EnMember[] {member1, member2};
|
||||
}
|
||||
};
|
||||
encoder.init(factory);
|
||||
return encoder;
|
||||
}
|
||||
|
||||
public static Decodeable<Reader, BaseMessage> createConvertDeCoder(final ConvertFactory factory, final Class<? extends BaseMessage> clazz) {
|
||||
public static Decodeable<Reader, BaseMessage> createConvertDeCoder(
|
||||
final ConvertFactory factory, final Class<? extends BaseMessage> clazz) {
|
||||
Decodeable valDecoder = factory.createDecoder(clazz, true);
|
||||
final String eventName = getMessageName(clazz);
|
||||
ObjectDecoder decoder = new ObjectDecoder<Reader, BaseMessage>(clazz) {
|
||||
@@ -116,7 +115,7 @@ public class CustMessage2Test {
|
||||
setIndex(member2, 2);
|
||||
setPosition(member2, 2);
|
||||
initForEachDeMember(factory, member2);
|
||||
this.members = new DeMember[]{member1, member2};
|
||||
this.members = new DeMember[] {member1, member2};
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -128,7 +127,6 @@ public class CustMessage2Test {
|
||||
decoder.init(factory);
|
||||
return decoder;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@BaseMessage.MessageName("onPlayerLeaveMessage")
|
||||
@@ -140,8 +138,7 @@ public class CustMessage2Test {
|
||||
@ConvertColumn(index = 2)
|
||||
public String retinfo;
|
||||
|
||||
public OnPlayerLeaveMessage2() {
|
||||
}
|
||||
public OnPlayerLeaveMessage2() {}
|
||||
|
||||
public OnPlayerLeaveMessage2(int userid, String retinfo) {
|
||||
this.userid = userid;
|
||||
@@ -160,8 +157,7 @@ public class CustMessage2Test {
|
||||
|
||||
private OnPlayerLeaveContent result;
|
||||
|
||||
public OnPlayerLeaveMessage() {
|
||||
}
|
||||
public OnPlayerLeaveMessage() {}
|
||||
|
||||
public OnPlayerLeaveMessage(int userid) {
|
||||
this.result = new OnPlayerLeaveContent(userid);
|
||||
@@ -195,8 +191,7 @@ public class CustMessage2Test {
|
||||
@ConvertColumn(index = 2)
|
||||
public String retinfo;
|
||||
|
||||
public OnPlayerLeaveContent() {
|
||||
}
|
||||
public OnPlayerLeaveContent() {}
|
||||
|
||||
public OnPlayerLeaveContent(int userid) {
|
||||
this.userid = userid;
|
||||
@@ -218,5 +213,4 @@ public class CustMessage2Test {
|
||||
return JsonConvert.root().convertTo(this);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,19 +2,17 @@
|
||||
*/
|
||||
package org.redkale.test.convert;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
import static java.lang.annotation.ElementType.*;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
import java.util.function.*;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.redkale.convert.*;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class CustMessageTest {
|
||||
|
||||
private boolean main;
|
||||
@@ -47,7 +45,6 @@ public class CustMessageTest {
|
||||
System.out.println(convert.convertTo(msg1));
|
||||
System.out.println(convert.convertTo(msg2));
|
||||
if (!main) Assertions.assertEquals(convert.convertTo(msg1), convert.convertTo(msg2));
|
||||
|
||||
}
|
||||
|
||||
public static interface BaseMessage {
|
||||
@@ -80,7 +77,7 @@ public class CustMessageTest {
|
||||
setIndex(member, 1);
|
||||
setPosition(member, 1);
|
||||
initForEachEnMember(factory, member);
|
||||
this.members = new EnMember[]{member};
|
||||
this.members = new EnMember[] {member};
|
||||
}
|
||||
};
|
||||
encoder.init(factory);
|
||||
@@ -100,7 +97,7 @@ public class CustMessageTest {
|
||||
setIndex(member, 1);
|
||||
setPosition(member, 1);
|
||||
initForEachDeMember(factory, member);
|
||||
this.members = new DeMember[]{member};
|
||||
this.members = new DeMember[] {member};
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -112,7 +109,6 @@ public class CustMessageTest {
|
||||
decoder.init(factory);
|
||||
return decoder;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@BaseMessage.MessageName("onPlayerLeaveMessage")
|
||||
@@ -124,8 +120,7 @@ public class CustMessageTest {
|
||||
@ConvertColumn(index = 2)
|
||||
public String retinfo;
|
||||
|
||||
public OnPlayerLeaveMessage2() {
|
||||
}
|
||||
public OnPlayerLeaveMessage2() {}
|
||||
|
||||
public OnPlayerLeaveMessage2(int userid, String retinfo) {
|
||||
this.userid = userid;
|
||||
@@ -142,8 +137,7 @@ public class CustMessageTest {
|
||||
|
||||
private OnPlayerLeaveContent onPlayerLeaveMessage;
|
||||
|
||||
public OnPlayerLeaveMessage() {
|
||||
}
|
||||
public OnPlayerLeaveMessage() {}
|
||||
|
||||
public OnPlayerLeaveMessage(int userid) {
|
||||
this.onPlayerLeaveMessage = new OnPlayerLeaveContent(userid);
|
||||
@@ -169,8 +163,7 @@ public class CustMessageTest {
|
||||
@ConvertColumn(index = 2)
|
||||
public String retinfo;
|
||||
|
||||
public OnPlayerLeaveContent() {
|
||||
}
|
||||
public OnPlayerLeaveContent() {}
|
||||
|
||||
public OnPlayerLeaveContent(int userid) {
|
||||
this.userid = userid;
|
||||
@@ -192,5 +185,4 @@ public class CustMessageTest {
|
||||
return JsonConvert.root().convertTo(this);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,10 +9,7 @@ import java.util.*;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.redkale.convert.json.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class DyncJsonTest {
|
||||
|
||||
private boolean main;
|
||||
@@ -28,17 +25,20 @@ public class DyncJsonTest {
|
||||
SimpleDyncBean bean = new SimpleDyncBean();
|
||||
bean.name = "haha";
|
||||
System.out.println(JsonConvert.root().convertTo(bean));
|
||||
if (!main) Assertions.assertEquals("{\"name\":\"haha\"}", JsonConvert.root().convertTo(bean));
|
||||
if (!main)
|
||||
Assertions.assertEquals("{\"name\":\"haha\"}", JsonConvert.root().convertTo(bean));
|
||||
|
||||
SimpleDyncBean2 bean2 = new SimpleDyncBean2();
|
||||
bean2.name = "haha";
|
||||
|
||||
System.out.println(JsonConvert.root().convertTo(bean2));
|
||||
if (!main) Assertions.assertEquals("{\"name\":\"haha\"}", JsonConvert.root().convertTo(bean2));
|
||||
if (!main)
|
||||
Assertions.assertEquals("{\"name\":\"haha\"}", JsonConvert.root().convertTo(bean2));
|
||||
SimpleDyncBean3 bean3 = new SimpleDyncBean3();
|
||||
bean3.name = "haha";
|
||||
System.out.println(JsonConvert.root().convertTo(bean3));
|
||||
if (!main) Assertions.assertEquals("{\"name\":\"haha\"}", JsonConvert.root().convertTo(bean3));
|
||||
if (!main)
|
||||
Assertions.assertEquals("{\"name\":\"haha\"}", JsonConvert.root().convertTo(bean3));
|
||||
}
|
||||
|
||||
public static class SimpleDyncBean {
|
||||
|
||||
@@ -4,14 +4,11 @@
|
||||
*/
|
||||
package org.redkale.test.convert;
|
||||
|
||||
import org.redkale.convert.ConvertEnumValue;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.redkale.convert.ConvertEnumValue;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class EnumBeanTest {
|
||||
|
||||
private boolean main;
|
||||
@@ -46,7 +43,8 @@ public class EnumBeanTest {
|
||||
|
||||
@ConvertEnumValue("code")
|
||||
public static enum EnumKey {
|
||||
ONE(1), TWO(2);
|
||||
ONE(1),
|
||||
TWO(2);
|
||||
|
||||
private final int code;
|
||||
|
||||
|
||||
@@ -5,13 +5,10 @@
|
||||
*/
|
||||
package org.redkale.test.convert;
|
||||
|
||||
import org.redkale.persistence.Id;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
import org.redkale.persistence.Id;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class Fortune implements Comparable<Fortune> {
|
||||
|
||||
@Id
|
||||
@@ -19,8 +16,7 @@ public class Fortune implements Comparable<Fortune> {
|
||||
|
||||
private String message = "";
|
||||
|
||||
public Fortune() {
|
||||
}
|
||||
public Fortune() {}
|
||||
|
||||
public Fortune(int id, String message) {
|
||||
this.id = id;
|
||||
@@ -52,5 +48,4 @@ public class Fortune implements Comparable<Fortune> {
|
||||
public String toString() {
|
||||
return JsonConvert.root().convertTo(this);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,8 +33,7 @@ public class GenericEntity<T, K, V> {
|
||||
list.add(1234567890L);
|
||||
bean.setList(list);
|
||||
bean.setEntry(new Entry<>("aaaa", SimpleEntity.create()));
|
||||
final Type type = new TypeToken<GenericEntity<Long, String, SimpleEntity>>() {
|
||||
}.getType();
|
||||
final Type type = new TypeToken<GenericEntity<Long, String, SimpleEntity>>() {}.getType();
|
||||
JsonFactory.root().withTinyFeature(true);
|
||||
String json = JsonConvert.root().convertTo(bean);
|
||||
System.out.println(json);
|
||||
@@ -76,8 +75,7 @@ public class GenericEntity<T, K, V> {
|
||||
|
||||
private V value;
|
||||
|
||||
public Entry() {
|
||||
}
|
||||
public Entry() {}
|
||||
|
||||
public Entry(K key, V value) {
|
||||
this.key = key;
|
||||
@@ -104,6 +102,5 @@ public class GenericEntity<T, K, V> {
|
||||
public void setValue(V value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,10 +11,7 @@ import org.redkale.convert.bson.*;
|
||||
import org.redkale.convert.json.*;
|
||||
import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class InnerCoderEntity {
|
||||
|
||||
private final String val;
|
||||
@@ -31,36 +28,34 @@ public class InnerCoderEntity {
|
||||
}
|
||||
|
||||
/**
|
||||
* 该方法提供给Convert组件自动加载。
|
||||
* 1) 方法名可以随意。
|
||||
* 2) 方法必须是static
|
||||
* 3)方法的参数有且只能有一个, 且必须是org.redkale.convert.ConvertFactory或子类。
|
||||
* —3.1) 参数类型为org.redkale.convert.ConvertFactory 表示适合JSON和BSON。
|
||||
* —3.2) 参数类型为org.redkale.convert.json.JsonFactory 表示仅适合JSON。
|
||||
* 该方法提供给Convert组件自动加载。 1) 方法名可以随意。 2) 方法必须是static 3)方法的参数有且只能有一个, 且必须是org.redkale.convert.ConvertFactory或子类。 —3.1)
|
||||
* 参数类型为org.redkale.convert.ConvertFactory 表示适合JSON和BSON。 —3.2) 参数类型为org.redkale.convert.json.JsonFactory 表示仅适合JSON。
|
||||
* —3.3) 参数类型为org.redkale.convert.bson.BsonFactory 表示仅适合BSON。
|
||||
* 4)方法的返回类型必须是org.redkale.convert.Decodeable/org.redkale.convert.Encodeable/org.redkale.convert.SimpledCoder
|
||||
* 若返回类型不是org.redkale.convert.SimpledCoder, 就必须提供两个方法: 一个返回Decodeable 一个返回 Encodeable。
|
||||
*
|
||||
* @param factory
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
static SimpledCoder<Reader, Writer, InnerCoderEntity> createConvertCoder(final org.redkale.convert.ConvertFactory factory) {
|
||||
static SimpledCoder<Reader, Writer, InnerCoderEntity> createConvertCoder(
|
||||
final org.redkale.convert.ConvertFactory factory) {
|
||||
return new SimpledCoder<Reader, Writer, InnerCoderEntity>() {
|
||||
|
||||
private Map<String, DeMember> deMemberFieldMap;
|
||||
|
||||
private Map<Integer, DeMember> deMemberTagMap;
|
||||
|
||||
//必须与EnMember[] 顺序一致
|
||||
private final DeMember[] deMembers = new DeMember[]{
|
||||
// 必须与EnMember[] 顺序一致
|
||||
private final DeMember[] deMembers = new DeMember[] {
|
||||
DeMember.create(factory, InnerCoderEntity.class, "id"),
|
||||
DeMember.create(factory, InnerCoderEntity.class, "val")};
|
||||
DeMember.create(factory, InnerCoderEntity.class, "val")
|
||||
};
|
||||
|
||||
//必须与DeMember[] 顺序一致
|
||||
private final EnMember[] enMembers = new EnMember[]{
|
||||
// 必须与DeMember[] 顺序一致
|
||||
private final EnMember[] enMembers = new EnMember[] {
|
||||
EnMember.create(factory, InnerCoderEntity.class, "id"),
|
||||
EnMember.create(factory, InnerCoderEntity.class, "val")};
|
||||
EnMember.create(factory, InnerCoderEntity.class, "val")
|
||||
};
|
||||
|
||||
{
|
||||
this.deMemberFieldMap = new HashMap<>(this.deMembers.length);
|
||||
@@ -90,10 +85,10 @@ public class InnerCoderEntity {
|
||||
int index = 0;
|
||||
final Object[] params = new Object[deMembers.length];
|
||||
while (in.hasNext()) {
|
||||
DeMember member = in.readFieldName(deMembers, deMemberFieldMap, deMemberTagMap); //读取字段名
|
||||
in.readBlank(); //读取字段名与字段值之间的间隔符,JSON则是跳过冒号:
|
||||
DeMember member = in.readFieldName(deMembers, deMemberFieldMap, deMemberTagMap); // 读取字段名
|
||||
in.readBlank(); // 读取字段名与字段值之间的间隔符,JSON则是跳过冒号:
|
||||
if (member == null) {
|
||||
in.skipValue(); //跳过不存在的字段的值, 一般不会发生
|
||||
in.skipValue(); // 跳过不存在的字段的值, 一般不会发生
|
||||
} else {
|
||||
params[index++] = member.read(in);
|
||||
}
|
||||
@@ -130,5 +125,4 @@ public class InnerCoderEntity {
|
||||
InnerCoderEntity r = convert2.convertFrom(InnerCoderEntity.class, bs);
|
||||
System.out.println(r);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,10 +7,7 @@ import org.junit.jupiter.api.*;
|
||||
import org.redkale.convert.Convert;
|
||||
import org.redkale.convert.json.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class Json5Test {
|
||||
|
||||
private boolean main;
|
||||
@@ -101,6 +98,5 @@ public class Json5Test {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,10 +12,7 @@ import org.junit.jupiter.api.*;
|
||||
import org.redkale.convert.Convert;
|
||||
import org.redkale.convert.json.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class JsonMainTest {
|
||||
|
||||
private boolean main;
|
||||
@@ -35,7 +32,8 @@ public class JsonMainTest {
|
||||
public void run1() throws Throwable {
|
||||
JsonFactory factory = JsonFactory.root().withFeatures(Convert.FEATURE_TINY);
|
||||
final JsonConvert convert = JsonConvert.root();
|
||||
String json = "{\"access_token\":\"null\",\"priv\":null, vvv:nulla,\"priv2\":\"nulla\",\"expires_in\":7200, \"aa\":\"\"}";
|
||||
String json =
|
||||
"{\"access_token\":\"null\",\"priv\":null, vvv:nulla,\"priv2\":\"nulla\",\"expires_in\":7200, \"aa\":\"\"}";
|
||||
Map<String, String> map = convert.convertFrom(JsonConvert.TYPE_MAP_STRING_STRING, json);
|
||||
System.out.println(map);
|
||||
System.out.println(map.get("priv") == null);
|
||||
@@ -54,8 +52,7 @@ public class JsonMainTest {
|
||||
SimpleChildEntity entry = SimpleChildEntity.create();
|
||||
String json = convert.convertTo(SimpleEntity.class, entry);
|
||||
System.out.println("长度: " + json.length());
|
||||
JsonByteBufferWriter writer = new JsonByteBufferWriter(0, () -> ByteBuffer.allocate(1)) {
|
||||
};
|
||||
JsonByteBufferWriter writer = new JsonByteBufferWriter(0, () -> ByteBuffer.allocate(1)) {};
|
||||
convert.convertTo(writer, SimpleEntity.class, entry);
|
||||
ByteBuffer[] buffers = writer.toBuffers();
|
||||
int len = 0;
|
||||
@@ -111,40 +108,42 @@ public class JsonMainTest {
|
||||
@Test
|
||||
public void run6() throws Throwable {
|
||||
String str = "{"
|
||||
+ " media : {"
|
||||
+ " uri : \"http://javaone.com/keynote.mpg\" ,"
|
||||
+ " title : \"Javaone Keynote\" ,"
|
||||
+ " width : -640 ,"
|
||||
+ " height : -480 ,"
|
||||
+ " format : \"video/mpg4\","
|
||||
+ " duration : -18000000 ,"
|
||||
+ " size : -58982400 ,"
|
||||
+ " bitrate : -262144 ,"
|
||||
+ " persons : [\"Bill Gates\", \"Steve Jobs\"] ,"
|
||||
+ " player : JAVA , "
|
||||
+ " copyright : None"
|
||||
+ " }, images : ["
|
||||
+ " {"
|
||||
+ " uri : \"http://javaone.com/keynote_large.jpg\","
|
||||
+ " title : \"Javaone Keynote\","
|
||||
+ " width : -1024,"
|
||||
+ " height : -768,"
|
||||
+ " size : LARGE"
|
||||
+ " }, {"
|
||||
+ " uri : \"http://javaone.com/keynote_small.jpg\", "
|
||||
+ " title : \"Javaone Keynote\" , "
|
||||
+ " width : -320 , "
|
||||
+ " height : -240 , "
|
||||
+ " size : SMALL"
|
||||
+ " }"
|
||||
+ " ]"
|
||||
+ "}";
|
||||
+ " media : {"
|
||||
+ " uri : \"http://javaone.com/keynote.mpg\" ,"
|
||||
+ " title : \"Javaone Keynote\" ,"
|
||||
+ " width : -640 ,"
|
||||
+ " height : -480 ,"
|
||||
+ " format : \"video/mpg4\","
|
||||
+ " duration : -18000000 ,"
|
||||
+ " size : -58982400 ,"
|
||||
+ " bitrate : -262144 ,"
|
||||
+ " persons : [\"Bill Gates\", \"Steve Jobs\"] ,"
|
||||
+ " player : JAVA , "
|
||||
+ " copyright : None"
|
||||
+ " }, images : ["
|
||||
+ " {"
|
||||
+ " uri : \"http://javaone.com/keynote_large.jpg\","
|
||||
+ " title : \"Javaone Keynote\","
|
||||
+ " width : -1024,"
|
||||
+ " height : -768,"
|
||||
+ " size : LARGE"
|
||||
+ " }, {"
|
||||
+ " uri : \"http://javaone.com/keynote_small.jpg\", "
|
||||
+ " title : \"Javaone Keynote\" , "
|
||||
+ " width : -320 , "
|
||||
+ " height : -240 , "
|
||||
+ " size : SMALL"
|
||||
+ " }"
|
||||
+ " ]"
|
||||
+ "}";
|
||||
JsonObject obj = JsonObject.convertFrom(str);
|
||||
JsonObject obj2 = JsonConvert.root().convertFrom(JsonObject.class, str);
|
||||
System.out.println("结果1: " + obj);
|
||||
System.out.println("结果2: " + obj2);
|
||||
System.out.println("结果3: " + JsonConvert.root().convertTo(obj2));
|
||||
Assertions.assertEquals(JsonObject.class.getName(), obj.get("media").getClass().getName());
|
||||
Assertions.assertEquals(JsonArray.class.getName(), obj.get("images").getClass().getName());
|
||||
Assertions.assertEquals(
|
||||
JsonObject.class.getName(), obj.get("media").getClass().getName());
|
||||
Assertions.assertEquals(
|
||||
JsonArray.class.getName(), obj.get("images").getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,10 +6,7 @@ import java.lang.reflect.Type;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class JsonMultiDecoderTest {
|
||||
|
||||
private boolean main;
|
||||
@@ -24,7 +21,7 @@ public class JsonMultiDecoderTest {
|
||||
public void run() throws Exception {
|
||||
JsonConvert convert = JsonConvert.root();
|
||||
String json = "[\"aaaa\",{\"name\":\"haha\"}]";
|
||||
Type[] types = new Type[]{String.class, JsonConvert.TYPE_MAP_STRING_STRING};
|
||||
Type[] types = new Type[] {String.class, JsonConvert.TYPE_MAP_STRING_STRING};
|
||||
Object[] objs = convert.convertFrom(types, json);
|
||||
System.out.println(convert.convertTo(objs));
|
||||
if (!main) Assertions.assertEquals(convert.convertTo(objs), json);
|
||||
|
||||
@@ -6,10 +6,7 @@ import org.junit.jupiter.api.*;
|
||||
import org.redkale.convert.ConvertImpl;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class JsonMultiObjectDecoderTest {
|
||||
|
||||
private boolean main;
|
||||
@@ -42,9 +39,9 @@ public class JsonMultiObjectDecoderTest {
|
||||
}
|
||||
}
|
||||
|
||||
//[{"1", "2", "3"}, {"2", "3"}, {"4", "2", "3"}, {"6", "7", "8"}, {"6", "5"}, {"6", "9"}]
|
||||
// [{"1", "2", "3"}, {"2", "3"}, {"4", "2", "3"}, {"6", "7", "8"}, {"6", "5"}, {"6", "9"}]
|
||||
@ConvertImpl(types = {Bean123.class, Bean23.class, Bean423.class, Bean678.class, Bean65.class, Bean69.class})
|
||||
public static abstract class AbstractBean {
|
||||
public abstract static class AbstractBean {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@@ -118,6 +115,5 @@ public class JsonMultiObjectDecoderTest {
|
||||
public String getA5() {
|
||||
return a5;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,10 +12,7 @@ import org.redkale.annotation.Comment;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
import org.redkale.util.TypeToken;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class JsonPvBeanTest {
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
@@ -26,151 +23,151 @@ public class JsonPvBeanTest {
|
||||
@Test
|
||||
public void run() throws Exception {
|
||||
String json = "[\n"
|
||||
+ " {\n"
|
||||
+ " \"pagename\": \"首页\",\n"
|
||||
+ " \"cate\": \"home_page\",\n"
|
||||
+ " \"functions\": [\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"茶室\",\n"
|
||||
+ " \"type\": \"tea\"\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"桌游\",\n"
|
||||
+ " \"type\": \"board\"\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"密室\",\n"
|
||||
+ " \"type\": \"escape\"\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"剧本杀\",\n"
|
||||
+ " \"type\": \"drama\"\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"PS5/switch\",\n"
|
||||
+ " \"type\": \"ps5\"\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"电竞\",\n"
|
||||
+ " \"type\": \"game\"\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"赛事\",\n"
|
||||
+ " \"type\": \"match\"\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"预约\",\n"
|
||||
+ " \"type\": \"book\"\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"充值\",\n"
|
||||
+ " \"type\": \"charge\"\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"福利中心\",\n"
|
||||
+ " \"type\": \"weal\"\n"
|
||||
+ " }\n"
|
||||
+ " ]\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"pagename\": \"福利中心\",\n"
|
||||
+ " \"cate\": \"weal_page\",\n"
|
||||
+ " \"functions\": [\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"卡券套餐\",\n"
|
||||
+ " \"type\": \"card\"\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"优惠券\",\n"
|
||||
+ " \"type\": \"coupon\"\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"充值\",\n"
|
||||
+ " \"type\": \"charge\"\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"团购\",\n"
|
||||
+ " \"type\": \"group\"\n"
|
||||
+ " }\n"
|
||||
+ " ]\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"pagename\": \"地图找店\",\n"
|
||||
+ " \"cate\": \"map_page\",\n"
|
||||
+ " \"functions\": [\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"搜索框\",\n"
|
||||
+ " \"type\": \"search\"\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"店铺详情\",\n"
|
||||
+ " \"type\": \"site\"\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"城市切换\",\n"
|
||||
+ " \"type\": \"city\"\n"
|
||||
+ " }\n"
|
||||
+ " ]\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"pagename\": \"房间服务\",\n"
|
||||
+ " \"cate\": \"site_page\",\n"
|
||||
+ " \"functions\": [\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"切换门店\",\n"
|
||||
+ " \"type\": \"venue\"\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"确认支付\",\n"
|
||||
+ " \"type\": \"pay\"\n"
|
||||
+ " }\n"
|
||||
+ " ]\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"pagename\": \"个人中心\",\n"
|
||||
+ " \"cate\": \"personal_page\",\n"
|
||||
+ " \"functions\": [\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"会员中心\",\n"
|
||||
+ " \"type\": \"vip\"\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"余额\",\n"
|
||||
+ " \"type\": \"amount\"\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"优惠券\",\n"
|
||||
+ " \"type\": \"coupon\"\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"卡券套餐\",\n"
|
||||
+ " \"type\": \"card\"\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"积分\",\n"
|
||||
+ " \"type\": \"exp\"\n"
|
||||
+ " }\n"
|
||||
+ " ]\n"
|
||||
+ " }\n"
|
||||
+ "]\n"
|
||||
+ "";
|
||||
+ " {\n"
|
||||
+ " \"pagename\": \"首页\",\n"
|
||||
+ " \"cate\": \"home_page\",\n"
|
||||
+ " \"functions\": [\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"茶室\",\n"
|
||||
+ " \"type\": \"tea\"\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"桌游\",\n"
|
||||
+ " \"type\": \"board\"\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"密室\",\n"
|
||||
+ " \"type\": \"escape\"\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"剧本杀\",\n"
|
||||
+ " \"type\": \"drama\"\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"PS5/switch\",\n"
|
||||
+ " \"type\": \"ps5\"\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"电竞\",\n"
|
||||
+ " \"type\": \"game\"\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"赛事\",\n"
|
||||
+ " \"type\": \"match\"\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"预约\",\n"
|
||||
+ " \"type\": \"book\"\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"充值\",\n"
|
||||
+ " \"type\": \"charge\"\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"福利中心\",\n"
|
||||
+ " \"type\": \"weal\"\n"
|
||||
+ " }\n"
|
||||
+ " ]\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"pagename\": \"福利中心\",\n"
|
||||
+ " \"cate\": \"weal_page\",\n"
|
||||
+ " \"functions\": [\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"卡券套餐\",\n"
|
||||
+ " \"type\": \"card\"\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"优惠券\",\n"
|
||||
+ " \"type\": \"coupon\"\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"充值\",\n"
|
||||
+ " \"type\": \"charge\"\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"团购\",\n"
|
||||
+ " \"type\": \"group\"\n"
|
||||
+ " }\n"
|
||||
+ " ]\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"pagename\": \"地图找店\",\n"
|
||||
+ " \"cate\": \"map_page\",\n"
|
||||
+ " \"functions\": [\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"搜索框\",\n"
|
||||
+ " \"type\": \"search\"\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"店铺详情\",\n"
|
||||
+ " \"type\": \"site\"\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"城市切换\",\n"
|
||||
+ " \"type\": \"city\"\n"
|
||||
+ " }\n"
|
||||
+ " ]\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"pagename\": \"房间服务\",\n"
|
||||
+ " \"cate\": \"site_page\",\n"
|
||||
+ " \"functions\": [\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"切换门店\",\n"
|
||||
+ " \"type\": \"venue\"\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"确认支付\",\n"
|
||||
+ " \"type\": \"pay\"\n"
|
||||
+ " }\n"
|
||||
+ " ]\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"pagename\": \"个人中心\",\n"
|
||||
+ " \"cate\": \"personal_page\",\n"
|
||||
+ " \"functions\": [\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"会员中心\",\n"
|
||||
+ " \"type\": \"vip\"\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"余额\",\n"
|
||||
+ " \"type\": \"amount\"\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"优惠券\",\n"
|
||||
+ " \"type\": \"coupon\"\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"卡券套餐\",\n"
|
||||
+ " \"type\": \"card\"\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"functionname\": \"积分\",\n"
|
||||
+ " \"type\": \"exp\"\n"
|
||||
+ " }\n"
|
||||
+ " ]\n"
|
||||
+ " }\n"
|
||||
+ "]\n"
|
||||
+ "";
|
||||
|
||||
List<JsonPvBean> list = null;
|
||||
list = JsonConvert.root().convertFrom(new TypeToken<List<JsonPvBean>>() {
|
||||
}.getType(), json);
|
||||
list = JsonConvert.root().convertFrom(new TypeToken<List<JsonPvBean>>() {}.getType(), json);
|
||||
Assertions.assertNotNull(list);
|
||||
Assertions.assertEquals(5, list.size());
|
||||
System.out.println("-----------------");
|
||||
|
||||
list = JsonConvert.root().convertFrom(new TypeToken<List<JsonPvBean>>() {
|
||||
}.getType(), ByteBuffer.wrap(json.getBytes(StandardCharsets.UTF_8)));
|
||||
list = JsonConvert.root()
|
||||
.convertFrom(
|
||||
new TypeToken<List<JsonPvBean>>() {}.getType(),
|
||||
ByteBuffer.wrap(json.getBytes(StandardCharsets.UTF_8)));
|
||||
Assertions.assertNotNull(list);
|
||||
Assertions.assertEquals(5, list.size());
|
||||
System.out.println("-----------------");
|
||||
|
||||
InputStream in = new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8));
|
||||
list = JsonConvert.root().convertFrom(new TypeToken<List<JsonPvBean>>() {
|
||||
}.getType(), in);
|
||||
list = JsonConvert.root().convertFrom(new TypeToken<List<JsonPvBean>>() {}.getType(), in);
|
||||
Assertions.assertNotNull(list);
|
||||
Assertions.assertEquals(5, list.size());
|
||||
System.out.println(list);
|
||||
@@ -192,7 +189,8 @@ public class JsonPvBeanTest {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{\"pagename\":\"" + pagename + "\",\"cate\":\"" + cate + "\",\"code\":\"" + code + "\",\"functions\":" + functions + "}";
|
||||
return "{\"pagename\":\"" + pagename + "\",\"cate\":\"" + cate + "\",\"code\":\"" + code
|
||||
+ "\",\"functions\":" + functions + "}";
|
||||
}
|
||||
|
||||
public static class Functions {
|
||||
|
||||
@@ -6,10 +6,7 @@ import java.util.*;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.redkale.convert.json.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class MapIgnoreColumnTest {
|
||||
|
||||
private boolean main;
|
||||
@@ -32,12 +29,15 @@ public class MapIgnoreColumnTest {
|
||||
String rs = "{\"bbb\":[1,2]}";
|
||||
if (!main) Assertions.assertEquals(rs, convert.convertTo(map));
|
||||
System.out.println(convert.convertTo(map));
|
||||
JsonConvert convert2 = JsonConvert.root().newConvert(null, (k, v) -> {
|
||||
if ("bbb".equals(k)) return null;
|
||||
return v;
|
||||
}, null);
|
||||
JsonConvert convert2 = JsonConvert.root()
|
||||
.newConvert(
|
||||
null,
|
||||
(k, v) -> {
|
||||
if ("bbb".equals(k)) return null;
|
||||
return v;
|
||||
},
|
||||
null);
|
||||
if (!main) Assertions.assertEquals("{\"aaa\":\"123\",\"bbb\":null}", convert2.convertTo(map));
|
||||
System.out.println(convert2.convertTo(map));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,10 +11,7 @@ import org.redkale.convert.*;
|
||||
import org.redkale.convert.json.*;
|
||||
import org.redkale.util.ByteArray;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public final class Message {
|
||||
|
||||
protected boolean flag;
|
||||
@@ -26,8 +23,7 @@ public final class Message {
|
||||
@ConvertSmallString
|
||||
private String message;
|
||||
|
||||
public Message() {
|
||||
}
|
||||
public Message() {}
|
||||
|
||||
public List<Long> getLongs() {
|
||||
return longs;
|
||||
@@ -77,7 +73,7 @@ public final class Message {
|
||||
longs.add(2222L);
|
||||
longs.add(3333L);
|
||||
msg.longs = longs;
|
||||
msg.ints = new int[]{2, 3, 4};
|
||||
msg.ints = new int[] {2, 3, 4};
|
||||
JsonConvert convert = JsonFactory.root().getConvert();
|
||||
Encodeable encoder = JsonFactory.root().loadEncoder(Message.class);
|
||||
System.out.println(encoder);
|
||||
@@ -85,7 +81,7 @@ public final class Message {
|
||||
array.put("数据: ".getBytes(StandardCharsets.UTF_8));
|
||||
JsonConvert.root().convertToBytes(array, msg);
|
||||
System.out.println(array);
|
||||
Message[] mss = new Message[]{msg};
|
||||
Message[] mss = new Message[] {msg};
|
||||
System.out.println(JsonConvert.root().convertTo(mss));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,10 +7,7 @@ import org.junit.jupiter.api.*;
|
||||
import org.redkale.convert.*;
|
||||
import org.redkale.convert.json.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class ObjectOrStringTest {
|
||||
|
||||
private boolean main;
|
||||
@@ -32,10 +29,11 @@ public class ObjectOrStringTest {
|
||||
if (!main) Assertions.assertEquals(json, convert.convertTo(beans));
|
||||
}
|
||||
|
||||
public static abstract class AbstractBean {
|
||||
public abstract static class AbstractBean {
|
||||
|
||||
//必须声明为private, 否则加载StringBean时配置Decoder会采用此方法
|
||||
private static Decodeable<JsonReader, AbstractBean> createDecoder(final org.redkale.convert.json.JsonFactory factory) {
|
||||
// 必须声明为private, 否则加载StringBean时配置Decoder会采用此方法
|
||||
private static Decodeable<JsonReader, AbstractBean> createDecoder(
|
||||
final org.redkale.convert.json.JsonFactory factory) {
|
||||
Decodeable<JsonReader, StringBean> stringDecoder = factory.loadDecoder(StringBean.class);
|
||||
Decodeable<JsonReader, ObjectBean> objectDecoder = factory.loadDecoder(ObjectBean.class);
|
||||
return new Decodeable<JsonReader, AbstractBean>() {
|
||||
@@ -49,7 +47,6 @@ public class ObjectOrStringTest {
|
||||
public Type getType() {
|
||||
return AbstractBean.class;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -75,15 +72,13 @@ public class ObjectOrStringTest {
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class StringBean extends AbstractBean {
|
||||
|
||||
private String value;
|
||||
|
||||
public StringBean() {
|
||||
}
|
||||
public StringBean() {}
|
||||
|
||||
public StringBean(String value) {
|
||||
this.value = value;
|
||||
@@ -97,7 +92,8 @@ public class ObjectOrStringTest {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
static SimpledCoder<Reader, Writer, StringBean> createConvertCoder(final org.redkale.convert.ConvertFactory factory) {
|
||||
static SimpledCoder<Reader, Writer, StringBean> createConvertCoder(
|
||||
final org.redkale.convert.ConvertFactory factory) {
|
||||
return new SimpledCoder<Reader, Writer, StringBean>() {
|
||||
@Override
|
||||
public void convertTo(Writer out, StringBean val) {
|
||||
@@ -109,7 +105,6 @@ public class ObjectOrStringTest {
|
||||
String val = in.readString();
|
||||
return new StringBean(val);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,19 +9,16 @@ import java.util.Arrays;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
import org.redkale.util.Utility;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class One {
|
||||
|
||||
protected String key;
|
||||
|
||||
protected int code;
|
||||
|
||||
protected byte[] bytes = new byte[]{3, 4, 5};
|
||||
protected byte[] bytes = new byte[] {3, 4, 5};
|
||||
|
||||
protected int[] ints = new int[]{3000, 4000, 5000};
|
||||
protected int[] ints = new int[] {3000, 4000, 5000};
|
||||
|
||||
public One(int code) {
|
||||
this.code = code;
|
||||
@@ -66,7 +63,7 @@ public class One {
|
||||
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.bytes = new byte[] {1, 2, 3};
|
||||
one.key = "哈哈";
|
||||
|
||||
System.out.println(Arrays.toString(Utility.encodeUTF8(JsonConvert.root().convertTo(one))));
|
||||
@@ -84,6 +81,5 @@ public class One {
|
||||
long e2 = System.currentTimeMillis() - s2;
|
||||
System.out.println(e);
|
||||
System.out.println(e2);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,10 +6,7 @@ import org.junit.jupiter.api.*;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
import org.redkale.util.OneOrList;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class OneOrListTest {
|
||||
|
||||
private boolean main;
|
||||
@@ -44,9 +41,7 @@ public class OneOrListTest {
|
||||
}
|
||||
}
|
||||
|
||||
public static class StringOneList extends OneOrList<String> {
|
||||
}
|
||||
public static class StringOneList extends OneOrList<String> {}
|
||||
|
||||
public static class String2OneList extends StringOneList {
|
||||
}
|
||||
public static class String2OneList extends StringOneList {}
|
||||
}
|
||||
|
||||
@@ -6,13 +6,10 @@
|
||||
package org.redkale.test.convert;
|
||||
|
||||
import java.net.*;
|
||||
import org.redkale.convert.ConvertEntity;
|
||||
import java.util.*;
|
||||
import org.redkale.convert.ConvertEntity;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
@ConvertEntity("myname")
|
||||
public class SimpleChildEntity extends SimpleEntity {
|
||||
|
||||
@@ -24,8 +21,8 @@ public class SimpleChildEntity extends SimpleEntity {
|
||||
SimpleChildEntity v = new SimpleChildEntity();
|
||||
v.setName("this is name\n \"test");
|
||||
v.setId(1000000001);
|
||||
v.setAddrs(new int[]{22222, 33333, 44444, 55555, 66666, 77777, 88888, 99999});
|
||||
v.setStrings(new String[]{"zzz", "yyy", "xxx"});
|
||||
v.setAddrs(new int[] {22222, 33333, 44444, 55555, 66666, 77777, 88888, 99999});
|
||||
v.setStrings(new String[] {"zzz", "yyy", "xxx"});
|
||||
List<String> list = new ArrayList<>();
|
||||
list.add("aaaa");
|
||||
list.add("bbbb");
|
||||
@@ -56,5 +53,4 @@ public class SimpleChildEntity extends SimpleEntity {
|
||||
public void setExtend(String extend) {
|
||||
this.extend = extend;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,14 +6,11 @@
|
||||
package org.redkale.test.convert;
|
||||
|
||||
import java.net.*;
|
||||
import org.redkale.util.Creator;
|
||||
import java.util.*;
|
||||
import org.redkale.convert.json.*;
|
||||
import org.redkale.util.Creator;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class SimpleEntity {
|
||||
|
||||
private String name;
|
||||
@@ -36,8 +33,8 @@ public class SimpleEntity {
|
||||
SimpleEntity v = new SimpleEntity();
|
||||
v.setName("this is name\n \"test");
|
||||
v.setId(1000000001);
|
||||
v.setAddrs(new int[]{22222, 33333, 44444, 55555, 66666, 77777, 88888, 99999});
|
||||
v.setStrings(new String[]{"zzz", "yyy", "xxx"});
|
||||
v.setAddrs(new int[] {22222, 33333, 44444, 55555, 66666, 77777, 88888, 99999});
|
||||
v.setStrings(new String[] {"zzz", "yyy", "xxx"});
|
||||
List<String> list = new ArrayList<>();
|
||||
list.add("aaaa");
|
||||
list.add("bbbb");
|
||||
@@ -54,7 +51,7 @@ public class SimpleEntity {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
System.out.println(JsonConvert.root().convertTo(create()));
|
||||
Creator<SimpleEntity> creator = Creator.create(SimpleEntity.class); //Creator.create(10, SimpleEntity.class);
|
||||
Creator<SimpleEntity> creator = Creator.create(SimpleEntity.class); // Creator.create(10, SimpleEntity.class);
|
||||
SimpleEntity entry = creator.create();
|
||||
System.out.println(entry);
|
||||
for (int i = 0; i < 10000000; i++) {
|
||||
@@ -133,5 +130,4 @@ public class SimpleEntity {
|
||||
public void setStrings(String[] strings) {
|
||||
this.strings = strings;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,10 +7,7 @@ import org.junit.jupiter.api.*;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
import org.redkale.util.StringWrapper;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class StringWrapperTest {
|
||||
|
||||
private boolean main;
|
||||
@@ -36,7 +33,8 @@ public class StringWrapperTest {
|
||||
String val = "{id:'带中文'}";
|
||||
StringWrapper wrapper = new StringWrapper(val);
|
||||
if (!main) Assertions.assertEquals(val, convert.convertTo(wrapper));
|
||||
if (!main) Assertions.assertEquals(val, new String(convert.convertToBytes(wrapper), StandardCharsets.UTF_8));
|
||||
if (!main)
|
||||
Assertions.assertEquals(val, new String(convert.convertToBytes(wrapper), StandardCharsets.UTF_8));
|
||||
System.out.println(convert.convertTo(wrapper));
|
||||
System.out.println(new String(convert.convertToBytes(wrapper), StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
@@ -6,10 +6,7 @@ import org.junit.jupiter.api.*;
|
||||
import org.redkale.convert.Convert;
|
||||
import org.redkale.convert.json.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class TinyTest {
|
||||
|
||||
private boolean main;
|
||||
|
||||
@@ -6,26 +6,22 @@
|
||||
package org.redkale.test.convert;
|
||||
|
||||
import java.util.*;
|
||||
import org.redkale.convert.bson.BsonFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class Two extends One {
|
||||
|
||||
public Two() {
|
||||
super(90100119);
|
||||
}
|
||||
|
||||
protected List<String> list;
|
||||
|
||||
protected Map<String, String> stringMap;
|
||||
|
||||
protected List<ConvertRecord> records;
|
||||
protected List<String> list;
|
||||
|
||||
protected Map<String, String> stringMap;
|
||||
|
||||
protected List<ConvertRecord> records;
|
||||
|
||||
protected Map<String, ConvertRecord> recordMap;
|
||||
|
||||
protected Map<String, ConvertRecord> recordMap;
|
||||
|
||||
public Map<String, String> getStringMap() {
|
||||
return stringMap;
|
||||
}
|
||||
@@ -67,6 +63,4 @@ public class Two extends One {
|
||||
public void setRecordMap(Map<String, ConvertRecord> recordMap) {
|
||||
this.recordMap = recordMap;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,13 +5,10 @@
|
||||
*/
|
||||
package org.redkale.test.convert;
|
||||
|
||||
import org.redkale.persistence.Id;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
import org.redkale.persistence.Id;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class World implements Comparable<World> {
|
||||
|
||||
@Id
|
||||
@@ -44,13 +41,14 @@ public class World implements Comparable<World> {
|
||||
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++){
|
||||
for (int i = 0; i < worlds.length; i++) {
|
||||
worlds[i] = new World();
|
||||
worlds[i].setId(8866+i);
|
||||
worlds[i].setRandomNumber(9966+i);
|
||||
worlds[i].setId(8866 + i);
|
||||
worlds[i].setRandomNumber(9966 + i);
|
||||
}
|
||||
System.out.println(JsonConvert.root().convertTo(worlds));
|
||||
}
|
||||
|
||||
@@ -8,10 +8,7 @@ package org.redkale.test.convert;
|
||||
import java.lang.reflect.Type;
|
||||
import org.redkale.convert.json.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class _DyncFortuneJsonEncoder extends JsonDynEncoder<Fortune> {
|
||||
|
||||
protected final byte[] idFieldBytes = "\"id\":".getBytes();
|
||||
@@ -32,7 +29,7 @@ public class _DyncFortuneJsonEncoder extends JsonDynEncoder<Fortune> {
|
||||
objectEncoder.convertTo(out, value);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
out.writeTo('{');
|
||||
|
||||
out.writeTo(idFieldBytes);
|
||||
|
||||
@@ -8,10 +8,7 @@ package org.redkale.test.convert;
|
||||
import java.lang.reflect.Type;
|
||||
import org.redkale.convert.json.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class _DyncMessageJsonEncoder extends JsonDynEncoder<Message> {
|
||||
|
||||
protected final byte[] messageFieldBytes = "\"message\":".getBytes();
|
||||
@@ -43,9 +40,8 @@ public class _DyncMessageJsonEncoder extends JsonDynEncoder<Message> {
|
||||
out.writeTo(messageFieldBytes);
|
||||
comma = true;
|
||||
}
|
||||
out.writeLatin1To(true, message); //out.writeString(message);
|
||||
out.writeLatin1To(true, message); // out.writeString(message);
|
||||
}
|
||||
out.writeTo('}');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,10 +8,7 @@ package org.redkale.test.convert;
|
||||
import java.lang.reflect.Type;
|
||||
import org.redkale.convert.json.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class _DyncWorldJsonEncoder extends JsonDynEncoder<World> {
|
||||
|
||||
protected final byte[] idFieldBytes = "\"id\":".getBytes();
|
||||
@@ -32,13 +29,13 @@ public class _DyncWorldJsonEncoder extends JsonDynEncoder<World> {
|
||||
objectEncoder.convertTo(out, value);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
out.writeTo('{');
|
||||
boolean comma = false;
|
||||
|
||||
|
||||
out.writeTo(idFieldBytes);
|
||||
out.writeInt(value.getId());
|
||||
|
||||
|
||||
out.writeTo(randomNumberFieldBytes);
|
||||
out.writeInt(value.getRandomNumber());
|
||||
|
||||
|
||||
@@ -5,21 +5,19 @@
|
||||
*/
|
||||
package org.redkale.test.convert.media;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author redkale
|
||||
*/
|
||||
/** @author redkale */
|
||||
public class Image implements java.io.Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public enum Size {
|
||||
SMALL, LARGE
|
||||
SMALL,
|
||||
LARGE
|
||||
}
|
||||
|
||||
private String uri;
|
||||
|
||||
private String title; // Can be null
|
||||
private String title; // Can be null
|
||||
|
||||
private int width;
|
||||
|
||||
@@ -27,8 +25,7 @@ public class Image implements java.io.Serializable {
|
||||
|
||||
private Size size;
|
||||
|
||||
public Image() {
|
||||
}
|
||||
public Image() {}
|
||||
|
||||
public Image(String uri, String title, int width, int height, Size size) {
|
||||
this.height = height;
|
||||
|
||||
@@ -7,20 +7,17 @@ package org.redkale.test.convert.media;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author redkale
|
||||
*/
|
||||
/** @author redkale */
|
||||
public class Media implements java.io.Serializable {
|
||||
|
||||
public enum Player {
|
||||
JAVA, FLASH;
|
||||
|
||||
JAVA,
|
||||
FLASH;
|
||||
}
|
||||
|
||||
private String uri;
|
||||
|
||||
private String title; // Can be unset.
|
||||
private String title; // Can be unset.
|
||||
|
||||
private int width;
|
||||
|
||||
@@ -32,19 +29,29 @@ public class Media implements java.io.Serializable {
|
||||
|
||||
private long size;
|
||||
|
||||
private int bitrate; // Can be unset.
|
||||
private int bitrate; // Can be unset.
|
||||
|
||||
private List<String> persons;
|
||||
|
||||
private Player player;
|
||||
|
||||
private String copyright; // Can be unset.
|
||||
private String copyright; // Can be unset.
|
||||
|
||||
public Media() {
|
||||
}
|
||||
public Media() {}
|
||||
|
||||
public Media(String uri, String title, int width, int height, String format, long duration, long size,
|
||||
int bitrate, boolean hasBitrate, List<String> persons, Player player, String copyright) {
|
||||
public Media(
|
||||
String uri,
|
||||
String title,
|
||||
int width,
|
||||
int height,
|
||||
String format,
|
||||
long duration,
|
||||
long size,
|
||||
int bitrate,
|
||||
boolean hasBitrate,
|
||||
List<String> persons,
|
||||
Player player,
|
||||
String copyright) {
|
||||
this.uri = uri;
|
||||
this.title = title;
|
||||
this.width = width;
|
||||
|
||||
@@ -9,18 +9,14 @@ import java.util.*;
|
||||
import org.redkale.convert.json.*;
|
||||
import org.redkale.test.convert.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author redkale
|
||||
*/
|
||||
/** @author redkale */
|
||||
public class MediaContent implements java.io.Serializable {
|
||||
|
||||
private Media media;
|
||||
|
||||
private List<Image> images;
|
||||
|
||||
public MediaContent() {
|
||||
}
|
||||
public MediaContent() {}
|
||||
|
||||
public MediaContent(Media media, List<Image> images) {
|
||||
this.media = media;
|
||||
|
||||
@@ -6,13 +6,10 @@
|
||||
package org.redkale.test.convert.proto;
|
||||
|
||||
import java.util.*;
|
||||
import org.redkale.util.Utility;
|
||||
import org.redkale.convert.proto.ProtobufConvert;
|
||||
import org.redkale.util.Utility;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class ArrayBean {
|
||||
|
||||
public static class IntArrayBean {
|
||||
@@ -32,11 +29,11 @@ public class ArrayBean {
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
IntArrayBean bean1 = new IntArrayBean();
|
||||
bean1.values1 = new int[]{2, 3, 4};
|
||||
bean1.values1 = new int[] {2, 3, 4};
|
||||
IntListBean bean2 = new IntListBean();
|
||||
bean2.values2 = Utility.ofList(2, 3, 4);
|
||||
IntegerArrayBean bean3 = new IntegerArrayBean();
|
||||
bean3.values3 = new Integer[]{2, 3, 4};
|
||||
bean3.values3 = new Integer[] {2, 3, 4};
|
||||
byte[] bs1 = ProtobufConvert.root().convertTo(bean1);
|
||||
byte[] bs2 = ProtobufConvert.root().convertTo(bean2);
|
||||
byte[] bs3 = ProtobufConvert.root().convertTo(bean3);
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
*/
|
||||
package org.redkale.test.convert.proto;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
import static java.lang.annotation.ElementType.TYPE;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.function.*;
|
||||
import org.junit.jupiter.api.*;
|
||||
@@ -16,10 +17,7 @@ import org.redkale.convert.proto.ProtobufObjectEncoder;
|
||||
import org.redkale.convert.proto.ProtobufReader;
|
||||
import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
@SuppressWarnings("unchecked")
|
||||
public class PBCustMessage2Test {
|
||||
|
||||
@@ -88,10 +86,11 @@ public class PBCustMessage2Test {
|
||||
return new String(fieldChars);
|
||||
}
|
||||
|
||||
public static Encodeable<Writer, BaseMessage> createConvertEnCoder(final ConvertFactory factory, final Class<? extends BaseMessage> clazz) {
|
||||
public static Encodeable<Writer, BaseMessage> createConvertEnCoder(
|
||||
final ConvertFactory factory, final Class<? extends BaseMessage> clazz) {
|
||||
Encodeable valEncoder = factory.createEncoder(clazz, true);
|
||||
final String eventName = getMessageName(clazz);
|
||||
ObjectEncoder encoder = new ProtobufObjectEncoder< BaseMessage>(clazz) {
|
||||
ObjectEncoder encoder = new ProtobufObjectEncoder<BaseMessage>(clazz) {
|
||||
@Override
|
||||
protected void afterInitEnMember(ConvertFactory factory) {
|
||||
Function func1 = t -> eventName;
|
||||
@@ -107,17 +106,18 @@ public class PBCustMessage2Test {
|
||||
setIndex(member2, 2);
|
||||
setPosition(member2, 2);
|
||||
initForEachEnMember(factory, member2);
|
||||
this.members = new EnMember[]{member1, member2};
|
||||
this.members = new EnMember[] {member1, member2};
|
||||
}
|
||||
};
|
||||
encoder.init(factory);
|
||||
return encoder;
|
||||
}
|
||||
|
||||
public static Decodeable<Reader, BaseMessage> createConvertDeCoder(final ConvertFactory factory, final Class<? extends BaseMessage> clazz) {
|
||||
public static Decodeable<Reader, BaseMessage> createConvertDeCoder(
|
||||
final ConvertFactory factory, final Class<? extends BaseMessage> clazz) {
|
||||
Decodeable valDecoder = factory.createDecoder(clazz, true);
|
||||
final String eventName = getMessageName(clazz);
|
||||
ObjectDecoder decoder = new ProtobufObjectDecoder< BaseMessage>(clazz) {
|
||||
ObjectDecoder decoder = new ProtobufObjectDecoder<BaseMessage>(clazz) {
|
||||
@Override
|
||||
protected void afterInitDeMember(ConvertFactory factory) {
|
||||
Function func1 = t -> eventName;
|
||||
@@ -135,7 +135,7 @@ public class PBCustMessage2Test {
|
||||
setIndex(member2, 2);
|
||||
setPosition(member2, 2);
|
||||
initForEachDeMember(factory, member2);
|
||||
this.members = new DeMember[]{member1, member2};
|
||||
this.members = new DeMember[] {member1, member2};
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -147,7 +147,6 @@ public class PBCustMessage2Test {
|
||||
decoder.init(factory);
|
||||
return decoder;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@BaseMessage.MessageName("onPlayerLeaveMessage")
|
||||
@@ -159,8 +158,7 @@ public class PBCustMessage2Test {
|
||||
@ConvertColumn(index = 2)
|
||||
public String retinfo;
|
||||
|
||||
public OnPlayerLeaveMessage2() {
|
||||
}
|
||||
public OnPlayerLeaveMessage2() {}
|
||||
|
||||
public OnPlayerLeaveMessage2(int userid, String retinfo) {
|
||||
this.userid = userid;
|
||||
@@ -181,8 +179,7 @@ public class PBCustMessage2Test {
|
||||
@ConvertColumn(index = 2)
|
||||
private OnPlayerLeaveContent result;
|
||||
|
||||
public OnPlayerLeaveMessage() {
|
||||
}
|
||||
public OnPlayerLeaveMessage() {}
|
||||
|
||||
public OnPlayerLeaveMessage(int userid) {
|
||||
this.result = new OnPlayerLeaveContent(userid);
|
||||
@@ -216,8 +213,7 @@ public class PBCustMessage2Test {
|
||||
@ConvertColumn(index = 2)
|
||||
public String retinfo;
|
||||
|
||||
public OnPlayerLeaveContent() {
|
||||
}
|
||||
public OnPlayerLeaveContent() {}
|
||||
|
||||
public OnPlayerLeaveContent(int userid) {
|
||||
this.userid = userid;
|
||||
@@ -239,5 +235,4 @@ public class PBCustMessage2Test {
|
||||
return JsonConvert.root().convertTo(this);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
*/
|
||||
package org.redkale.test.convert.proto;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
import static java.lang.annotation.ElementType.TYPE;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
import java.util.*;
|
||||
import java.util.function.*;
|
||||
import org.junit.jupiter.api.*;
|
||||
@@ -17,10 +18,7 @@ import org.redkale.convert.proto.ProtobufObjectEncoder;
|
||||
import org.redkale.convert.proto.ProtobufReader;
|
||||
import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class PBCustMessageTest {
|
||||
|
||||
private boolean main;
|
||||
@@ -55,7 +53,8 @@ public class PBCustMessageTest {
|
||||
ProtobufConvert convert = ProtobufConvert.root().newConvert(objFieldFunc);
|
||||
System.out.println(Arrays.toString(convert.convertTo(msg1)));
|
||||
System.out.println(Arrays.toString(convert.convertTo(msg2)));
|
||||
if (!main) Assertions.assertEquals(Arrays.toString(convert.convertTo(msg1)), Arrays.toString(convert.convertTo(msg2)));
|
||||
if (!main)
|
||||
Assertions.assertEquals(Arrays.toString(convert.convertTo(msg1)), Arrays.toString(convert.convertTo(msg2)));
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
@@ -80,7 +79,7 @@ public class PBCustMessageTest {
|
||||
|
||||
public static Encodeable<Writer, BaseMessage> createConvertCoder(ProtobufFactory factory, Class<?> clazz) {
|
||||
Encodeable valEncoder = factory.createEncoder(clazz, true);
|
||||
ObjectEncoder encoder = new ProtobufObjectEncoder< BaseMessage>(clazz) {
|
||||
ObjectEncoder encoder = new ProtobufObjectEncoder<BaseMessage>(clazz) {
|
||||
@Override
|
||||
protected void afterInitEnMember(ConvertFactory factory) {
|
||||
Function func = t -> t;
|
||||
@@ -89,7 +88,7 @@ public class PBCustMessageTest {
|
||||
setIndex(member, 1);
|
||||
setPosition(member, 1);
|
||||
initForEachEnMember(factory, member);
|
||||
this.members = new EnMember[]{member};
|
||||
this.members = new EnMember[] {member};
|
||||
}
|
||||
};
|
||||
encoder.init(factory);
|
||||
@@ -98,7 +97,7 @@ public class PBCustMessageTest {
|
||||
|
||||
public static Decodeable<Reader, BaseMessage> createConvertDeCoder(ProtobufFactory factory, Class<?> clazz) {
|
||||
Decodeable valDecoder = factory.createDecoder(clazz, true);
|
||||
ObjectDecoder decoder = new ProtobufObjectDecoder< BaseMessage>(clazz) {
|
||||
ObjectDecoder decoder = new ProtobufObjectDecoder<BaseMessage>(clazz) {
|
||||
@Override
|
||||
protected void afterInitDeMember(ConvertFactory factory) {
|
||||
this.creator = (Creator) objs -> new Object[1];
|
||||
@@ -109,7 +108,7 @@ public class PBCustMessageTest {
|
||||
setIndex(member, 1);
|
||||
setPosition(member, 1);
|
||||
initForEachDeMember(factory, member);
|
||||
this.members = new DeMember[]{member};
|
||||
this.members = new DeMember[] {member};
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -132,8 +131,7 @@ public class PBCustMessageTest {
|
||||
@ConvertColumn(index = 2)
|
||||
public String retinfo;
|
||||
|
||||
public OnPlayerLeaveMessage2() {
|
||||
}
|
||||
public OnPlayerLeaveMessage2() {}
|
||||
|
||||
public OnPlayerLeaveMessage2(int userid, String retinfo) {
|
||||
this.userid = userid;
|
||||
@@ -151,8 +149,7 @@ public class PBCustMessageTest {
|
||||
@ConvertColumn(index = 1)
|
||||
private OnPlayerLeaveContent onPlayerLeaveMessage;
|
||||
|
||||
public OnPlayerLeaveMessage() {
|
||||
}
|
||||
public OnPlayerLeaveMessage() {}
|
||||
|
||||
public OnPlayerLeaveMessage(int userid) {
|
||||
this.onPlayerLeaveMessage = new OnPlayerLeaveContent(userid);
|
||||
@@ -178,8 +175,7 @@ public class PBCustMessageTest {
|
||||
@ConvertColumn(index = 2)
|
||||
public String retinfo;
|
||||
|
||||
public OnPlayerLeaveContent() {
|
||||
}
|
||||
public OnPlayerLeaveContent() {}
|
||||
|
||||
public OnPlayerLeaveContent(int userid) {
|
||||
this.userid = userid;
|
||||
@@ -201,5 +197,4 @@ public class PBCustMessageTest {
|
||||
return JsonConvert.root().convertTo(this);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@ package org.redkale.test.convert.proto;
|
||||
//// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
//// source: src/test/java/org/redkalex/test/protobuf/PSimpleBean.proto
|
||||
//
|
||||
//package org.redkalex.test.protobuf;
|
||||
// package org.redkalex.test.protobuf;
|
||||
//
|
||||
//public final class PSimpleBeanOuterClass {
|
||||
// public final class PSimpleBeanOuterClass {
|
||||
// private PSimpleBeanOuterClass() {}
|
||||
// public static void registerAllExtensions(
|
||||
// com.google.protobuf.ExtensionRegistryLite registry) {
|
||||
@@ -95,7 +95,8 @@ package org.redkale.test.convert.proto;
|
||||
// internalGetFieldAccessorTable() {
|
||||
// return org.redkalex.test.protobuf.PSimpleBeanOuterClass.internal_static_PSimpleBean_fieldAccessorTable
|
||||
// .ensureFieldAccessorsInitialized(
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.class, org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.Builder.class);
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.class,
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.Builder.class);
|
||||
// }
|
||||
//
|
||||
// public interface PSimpleEntryOrBuilder extends
|
||||
@@ -164,9 +165,11 @@ package org.redkale.test.convert.proto;
|
||||
// @java.lang.Override
|
||||
// protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
|
||||
// internalGetFieldAccessorTable() {
|
||||
// return org.redkalex.test.protobuf.PSimpleBeanOuterClass.internal_static_PSimpleBean_PSimpleEntry_fieldAccessorTable
|
||||
// return
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.internal_static_PSimpleBean_PSimpleEntry_fieldAccessorTable
|
||||
// .ensureFieldAccessorsInitialized(
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.class, org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.Builder.class);
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.class,
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.Builder.class);
|
||||
// }
|
||||
//
|
||||
// public static final int ID_FIELD_NUMBER = 1;
|
||||
@@ -193,7 +196,7 @@ package org.redkale.test.convert.proto;
|
||||
// if (ref instanceof java.lang.String) {
|
||||
// return (java.lang.String) ref;
|
||||
// } else {
|
||||
// com.google.protobuf.ByteString bs =
|
||||
// com.google.protobuf.ByteString bs =
|
||||
// (com.google.protobuf.ByteString) ref;
|
||||
// java.lang.String s = bs.toStringUtf8();
|
||||
// name_ = s;
|
||||
@@ -209,7 +212,7 @@ package org.redkale.test.convert.proto;
|
||||
// getNameBytes() {
|
||||
// java.lang.Object ref = name_;
|
||||
// if (ref instanceof java.lang.String) {
|
||||
// com.google.protobuf.ByteString b =
|
||||
// com.google.protobuf.ByteString b =
|
||||
// com.google.protobuf.ByteString.copyFromUtf8(
|
||||
// (java.lang.String) ref);
|
||||
// name_ = b;
|
||||
@@ -232,7 +235,7 @@ package org.redkale.test.convert.proto;
|
||||
// if (ref instanceof java.lang.String) {
|
||||
// return (java.lang.String) ref;
|
||||
// } else {
|
||||
// com.google.protobuf.ByteString bs =
|
||||
// com.google.protobuf.ByteString bs =
|
||||
// (com.google.protobuf.ByteString) ref;
|
||||
// java.lang.String s = bs.toStringUtf8();
|
||||
// email_ = s;
|
||||
@@ -248,7 +251,7 @@ package org.redkale.test.convert.proto;
|
||||
// getEmailBytes() {
|
||||
// java.lang.Object ref = email_;
|
||||
// if (ref instanceof java.lang.String) {
|
||||
// com.google.protobuf.ByteString b =
|
||||
// com.google.protobuf.ByteString b =
|
||||
// com.google.protobuf.ByteString.copyFromUtf8(
|
||||
// (java.lang.String) ref);
|
||||
// email_ = b;
|
||||
@@ -313,7 +316,8 @@ package org.redkale.test.convert.proto;
|
||||
// if (!(obj instanceof org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry)) {
|
||||
// return super.equals(obj);
|
||||
// }
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry other = (org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry) obj;
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry other =
|
||||
// (org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry) obj;
|
||||
//
|
||||
// if (getId()
|
||||
// != other.getId()) return false;
|
||||
@@ -375,7 +379,8 @@ package org.redkale.test.convert.proto;
|
||||
// throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
// return PARSER.parseFrom(data, extensionRegistry);
|
||||
// }
|
||||
// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry parseFrom(java.io.InputStream input)
|
||||
// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry
|
||||
// parseFrom(java.io.InputStream input)
|
||||
// throws java.io.IOException {
|
||||
// return com.google.protobuf.GeneratedMessageV3
|
||||
// .parseWithIOException(PARSER, input);
|
||||
@@ -388,7 +393,8 @@ package org.redkale.test.convert.proto;
|
||||
// .parseWithIOException(PARSER, input, extensionRegistry);
|
||||
// }
|
||||
//
|
||||
// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry parseDelimitedFrom(java.io.InputStream input)
|
||||
// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry
|
||||
// parseDelimitedFrom(java.io.InputStream input)
|
||||
// throws java.io.IOException {
|
||||
// return com.google.protobuf.GeneratedMessageV3
|
||||
// .parseDelimitedWithIOException(PARSER, input);
|
||||
@@ -420,7 +426,8 @@ package org.redkale.test.convert.proto;
|
||||
// public static Builder newBuilder() {
|
||||
// return DEFAULT_INSTANCE.toBuilder();
|
||||
// }
|
||||
// public static Builder newBuilder(org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry prototype) {
|
||||
// public static Builder newBuilder(org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry
|
||||
// prototype) {
|
||||
// return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
|
||||
// }
|
||||
// @java.lang.Override
|
||||
@@ -450,9 +457,11 @@ package org.redkale.test.convert.proto;
|
||||
// @java.lang.Override
|
||||
// protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
|
||||
// internalGetFieldAccessorTable() {
|
||||
// return org.redkalex.test.protobuf.PSimpleBeanOuterClass.internal_static_PSimpleBean_PSimpleEntry_fieldAccessorTable
|
||||
// return
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.internal_static_PSimpleBean_PSimpleEntry_fieldAccessorTable
|
||||
// .ensureFieldAccessorsInitialized(
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.class, org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.Builder.class);
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.class,
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.Builder.class);
|
||||
// }
|
||||
//
|
||||
// // Construct using org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.newBuilder()
|
||||
@@ -497,7 +506,8 @@ package org.redkale.test.convert.proto;
|
||||
//
|
||||
// @java.lang.Override
|
||||
// public org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry buildPartial() {
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry result = new org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry(this);
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry result = new
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry(this);
|
||||
// if (bitField0_ != 0) { buildPartial0(result); }
|
||||
// onBuilt();
|
||||
// return result;
|
||||
@@ -559,7 +569,8 @@ package org.redkale.test.convert.proto;
|
||||
// }
|
||||
//
|
||||
// public Builder mergeFrom(org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry other) {
|
||||
// if (other == org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.getDefaultInstance()) return this;
|
||||
// if (other == org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.getDefaultInstance())
|
||||
// return this;
|
||||
// if (other.getId() != 0) {
|
||||
// setId(other.getId());
|
||||
// }
|
||||
@@ -688,7 +699,7 @@ package org.redkale.test.convert.proto;
|
||||
// getNameBytes() {
|
||||
// java.lang.Object ref = name_;
|
||||
// if (ref instanceof String) {
|
||||
// com.google.protobuf.ByteString b =
|
||||
// com.google.protobuf.ByteString b =
|
||||
// com.google.protobuf.ByteString.copyFromUtf8(
|
||||
// (java.lang.String) ref);
|
||||
// name_ = b;
|
||||
@@ -760,7 +771,7 @@ package org.redkale.test.convert.proto;
|
||||
// getEmailBytes() {
|
||||
// java.lang.Object ref = email_;
|
||||
// if (ref instanceof String) {
|
||||
// com.google.protobuf.ByteString b =
|
||||
// com.google.protobuf.ByteString b =
|
||||
// com.google.protobuf.ByteString.copyFromUtf8(
|
||||
// (java.lang.String) ref);
|
||||
// email_ = b;
|
||||
@@ -916,9 +927,11 @@ package org.redkale.test.convert.proto;
|
||||
// @java.lang.Override
|
||||
// protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
|
||||
// internalGetFieldAccessorTable() {
|
||||
// return org.redkalex.test.protobuf.PSimpleBeanOuterClass.internal_static_PSimpleBean_PTwoEntry_fieldAccessorTable
|
||||
// return
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.internal_static_PSimpleBean_PTwoEntry_fieldAccessorTable
|
||||
// .ensureFieldAccessorsInitialized(
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry.class, org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry.Builder.class);
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry.class,
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry.Builder.class);
|
||||
// }
|
||||
//
|
||||
// public static final int STATUS_FIELD_NUMBER = 1;
|
||||
@@ -993,7 +1006,8 @@ package org.redkale.test.convert.proto;
|
||||
// if (!(obj instanceof org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry)) {
|
||||
// return super.equals(obj);
|
||||
// }
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry other = (org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry) obj;
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry other =
|
||||
// (org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry) obj;
|
||||
//
|
||||
// if (getStatus()
|
||||
// != other.getStatus()) return false;
|
||||
@@ -1052,7 +1066,8 @@ package org.redkale.test.convert.proto;
|
||||
// throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
// return PARSER.parseFrom(data, extensionRegistry);
|
||||
// }
|
||||
// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry parseFrom(java.io.InputStream input)
|
||||
// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry
|
||||
// parseFrom(java.io.InputStream input)
|
||||
// throws java.io.IOException {
|
||||
// return com.google.protobuf.GeneratedMessageV3
|
||||
// .parseWithIOException(PARSER, input);
|
||||
@@ -1065,7 +1080,8 @@ package org.redkale.test.convert.proto;
|
||||
// .parseWithIOException(PARSER, input, extensionRegistry);
|
||||
// }
|
||||
//
|
||||
// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry parseDelimitedFrom(java.io.InputStream input)
|
||||
// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry
|
||||
// parseDelimitedFrom(java.io.InputStream input)
|
||||
// throws java.io.IOException {
|
||||
// return com.google.protobuf.GeneratedMessageV3
|
||||
// .parseDelimitedWithIOException(PARSER, input);
|
||||
@@ -1097,7 +1113,8 @@ package org.redkale.test.convert.proto;
|
||||
// public static Builder newBuilder() {
|
||||
// return DEFAULT_INSTANCE.toBuilder();
|
||||
// }
|
||||
// public static Builder newBuilder(org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry prototype) {
|
||||
// public static Builder newBuilder(org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry
|
||||
// prototype) {
|
||||
// return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
|
||||
// }
|
||||
// @java.lang.Override
|
||||
@@ -1127,9 +1144,11 @@ package org.redkale.test.convert.proto;
|
||||
// @java.lang.Override
|
||||
// protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
|
||||
// internalGetFieldAccessorTable() {
|
||||
// return org.redkalex.test.protobuf.PSimpleBeanOuterClass.internal_static_PSimpleBean_PTwoEntry_fieldAccessorTable
|
||||
// return
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.internal_static_PSimpleBean_PTwoEntry_fieldAccessorTable
|
||||
// .ensureFieldAccessorsInitialized(
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry.class, org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry.Builder.class);
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry.class,
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry.Builder.class);
|
||||
// }
|
||||
//
|
||||
// // Construct using org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry.newBuilder()
|
||||
@@ -1173,7 +1192,8 @@ package org.redkale.test.convert.proto;
|
||||
//
|
||||
// @java.lang.Override
|
||||
// public org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry buildPartial() {
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry result = new org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry(this);
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry result = new
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry(this);
|
||||
// if (bitField0_ != 0) { buildPartial0(result); }
|
||||
// onBuilt();
|
||||
// return result;
|
||||
@@ -1232,7 +1252,8 @@ package org.redkale.test.convert.proto;
|
||||
// }
|
||||
//
|
||||
// public Builder mergeFrom(org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry other) {
|
||||
// if (other == org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry.getDefaultInstance()) return this;
|
||||
// if (other == org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry.getDefaultInstance())
|
||||
// return this;
|
||||
// if (other.getStatus() != 0) {
|
||||
// setStatus(other.getStatus());
|
||||
// }
|
||||
@@ -1435,14 +1456,16 @@ package org.redkale.test.convert.proto;
|
||||
// */
|
||||
// @java.lang.Override
|
||||
// public org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry getSimple() {
|
||||
// return simple_ == null ? org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.getDefaultInstance() : simple_;
|
||||
// return simple_ == null ?
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.getDefaultInstance() : simple_;
|
||||
// }
|
||||
// /**
|
||||
// * <code>.PSimpleBean.PSimpleEntry simple = 1;</code>
|
||||
// */
|
||||
// @java.lang.Override
|
||||
// public org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntryOrBuilder getSimpleOrBuilder() {
|
||||
// return simple_ == null ? org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.getDefaultInstance() : simple_;
|
||||
// return simple_ == null ?
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.getDefaultInstance() : simple_;
|
||||
// }
|
||||
//
|
||||
// public static final int TWO_FIELD_NUMBER = 2;
|
||||
@@ -1461,14 +1484,16 @@ package org.redkale.test.convert.proto;
|
||||
// */
|
||||
// @java.lang.Override
|
||||
// public org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry getTwo() {
|
||||
// return two_ == null ? org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry.getDefaultInstance() : two_;
|
||||
// return two_ == null ?
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry.getDefaultInstance() : two_;
|
||||
// }
|
||||
// /**
|
||||
// * <code>.PSimpleBean.PTwoEntry two = 2;</code>
|
||||
// */
|
||||
// @java.lang.Override
|
||||
// public org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntryOrBuilder getTwoOrBuilder() {
|
||||
// return two_ == null ? org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry.getDefaultInstance() : two_;
|
||||
// return two_ == null ?
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry.getDefaultInstance() : two_;
|
||||
// }
|
||||
//
|
||||
// public static final int STRINGS_FIELD_NUMBER = 3;
|
||||
@@ -1484,7 +1509,7 @@ package org.redkale.test.convert.proto;
|
||||
// if (ref instanceof java.lang.String) {
|
||||
// return (java.lang.String) ref;
|
||||
// } else {
|
||||
// com.google.protobuf.ByteString bs =
|
||||
// com.google.protobuf.ByteString bs =
|
||||
// (com.google.protobuf.ByteString) ref;
|
||||
// java.lang.String s = bs.toStringUtf8();
|
||||
// strings_ = s;
|
||||
@@ -1500,7 +1525,7 @@ package org.redkale.test.convert.proto;
|
||||
// getStringsBytes() {
|
||||
// java.lang.Object ref = strings_;
|
||||
// if (ref instanceof java.lang.String) {
|
||||
// com.google.protobuf.ByteString b =
|
||||
// com.google.protobuf.ByteString b =
|
||||
// com.google.protobuf.ByteString.copyFromUtf8(
|
||||
// (java.lang.String) ref);
|
||||
// strings_ = b;
|
||||
@@ -1566,7 +1591,8 @@ package org.redkale.test.convert.proto;
|
||||
// if (!(obj instanceof org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean)) {
|
||||
// return super.equals(obj);
|
||||
// }
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean other = (org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean) obj;
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean other =
|
||||
// (org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean) obj;
|
||||
//
|
||||
// if (hasSimple() != other.hasSimple()) return false;
|
||||
// if (hasSimple()) {
|
||||
@@ -1651,7 +1677,8 @@ package org.redkale.test.convert.proto;
|
||||
// .parseWithIOException(PARSER, input, extensionRegistry);
|
||||
// }
|
||||
//
|
||||
// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean parseDelimitedFrom(java.io.InputStream input)
|
||||
// public static org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean parseDelimitedFrom(java.io.InputStream
|
||||
// input)
|
||||
// throws java.io.IOException {
|
||||
// return com.google.protobuf.GeneratedMessageV3
|
||||
// .parseDelimitedWithIOException(PARSER, input);
|
||||
@@ -1715,7 +1742,8 @@ package org.redkale.test.convert.proto;
|
||||
// internalGetFieldAccessorTable() {
|
||||
// return org.redkalex.test.protobuf.PSimpleBeanOuterClass.internal_static_PSimpleBean_fieldAccessorTable
|
||||
// .ensureFieldAccessorsInitialized(
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.class, org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.Builder.class);
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.class,
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.Builder.class);
|
||||
// }
|
||||
//
|
||||
// // Construct using org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.newBuilder()
|
||||
@@ -1768,7 +1796,8 @@ package org.redkale.test.convert.proto;
|
||||
//
|
||||
// @java.lang.Override
|
||||
// public org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean buildPartial() {
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean result = new org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean(this);
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean result = new
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean(this);
|
||||
// if (bitField0_ != 0) { buildPartial0(result); }
|
||||
// onBuilt();
|
||||
// return result;
|
||||
@@ -1910,7 +1939,9 @@ package org.redkale.test.convert.proto;
|
||||
//
|
||||
// private org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry simple_;
|
||||
// private com.google.protobuf.SingleFieldBuilderV3<
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry, org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.Builder, org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntryOrBuilder> simpleBuilder_;
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry,
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.Builder,
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntryOrBuilder> simpleBuilder_;
|
||||
// /**
|
||||
// * <code>.PSimpleBean.PSimpleEntry simple = 1;</code>
|
||||
// * @return Whether the simple field is set.
|
||||
@@ -1924,7 +1955,8 @@ package org.redkale.test.convert.proto;
|
||||
// */
|
||||
// public org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry getSimple() {
|
||||
// if (simpleBuilder_ == null) {
|
||||
// return simple_ == null ? org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.getDefaultInstance() : simple_;
|
||||
// return simple_ == null ?
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.getDefaultInstance() : simple_;
|
||||
// } else {
|
||||
// return simpleBuilder_.getMessage();
|
||||
// }
|
||||
@@ -1966,7 +1998,8 @@ package org.redkale.test.convert.proto;
|
||||
// if (simpleBuilder_ == null) {
|
||||
// if (((bitField0_ & 0x00000001) != 0) &&
|
||||
// simple_ != null &&
|
||||
// simple_ != org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.getDefaultInstance()) {
|
||||
// simple_ != org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.getDefaultInstance())
|
||||
// {
|
||||
// getSimpleBuilder().mergeFrom(value);
|
||||
// } else {
|
||||
// simple_ = value;
|
||||
@@ -2007,18 +2040,23 @@ package org.redkale.test.convert.proto;
|
||||
// return simpleBuilder_.getMessageOrBuilder();
|
||||
// } else {
|
||||
// return simple_ == null ?
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.getDefaultInstance() : simple_;
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.getDefaultInstance() :
|
||||
// simple_;
|
||||
// }
|
||||
// }
|
||||
// /**
|
||||
// * <code>.PSimpleBean.PSimpleEntry simple = 1;</code>
|
||||
// */
|
||||
// private com.google.protobuf.SingleFieldBuilderV3<
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry, org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.Builder, org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntryOrBuilder>
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry,
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.Builder,
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntryOrBuilder>
|
||||
// getSimpleFieldBuilder() {
|
||||
// if (simpleBuilder_ == null) {
|
||||
// simpleBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry, org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.Builder, org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntryOrBuilder>(
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry,
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.Builder,
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PSimpleEntryOrBuilder>(
|
||||
// getSimple(),
|
||||
// getParentForChildren(),
|
||||
// isClean());
|
||||
@@ -2029,7 +2067,9 @@ package org.redkale.test.convert.proto;
|
||||
//
|
||||
// private org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry two_;
|
||||
// private com.google.protobuf.SingleFieldBuilderV3<
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry, org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry.Builder, org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntryOrBuilder> twoBuilder_;
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry,
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry.Builder,
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntryOrBuilder> twoBuilder_;
|
||||
// /**
|
||||
// * <code>.PSimpleBean.PTwoEntry two = 2;</code>
|
||||
// * @return Whether the two field is set.
|
||||
@@ -2043,7 +2083,8 @@ package org.redkale.test.convert.proto;
|
||||
// */
|
||||
// public org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry getTwo() {
|
||||
// if (twoBuilder_ == null) {
|
||||
// return two_ == null ? org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry.getDefaultInstance() : two_;
|
||||
// return two_ == null ?
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry.getDefaultInstance() : two_;
|
||||
// } else {
|
||||
// return twoBuilder_.getMessage();
|
||||
// }
|
||||
@@ -2133,11 +2174,15 @@ package org.redkale.test.convert.proto;
|
||||
// * <code>.PSimpleBean.PTwoEntry two = 2;</code>
|
||||
// */
|
||||
// private com.google.protobuf.SingleFieldBuilderV3<
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry, org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry.Builder, org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntryOrBuilder>
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry,
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry.Builder,
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntryOrBuilder>
|
||||
// getTwoFieldBuilder() {
|
||||
// if (twoBuilder_ == null) {
|
||||
// twoBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry, org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry.Builder, org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntryOrBuilder>(
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry,
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntry.Builder,
|
||||
// org.redkalex.test.protobuf.PSimpleBeanOuterClass.PSimpleBean.PTwoEntryOrBuilder>(
|
||||
// getTwo(),
|
||||
// getParentForChildren(),
|
||||
// isClean());
|
||||
@@ -2171,7 +2216,7 @@ package org.redkale.test.convert.proto;
|
||||
// getStringsBytes() {
|
||||
// java.lang.Object ref = strings_;
|
||||
// if (ref instanceof String) {
|
||||
// com.google.protobuf.ByteString b =
|
||||
// com.google.protobuf.ByteString b =
|
||||
// com.google.protobuf.ByteString.copyFromUtf8(
|
||||
// (java.lang.String) ref);
|
||||
// strings_ = b;
|
||||
@@ -2283,17 +2328,17 @@ package org.redkale.test.convert.proto;
|
||||
//
|
||||
// private static final com.google.protobuf.Descriptors.Descriptor
|
||||
// internal_static_PSimpleBean_descriptor;
|
||||
// private static final
|
||||
// private static final
|
||||
// com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
|
||||
// internal_static_PSimpleBean_fieldAccessorTable;
|
||||
// private static final com.google.protobuf.Descriptors.Descriptor
|
||||
// internal_static_PSimpleBean_PSimpleEntry_descriptor;
|
||||
// private static final
|
||||
// private static final
|
||||
// com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
|
||||
// internal_static_PSimpleBean_PSimpleEntry_fieldAccessorTable;
|
||||
// private static final com.google.protobuf.Descriptors.Descriptor
|
||||
// internal_static_PSimpleBean_PTwoEntry_descriptor;
|
||||
// private static final
|
||||
// private static final
|
||||
// com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
|
||||
// internal_static_PSimpleBean_PTwoEntry_fieldAccessorTable;
|
||||
//
|
||||
@@ -2339,4 +2384,4 @@ package org.redkale.test.convert.proto;
|
||||
// }
|
||||
//
|
||||
// // @@protoc_insertion_point(outer_class_scope)
|
||||
//}
|
||||
// }
|
||||
|
||||
@@ -3,9 +3,9 @@ package org.redkale.test.convert.proto;
|
||||
//// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
//// source: src/test/java/org/redkalex/test/protobuf/PTestBean.proto
|
||||
//
|
||||
//package org.redkalex.test.protobuf;
|
||||
// package org.redkalex.test.protobuf;
|
||||
//
|
||||
//public final class PTestBeanOuterClass {
|
||||
// public final class PTestBeanOuterClass {
|
||||
// private PTestBeanOuterClass() {}
|
||||
// public static void registerAllExtensions(
|
||||
// com.google.protobuf.ExtensionRegistryLite registry) {
|
||||
@@ -74,7 +74,7 @@ package org.redkale.test.convert.proto;
|
||||
// /**
|
||||
// * <code>repeated .PTestBean.PTestEntry entrys = 4;</code>
|
||||
// */
|
||||
// java.util.List<org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry>
|
||||
// java.util.List<org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry>
|
||||
// getEntrysList();
|
||||
// /**
|
||||
// * <code>repeated .PTestBean.PTestEntry entrys = 4;</code>
|
||||
@@ -87,7 +87,7 @@ package org.redkale.test.convert.proto;
|
||||
// /**
|
||||
// * <code>repeated .PTestBean.PTestEntry entrys = 4;</code>
|
||||
// */
|
||||
// java.util.List<? extends org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntryOrBuilder>
|
||||
// java.util.List<? extends org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntryOrBuilder>
|
||||
// getEntrysOrBuilderList();
|
||||
// /**
|
||||
// * <code>repeated .PTestBean.PTestEntry entrys = 4;</code>
|
||||
@@ -331,7 +331,8 @@ package org.redkale.test.convert.proto;
|
||||
// internalGetFieldAccessorTable() {
|
||||
// return org.redkalex.test.protobuf.PTestBeanOuterClass.internal_static_PTestBean_fieldAccessorTable
|
||||
// .ensureFieldAccessorsInitialized(
|
||||
// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.class, org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.Builder.class);
|
||||
// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.class,
|
||||
// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.Builder.class);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
@@ -559,7 +560,8 @@ package org.redkale.test.convert.proto;
|
||||
// internalGetFieldAccessorTable() {
|
||||
// return org.redkalex.test.protobuf.PTestBeanOuterClass.internal_static_PTestBean_PTestEntry_fieldAccessorTable
|
||||
// .ensureFieldAccessorsInitialized(
|
||||
// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry.class, org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry.Builder.class);
|
||||
// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry.class,
|
||||
// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry.Builder.class);
|
||||
// }
|
||||
//
|
||||
// public static final int BOOLS_FIELD_NUMBER = 1;
|
||||
@@ -786,7 +788,8 @@ package org.redkale.test.convert.proto;
|
||||
// if (!(obj instanceof org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry)) {
|
||||
// return super.equals(obj);
|
||||
// }
|
||||
// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry other = (org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry) obj;
|
||||
// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry other =
|
||||
// (org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry) obj;
|
||||
//
|
||||
// if (!getBoolsList()
|
||||
// .equals(other.getBoolsList())) return false;
|
||||
@@ -860,7 +863,8 @@ package org.redkale.test.convert.proto;
|
||||
// throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
// return PARSER.parseFrom(data, extensionRegistry);
|
||||
// }
|
||||
// public static org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry parseFrom(java.io.InputStream input)
|
||||
// public static org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry parseFrom(java.io.InputStream
|
||||
// input)
|
||||
// throws java.io.IOException {
|
||||
// return com.google.protobuf.GeneratedMessageV3
|
||||
// .parseWithIOException(PARSER, input);
|
||||
@@ -873,7 +877,8 @@ package org.redkale.test.convert.proto;
|
||||
// .parseWithIOException(PARSER, input, extensionRegistry);
|
||||
// }
|
||||
//
|
||||
// public static org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry parseDelimitedFrom(java.io.InputStream input)
|
||||
// public static org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry
|
||||
// parseDelimitedFrom(java.io.InputStream input)
|
||||
// throws java.io.IOException {
|
||||
// return com.google.protobuf.GeneratedMessageV3
|
||||
// .parseDelimitedWithIOException(PARSER, input);
|
||||
@@ -905,7 +910,8 @@ package org.redkale.test.convert.proto;
|
||||
// public static Builder newBuilder() {
|
||||
// return DEFAULT_INSTANCE.toBuilder();
|
||||
// }
|
||||
// public static Builder newBuilder(org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry prototype) {
|
||||
// public static Builder newBuilder(org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry prototype)
|
||||
// {
|
||||
// return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
|
||||
// }
|
||||
// @java.lang.Override
|
||||
@@ -935,9 +941,11 @@ package org.redkale.test.convert.proto;
|
||||
// @java.lang.Override
|
||||
// protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
|
||||
// internalGetFieldAccessorTable() {
|
||||
// return org.redkalex.test.protobuf.PTestBeanOuterClass.internal_static_PTestBean_PTestEntry_fieldAccessorTable
|
||||
// return
|
||||
// org.redkalex.test.protobuf.PTestBeanOuterClass.internal_static_PTestBean_PTestEntry_fieldAccessorTable
|
||||
// .ensureFieldAccessorsInitialized(
|
||||
// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry.class, org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry.Builder.class);
|
||||
// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry.class,
|
||||
// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry.Builder.class);
|
||||
// }
|
||||
//
|
||||
// // Construct using org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry.newBuilder()
|
||||
@@ -983,14 +991,16 @@ package org.redkale.test.convert.proto;
|
||||
//
|
||||
// @java.lang.Override
|
||||
// public org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry buildPartial() {
|
||||
// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry result = new org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry(this);
|
||||
// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry result = new
|
||||
// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry(this);
|
||||
// buildPartialRepeatedFields(result);
|
||||
// if (bitField0_ != 0) { buildPartial0(result); }
|
||||
// onBuilt();
|
||||
// return result;
|
||||
// }
|
||||
//
|
||||
// private void buildPartialRepeatedFields(org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry result) {
|
||||
// private void buildPartialRepeatedFields(org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry
|
||||
// result) {
|
||||
// if (((bitField0_ & 0x00000001) != 0)) {
|
||||
// bools_.makeImmutable();
|
||||
// bitField0_ = (bitField0_ & ~0x00000001);
|
||||
@@ -1060,7 +1070,8 @@ package org.redkale.test.convert.proto;
|
||||
// }
|
||||
//
|
||||
// public Builder mergeFrom(org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry other) {
|
||||
// if (other == org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry.getDefaultInstance()) return this;
|
||||
// if (other == org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry.getDefaultInstance())
|
||||
// return this;
|
||||
// if (!other.bools_.isEmpty()) {
|
||||
// if (bools_.isEmpty()) {
|
||||
// bools_ = other.bools_;
|
||||
@@ -1685,7 +1696,7 @@ package org.redkale.test.convert.proto;
|
||||
// * <code>repeated .PTestBean.PTestEntry entrys = 4;</code>
|
||||
// */
|
||||
// @java.lang.Override
|
||||
// public java.util.List<? extends org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntryOrBuilder>
|
||||
// public java.util.List<? extends org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntryOrBuilder>
|
||||
// getEntrysOrBuilderList() {
|
||||
// return entrys_;
|
||||
// }
|
||||
@@ -1889,7 +1900,7 @@ package org.redkale.test.convert.proto;
|
||||
// if (ref instanceof java.lang.String) {
|
||||
// return (java.lang.String) ref;
|
||||
// } else {
|
||||
// com.google.protobuf.ByteString bs =
|
||||
// com.google.protobuf.ByteString bs =
|
||||
// (com.google.protobuf.ByteString) ref;
|
||||
// java.lang.String s = bs.toStringUtf8();
|
||||
// name_ = s;
|
||||
@@ -1905,7 +1916,7 @@ package org.redkale.test.convert.proto;
|
||||
// getNameBytes() {
|
||||
// java.lang.Object ref = name_;
|
||||
// if (ref instanceof java.lang.String) {
|
||||
// com.google.protobuf.ByteString b =
|
||||
// com.google.protobuf.ByteString b =
|
||||
// com.google.protobuf.ByteString.copyFromUtf8(
|
||||
// (java.lang.String) ref);
|
||||
// name_ = b;
|
||||
@@ -1928,7 +1939,7 @@ package org.redkale.test.convert.proto;
|
||||
// if (ref instanceof java.lang.String) {
|
||||
// return (java.lang.String) ref;
|
||||
// } else {
|
||||
// com.google.protobuf.ByteString bs =
|
||||
// com.google.protobuf.ByteString bs =
|
||||
// (com.google.protobuf.ByteString) ref;
|
||||
// java.lang.String s = bs.toStringUtf8();
|
||||
// email_ = s;
|
||||
@@ -1944,7 +1955,7 @@ package org.redkale.test.convert.proto;
|
||||
// getEmailBytes() {
|
||||
// java.lang.Object ref = email_;
|
||||
// if (ref instanceof java.lang.String) {
|
||||
// com.google.protobuf.ByteString b =
|
||||
// com.google.protobuf.ByteString b =
|
||||
// com.google.protobuf.ByteString.copyFromUtf8(
|
||||
// (java.lang.String) ref);
|
||||
// email_ = b;
|
||||
@@ -1968,7 +1979,8 @@ package org.redkale.test.convert.proto;
|
||||
// * @return The kind.
|
||||
// */
|
||||
// @java.lang.Override public org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.Kind getKind() {
|
||||
// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.Kind result = org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.Kind.forNumber(kind_);
|
||||
// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.Kind result =
|
||||
// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.Kind.forNumber(kind_);
|
||||
// return result == null ? org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.Kind.UNRECOGNIZED : result;
|
||||
// }
|
||||
//
|
||||
@@ -1978,7 +1990,7 @@ package org.redkale.test.convert.proto;
|
||||
// java.lang.String, java.lang.Integer> defaultEntry =
|
||||
// com.google.protobuf.MapEntry
|
||||
// .<java.lang.String, java.lang.Integer>newDefaultInstance(
|
||||
// org.redkalex.test.protobuf.PTestBeanOuterClass.internal_static_PTestBean_MapEntry_descriptor,
|
||||
// org.redkalex.test.protobuf.PTestBeanOuterClass.internal_static_PTestBean_MapEntry_descriptor,
|
||||
// com.google.protobuf.WireFormat.FieldType.STRING,
|
||||
// "",
|
||||
// com.google.protobuf.WireFormat.FieldType.SINT32,
|
||||
@@ -2062,7 +2074,7 @@ package org.redkale.test.convert.proto;
|
||||
// if (ref instanceof java.lang.String) {
|
||||
// return (java.lang.String) ref;
|
||||
// } else {
|
||||
// com.google.protobuf.ByteString bs =
|
||||
// com.google.protobuf.ByteString bs =
|
||||
// (com.google.protobuf.ByteString) ref;
|
||||
// java.lang.String s = bs.toStringUtf8();
|
||||
// end_ = s;
|
||||
@@ -2078,7 +2090,7 @@ package org.redkale.test.convert.proto;
|
||||
// getEndBytes() {
|
||||
// java.lang.Object ref = end_;
|
||||
// if (ref instanceof java.lang.String) {
|
||||
// com.google.protobuf.ByteString b =
|
||||
// com.google.protobuf.ByteString b =
|
||||
// com.google.protobuf.ByteString.copyFromUtf8(
|
||||
// (java.lang.String) ref);
|
||||
// end_ = b;
|
||||
@@ -2320,7 +2332,8 @@ package org.redkale.test.convert.proto;
|
||||
// if (!(obj instanceof org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean)) {
|
||||
// return super.equals(obj);
|
||||
// }
|
||||
// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean other = (org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean) obj;
|
||||
// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean other =
|
||||
// (org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean) obj;
|
||||
//
|
||||
// if (!getBoolsList()
|
||||
// .equals(other.getBoolsList())) return false;
|
||||
@@ -2462,7 +2475,8 @@ package org.redkale.test.convert.proto;
|
||||
// .parseWithIOException(PARSER, input, extensionRegistry);
|
||||
// }
|
||||
//
|
||||
// public static org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean parseDelimitedFrom(java.io.InputStream input)
|
||||
// public static org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean parseDelimitedFrom(java.io.InputStream
|
||||
// input)
|
||||
// throws java.io.IOException {
|
||||
// return com.google.protobuf.GeneratedMessageV3
|
||||
// .parseDelimitedWithIOException(PARSER, input);
|
||||
@@ -2548,7 +2562,8 @@ package org.redkale.test.convert.proto;
|
||||
// internalGetFieldAccessorTable() {
|
||||
// return org.redkalex.test.protobuf.PTestBeanOuterClass.internal_static_PTestBean_fieldAccessorTable
|
||||
// .ensureFieldAccessorsInitialized(
|
||||
// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.class, org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.Builder.class);
|
||||
// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.class,
|
||||
// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.Builder.class);
|
||||
// }
|
||||
//
|
||||
// // Construct using org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.newBuilder()
|
||||
@@ -2612,7 +2627,8 @@ package org.redkale.test.convert.proto;
|
||||
//
|
||||
// @java.lang.Override
|
||||
// public org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean buildPartial() {
|
||||
// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean result = new org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean(this);
|
||||
// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean result = new
|
||||
// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean(this);
|
||||
// buildPartialRepeatedFields(result);
|
||||
// if (bitField0_ != 0) { buildPartial0(result); }
|
||||
// onBuilt();
|
||||
@@ -2785,7 +2801,7 @@ package org.redkale.test.convert.proto;
|
||||
// entrysBuilder_ = null;
|
||||
// entrys_ = other.entrys_;
|
||||
// bitField0_ = (bitField0_ & ~0x00000008);
|
||||
// entrysBuilder_ =
|
||||
// entrysBuilder_ =
|
||||
// com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ?
|
||||
// getEntrysFieldBuilder() : null;
|
||||
// } else {
|
||||
@@ -3312,13 +3328,16 @@ package org.redkale.test.convert.proto;
|
||||
// java.util.Collections.emptyList();
|
||||
// private void ensureEntrysIsMutable() {
|
||||
// if (!((bitField0_ & 0x00000008) != 0)) {
|
||||
// entrys_ = new java.util.ArrayList<org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry>(entrys_);
|
||||
// entrys_ = new
|
||||
// java.util.ArrayList<org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry>(entrys_);
|
||||
// bitField0_ |= 0x00000008;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private com.google.protobuf.RepeatedFieldBuilderV3<
|
||||
// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry, org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry.Builder, org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntryOrBuilder> entrysBuilder_;
|
||||
// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry,
|
||||
// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry.Builder,
|
||||
// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntryOrBuilder> entrysBuilder_;
|
||||
//
|
||||
// /**
|
||||
// * <code>repeated .PTestBean.PTestEntry entrys = 4;</code>
|
||||
@@ -3503,7 +3522,7 @@ package org.redkale.test.convert.proto;
|
||||
// /**
|
||||
// * <code>repeated .PTestBean.PTestEntry entrys = 4;</code>
|
||||
// */
|
||||
// public java.util.List<? extends org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntryOrBuilder>
|
||||
// public java.util.List<? extends org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntryOrBuilder>
|
||||
// getEntrysOrBuilderList() {
|
||||
// if (entrysBuilder_ != null) {
|
||||
// return entrysBuilder_.getMessageOrBuilderList();
|
||||
@@ -3529,16 +3548,20 @@ package org.redkale.test.convert.proto;
|
||||
// /**
|
||||
// * <code>repeated .PTestBean.PTestEntry entrys = 4;</code>
|
||||
// */
|
||||
// public java.util.List<org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry.Builder>
|
||||
// public java.util.List<org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry.Builder>
|
||||
// getEntrysBuilderList() {
|
||||
// return getEntrysFieldBuilder().getBuilderList();
|
||||
// }
|
||||
// private com.google.protobuf.RepeatedFieldBuilderV3<
|
||||
// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry, org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry.Builder, org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntryOrBuilder>
|
||||
// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry,
|
||||
// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry.Builder,
|
||||
// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntryOrBuilder>
|
||||
// getEntrysFieldBuilder() {
|
||||
// if (entrysBuilder_ == null) {
|
||||
// entrysBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
|
||||
// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry, org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry.Builder, org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntryOrBuilder>(
|
||||
// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry,
|
||||
// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntry.Builder,
|
||||
// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.PTestEntryOrBuilder>(
|
||||
// entrys_,
|
||||
// ((bitField0_ & 0x00000008) != 0),
|
||||
// getParentForChildren(),
|
||||
@@ -4040,7 +4063,7 @@ package org.redkale.test.convert.proto;
|
||||
// getNameBytes() {
|
||||
// java.lang.Object ref = name_;
|
||||
// if (ref instanceof String) {
|
||||
// com.google.protobuf.ByteString b =
|
||||
// com.google.protobuf.ByteString b =
|
||||
// com.google.protobuf.ByteString.copyFromUtf8(
|
||||
// (java.lang.String) ref);
|
||||
// name_ = b;
|
||||
@@ -4112,7 +4135,7 @@ package org.redkale.test.convert.proto;
|
||||
// getEmailBytes() {
|
||||
// java.lang.Object ref = email_;
|
||||
// if (ref instanceof String) {
|
||||
// com.google.protobuf.ByteString b =
|
||||
// com.google.protobuf.ByteString b =
|
||||
// com.google.protobuf.ByteString.copyFromUtf8(
|
||||
// (java.lang.String) ref);
|
||||
// email_ = b;
|
||||
@@ -4184,7 +4207,8 @@ package org.redkale.test.convert.proto;
|
||||
// */
|
||||
// @java.lang.Override
|
||||
// public org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.Kind getKind() {
|
||||
// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.Kind result = org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.Kind.forNumber(kind_);
|
||||
// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.Kind result =
|
||||
// org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.Kind.forNumber(kind_);
|
||||
// return result == null ? org.redkalex.test.protobuf.PTestBeanOuterClass.PTestBean.Kind.UNRECOGNIZED : result;
|
||||
// }
|
||||
// /**
|
||||
@@ -4362,7 +4386,7 @@ package org.redkale.test.convert.proto;
|
||||
// getEndBytes() {
|
||||
// java.lang.Object ref = end_;
|
||||
// if (ref instanceof String) {
|
||||
// com.google.protobuf.ByteString b =
|
||||
// com.google.protobuf.ByteString b =
|
||||
// com.google.protobuf.ByteString.copyFromUtf8(
|
||||
// (java.lang.String) ref);
|
||||
// end_ = b;
|
||||
@@ -4474,17 +4498,17 @@ package org.redkale.test.convert.proto;
|
||||
//
|
||||
// private static final com.google.protobuf.Descriptors.Descriptor
|
||||
// internal_static_PTestBean_descriptor;
|
||||
// private static final
|
||||
// private static final
|
||||
// com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
|
||||
// internal_static_PTestBean_fieldAccessorTable;
|
||||
// private static final com.google.protobuf.Descriptors.Descriptor
|
||||
// internal_static_PTestBean_PTestEntry_descriptor;
|
||||
// private static final
|
||||
// private static final
|
||||
// com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
|
||||
// internal_static_PTestBean_PTestEntry_fieldAccessorTable;
|
||||
// private static final com.google.protobuf.Descriptors.Descriptor
|
||||
// internal_static_PTestBean_MapEntry_descriptor;
|
||||
// private static final
|
||||
// private static final
|
||||
// com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
|
||||
// internal_static_PTestBean_MapEntry_fieldAccessorTable;
|
||||
//
|
||||
@@ -4520,7 +4544,8 @@ package org.redkale.test.convert.proto;
|
||||
// internal_static_PTestBean_fieldAccessorTable = new
|
||||
// com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
|
||||
// internal_static_PTestBean_descriptor,
|
||||
// new java.lang.String[] { "Bools", "Bytes", "Chars", "Entrys", "Ints", "Floats", "Longs", "Doubles", "Strings", "Id", "Name", "Email", "Kind", "Map", "End", });
|
||||
// new java.lang.String[] { "Bools", "Bytes", "Chars", "Entrys", "Ints", "Floats", "Longs", "Doubles", "Strings",
|
||||
// "Id", "Name", "Email", "Kind", "Map", "End", });
|
||||
// internal_static_PTestBean_PTestEntry_descriptor =
|
||||
// internal_static_PTestBean_descriptor.getNestedTypes().get(0);
|
||||
// internal_static_PTestBean_PTestEntry_fieldAccessorTable = new
|
||||
@@ -4536,4 +4561,4 @@ package org.redkale.test.convert.proto;
|
||||
// }
|
||||
//
|
||||
// // @@protoc_insertion_point(outer_class_scope)
|
||||
//}
|
||||
// }
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
package org.redkale.test.convert.proto;
|
||||
|
||||
///*
|
||||
/// *
|
||||
// * 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.redkalex.test.protobuf;
|
||||
// package org.redkalex.test.protobuf;
|
||||
//
|
||||
//import java.util.Arrays;
|
||||
//import org.redkale.convert.ConvertColumn;
|
||||
//import org.redkale.convert.json.JsonConvert;
|
||||
//import org.redkale.util.Utility;
|
||||
//import org.redkalex.convert.protobuf.ProtobufConvert;
|
||||
// import java.util.Arrays;
|
||||
// import org.redkale.convert.ConvertColumn;
|
||||
// import org.redkale.convert.json.JsonConvert;
|
||||
// import org.redkale.util.Utility;
|
||||
// import org.redkalex.convert.protobuf.ProtobufConvert;
|
||||
//
|
||||
///**
|
||||
/// **
|
||||
// *
|
||||
// * @author zhangjx
|
||||
// */
|
||||
//public class SimpleBean {
|
||||
// public class SimpleBean {
|
||||
//
|
||||
// public static class PSimpleEntry {
|
||||
//
|
||||
@@ -80,19 +80,22 @@ package org.redkale.test.convert.proto;
|
||||
//
|
||||
// }
|
||||
//
|
||||
// private static PSimpleBeanOuterClass.PSimpleBean createPSimpleBean(SimpleBean bean, PSimpleBeanOuterClass.PSimpleBean.Builder builder) {
|
||||
// private static PSimpleBeanOuterClass.PSimpleBean createPSimpleBean(SimpleBean bean,
|
||||
// PSimpleBeanOuterClass.PSimpleBean.Builder builder) {
|
||||
// if (builder == null) {
|
||||
// builder = PSimpleBeanOuterClass.PSimpleBean.newBuilder();
|
||||
// } else {
|
||||
// builder.clear();
|
||||
// }
|
||||
// PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.Builder sentry = PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.newBuilder();
|
||||
// PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.Builder sentry =
|
||||
// PSimpleBeanOuterClass.PSimpleBean.PSimpleEntry.newBuilder();
|
||||
// sentry.setId(bean.simple.id);
|
||||
// sentry.setName(bean.simple.name);
|
||||
// sentry.setEmail(bean.simple.email);
|
||||
// builder.setSimple(sentry.build());
|
||||
//
|
||||
// PSimpleBeanOuterClass.PSimpleBean.PTwoEntry.Builder tentry = PSimpleBeanOuterClass.PSimpleBean.PTwoEntry.newBuilder();
|
||||
// PSimpleBeanOuterClass.PSimpleBean.PTwoEntry.Builder tentry =
|
||||
// PSimpleBeanOuterClass.PSimpleBean.PTwoEntry.newBuilder();
|
||||
// tentry.setStatus(bean.two.status);
|
||||
// tentry.setCreatetime(bean.two.createtime);
|
||||
// builder.setTwo(tentry.build());
|
||||
@@ -102,4 +105,4 @@ package org.redkale.test.convert.proto;
|
||||
// PSimpleBeanOuterClass.PSimpleBean bean2 = builder.build();
|
||||
// return bean2;
|
||||
// }
|
||||
//}
|
||||
// }
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
package org.redkale.test.convert.proto;
|
||||
|
||||
///*
|
||||
/// *
|
||||
// * 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.redkalex.test.protobuf;
|
||||
// package org.redkalex.test.protobuf;
|
||||
//
|
||||
//import org.redkalex.convert.protobuf.ProtobufReader;
|
||||
//import org.redkalex.convert.protobuf.ProtobufConvert;
|
||||
//import com.google.protobuf.*;
|
||||
//import java.util.*;
|
||||
//import org.redkale.convert.ConvertColumn;
|
||||
//import org.redkale.convert.json.JsonConvert;
|
||||
//import org.redkale.service.RetResult;
|
||||
//import org.redkale.util.*;
|
||||
// import org.redkalex.convert.protobuf.ProtobufReader;
|
||||
// import org.redkalex.convert.protobuf.ProtobufConvert;
|
||||
// import com.google.protobuf.*;
|
||||
// import java.util.*;
|
||||
// import org.redkale.convert.ConvertColumn;
|
||||
// import org.redkale.convert.json.JsonConvert;
|
||||
// import org.redkale.service.RetResult;
|
||||
// import org.redkale.util.*;
|
||||
//
|
||||
///**
|
||||
/// **
|
||||
// *
|
||||
// * @author zhangjx
|
||||
// */
|
||||
//public class TestBean {
|
||||
// public class TestBean {
|
||||
//
|
||||
// public static class PTestEntry {
|
||||
//
|
||||
@@ -181,7 +181,8 @@ package org.redkale.test.convert.proto;
|
||||
// System.out.println("原生编译protobuf耗时-------" + e);
|
||||
// }
|
||||
//
|
||||
// private static PTestBeanOuterClass.PTestBean createPTestBean(TestBean bean, PTestBeanOuterClass.PTestBean.Builder builder) {
|
||||
// private static PTestBeanOuterClass.PTestBean createPTestBean(TestBean bean, PTestBeanOuterClass.PTestBean.Builder
|
||||
// builder) {
|
||||
// if (builder == null) {
|
||||
// builder = PTestBeanOuterClass.PTestBean.newBuilder();
|
||||
// } else {
|
||||
@@ -195,7 +196,8 @@ package org.redkale.test.convert.proto;
|
||||
// builder.addChars(bean.chars[i]);
|
||||
// }
|
||||
// for (int i = 0; bean.entrys != null && i < bean.entrys.length; i++) {
|
||||
// PTestBeanOuterClass.PTestBean.PTestEntry.Builder entry = PTestBeanOuterClass.PTestBean.PTestEntry.newBuilder();
|
||||
// PTestBeanOuterClass.PTestBean.PTestEntry.Builder entry =
|
||||
// PTestBeanOuterClass.PTestBean.PTestEntry.newBuilder();
|
||||
// if (bean.entrys[i] == null) {
|
||||
// builder.addEntrys(entry.build());
|
||||
// continue;
|
||||
@@ -236,6 +238,7 @@ package org.redkale.test.convert.proto;
|
||||
// PTestBeanOuterClass.PTestBean bean2 = builder.build();
|
||||
// return bean2;
|
||||
// }
|
||||
//}
|
||||
// }
|
||||
//
|
||||
////protoc --java_out=D:\Java-Projects\RedkalePluginsProject\test\ --proto_path=D:\Java-Projects\RedkalePluginsProject\test\org\redkalex\test\protobuf\ PTestBean.proto
|
||||
//// protoc --java_out=D:\Java-Projects\RedkalePluginsProject\test\
|
||||
// --proto_path=D:\Java-Projects\RedkalePluginsProject\test\org\redkalex\test\protobuf\ PTestBean.proto
|
||||
|
||||
@@ -14,97 +14,94 @@ import org.redkale.convert.json.*;
|
||||
import org.redkale.net.http.*;
|
||||
import org.redkale.util.AnyValue;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public interface HttpRequestDesc {
|
||||
|
||||
//获取客户端地址IP
|
||||
// 获取客户端地址IP
|
||||
public SocketAddress getRemoteAddress();
|
||||
|
||||
//获取客户端地址IP, 与getRemoteAddres() 的区别在于:
|
||||
//本方法优先取header中指定为RemoteAddress名的值,没有则返回getRemoteAddres()的getHostAddress()。
|
||||
//本方法适用于服务前端有如nginx的代理服务器进行中转,通过getRemoteAddres()是获取不到客户端的真实IP。
|
||||
// 获取客户端地址IP, 与getRemoteAddres() 的区别在于:
|
||||
// 本方法优先取header中指定为RemoteAddress名的值,没有则返回getRemoteAddres()的getHostAddress()。
|
||||
// 本方法适用于服务前端有如nginx的代理服务器进行中转,通过getRemoteAddres()是获取不到客户端的真实IP。
|
||||
public String getRemoteAddr();
|
||||
|
||||
//获取请求内容指定的编码字符串
|
||||
// 获取请求内容指定的编码字符串
|
||||
public String getBody(Charset charset);
|
||||
|
||||
//获取请求内容的UTF-8编码字符串
|
||||
// 获取请求内容的UTF-8编码字符串
|
||||
public String getBodyUTF8();
|
||||
|
||||
//获取请求内容的byte[]
|
||||
// 获取请求内容的byte[]
|
||||
public byte[] getBody();
|
||||
|
||||
//获取请求内容的JavaBean对象
|
||||
|
||||
// 获取请求内容的JavaBean对象
|
||||
public <T> T getBodyJson(java.lang.reflect.Type type);
|
||||
|
||||
//获取请求内容的JavaBean对象
|
||||
// 获取请求内容的JavaBean对象
|
||||
public <T> T getBodyJson(JsonConvert convert, java.lang.reflect.Type type);
|
||||
|
||||
//获取文件上传对象
|
||||
|
||||
// 获取文件上传对象
|
||||
public MultiContext getMultiContext();
|
||||
|
||||
//获取文件上传信息列表 等价于 getMultiContext().parts();
|
||||
// 获取文件上传信息列表 等价于 getMultiContext().parts();
|
||||
public Iterable<MultiPart> multiParts() throws IOException;
|
||||
|
||||
//设置当前用户信息, 通常在HttpServlet.preExecute方法里设置currentUser
|
||||
//数据类型由@HttpUserType指定
|
||||
// 设置当前用户信息, 通常在HttpServlet.preExecute方法里设置currentUser
|
||||
// 数据类型由@HttpUserType指定
|
||||
public <T> HttpRequest setCurrentUser(T user);
|
||||
|
||||
//获取当前用户信息 数据类型由@HttpUserType指定
|
||||
|
||||
// 获取当前用户信息 数据类型由@HttpUserType指定
|
||||
public <T> T currentUser();
|
||||
|
||||
//获取模块ID,来自@HttpServlet.moduleid()
|
||||
|
||||
// 获取模块ID,来自@HttpServlet.moduleid()
|
||||
public int getModuleid();
|
||||
|
||||
//获取操作ID,来自@HttpMapping.actionid()
|
||||
|
||||
// 获取操作ID,来自@HttpMapping.actionid()
|
||||
public int getActionid();
|
||||
|
||||
//获取sessionid
|
||||
|
||||
// 获取sessionid
|
||||
public String getSessionid(boolean autoCreate);
|
||||
|
||||
//更新sessionid
|
||||
// 更新sessionid
|
||||
public String changeSessionid();
|
||||
|
||||
//指定值更新sessionid
|
||||
// 指定值更新sessionid
|
||||
public String changeSessionid(String newsessionid);
|
||||
|
||||
//使sessionid失效
|
||||
// 使sessionid失效
|
||||
public void invalidateSession();
|
||||
|
||||
//获取所有Cookie对象
|
||||
// 获取所有Cookie对象
|
||||
public java.net.HttpCookie[] getCookies();
|
||||
|
||||
//获取Cookie值
|
||||
// 获取Cookie值
|
||||
public String getCookie(String name);
|
||||
|
||||
//获取Cookie值, 没有返回默认值
|
||||
// 获取Cookie值, 没有返回默认值
|
||||
public String getCookie(String name, String defaultValue);
|
||||
|
||||
//获取协议名 http、https、ws、wss等
|
||||
// 获取协议名 http、https、ws、wss等
|
||||
public String getProtocol();
|
||||
|
||||
//获取请求方法 GET、POST等
|
||||
// 获取请求方法 GET、POST等
|
||||
public String getMethod();
|
||||
|
||||
//获取Content-Type的header值
|
||||
// 获取Content-Type的header值
|
||||
public String getContentType();
|
||||
|
||||
//获取请求内容的长度, 为-1表示内容长度不确定
|
||||
// 获取请求内容的长度, 为-1表示内容长度不确定
|
||||
public long getContentLength();
|
||||
|
||||
//获取Connection的Header值
|
||||
// 获取Connection的Header值
|
||||
public String getConnection();
|
||||
|
||||
//获取Host的Header值
|
||||
// 获取Host的Header值
|
||||
public String getHost();
|
||||
|
||||
//获取请求的URL
|
||||
// 获取请求的URL
|
||||
public String getRequestURI();
|
||||
|
||||
//截取getRequestURI最后的一个/后面的部分
|
||||
// 截取getRequestURI最后的一个/后面的部分
|
||||
public String getRequstURILastPath();
|
||||
|
||||
// 获取请求URL最后的一个/后面的部分的short值 <br>
|
||||
@@ -147,7 +144,7 @@ public interface HttpRequestDesc {
|
||||
// 获取type参数: double type = request.getRequstURILastPath(0.0); //type = 2.0
|
||||
public double getRequstURILastPath(double defvalue);
|
||||
|
||||
//从prefix之后截取getRequestURI再对"/"进行分隔
|
||||
// 从prefix之后截取getRequestURI再对"/"进行分隔
|
||||
public String[] getRequstURIPaths(String prefix);
|
||||
|
||||
// 获取请求URL分段中含prefix段的值
|
||||
@@ -177,8 +174,8 @@ public interface HttpRequestDesc {
|
||||
// 获取limit参数: int limit = request.getRequstURIPath(16, "limit:", 20); // limit = 16
|
||||
public int getRequstURIPath(int radix, String prefix, int defaultValue);
|
||||
|
||||
// 获取请求URL分段中含prefix段的float值
|
||||
// 例如请求URL /pipes/record/query/point:40.0
|
||||
// 获取请求URL分段中含prefix段的float值
|
||||
// 例如请求URL /pipes/record/query/point:40.0
|
||||
// 获取time参数: float point = request.getRequstURIPath("point:", 0.0f);
|
||||
public float getRequstURIPath(String prefix, float defvalue);
|
||||
|
||||
@@ -197,28 +194,28 @@ public interface HttpRequestDesc {
|
||||
// 获取time参数: double point = request.getRequstURIPath("point:", 0.0);
|
||||
public double getRequstURIPath(String prefix, double defvalue);
|
||||
|
||||
//获取所有的header名
|
||||
// 获取所有的header名
|
||||
public AnyValue getHeaders();
|
||||
|
||||
//将请求Header转换成Map
|
||||
|
||||
// 将请求Header转换成Map
|
||||
public Map<String, String> getHeadersToMap(Map<String, String> map);
|
||||
|
||||
//获取所有的header名
|
||||
|
||||
// 获取所有的header名
|
||||
public String[] getHeaderNames();
|
||||
|
||||
// 获取指定的header值
|
||||
public String getHeader(String name);
|
||||
|
||||
//获取指定的header值, 没有返回默认值
|
||||
// 获取指定的header值, 没有返回默认值
|
||||
public String getHeader(String name, String defaultValue);
|
||||
|
||||
//获取指定的header的json值
|
||||
// 获取指定的header的json值
|
||||
public <T> T getJsonHeader(Type type, String name);
|
||||
|
||||
//获取指定的header的json值
|
||||
// 获取指定的header的json值
|
||||
public <T> T getJsonHeader(JsonConvert convert, Type type, String name);
|
||||
|
||||
//获取指定的header的boolean值, 没有返回默认boolean值
|
||||
// 获取指定的header的boolean值, 没有返回默认boolean值
|
||||
public boolean getBooleanHeader(String name, boolean defaultValue);
|
||||
|
||||
// 获取指定的header的short值, 没有返回默认short值
|
||||
@@ -233,10 +230,10 @@ public interface HttpRequestDesc {
|
||||
// 获取指定的header的short值, 没有返回默认short值
|
||||
public short getShortHeader(int radix, String name, int defaultValue);
|
||||
|
||||
//获取指定的header的int值, 没有返回默认int值
|
||||
// 获取指定的header的int值, 没有返回默认int值
|
||||
public int getIntHeader(String name, int defaultValue);
|
||||
|
||||
//获取指定的header的int值, 没有返回默认int值
|
||||
// 获取指定的header的int值, 没有返回默认int值
|
||||
public int getIntHeader(int radix, String name, int defaultValue);
|
||||
|
||||
// 获取指定的header的long值, 没有返回默认long值
|
||||
@@ -248,101 +245,101 @@ public interface HttpRequestDesc {
|
||||
// 获取指定的header的float值, 没有返回默认float值
|
||||
public float getFloatHeader(String name, float defaultValue);
|
||||
|
||||
//获取指定的header的double值, 没有返回默认double值
|
||||
// 获取指定的header的double值, 没有返回默认double值
|
||||
public double getDoubleHeader(String name, double defaultValue);
|
||||
|
||||
//获取请求参数总对象
|
||||
// 获取请求参数总对象
|
||||
public AnyValue getParameters();
|
||||
|
||||
//将请求参数转换成Map
|
||||
|
||||
// 将请求参数转换成Map
|
||||
public Map<String, String> getParametersToMap(Map<String, String> map);
|
||||
|
||||
//将请求参数转换成String, 字符串格式为: bean1={}&id=13&name=xxx
|
||||
//不会返回null,没有参数返回空字符串
|
||||
|
||||
// 将请求参数转换成String, 字符串格式为: bean1={}&id=13&name=xxx
|
||||
// 不会返回null,没有参数返回空字符串
|
||||
public String getParametersToString();
|
||||
|
||||
//将请求参数转换成String, 字符串格式为: prefix + bean1={}&id=13&name=xxx
|
||||
//拼接前缀, 如果无参数,返回的字符串不会含有拼接前缀
|
||||
//不会返回null,没有参数返回空字符串
|
||||
|
||||
// 将请求参数转换成String, 字符串格式为: prefix + bean1={}&id=13&name=xxx
|
||||
// 拼接前缀, 如果无参数,返回的字符串不会含有拼接前缀
|
||||
// 不会返回null,没有参数返回空字符串
|
||||
public String getParametersToString(String prefix);
|
||||
|
||||
//获取所有参数名
|
||||
|
||||
// 获取所有参数名
|
||||
public String[] getParameterNames();
|
||||
|
||||
//获取指定的参数值
|
||||
// 获取指定的参数值
|
||||
public String getParameter(String name);
|
||||
|
||||
//获取指定的参数值, 没有返回默认值
|
||||
// 获取指定的参数值, 没有返回默认值
|
||||
public String getParameter(String name, String defaultValue);
|
||||
|
||||
//获取指定的参数json值
|
||||
// 获取指定的参数json值
|
||||
public <T> T getJsonParameter(Type type, String name);
|
||||
|
||||
//获取指定的参数json值
|
||||
// 获取指定的参数json值
|
||||
public <T> T getJsonParameter(JsonConvert convert, Type type, String name);
|
||||
|
||||
//获取指定的参数boolean值, 没有返回默认boolean值
|
||||
// 获取指定的参数boolean值, 没有返回默认boolean值
|
||||
public boolean getBooleanParameter(String name, boolean defaultValue);
|
||||
|
||||
//获取指定的参数short值, 没有返回默认short值
|
||||
// 获取指定的参数short值, 没有返回默认short值
|
||||
public short getShortParameter(String name, short defaultValue);
|
||||
|
||||
//获取指定的参数short值, 没有返回默认short值
|
||||
// 获取指定的参数short值, 没有返回默认short值
|
||||
public short getShortParameter(int radix, String name, short defaultValue);
|
||||
|
||||
//获取指定的参数short值, 没有返回默认short值
|
||||
// 获取指定的参数short值, 没有返回默认short值
|
||||
public short getShortParameter(int radix, String name, int defaultValue);
|
||||
|
||||
//获取指定的参数int值, 没有返回默认int值
|
||||
// 获取指定的参数int值, 没有返回默认int值
|
||||
public int getIntParameter(String name, int defaultValue);
|
||||
|
||||
//获取指定的参数int值, 没有返回默认int值
|
||||
// 获取指定的参数int值, 没有返回默认int值
|
||||
public int getIntParameter(int radix, String name, int defaultValue);
|
||||
|
||||
//获取指定的参数long值, 没有返回默认long值
|
||||
// 获取指定的参数long值, 没有返回默认long值
|
||||
public long getLongParameter(String name, long defaultValue);
|
||||
|
||||
//获取指定的参数long值, 没有返回默认long值
|
||||
// 获取指定的参数long值, 没有返回默认long值
|
||||
public long getLongParameter(int radix, String name, long defaultValue);
|
||||
|
||||
//获取指定的参数float值, 没有返回默认float值
|
||||
// 获取指定的参数float值, 没有返回默认float值
|
||||
public float getFloatParameter(String name, float defaultValue);
|
||||
|
||||
//获取指定的参数double值, 没有返回默认double值
|
||||
// 获取指定的参数double值, 没有返回默认double值
|
||||
public double getDoubleParameter(String name, double defaultValue);
|
||||
|
||||
//获取翻页对象 同 getFlipper("flipper", false, 0);
|
||||
// 获取翻页对象 同 getFlipper("flipper", false, 0);
|
||||
public org.redkale.source.Flipper getFlipper();
|
||||
|
||||
//获取翻页对象 同 getFlipper("flipper", needcreate, 0);
|
||||
// 获取翻页对象 同 getFlipper("flipper", needcreate, 0);
|
||||
public org.redkale.source.Flipper getFlipper(boolean needcreate);
|
||||
|
||||
//获取翻页对象 同 getFlipper("flipper", false, maxLimit);
|
||||
// 获取翻页对象 同 getFlipper("flipper", false, maxLimit);
|
||||
public org.redkale.source.Flipper getFlipper(int maxLimit);
|
||||
|
||||
//获取翻页对象 同 getFlipper("flipper", needcreate, maxLimit)
|
||||
// 获取翻页对象 同 getFlipper("flipper", needcreate, maxLimit)
|
||||
public org.redkale.source.Flipper getFlipper(boolean needcreate, int maxLimit);
|
||||
|
||||
//获取翻页对象 http://redkale.org/pipes/records/list/offset:0/limit:20/sort:createtime%20ASC
|
||||
//http://redkale.org/pipes/records/list?flipper={'offset':0,'limit':20, 'sort':'createtime ASC'}
|
||||
//以上两种接口都可以获取到翻页对象
|
||||
// 获取翻页对象 http://redkale.org/pipes/records/list/offset:0/limit:20/sort:createtime%20ASC
|
||||
// http://redkale.org/pipes/records/list?flipper={'offset':0,'limit':20, 'sort':'createtime ASC'}
|
||||
// 以上两种接口都可以获取到翻页对象
|
||||
public org.redkale.source.Flipper getFlipper(String name, boolean needcreate, int maxLimit);
|
||||
|
||||
//获取HTTP上下文对象
|
||||
// 获取HTTP上下文对象
|
||||
public HttpContext getContext();
|
||||
|
||||
//获取所有属性值, servlet执行完后会被清空
|
||||
// 获取所有属性值, servlet执行完后会被清空
|
||||
public Map<String, Object> getAttributes();
|
||||
|
||||
//获取指定属性值, servlet执行完后会被清空
|
||||
// 获取指定属性值, servlet执行完后会被清空
|
||||
public <T> T getAttribute(String name);
|
||||
|
||||
//删除指定属性
|
||||
// 删除指定属性
|
||||
public void removeAttribute(String name);
|
||||
|
||||
//设置属性值, servlet执行完后会被清空
|
||||
// 设置属性值, servlet执行完后会被清空
|
||||
public void setAttribute(String name, Object value);
|
||||
|
||||
//获取request创建时间
|
||||
// 获取request创建时间
|
||||
public long getCreatetime();
|
||||
}
|
||||
|
||||
@@ -17,159 +17,155 @@ import org.redkale.convert.Convert;
|
||||
import org.redkale.convert.json.*;
|
||||
import org.redkale.net.http.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public interface HttpResponseDesc {
|
||||
|
||||
//增加Cookie值
|
||||
// 增加Cookie值
|
||||
public HttpResponse addCookie(HttpCookie... cookies);
|
||||
|
||||
//增加Cookie值
|
||||
// 增加Cookie值
|
||||
public HttpResponse addCookie(Collection<HttpCookie> cookies);
|
||||
|
||||
//创建CompletionHandler实例,将非字符串对象以JSON格式输出,字符串以文本输出
|
||||
// 创建CompletionHandler实例,将非字符串对象以JSON格式输出,字符串以文本输出
|
||||
public CompletionHandler createAsyncHandler();
|
||||
|
||||
//传入的CompletionHandler子类必须是public,且保证其子类可被继承且completed、failed可被重载且包含空参数的构造函数
|
||||
// 传入的CompletionHandler子类必须是public,且保证其子类可被继承且completed、failed可被重载且包含空参数的构造函数
|
||||
public <H extends CompletionHandler> H createAsyncHandler(Class<H> handlerClass);
|
||||
|
||||
//获取ByteBuffer生成器
|
||||
// 获取ByteBuffer生成器
|
||||
public Supplier<ByteBuffer> getBufferSupplier();
|
||||
|
||||
//设置状态码
|
||||
// 设置状态码
|
||||
public void setStatus(int status);
|
||||
|
||||
//获取状态码
|
||||
// 获取状态码
|
||||
public int getStatus();
|
||||
|
||||
//获取 ContentType
|
||||
// 获取 ContentType
|
||||
public String getContentType();
|
||||
|
||||
//设置 ContentType
|
||||
// 设置 ContentType
|
||||
public HttpResponse setContentType(String contentType);
|
||||
|
||||
//获取内容长度
|
||||
// 获取内容长度
|
||||
public long getContentLength();
|
||||
|
||||
//设置内容长度
|
||||
// 设置内容长度
|
||||
public HttpResponse setContentLength(long contentLength);
|
||||
|
||||
//设置Header值
|
||||
// 设置Header值
|
||||
public HttpResponse setHeader(String name, Object value);
|
||||
|
||||
//添加Header值
|
||||
// 添加Header值
|
||||
public HttpResponse addHeader(String name, Object value);
|
||||
|
||||
//添加Header值
|
||||
// 添加Header值
|
||||
public HttpResponse addHeader(Map<String, ?> map);
|
||||
|
||||
//跳过header的输出
|
||||
//通常应用场景是,调用者的输出内容里已经包含了HTTP的响应头信息,因此需要调用此方法避免重复输出HTTP响应头信息。
|
||||
// 跳过header的输出
|
||||
// 通常应用场景是,调用者的输出内容里已经包含了HTTP的响应头信息,因此需要调用此方法避免重复输出HTTP响应头信息。
|
||||
public HttpResponse skipHeader();
|
||||
|
||||
//异步输出指定内容
|
||||
// 异步输出指定内容
|
||||
public <A> void sendBody(ByteBuffer buffer, A attachment, CompletionHandler<Integer, A> handler);
|
||||
|
||||
//异步输出指定内容
|
||||
// 异步输出指定内容
|
||||
public <A> void sendBody(ByteBuffer[] buffers, A attachment, CompletionHandler<Integer, A> handler);
|
||||
|
||||
//关闭HTTP连接,如果是keep-alive则不强制关闭
|
||||
// 关闭HTTP连接,如果是keep-alive则不强制关闭
|
||||
public void finish();
|
||||
|
||||
//强制关闭HTTP连接
|
||||
// 强制关闭HTTP连接
|
||||
public void finish(boolean kill);
|
||||
|
||||
//将对象以JSON格式输出
|
||||
// 将对象以JSON格式输出
|
||||
public void finishJson(Object obj);
|
||||
|
||||
//将对象数组用Map的形式以JSON格式输出
|
||||
//例如: finishMap("a",2,"b",3) 输出结果为 {"a":2,"b":3}
|
||||
// 将对象数组用Map的形式以JSON格式输出
|
||||
// 例如: finishMap("a",2,"b",3) 输出结果为 {"a":2,"b":3}
|
||||
public void finishMapJson(final Object... objs);
|
||||
|
||||
//将对象以JSON格式输出
|
||||
// 将对象以JSON格式输出
|
||||
public void finishJson(JsonConvert convert, Object obj);
|
||||
|
||||
//将对象数组用Map的形式以JSON格式输出
|
||||
//例如: finishMap("a",2,"b",3) 输出结果为 {"a":2,"b":3}
|
||||
// 将对象数组用Map的形式以JSON格式输出
|
||||
// 例如: finishMap("a",2,"b",3) 输出结果为 {"a":2,"b":3}
|
||||
public void finishMapJson(final JsonConvert convert, final Object... objs);
|
||||
|
||||
//将对象以JSON格式输出
|
||||
// 将对象以JSON格式输出
|
||||
public void finishJson(Type type, Object obj);
|
||||
|
||||
//将对象以JSON格式输出
|
||||
// 将对象以JSON格式输出
|
||||
public void finishJson(final JsonConvert convert, final Type type, final Object obj);
|
||||
|
||||
//将对象以JSON格式输出
|
||||
// 将对象以JSON格式输出
|
||||
public void finishJson(final Object... objs);
|
||||
|
||||
//将RetResult对象以JSON格式输出
|
||||
// 将RetResult对象以JSON格式输出
|
||||
public void finishJson(final org.redkale.service.RetResult ret);
|
||||
|
||||
//将RetResult对象以JSON格式输出
|
||||
// 将RetResult对象以JSON格式输出
|
||||
public void finishJson(final JsonConvert convert, final org.redkale.service.RetResult ret);
|
||||
|
||||
//将CompletableFuture的结果对象以JSON格式输出
|
||||
// 将CompletableFuture的结果对象以JSON格式输出
|
||||
public void finishJson(final CompletableFuture future);
|
||||
|
||||
//将CompletableFuture的结果对象以JSON格式输出
|
||||
// 将CompletableFuture的结果对象以JSON格式输出
|
||||
public void finishJson(final JsonConvert convert, final CompletableFuture future);
|
||||
|
||||
//将CompletableFuture的结果对象以JSON格式输出
|
||||
// 将CompletableFuture的结果对象以JSON格式输出
|
||||
public void finishJson(final JsonConvert convert, final Type type, final CompletableFuture future);
|
||||
|
||||
//将HttpResult的结果对象以JSON格式输出
|
||||
// 将HttpResult的结果对象以JSON格式输出
|
||||
public void finishJson(final HttpResult result);
|
||||
|
||||
//将HttpResult的结果对象以JSON格式输出
|
||||
// 将HttpResult的结果对象以JSON格式输出
|
||||
public void finishJson(final JsonConvert convert, final HttpResult result);
|
||||
|
||||
//将指定字符串以响应结果输出
|
||||
// 将指定字符串以响应结果输出
|
||||
public void finish(String obj);
|
||||
|
||||
//以指定响应码附带内容输出, message 可以为null
|
||||
// 以指定响应码附带内容输出, message 可以为null
|
||||
public void finish(int status, String message);
|
||||
|
||||
//将结果对象输出
|
||||
// 将结果对象输出
|
||||
public void finish(final Object obj);
|
||||
|
||||
//将结果对象输出
|
||||
// 将结果对象输出
|
||||
public void finish(final Convert convert, final Object obj);
|
||||
|
||||
//将结果对象输出
|
||||
// 将结果对象输出
|
||||
public void finish(final Convert convert, final Type type, final Object obj);
|
||||
|
||||
//以304状态码输出
|
||||
// 以304状态码输出
|
||||
public void finish304();
|
||||
|
||||
//以404状态码输出
|
||||
// 以404状态码输出
|
||||
public void finish404();
|
||||
|
||||
//将指定byte[]按响应结果输出
|
||||
// 将指定byte[]按响应结果输出
|
||||
public void finish(final byte[] bs);
|
||||
|
||||
//将指定ByteBuffer按响应结果输出
|
||||
// 将指定ByteBuffer按响应结果输出
|
||||
public void finish(ByteBuffer buffer);
|
||||
|
||||
//将指定ByteBuffer按响应结果输出
|
||||
//kill 输出后是否强制关闭连接
|
||||
// 将指定ByteBuffer按响应结果输出
|
||||
// kill 输出后是否强制关闭连接
|
||||
public void finish(boolean kill, ByteBuffer buffer);
|
||||
|
||||
//将指定ByteBuffer数组按响应结果输出
|
||||
// 将指定ByteBuffer数组按响应结果输出
|
||||
public void finish(ByteBuffer... buffers);
|
||||
|
||||
//将指定ByteBuffer数组按响应结果输出
|
||||
//kill 输出后是否强制关闭连接
|
||||
// 将指定ByteBuffer数组按响应结果输出
|
||||
// kill 输出后是否强制关闭连接
|
||||
public void finish(boolean kill, ByteBuffer... buffers);
|
||||
|
||||
//将指定文件按响应结果输出
|
||||
// 将指定文件按响应结果输出
|
||||
public void finish(File file) throws IOException;
|
||||
|
||||
//将文件按指定文件名输出
|
||||
// 将文件按指定文件名输出
|
||||
public void finish(final String filename, File file) throws IOException;
|
||||
|
||||
//HttpResponse回收时回调的监听方法
|
||||
// HttpResponse回收时回调的监听方法
|
||||
public void recycleListener(BiConsumer<HttpRequest, HttpResponse> recycleListener);
|
||||
|
||||
}
|
||||
|
||||
@@ -15,10 +15,7 @@ import org.redkale.net.http.WebClient;
|
||||
import org.redkale.net.http.WebRequest;
|
||||
import org.redkale.util.AnyValueWriter;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class HttpSimpleClientTest {
|
||||
|
||||
private static int port = 0;
|
||||
@@ -40,14 +37,15 @@ public class HttpSimpleClientTest {
|
||||
@Test
|
||||
public void run() throws Exception {
|
||||
runServer();
|
||||
//Utility.sleep(50000);
|
||||
// Utility.sleep(50000);
|
||||
final AsyncIOGroup asyncGroup = new AsyncIOGroup(8192, 16);
|
||||
asyncGroup.start();
|
||||
WebClient client = WebClient.create(asyncGroup);
|
||||
InetSocketAddress addr = new InetSocketAddress("127.0.0.1", port);
|
||||
{
|
||||
WebRequest req = WebRequest.createPostPath("/test").param("id", 100);
|
||||
System.out.println(client.getAsync("http://127.0.0.1:" + port + req.getPath() + "?id=100").join());
|
||||
System.out.println(client.getAsync("http://127.0.0.1:" + port + req.getPath() + "?id=100")
|
||||
.join());
|
||||
System.out.println(client.sendAsync(addr, req).join());
|
||||
}
|
||||
final int count = 10;
|
||||
@@ -56,10 +54,11 @@ public class HttpSimpleClientTest {
|
||||
for (int i = 100; i < 100 + count; i++) {
|
||||
final int index = i;
|
||||
WebRequest req = WebRequest.createPostPath("/test").param("id", index);
|
||||
client.getAsync("http://127.0.0.1:" + port + req.getPath() + "?id=" + index).whenComplete((v, t) -> {
|
||||
cdl.countDown();
|
||||
Assertions.assertEquals("ok-" + index, new String((byte[]) v.getResult()));
|
||||
});
|
||||
client.getAsync("http://127.0.0.1:" + port + req.getPath() + "?id=" + index)
|
||||
.whenComplete((v, t) -> {
|
||||
cdl.countDown();
|
||||
Assertions.assertEquals("ok-" + index, new String((byte[]) v.getResult()));
|
||||
});
|
||||
}
|
||||
cdl.await();
|
||||
System.out.println("结束并发1");
|
||||
|
||||
@@ -9,10 +9,7 @@ import org.redkale.net.http.HttpRequest;
|
||||
import org.redkale.net.http.HttpResponse;
|
||||
import org.redkale.net.http.HttpServlet;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class HttpSimpleServlet extends HttpServlet {
|
||||
|
||||
@HttpMapping(url = "/test")
|
||||
|
||||
@@ -10,10 +10,7 @@ import org.redkale.mq.spi.WebRequestCoder;
|
||||
import org.redkale.net.client.ClientRequest;
|
||||
import org.redkale.net.http.WebRequest;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class RequestCoderTest {
|
||||
|
||||
private boolean main;
|
||||
|
||||
@@ -7,10 +7,7 @@ import org.redkale.net.http.RestService;
|
||||
import org.redkale.service.AbstractService;
|
||||
import org.redkale.util.Utility;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
@RestService(name = "test", autoMapping = true)
|
||||
public class RestSleepService extends AbstractService {
|
||||
|
||||
|
||||
@@ -15,10 +15,7 @@ import org.redkale.net.http.*;
|
||||
import org.redkale.net.sncp.Sncp;
|
||||
import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class RestSleepTest {
|
||||
|
||||
private boolean main;
|
||||
@@ -39,7 +36,7 @@ public class RestSleepTest {
|
||||
resFactory.register(JsonConvert.root());
|
||||
resFactory.register(BsonConvert.root());
|
||||
|
||||
//------------------------ 初始化 CService ------------------------------------
|
||||
// ------------------------ 初始化 CService ------------------------------------
|
||||
RestSleepService service = Sncp.createSimpleLocalService(RestSleepService.class, resFactory);
|
||||
HttpServer server = new HttpServer(application, System.currentTimeMillis(), resFactory);
|
||||
server.getResourceFactory().register(application);
|
||||
@@ -53,14 +50,15 @@ public class RestSleepTest {
|
||||
Socket socket = new Socket(httpAddress.getAddress(), port);
|
||||
OutputStream out = socket.getOutputStream();
|
||||
out.write(("GET /test/sleep200 HTTP/1.1\r\n"
|
||||
+ "Connection: Keep-Alive\r\n"
|
||||
+ "\r\n"
|
||||
+ "GET /test/sleep300 HTTP/1.1\r\n"
|
||||
+ "Connection: Keep-Alive\r\n"
|
||||
+ "\r\n"
|
||||
+ "GET /test/sleep500 HTTP/1.1\r\n"
|
||||
+ "Connection: Keep-Alive\r\n"
|
||||
+ "\r\n").getBytes());
|
||||
+ "Connection: Keep-Alive\r\n"
|
||||
+ "\r\n"
|
||||
+ "GET /test/sleep300 HTTP/1.1\r\n"
|
||||
+ "Connection: Keep-Alive\r\n"
|
||||
+ "\r\n"
|
||||
+ "GET /test/sleep500 HTTP/1.1\r\n"
|
||||
+ "Connection: Keep-Alive\r\n"
|
||||
+ "\r\n")
|
||||
.getBytes());
|
||||
InputStream in = socket.getInputStream();
|
||||
byte[] bytes = new byte[8192];
|
||||
long s = System.currentTimeMillis();
|
||||
|
||||
@@ -7,21 +7,22 @@ package org.redkale.test.http;
|
||||
|
||||
import java.net.Socket;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @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()
|
||||
.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()
|
||||
.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());
|
||||
@@ -32,5 +33,4 @@ public class SocketMain {
|
||||
rs = socket.getInputStream().read(bs);
|
||||
System.out.println(new String(bs, 0, rs));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,11 +8,8 @@ package org.redkale.test.http;
|
||||
import java.io.IOException;
|
||||
import org.redkale.net.http.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
//@WebServlet({"/uploadtest/form", "/uploadtest/send"})
|
||||
/** @author zhangjx */
|
||||
// @WebServlet({"/uploadtest/form", "/uploadtest/send"})
|
||||
public class UploadTestServlet extends HttpServlet {
|
||||
|
||||
@Override
|
||||
@@ -26,8 +23,7 @@ public class UploadTestServlet extends HttpServlet {
|
||||
|
||||
public void form(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
resp.setContentType("text/html");
|
||||
resp.finish(
|
||||
"<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/></head>"
|
||||
resp.finish("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/></head>"
|
||||
+ "<div style='margin-top:150px;margin-left:400px;'><form action=\"/pipes/uploadtest/send\" method=\"post\" enctype=\"multipart/form-data\">"
|
||||
+ "描述: <input name=\"desc1\"/> 文件1: <input type=\"file\" name=\"filepath1\"/><br/><br/>"
|
||||
+ "描述: <input name=\"desc2\"/> 文件2: <input type=\"file\" name=\"filepath2\"/><br/><br/>"
|
||||
|
||||
@@ -15,190 +15,184 @@ import java.util.stream.Stream;
|
||||
import org.redkale.convert.Convert;
|
||||
import org.redkale.net.http.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public interface WebSocketDesc<G, T> {
|
||||
|
||||
//给自身发送消息, 消息类型是String或byte[]或可JavaBean对象 返回结果0表示成功,非0表示错误码
|
||||
// 给自身发送消息, 消息类型是String或byte[]或可JavaBean对象 返回结果0表示成功,非0表示错误码
|
||||
public CompletableFuture<Integer> send(Object message);
|
||||
|
||||
//给自身发送消息, 消息类型是key-value键值对 返回结果0表示成功,非0表示错误码
|
||||
// 给自身发送消息, 消息类型是key-value键值对 返回结果0表示成功,非0表示错误码
|
||||
public CompletableFuture<Integer> sendMap(Object... messages);
|
||||
|
||||
//给自身发送消息, 消息类型是String或byte[]或可JavaBean对象 返回结果0表示成功,非0表示错误码
|
||||
// 给自身发送消息, 消息类型是String或byte[]或可JavaBean对象 返回结果0表示成功,非0表示错误码
|
||||
public CompletableFuture<Integer> send(Object message, boolean last);
|
||||
|
||||
//给自身发送消息, 消息类型是key-value键值对 返回结果0表示成功,非0表示错误码
|
||||
// 给自身发送消息, 消息类型是key-value键值对 返回结果0表示成功,非0表示错误码
|
||||
public CompletableFuture<Integer> sendMap(boolean last, Object... messages);
|
||||
|
||||
//给自身发送消息, 消息类型是JavaBean对象 返回结果0表示成功,非0表示错误码
|
||||
// 给自身发送消息, 消息类型是JavaBean对象 返回结果0表示成功,非0表示错误码
|
||||
public CompletableFuture<Integer> send(Convert convert, Object message);
|
||||
|
||||
//给自身发送消息, 消息类型是JavaBean对象 返回结果0表示成功,非0表示错误码
|
||||
// 给自身发送消息, 消息类型是JavaBean对象 返回结果0表示成功,非0表示错误码
|
||||
public CompletableFuture<Integer> send(Convert convert, Object message, boolean last);
|
||||
|
||||
//给指定userid的WebSocket节点发送 二进制消息/文本消息/JavaBean对象消息 返回结果0表示成功,非0表示错误码
|
||||
// 给指定userid的WebSocket节点发送 二进制消息/文本消息/JavaBean对象消息 返回结果0表示成功,非0表示错误码
|
||||
public CompletableFuture<Integer> sendMessage(Object message, G... userids);
|
||||
|
||||
//给指定userid的WebSocket节点发送 二进制消息/文本消息/JavaBean对象消息 返回结果0表示成功,非0表示错误码
|
||||
// 给指定userid的WebSocket节点发送 二进制消息/文本消息/JavaBean对象消息 返回结果0表示成功,非0表示错误码
|
||||
public CompletableFuture<Integer> sendMessage(Object message, Stream<G> userids);
|
||||
|
||||
//给指定userid的WebSocket节点发送 二进制消息/文本消息/JavaBean对象消息 返回结果0表示成功,非0表示错误码
|
||||
// 给指定userid的WebSocket节点发送 二进制消息/文本消息/JavaBean对象消息 返回结果0表示成功,非0表示错误码
|
||||
public CompletableFuture<Integer> sendMessage(Convert convert, Object message, G... userids);
|
||||
|
||||
//给指定userid的WebSocket节点发送 二进制消息/文本消息/JavaBean对象消息 返回结果0表示成功,非0表示错误码
|
||||
// 给指定userid的WebSocket节点发送 二进制消息/文本消息/JavaBean对象消息 返回结果0表示成功,非0表示错误码
|
||||
public CompletableFuture<Integer> sendMessage(Convert convert, Object message, Stream<G> userids);
|
||||
|
||||
//给指定userid的WebSocket节点发送 二进制消息/文本消息/JavaBean对象消息 返回结果0表示成功,非0表示错误码
|
||||
// 给指定userid的WebSocket节点发送 二进制消息/文本消息/JavaBean对象消息 返回结果0表示成功,非0表示错误码
|
||||
public CompletableFuture<Integer> sendMessage(Object message, boolean last, G... userids);
|
||||
|
||||
//给指定userid的WebSocket节点发送 二进制消息/文本消息/JavaBean对象消息 返回结果0表示成功,非0表示错误码
|
||||
// 给指定userid的WebSocket节点发送 二进制消息/文本消息/JavaBean对象消息 返回结果0表示成功,非0表示错误码
|
||||
public CompletableFuture<Integer> sendMessage(Object message, boolean last, Stream<G> userids);
|
||||
|
||||
//给指定userid的WebSocket节点发送 二进制消息/文本消息/JavaBean对象消息 返回结果0表示成功,非0表示错误码
|
||||
// 给指定userid的WebSocket节点发送 二进制消息/文本消息/JavaBean对象消息 返回结果0表示成功,非0表示错误码
|
||||
public CompletableFuture<Integer> sendMessage(Convert convert, Object message, boolean last, G... userids);
|
||||
|
||||
//给指定userid的WebSocket节点发送 二进制消息/文本消息/JavaBean对象消息 返回结果0表示成功,非0表示错误码
|
||||
// 给指定userid的WebSocket节点发送 二进制消息/文本消息/JavaBean对象消息 返回结果0表示成功,非0表示错误码
|
||||
public CompletableFuture<Integer> sendMessage(Convert convert, Object message, boolean last, Stream<G> userids);
|
||||
|
||||
//给所有人广播消息, 返回结果0表示成功,非0表示错误码
|
||||
// 给所有人广播消息, 返回结果0表示成功,非0表示错误码
|
||||
public CompletableFuture<Integer> broadcastMessage(final Object message);
|
||||
|
||||
//给所有人广播消息, 返回结果0表示成功,非0表示错误码
|
||||
// 给所有人广播消息, 返回结果0表示成功,非0表示错误码
|
||||
public CompletableFuture<Integer> broadcastMessage(final Convert convert, final Object message);
|
||||
|
||||
//给符合条件的人群广播消息, 返回结果0表示成功,非0表示错误码
|
||||
// 给符合条件的人群广播消息, 返回结果0表示成功,非0表示错误码
|
||||
public CompletableFuture<Integer> broadcastMessage(final WebSocketRange wsrange, final Object message);
|
||||
|
||||
//给符合条件的人群广播消息, 返回结果0表示成功,非0表示错误码
|
||||
public CompletableFuture<Integer> broadcastMessage(final WebSocketRange wsrange, final Convert convert, final Object message);
|
||||
// 给符合条件的人群广播消息, 返回结果0表示成功,非0表示错误码
|
||||
public CompletableFuture<Integer> broadcastMessage(
|
||||
final WebSocketRange wsrange, final Convert convert, final Object message);
|
||||
|
||||
//给所有人广播消息, 返回结果0表示成功,非0表示错误码
|
||||
// 给所有人广播消息, 返回结果0表示成功,非0表示错误码
|
||||
public CompletableFuture<Integer> broadcastMessage(final Object message, boolean last);
|
||||
|
||||
//给所有人广播消息, 返回结果0表示成功,非0表示错误码
|
||||
// 给所有人广播消息, 返回结果0表示成功,非0表示错误码
|
||||
public CompletableFuture<Integer> broadcastMessage(final Convert convert, final Object message, boolean last);
|
||||
|
||||
//给符合条件的人群广播消息, 返回结果0表示成功,非0表示错误码
|
||||
public CompletableFuture<Integer> broadcastMessage(final WebSocketRange wsrange, final Object message, boolean last);
|
||||
// 给符合条件的人群广播消息, 返回结果0表示成功,非0表示错误码
|
||||
public CompletableFuture<Integer> broadcastMessage(
|
||||
final WebSocketRange wsrange, final Object message, boolean last);
|
||||
|
||||
//给符合条件的人群广播消息, 返回结果0表示成功,非0表示错误码
|
||||
public CompletableFuture<Integer> broadcastMessage(WebSocketRange wsrange, Convert convert, final Object message, boolean last);
|
||||
// 给符合条件的人群广播消息, 返回结果0表示成功,非0表示错误码
|
||||
public CompletableFuture<Integer> broadcastMessage(
|
||||
WebSocketRange wsrange, Convert convert, final Object message, boolean last);
|
||||
|
||||
//给指定userid的WebSocket节点发送操作
|
||||
// 给指定userid的WebSocket节点发送操作
|
||||
public CompletableFuture<Integer> sendAction(final WebSocketAction action, Serializable... userids);
|
||||
|
||||
//广播操作, 给所有人发操作指令
|
||||
// 广播操作, 给所有人发操作指令
|
||||
public CompletableFuture<Integer> broadcastAction(final WebSocketAction action);
|
||||
|
||||
//获取用户在线的SNCP节点地址列表,不是分布式则返回元素数量为1,且元素值为null的列表
|
||||
// 获取用户在线的SNCP节点地址列表,不是分布式则返回元素数量为1,且元素值为null的列表
|
||||
public CompletableFuture<Collection<InetSocketAddress>> getRpcNodeAddresses(final Serializable userid);
|
||||
|
||||
//获取在线用户的详细连接信息
|
||||
public CompletableFuture<Map<InetSocketAddress, List<String>>> getRpcNodeWebSocketAddresses(final Serializable userid);
|
||||
// 获取在线用户的详细连接信息
|
||||
public CompletableFuture<Map<InetSocketAddress, List<String>>> getRpcNodeWebSocketAddresses(
|
||||
final Serializable userid);
|
||||
|
||||
//发送PING消息 返回结果0表示成功,非0表示错误码
|
||||
// 发送PING消息 返回结果0表示成功,非0表示错误码
|
||||
public CompletableFuture<Integer> sendPing();
|
||||
|
||||
//发送PING消息,附带其他信息 返回结果0表示成功,非0表示错误码
|
||||
// 发送PING消息,附带其他信息 返回结果0表示成功,非0表示错误码
|
||||
public CompletableFuture<Integer> sendPing(byte[] data);
|
||||
|
||||
//发送PONG消息,附带其他信息 返回结果0表示成功,非0表示错误码
|
||||
// 发送PONG消息,附带其他信息 返回结果0表示成功,非0表示错误码
|
||||
public CompletableFuture<Integer> sendPong(byte[] data);
|
||||
|
||||
//强制关闭用户的所有WebSocket
|
||||
// 强制关闭用户的所有WebSocket
|
||||
public CompletableFuture<Integer> forceCloseWebSocket(Serializable userid);
|
||||
|
||||
//更改本WebSocket的userid
|
||||
// 更改本WebSocket的userid
|
||||
public CompletableFuture<Void> changeUserid(final G newuserid);
|
||||
|
||||
// 获取指定userid的WebSocket数组, 没有返回null 此方法用于单用户多连接模式
|
||||
/* protected */ Stream<WebSocket> getLocalWebSockets(G userid);
|
||||
|
||||
//获取指定userid的WebSocket数组, 没有返回null 此方法用于单用户多连接模式
|
||||
/* protected */ Stream<WebSocket> getLocalWebSockets(G userid);
|
||||
|
||||
|
||||
//获取指定userid的WebSocket数组, 没有返回null 此方法用于单用户单连接模式
|
||||
// 获取指定userid的WebSocket数组, 没有返回null 此方法用于单用户单连接模式
|
||||
/* protected */ WebSocket findLocalWebSocket(G userid);
|
||||
|
||||
|
||||
//获取当前进程节点所有在线的WebSocket
|
||||
// 获取当前进程节点所有在线的WebSocket
|
||||
/* protected */ Collection<WebSocket> getLocalWebSockets();
|
||||
|
||||
|
||||
//获取ByteBuffer资源池
|
||||
// 获取ByteBuffer资源池
|
||||
/* protected */ Supplier<ByteBuffer> getByteBufferSupplier();
|
||||
|
||||
|
||||
//返回sessionid, null表示连接不合法或异常,默认实现是request.sessionid(true),通常需要重写该方法
|
||||
// 返回sessionid, null表示连接不合法或异常,默认实现是request.sessionid(true),通常需要重写该方法
|
||||
/* protected */ CompletableFuture<String> onOpen(final HttpRequest request);
|
||||
|
||||
// 创建userid, null表示异常, 必须实现该方法
|
||||
/* protected abstract */ CompletableFuture<G> createUserid();
|
||||
|
||||
//创建userid, null表示异常, 必须实现该方法
|
||||
/* protected abstract */ CompletableFuture<G> createUserid();
|
||||
|
||||
|
||||
//WebSocket.broadcastMessage时的过滤条件
|
||||
// WebSocket.broadcastMessage时的过滤条件
|
||||
/* protected */ boolean predicate(WebSocketRange wsrange);
|
||||
|
||||
//WebSokcet连接成功后的回调方法
|
||||
// WebSokcet连接成功后的回调方法
|
||||
public void onConnected();
|
||||
|
||||
//ping后的回调方法
|
||||
// ping后的回调方法
|
||||
public void onPing(byte[] bytes);
|
||||
|
||||
//pong后的回调方法
|
||||
// pong后的回调方法
|
||||
public void onPong(byte[] bytes);
|
||||
|
||||
//接收到消息的回调方法
|
||||
// 接收到消息的回调方法
|
||||
public void onMessage(T message, boolean last);
|
||||
|
||||
//接收到文本消息的回调方法
|
||||
// 接收到文本消息的回调方法
|
||||
public void onMessage(String message, boolean last);
|
||||
|
||||
//接收到二进制消息的回调方法
|
||||
// 接收到二进制消息的回调方法
|
||||
public void onMessage(byte[] bytes, boolean last);
|
||||
|
||||
//关闭的回调方法,调用此方法时WebSocket已经被关闭
|
||||
// 关闭的回调方法,调用此方法时WebSocket已经被关闭
|
||||
public void onClose(int code, String reason);
|
||||
|
||||
//获取当前WebSocket下的属性
|
||||
// 获取当前WebSocket下的属性
|
||||
public T getAttribute(String name);
|
||||
|
||||
//移出当前WebSocket下的属性
|
||||
// 移出当前WebSocket下的属性
|
||||
public T removeAttribute(String name);
|
||||
|
||||
//给当前WebSocket下的增加属性
|
||||
// 给当前WebSocket下的增加属性
|
||||
public void setAttribute(String name, Object value);
|
||||
|
||||
//获取当前WebSocket所属的userid
|
||||
// 获取当前WebSocket所属的userid
|
||||
public G getUserid();
|
||||
|
||||
//获取当前WebSocket的会话ID, 不会为null
|
||||
// 获取当前WebSocket的会话ID, 不会为null
|
||||
public Serializable getSessionid();
|
||||
|
||||
//获取客户端直接地址, 当WebSocket连接是由代理服务器转发的,则该值固定为代理服务器的IP地址
|
||||
// 获取客户端直接地址, 当WebSocket连接是由代理服务器转发的,则该值固定为代理服务器的IP地址
|
||||
public SocketAddress getRemoteAddress();
|
||||
|
||||
//获取客户端真实地址 同 HttpRequest.getRemoteAddr()
|
||||
// 获取客户端真实地址 同 HttpRequest.getRemoteAddr()
|
||||
public String getRemoteAddr();
|
||||
|
||||
//获取WebSocket创建时间
|
||||
// 获取WebSocket创建时间
|
||||
public long getCreatetime();
|
||||
|
||||
//获取最后一次发送消息的时间
|
||||
// 获取最后一次发送消息的时间
|
||||
public long getLastSendTime();
|
||||
|
||||
//获取最后一次读取消息的时间
|
||||
// 获取最后一次读取消息的时间
|
||||
public long getLastReadTime();
|
||||
|
||||
//获取最后一次ping的时间
|
||||
// 获取最后一次ping的时间
|
||||
public long getLastPingTime();
|
||||
|
||||
//显式地关闭WebSocket
|
||||
// 显式地关闭WebSocket
|
||||
public void close();
|
||||
|
||||
//WebSocket是否已关闭
|
||||
// WebSocket是否已关闭
|
||||
public boolean isClosed();
|
||||
}
|
||||
|
||||
@@ -5,20 +5,18 @@
|
||||
*/
|
||||
package org.redkale.test.inject;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.annotation.*;
|
||||
import static java.lang.annotation.ElementType.FIELD;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.annotation.*;
|
||||
import java.lang.reflect.Field;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
import org.redkale.inject.ResourceAnnotationLoader;
|
||||
import org.redkale.inject.ResourceFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class ResourceAnnotationTest {
|
||||
|
||||
private boolean main;
|
||||
@@ -41,7 +39,13 @@ public class ResourceAnnotationTest {
|
||||
public static class CustomConfProvider implements ResourceAnnotationLoader<CustomConf> {
|
||||
|
||||
@Override
|
||||
public void load(ResourceFactory factory, String srcResourceName, Object srcObj, CustomConf annotation, Field field, Object attachment) {
|
||||
public void load(
|
||||
ResourceFactory factory,
|
||||
String srcResourceName,
|
||||
Object srcObj,
|
||||
CustomConf annotation,
|
||||
Field field,
|
||||
Object attachment) {
|
||||
try {
|
||||
field.set(srcObj, new File(annotation.path()));
|
||||
} catch (Exception e) {
|
||||
@@ -54,7 +58,6 @@ public class ResourceAnnotationTest {
|
||||
public Class<CustomConf> annotationType() {
|
||||
return CustomConf.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class InjectBean {
|
||||
@@ -75,5 +78,4 @@ public class ResourceAnnotationTest {
|
||||
|
||||
String path();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,10 +11,7 @@ import org.redkale.annotation.ResourceInjected;
|
||||
import org.redkale.inject.ResourceFactory;
|
||||
import org.redkale.service.Service;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class ResourceInjectedTest {
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
@@ -56,7 +53,7 @@ public class ResourceInjectedTest {
|
||||
private String name;
|
||||
|
||||
@ResourceInjected
|
||||
private void onInjected(Object src, String fieldName) {
|
||||
private void onInjected(Object src, String fieldName) {
|
||||
counter.incrementAndGet();
|
||||
System.out.println("资源被注入到对象(" + src + ")的字段(" + fieldName + ")上");
|
||||
}
|
||||
|
||||
@@ -11,10 +11,7 @@ import org.redkale.inject.ResourceEvent;
|
||||
import org.redkale.inject.ResourceFactory;
|
||||
import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class ResourceListenerTest {
|
||||
|
||||
private boolean main;
|
||||
@@ -84,14 +81,14 @@ public class ResourceListenerTest {
|
||||
private void changeResource(ResourceEvent[] events) {
|
||||
for (ResourceEvent event : events) {
|
||||
counter.incrementAndGet();
|
||||
System.out.println(getClass().getSimpleName() + " @Resource = " + event.name() + " 资源变更: newVal = " + event.newValue() + ", oldVal = " + event.oldValue());
|
||||
System.out.println(getClass().getSimpleName() + " @Resource = " + event.name() + " 资源变更: newVal = "
|
||||
+ event.newValue() + ", oldVal = " + event.oldValue());
|
||||
}
|
||||
}
|
||||
|
||||
public String test() {
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class BService {
|
||||
@@ -105,7 +102,8 @@ public class ResourceListenerTest {
|
||||
private void changeResource(ResourceEvent[] events) {
|
||||
for (ResourceEvent event : events) {
|
||||
counter.incrementAndGet();
|
||||
System.out.println(getClass().getSimpleName() + " @Resource = " + event.name() + " 资源变更: newVal = " + event.newValue() + ", oldVal = " + event.oldValue());
|
||||
System.out.println(getClass().getSimpleName() + " @Resource = " + event.name() + " 资源变更: newVal = "
|
||||
+ event.newValue() + ", oldVal = " + event.oldValue());
|
||||
}
|
||||
System.out.println(getClass().getSimpleName() + " env = " + env);
|
||||
}
|
||||
@@ -129,7 +127,8 @@ public class ResourceListenerTest {
|
||||
private void changeResource(ResourceEvent[] events) {
|
||||
for (ResourceEvent event : events) {
|
||||
counter.incrementAndGet();
|
||||
System.out.println(getClass().getSimpleName() + " @Resource = " + event.name() + " 资源变更: newVal = " + event.newValue() + ", oldVal = " + event.oldValue());
|
||||
System.out.println(getClass().getSimpleName() + " @Resource = " + event.name() + " 资源变更: newVal = "
|
||||
+ event.newValue() + ", oldVal = " + event.oldValue());
|
||||
}
|
||||
System.out.println(getClass().getSimpleName() + " env = " + env);
|
||||
}
|
||||
|
||||
@@ -7,13 +7,9 @@ import org.redkale.annotation.Resource;
|
||||
import org.redkale.convert.json.JsonFactory;
|
||||
import org.redkale.inject.ResourceFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class ResourceLoaderTest {
|
||||
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
ResourceLoaderTest test = new ResourceLoaderTest();
|
||||
test.run();
|
||||
@@ -50,8 +46,7 @@ public class ResourceLoaderTest {
|
||||
@Resource(name = "@.name")
|
||||
public String name;
|
||||
|
||||
public Bean() {
|
||||
}
|
||||
public Bean() {}
|
||||
|
||||
public Bean(int id, String name) {
|
||||
this.id = id;
|
||||
|
||||
@@ -12,10 +12,7 @@ import org.redkale.annotation.*;
|
||||
import org.redkale.inject.ResourceEvent;
|
||||
import org.redkale.inject.ResourceFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class ResourceTest {
|
||||
|
||||
private boolean main;
|
||||
@@ -29,26 +26,31 @@ public class ResourceTest {
|
||||
@Test
|
||||
public void run() throws Exception {
|
||||
ResourceFactory factory = ResourceFactory.create();
|
||||
factory.register("id", "2345"); //注入String类型的property.id
|
||||
factory.register("id", "2345"); // 注入String类型的property.id
|
||||
AService aservice = new AService();
|
||||
BService bservice = new BService("eeeee");
|
||||
|
||||
factory.register(aservice); //放进Resource池内,默认的资源名name为""
|
||||
factory.register(bservice); //放进Resource池内,默认的资源名name为""
|
||||
factory.register(aservice); // 放进Resource池内,默认的资源名name为""
|
||||
factory.register(bservice); // 放进Resource池内,默认的资源名name为""
|
||||
|
||||
factory.inject(aservice); //给aservice注入id、bservice,bigint没有资源,所以为null
|
||||
factory.inject(bservice); //给bservice注入id、aservice
|
||||
System.out.println(aservice); //输出结果为:{id:"2345", intid: 2345, bigint:null, bservice:{name:eeeee}}
|
||||
System.out.println(bservice); //输出结果为:{name:"eeeee", id: 2345, aserivce:{id:"2345", intid: 2345, bigint:null, bservice:{name:eeeee}}}
|
||||
factory.inject(aservice); // 给aservice注入id、bservice,bigint没有资源,所以为null
|
||||
factory.inject(bservice); // 给bservice注入id、aservice
|
||||
System.out.println(aservice); // 输出结果为:{id:"2345", intid: 2345, bigint:null, bservice:{name:eeeee}}
|
||||
System.out.println(bservice); // 输出结果为:{name:"eeeee", id: 2345, aserivce:{id:"2345", intid: 2345, bigint:null,
|
||||
// bservice:{name:eeeee}}}
|
||||
|
||||
factory.register("seqid", 200); //放进Resource池内, 同时ResourceFactory会自动更新aservice的seqid值
|
||||
System.out.println(factory.find("seqid", int.class)); //输出结果为:200
|
||||
factory.register("bigint", new BigInteger("666666666666666")); //放进Resource池内, 同时ResourceFactory会自动更新aservice对象的bigint值
|
||||
System.out.println(aservice); //输出结果为:{id:"2345", intid: 2345, bigint:666666666666666, bservice:{name:eeeee}} 可以看出seqid与bigint值都已自动更新
|
||||
factory.register("seqid", 200); // 放进Resource池内, 同时ResourceFactory会自动更新aservice的seqid值
|
||||
System.out.println(factory.find("seqid", int.class)); // 输出结果为:200
|
||||
factory.register(
|
||||
"bigint", new BigInteger("666666666666666")); // 放进Resource池内, 同时ResourceFactory会自动更新aservice对象的bigint值
|
||||
System.out.println(aservice); // 输出结果为:{id:"2345", intid: 2345, bigint:666666666666666, bservice:{name:eeeee}}
|
||||
// 可以看出seqid与bigint值都已自动更新
|
||||
|
||||
factory.register("id", "6789"); //更新Resource池内的id资源值, 同时ResourceFactory会自动更新aservice、bservice的id值
|
||||
System.out.println(aservice); //输出结果为:{id:"6789", intid: 6789, bigint:666666666666666, bservice:{name:eeeee}}
|
||||
System.out.println(bservice); //输出结果为:{name:"eeeee", id: 6789, aserivce:{id:"6789", intid: 6789, bigint:666666666666666, bservice:{name:eeeee}}}
|
||||
factory.register("id", "6789"); // 更新Resource池内的id资源值, 同时ResourceFactory会自动更新aservice、bservice的id值
|
||||
System.out.println(aservice); // 输出结果为:{id:"6789", intid: 6789, bigint:666666666666666, bservice:{name:eeeee}}
|
||||
System.out.println(
|
||||
bservice); // 输出结果为:{name:"eeeee", id: 6789, aserivce:{id:"6789", intid: 6789, bigint:666666666666666,
|
||||
// bservice:{name:eeeee}}}
|
||||
|
||||
Properties props = new Properties();
|
||||
props.put("id", "5555");
|
||||
@@ -56,12 +58,10 @@ public class ResourceTest {
|
||||
factory.register(props);
|
||||
|
||||
bservice = new BService("ffff");
|
||||
factory.register(bservice); //更新Resource池内name=""的BService资源, 同时ResourceFactory会自动更新aservice的bservice对象
|
||||
factory.register(bservice); // 更新Resource池内name=""的BService资源, 同时ResourceFactory会自动更新aservice的bservice对象
|
||||
factory.inject(bservice);
|
||||
System.out.println(aservice); //输出结果为:{id:"6789", intid: 6789, bigint:666666666666666, bservice:{name:ffff}}
|
||||
|
||||
System.out.println(aservice); // 输出结果为:{id:"6789", intid: 6789, bigint:666666666666666, bservice:{name:ffff}}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class BService {
|
||||
@@ -80,7 +80,8 @@ class BService {
|
||||
@ResourceChanged
|
||||
private void changeResource(ResourceEvent[] events) {
|
||||
for (ResourceEvent event : events) {
|
||||
System.out.println(getClass().getSimpleName() + " @Resource = " + event.name() + " 资源变更: newVal = " + event.newValue() + ", oldVal = " + event.oldValue());
|
||||
System.out.println(getClass().getSimpleName() + " @Resource = " + event.name() + " 资源变更: newVal = "
|
||||
+ event.newValue() + ", oldVal = " + event.oldValue());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,7 +125,7 @@ class AService {
|
||||
@Resource(name = "${id}")
|
||||
private String id;
|
||||
|
||||
@Resource(name = "id") //property.开头的资源名允许String自动转换成primitive数值类型
|
||||
@Resource(name = "id") // property.开头的资源名允许String自动转换成primitive数值类型
|
||||
private int intid;
|
||||
|
||||
@Resource(name = "bigint", required = false)
|
||||
@@ -138,7 +139,8 @@ class AService {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{id:\"" + id + "\", intid: " + intid + ", bigint:" + bigint + ", bservice:" + (bservice == null ? null : ("{name:" + bservice.getName() + "}")) + "}";
|
||||
return "{id:\"" + id + "\", intid: " + intid + ", bigint:" + bigint + ", bservice:"
|
||||
+ (bservice == null ? null : ("{name:" + bservice.getName() + "}")) + "}";
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
@@ -176,5 +178,4 @@ class AService {
|
||||
public void setBservice(BService bservice) {
|
||||
this.bservice = bservice;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import java.text.SimpleDateFormat;
|
||||
import org.redkale.convert.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
* @param <R> R
|
||||
* @param <W> W
|
||||
|
||||
@@ -7,10 +7,7 @@ package org.redkale.test.rest;
|
||||
|
||||
import java.nio.channels.CompletionHandler;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class HelloAsyncHandler implements CompletionHandler {
|
||||
|
||||
@Override
|
||||
@@ -20,7 +17,7 @@ public class HelloAsyncHandler implements CompletionHandler {
|
||||
|
||||
@Override
|
||||
public void failed(Throwable exc, Object attachment) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
throw new UnsupportedOperationException(
|
||||
"Not supported yet."); // To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,16 +9,16 @@ public class HelloBean implements FilterBean {
|
||||
private int helloid;
|
||||
|
||||
@RestHeader(name = "User-Agent")
|
||||
private String useragent; //从Http Header中获取浏览器信息
|
||||
|
||||
private String useragent; // 从Http Header中获取浏览器信息
|
||||
|
||||
@RestCookie(name = "hello-cookie")
|
||||
private String rescookie; //从Cookie中获取名为hello-cookie的值
|
||||
private String rescookie; // 从Cookie中获取名为hello-cookie的值
|
||||
|
||||
@RestAddress
|
||||
private String clientaddr; //客户端请求IP
|
||||
private String clientaddr; // 客户端请求IP
|
||||
|
||||
@RestSessionid
|
||||
private String sessionid; //用户Sessionid, 未登录时为null
|
||||
private String sessionid; // 用户Sessionid, 未登录时为null
|
||||
|
||||
/** 以下省略getter setter方法 */
|
||||
public int getHelloid() {
|
||||
@@ -65,5 +65,4 @@ public class HelloBean implements FilterBean {
|
||||
public String toString() {
|
||||
return JsonFactory.root().getConvert().convertTo(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package org.redkale.test.rest;
|
||||
|
||||
import java.util.Map;
|
||||
import org.redkale.persistence.Id;
|
||||
import org.redkale.convert.json.JsonFactory;
|
||||
import org.redkale.net.http.*;
|
||||
import org.redkale.persistence.Id;
|
||||
import org.redkale.persistence.VirtualEntity;
|
||||
|
||||
@VirtualEntity
|
||||
@@ -41,8 +41,7 @@ public class HelloEntity {
|
||||
@RestPath
|
||||
private String uri;
|
||||
|
||||
public HelloEntity() {
|
||||
}
|
||||
public HelloEntity() {}
|
||||
|
||||
public HelloEntity(int id) {
|
||||
this.helloid = id;
|
||||
|
||||
@@ -5,20 +5,12 @@ import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import org.redkale.annotation.Resource;
|
||||
import org.redkale.net.http.*;
|
||||
|
||||
import org.redkale.service.*;
|
||||
import org.redkale.source.DataSource;
|
||||
import org.redkale.source.Flipper;
|
||||
import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
* 类说明:
|
||||
* Flipper : Source组件中的翻页对象
|
||||
* UserInfo :当前用户类
|
||||
* HelloEntity: Hello模块的实体类
|
||||
* HelloBean: Hello模块实现FilterBean的过滤Bean类
|
||||
*
|
||||
*/
|
||||
/** 类说明: Flipper : Source组件中的翻页对象 UserInfo :当前用户类 HelloEntity: Hello模块的实体类 HelloBean: Hello模块实现FilterBean的过滤Bean类 */
|
||||
@RestService(autoMapping = true)
|
||||
public class HelloService implements Service {
|
||||
|
||||
@@ -27,17 +19,16 @@ public class HelloService implements Service {
|
||||
@Resource
|
||||
private DataSource source;
|
||||
|
||||
public HelloService() {
|
||||
}
|
||||
public HelloService() {}
|
||||
|
||||
public HelloService(int nodeid) {
|
||||
this.nodeid = nodeid;
|
||||
}
|
||||
|
||||
//增加记录
|
||||
// 增加记录
|
||||
public RetResult<HelloEntity> createHello(UserInfo info, HelloEntity entity, @RestBody Map<String, String> body) {
|
||||
System.out.println("增加记录----------------" + nodeid + ": body =" + body + ", entity =" + entity);
|
||||
entity.setCreator(info == null ? 0 : info.getUserid()); //设置当前用户ID
|
||||
entity.setCreator(info == null ? 0 : info.getUserid()); // 设置当前用户ID
|
||||
entity.setCreatetime(System.currentTimeMillis());
|
||||
if (source != null) source.insert(entity);
|
||||
return new RetResult<>(entity);
|
||||
@@ -48,75 +39,90 @@ public class HelloService implements Service {
|
||||
return new HttpResult("a");
|
||||
}
|
||||
|
||||
//删除记录
|
||||
public void deleteHello(int id) { //通过 /pipes/hello/delete/1234 删除对象
|
||||
// 删除记录
|
||||
public void deleteHello(int id) { // 通过 /pipes/hello/delete/1234 删除对象
|
||||
source.delete(HelloEntity.class, id);
|
||||
}
|
||||
|
||||
//修改记录
|
||||
public void updateHello(@RestAddress String clientAddr, HelloEntity entity) { //通过 /pipes/hello/update?bean={...} 修改对象
|
||||
// 修改记录
|
||||
public void updateHello(
|
||||
@RestAddress String clientAddr, HelloEntity entity) { // 通过 /pipes/hello/update?bean={...} 修改对象
|
||||
System.out.println("修改记录-" + nodeid + ": clientAddr = " + clientAddr + ", entity =" + entity);
|
||||
if (entity != null) entity.setUpdatetime(System.currentTimeMillis());
|
||||
if (source != null) source.update(entity);
|
||||
}
|
||||
|
||||
//修改记录
|
||||
public void update2Hello(@RestAddress String clientAddr, @RestUploadFile byte[] fs) { //通过 /pipes/hello/update2?bean={...} 修改对象
|
||||
// 修改记录
|
||||
public void update2Hello(
|
||||
@RestAddress String clientAddr, @RestUploadFile byte[] fs) { // 通过 /pipes/hello/update2?bean={...} 修改对象
|
||||
System.out.println("修改记录2-" + nodeid + ": clientAddr = " + clientAddr + ", fs =" + fs);
|
||||
}
|
||||
|
||||
//修改记录
|
||||
|
||||
// 修改记录
|
||||
@RestMapping(name = "partupdate")
|
||||
public void updateHello(HelloEntity entity, @RestParam(name = "cols") String[] columns) { //通过 /pipes/hello/partupdate?bean={...}&cols=... 修改对象
|
||||
public void updateHello(
|
||||
HelloEntity entity,
|
||||
@RestParam(name = "cols") String[] columns) { // 通过 /pipes/hello/partupdate?bean={...}&cols=... 修改对象
|
||||
entity.setUpdatetime(System.currentTimeMillis());
|
||||
source.updateColumn(entity, columns);
|
||||
}
|
||||
|
||||
//查询Sheet列表
|
||||
public Sheet<HelloEntity> queryHello(HelloBean bean, Flipper flipper) { //通过 /pipes/hello/query/offset:0/limit:20?bean={...} 查询Sheet列表
|
||||
// 查询Sheet列表
|
||||
public Sheet<HelloEntity> queryHello(
|
||||
HelloBean bean, Flipper flipper) { // 通过 /pipes/hello/query/offset:0/limit:20?bean={...} 查询Sheet列表
|
||||
return source.querySheet(HelloEntity.class, flipper, bean);
|
||||
}
|
||||
|
||||
//查询List列表
|
||||
// 查询List列表
|
||||
@RestMapping(name = "list")
|
||||
@RestConvert(type = HelloEntity.class, ignoreColumns = {"createtime"})
|
||||
public List<HelloEntity> queryHello(HelloBean bean) { //通过 /pipes/hello/list?bean={...} 查询List列表
|
||||
@RestConvert(
|
||||
type = HelloEntity.class,
|
||||
ignoreColumns = {"createtime"})
|
||||
public List<HelloEntity> queryHello(HelloBean bean) { // 通过 /pipes/hello/list?bean={...} 查询List列表
|
||||
return source.queryList(HelloEntity.class, bean);
|
||||
}
|
||||
|
||||
//查询List列表
|
||||
// 查询List列表
|
||||
@RestMapping(name = "listmap")
|
||||
public List<HelloEntity> queryHello(HelloBean bean, @RestParam(name = "map") Map<String, String> map) { //通过 /pipes/hello/list?bean={...} 查询List列表
|
||||
public List<HelloEntity> queryHello(
|
||||
HelloBean bean,
|
||||
@RestParam(name = "map") Map<String, String> map) { // 通过 /pipes/hello/list?bean={...} 查询List列表
|
||||
System.out.println("map参数: " + map);
|
||||
if (source != null) return source.queryList(HelloEntity.class, bean);
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
//查询单个
|
||||
// 查询单个
|
||||
@RestMapping(name = "find")
|
||||
public HelloEntity findHello(@RestParam(name = "#") int id) { //通过 /pipes/hello/find/1234、/pipes/hello/jsfind/1234 查询对象
|
||||
public HelloEntity findHello(
|
||||
@RestParam(name = "#") int id) { // 通过 /pipes/hello/find/1234、/pipes/hello/jsfind/1234 查询对象
|
||||
return source.find(HelloEntity.class, id);
|
||||
}
|
||||
|
||||
//异步查询单个
|
||||
// 异步查询单个
|
||||
@RestMapping(name = "asyncfind")
|
||||
public CompletableFuture<HelloEntity> asyncFindHello(@RestParam(name = "#") int id) { //通过 /pipes/hello/find/1234、/pipes/hello/jsfind/1234 查询对象
|
||||
public CompletableFuture<HelloEntity> asyncFindHello(
|
||||
@RestParam(name = "#") int id) { // 通过 /pipes/hello/find/1234、/pipes/hello/jsfind/1234 查询对象
|
||||
if (source != null) source.findAsync(HelloEntity.class, id);
|
||||
System.out.println("------------进入asyncfind1-------");
|
||||
return CompletableFuture.completedFuture(new HelloEntity());
|
||||
}
|
||||
|
||||
//异步查询单个
|
||||
// 异步查询单个
|
||||
@RestMapping(name = "asyncfind2")
|
||||
public void asyncFindHello(CompletionHandler hander, @RestParam(name = "#") int id) { //通过 /pipes/hello/find/1234、/pipes/hello/jsfind/1234 查询对象
|
||||
public void asyncFindHello(
|
||||
CompletionHandler hander,
|
||||
@RestParam(name = "#") int id) { // 通过 /pipes/hello/find/1234、/pipes/hello/jsfind/1234 查询对象
|
||||
if (source != null) source.findAsync(HelloEntity.class, id);
|
||||
System.out.println("-----------进入asyncfind2--------" + hander);
|
||||
hander.completed(new HelloEntity(id), id);
|
||||
}
|
||||
|
||||
//异步查询单个
|
||||
// 异步查询单个
|
||||
@RestMapping(name = "asyncfind3")
|
||||
public void asyncFindHello(HelloAsyncHandler hander, @RestParam(name = "#") int id) { //通过 /pipes/hello/find/1234、/pipes/hello/jsfind/1234 查询对象
|
||||
public void asyncFindHello(
|
||||
HelloAsyncHandler hander,
|
||||
@RestParam(name = "#") int id) { // 通过 /pipes/hello/find/1234、/pipes/hello/jsfind/1234 查询对象
|
||||
if (source != null) source.findAsync(HelloEntity.class, id);
|
||||
System.out.println("-----------进入asyncfind3--------" + hander);
|
||||
hander.completed(new HelloEntity(id), id);
|
||||
|
||||
@@ -11,52 +11,49 @@ import org.redkale.service.*;
|
||||
import org.redkale.source.*;
|
||||
import org.redkale.util.Sheet;
|
||||
|
||||
/**
|
||||
* 类说明:
|
||||
* Flipper : Source组件中的翻页对象
|
||||
* UserInfo :当前用户类
|
||||
* HelloEntity: Hello模块的实体类
|
||||
* HelloBean: Hello模块实现FilterBean的过滤Bean类
|
||||
*
|
||||
*/
|
||||
/** 类说明: Flipper : Source组件中的翻页对象 UserInfo :当前用户类 HelloEntity: Hello模块的实体类 HelloBean: Hello模块实现FilterBean的过滤Bean类 */
|
||||
@RestService(name = "hello", moduleid = 0, autoMapping = true, repair = true, ignore = false, comment = "Hello服务模块")
|
||||
public class HelloService2 implements Service {
|
||||
|
||||
@Resource
|
||||
private DataSource source;
|
||||
|
||||
//增加记录
|
||||
// 增加记录
|
||||
@RestMapping(name = "create", auth = false, comment = "创建Hello对象")
|
||||
public RetResult<HelloEntity> createHello(UserInfo info, @RestParam(name = "bean", comment = "Hello对象") HelloEntity entity) {
|
||||
entity.setCreator(info == null ? 0 : info.getUserid()); //设置当前用户ID
|
||||
public RetResult<HelloEntity> createHello(
|
||||
UserInfo info, @RestParam(name = "bean", comment = "Hello对象") HelloEntity entity) {
|
||||
entity.setCreator(info == null ? 0 : info.getUserid()); // 设置当前用户ID
|
||||
entity.setCreatetime(System.currentTimeMillis());
|
||||
source.insert(entity);
|
||||
return new RetResult<>(entity);
|
||||
}
|
||||
|
||||
//删除记录
|
||||
// 删除记录
|
||||
@RestMapping(name = "delete", auth = false, comment = "根据id删除Hello对象")
|
||||
public void deleteHello(@RestParam(name = "#", comment = "Hello对象id") int id) { //通过 /hello/delete/1234 删除对象
|
||||
public void deleteHello(@RestParam(name = "#", comment = "Hello对象id") int id) { // 通过 /hello/delete/1234 删除对象
|
||||
source.delete(HelloEntity.class, id);
|
||||
}
|
||||
|
||||
//修改记录
|
||||
// 修改记录
|
||||
@RestMapping(name = "update", auth = false, comment = "修改Hello对象")
|
||||
public void updateHello(@RestParam(name = "bean", comment = "Hello对象") HelloEntity entity) { //通过 /hello/update?bean={...} 修改对象
|
||||
public void updateHello(
|
||||
@RestParam(name = "bean", comment = "Hello对象") HelloEntity entity) { // 通过 /hello/update?bean={...} 修改对象
|
||||
entity.setUpdatetime(System.currentTimeMillis());
|
||||
source.update(entity);
|
||||
}
|
||||
|
||||
//查询列表
|
||||
// 查询列表
|
||||
@RestConvertCoder(type = HelloEntity.class, field = "createtime", coder = CreateTimeSimpleCoder.class)
|
||||
@RestMapping(name = "query", auth = false, comment = "查询Hello对象列表")
|
||||
public Sheet<HelloEntity> queryHello(@RestParam(name = "bean", comment = "过滤条件") HelloBean bean, Flipper flipper) { //通过 /hello/query/offset:0/limit:20?bean={...} 查询列表
|
||||
public Sheet<HelloEntity> queryHello(
|
||||
@RestParam(name = "bean", comment = "过滤条件") HelloBean bean,
|
||||
Flipper flipper) { // 通过 /hello/query/offset:0/limit:20?bean={...} 查询列表
|
||||
return source.querySheet(HelloEntity.class, flipper, bean);
|
||||
}
|
||||
|
||||
//查询单个
|
||||
// 查询单个
|
||||
@RestMapping(name = "find", auth = false, comment = "根据id查找单个Hello对象")
|
||||
public HelloEntity findHello(@RestParam(name = "#", comment = "Hello对象id") int id) { //通过 /hello/find/1234 查询对象
|
||||
public HelloEntity findHello(@RestParam(name = "#", comment = "Hello对象id") int id) { // 通过 /hello/find/1234 查询对象
|
||||
return source.find(HelloEntity.class, id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,10 +7,7 @@ package org.redkale.test.rest;
|
||||
|
||||
import org.redkale.convert.json.JsonFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class LoginBean {
|
||||
|
||||
private String account = "";
|
||||
|
||||
@@ -9,18 +9,13 @@ import java.lang.reflect.*;
|
||||
import java.util.*;
|
||||
import org.redkale.service.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public abstract class RetCodes {
|
||||
|
||||
protected static final Map<Integer, String> rets = new HashMap<>();
|
||||
|
||||
|
||||
protected RetCodes() {
|
||||
}
|
||||
//-----------------------------------------------------------------------------------------------------------
|
||||
protected RetCodes() {}
|
||||
// -----------------------------------------------------------------------------------------------------------
|
||||
|
||||
protected static void load(Class clazz) {
|
||||
for (Field field : clazz.getFields()) {
|
||||
@@ -49,10 +44,10 @@ public abstract class RetCodes {
|
||||
return rets.getOrDefault(retcode, "未知错误");
|
||||
}
|
||||
|
||||
//2000_0001 - 2999_9999 预留给 Redkale的扩展包redkalex使用
|
||||
//3000_0001 - 7999_9999 为平台系统使用
|
||||
//8000_0001 - 9999_9999 为OSS系统使用
|
||||
//------------------------------------- 通用模块 -----------------------------------------
|
||||
// 2000_0001 - 2999_9999 预留给 Redkale的扩展包redkalex使用
|
||||
// 3000_0001 - 7999_9999 为平台系统使用
|
||||
// 8000_0001 - 9999_9999 为OSS系统使用
|
||||
// ------------------------------------- 通用模块 -----------------------------------------
|
||||
@RetLabel("参数无效")
|
||||
public static final int RET_PARAMS_ILLEGAL = 30010001;
|
||||
|
||||
@@ -65,7 +60,7 @@ public abstract class RetCodes {
|
||||
@RetLabel("上传文件不是图片")
|
||||
public static final int RET_UPLOAD_NOTIMAGE = 30010004;
|
||||
|
||||
//------------------------------------- 用户模块 -----------------------------------------
|
||||
// ------------------------------------- 用户模块 -----------------------------------------
|
||||
@RetLabel("未登录")
|
||||
public static final int RET_USER_UNLOGIN = 30020001;
|
||||
|
||||
@@ -142,21 +137,20 @@ public abstract class RetCodes {
|
||||
public static final int RET_USER_QQID_INFO_FAIL = 30020025;
|
||||
|
||||
@RetLabel("验证码无效")
|
||||
public static final int RET_USER_RANDCODE_ILLEGAL = 30020026; //邮件或者短信验证码
|
||||
public static final int RET_USER_RANDCODE_ILLEGAL = 30020026; // 邮件或者短信验证码
|
||||
|
||||
@RetLabel("验证码已过期")
|
||||
public static final int RET_USER_RANDCODE_EXPIRED = 30020027; //邮件或者短信验证码
|
||||
public static final int RET_USER_RANDCODE_EXPIRED = 30020027; // 邮件或者短信验证码
|
||||
|
||||
@RetLabel("验证码错误或失效")
|
||||
public static final int RET_USER_CAPTCHA_ILLEGAL = 30020028; //图片验证码
|
||||
public static final int RET_USER_CAPTCHA_ILLEGAL = 30020028; // 图片验证码
|
||||
|
||||
@RetLabel("用户类型无效")
|
||||
public static final int RET_USER_TYPE_ILLEGAL = 30020029;
|
||||
|
||||
@RetLabel("用户设备ID无效")
|
||||
public static final int RET_USER_APPTOKEN_ILLEGAL = 30020030;
|
||||
|
||||
|
||||
|
||||
static {
|
||||
load(RetCodes.class);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package org.redkale.test.rest;
|
||||
|
||||
import java.io.IOException;
|
||||
import org.redkale.annotation.Resource;
|
||||
|
||||
import org.redkale.net.http.*;
|
||||
import org.redkale.service.RetResult;
|
||||
|
||||
@@ -25,7 +24,7 @@ public class SimpleRestServlet extends HttpServlet {
|
||||
response.nextEvent();
|
||||
}
|
||||
|
||||
//普通鉴权
|
||||
// 普通鉴权
|
||||
@Override
|
||||
public void authenticate(HttpRequest request, HttpResponse response) throws IOException {
|
||||
int userid = request.currentUserid(int.class);
|
||||
@@ -35,5 +34,4 @@ public class SimpleRestServlet extends HttpServlet {
|
||||
}
|
||||
response.nextEvent();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package org.redkale.test.rest;
|
||||
|
||||
import org.redkale.persistence.Id;
|
||||
import org.redkale.convert.json.JsonFactory;
|
||||
import org.redkale.persistence.Id;
|
||||
|
||||
/**
|
||||
* 当前用户对象
|
||||
@@ -21,7 +21,7 @@ public class UserInfo {
|
||||
|
||||
public boolean checkAuth(int moduleid, int actionid) {
|
||||
if (moduleid == 0 || actionid == 0) return true;
|
||||
//权限判断
|
||||
// 权限判断
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import org.redkale.service.*;
|
||||
*/
|
||||
public class UserService implements Service {
|
||||
|
||||
//根据登录态获取当前用户信息
|
||||
// 根据登录态获取当前用户信息
|
||||
public UserInfo current(String sessionid) {
|
||||
return new UserInfo();
|
||||
}
|
||||
|
||||
@@ -9,7 +9,9 @@ import org.redkale.service.RetResult;
|
||||
import org.redkale.source.Flipper;
|
||||
import org.redkale.util.*;
|
||||
|
||||
@WebServlet(value = {"/hello/*"}, repair = true)
|
||||
@WebServlet(
|
||||
value = {"/hello/*"},
|
||||
repair = true)
|
||||
public class _DynHelloRestServlet1 extends SimpleRestServlet {
|
||||
|
||||
@Resource
|
||||
@@ -35,7 +37,7 @@ public class _DynHelloRestServlet1 extends SimpleRestServlet {
|
||||
entity.setHelloname("my name");
|
||||
Map<String, Serializable> headers = new HashMap<>();
|
||||
headers.put("hello-res", "my res");
|
||||
//headers.put(Rest.REST_HEADER_RESNAME, "my-res");
|
||||
// headers.put(Rest.REST_HEADER_RESNAME, "my-res");
|
||||
String url = "http://127.0.0.1:" + port + "/pipes/hello/update?entity={}&bean2={}";
|
||||
System.out.println(Utility.postHttpContent(url, headers, null));
|
||||
url = "http://127.0.0.1:" + port + "/pipes/hello/update2?entity={}&bean2={}";
|
||||
@@ -56,12 +58,13 @@ public class _DynHelloRestServlet1 extends SimpleRestServlet {
|
||||
System.out.println("listmap: " + Utility.postHttpContent(url, headers, null));
|
||||
url = "http://127.0.0.1:" + port + "/pipes/hello/asyncfind3/333333";
|
||||
System.out.println("listmap: " + Utility.postHttpContent(url, headers, null));
|
||||
|
||||
}
|
||||
|
||||
@HttpMapping(url = "/hello/create", auth = false)
|
||||
public void create(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService service = _redkale_servicemap == null ? _redkale_service : _redkale_servicemap.get(req.getHeader(Rest.REST_HEADER_RESNAME, ""));
|
||||
HelloService service = _redkale_servicemap == null
|
||||
? _redkale_service
|
||||
: _redkale_servicemap.get(req.getHeader(Rest.REST_HEADER_RESNAME, ""));
|
||||
HelloEntity bean = req.getJsonParameter(HelloEntity.class, "bean");
|
||||
bean.setClientaddr(req.getRemoteAddr());
|
||||
bean.setResname(req.getHeader("hello-res"));
|
||||
@@ -72,7 +75,9 @@ public class _DynHelloRestServlet1 extends SimpleRestServlet {
|
||||
|
||||
@HttpMapping(url = "/hello/delete/", auth = false)
|
||||
public void delete(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService service = _redkale_servicemap == null ? _redkale_service : _redkale_servicemap.get(req.getHeader(Rest.REST_HEADER_RESNAME, ""));
|
||||
HelloService service = _redkale_servicemap == null
|
||||
? _redkale_service
|
||||
: _redkale_servicemap.get(req.getHeader(Rest.REST_HEADER_RESNAME, ""));
|
||||
int id = Integer.parseInt(req.getPathLastParam());
|
||||
service.deleteHello(id);
|
||||
resp.finishJson(RetResult.success());
|
||||
@@ -80,7 +85,9 @@ public class _DynHelloRestServlet1 extends SimpleRestServlet {
|
||||
|
||||
@HttpMapping(url = "/hello/update", auth = false)
|
||||
public void update(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService service = _redkale_servicemap == null ? _redkale_service : _redkale_servicemap.get(req.getHeader(Rest.REST_HEADER_RESNAME, ""));
|
||||
HelloService service = _redkale_servicemap == null
|
||||
? _redkale_service
|
||||
: _redkale_servicemap.get(req.getHeader(Rest.REST_HEADER_RESNAME, ""));
|
||||
String clientaddr = req.getRemoteAddr();
|
||||
HelloEntity bean = req.getJsonParameter(HelloEntity.class, "bean");
|
||||
bean.setClientaddr(req.getRemoteAddr());
|
||||
@@ -91,7 +98,9 @@ public class _DynHelloRestServlet1 extends SimpleRestServlet {
|
||||
|
||||
@HttpMapping(url = "/hello/partupdate", auth = false)
|
||||
public void partupdate(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService service = _redkale_servicemap == null ? _redkale_service : _redkale_servicemap.get(req.getHeader(Rest.REST_HEADER_RESNAME, ""));
|
||||
HelloService service = _redkale_servicemap == null
|
||||
? _redkale_service
|
||||
: _redkale_servicemap.get(req.getHeader(Rest.REST_HEADER_RESNAME, ""));
|
||||
HelloEntity bean = req.getJsonParameter(HelloEntity.class, "bean");
|
||||
bean.setClientaddr(req.getRemoteAddr());
|
||||
bean.setResname(req.getHeader("hello-res"));
|
||||
@@ -102,7 +111,9 @@ public class _DynHelloRestServlet1 extends SimpleRestServlet {
|
||||
|
||||
@HttpMapping(url = "/hello/query", auth = false)
|
||||
public void query(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService service = _redkale_servicemap == null ? _redkale_service : _redkale_servicemap.get(req.getHeader(Rest.REST_HEADER_RESNAME, ""));
|
||||
HelloService service = _redkale_servicemap == null
|
||||
? _redkale_service
|
||||
: _redkale_servicemap.get(req.getHeader(Rest.REST_HEADER_RESNAME, ""));
|
||||
HelloBean bean = req.getJsonParameter(HelloBean.class, "bean");
|
||||
bean.setClientaddr(req.getRemoteAddr());
|
||||
bean.setUseragent(req.getHeader("User-Agent"));
|
||||
@@ -115,7 +126,9 @@ public class _DynHelloRestServlet1 extends SimpleRestServlet {
|
||||
|
||||
@HttpMapping(url = "/hello/list", auth = false)
|
||||
public void list(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService service = _redkale_servicemap == null ? _redkale_service : _redkale_servicemap.get(req.getHeader(Rest.REST_HEADER_RESNAME, ""));
|
||||
HelloService service = _redkale_servicemap == null
|
||||
? _redkale_service
|
||||
: _redkale_servicemap.get(req.getHeader(Rest.REST_HEADER_RESNAME, ""));
|
||||
HelloBean bean = req.getJsonParameter(HelloBean.class, "bean");
|
||||
bean.setClientaddr(req.getRemoteAddr());
|
||||
bean.setUseragent(req.getHeader("User-Agent"));
|
||||
@@ -127,7 +140,9 @@ public class _DynHelloRestServlet1 extends SimpleRestServlet {
|
||||
|
||||
@HttpMapping(url = "/hello/find/", auth = false)
|
||||
public void find(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService service = _redkale_servicemap == null ? _redkale_service : _redkale_servicemap.get(req.getHeader(Rest.REST_HEADER_RESNAME, ""));
|
||||
HelloService service = _redkale_servicemap == null
|
||||
? _redkale_service
|
||||
: _redkale_servicemap.get(req.getHeader(Rest.REST_HEADER_RESNAME, ""));
|
||||
int id = Integer.parseInt(req.getPathLastParam());
|
||||
HelloEntity bean = service.findHello(id);
|
||||
resp.finishJson(bean);
|
||||
@@ -135,21 +150,27 @@ public class _DynHelloRestServlet1 extends SimpleRestServlet {
|
||||
|
||||
@HttpMapping(url = "/hello/asyncfind/", auth = false)
|
||||
public void asyncfind(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService service = _redkale_servicemap == null ? _redkale_service : _redkale_servicemap.get(req.getHeader(Rest.REST_HEADER_RESNAME, ""));
|
||||
HelloService service = _redkale_servicemap == null
|
||||
? _redkale_service
|
||||
: _redkale_servicemap.get(req.getHeader(Rest.REST_HEADER_RESNAME, ""));
|
||||
int id = Integer.parseInt(req.getPathLastParam());
|
||||
resp.finishJson(service.asyncFindHello(id));
|
||||
}
|
||||
|
||||
@HttpMapping(url = "/hello/asyncfind2/", auth = false)
|
||||
public void asyncfind2(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService service = _redkale_servicemap == null ? _redkale_service : _redkale_servicemap.get(req.getHeader(Rest.REST_HEADER_RESNAME, ""));
|
||||
HelloService service = _redkale_servicemap == null
|
||||
? _redkale_service
|
||||
: _redkale_servicemap.get(req.getHeader(Rest.REST_HEADER_RESNAME, ""));
|
||||
int id = Integer.parseInt(req.getPathLastParam());
|
||||
service.asyncFindHello(resp.createAsyncHandler(), id);
|
||||
}
|
||||
|
||||
@HttpMapping(url = "/hello/asyncfind3/", auth = false)
|
||||
public void asyncfind3(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService service = _redkale_servicemap == null ? _redkale_service : _redkale_servicemap.get(req.getHeader(Rest.REST_HEADER_RESNAME, ""));
|
||||
HelloService service = _redkale_servicemap == null
|
||||
? _redkale_service
|
||||
: _redkale_servicemap.get(req.getHeader(Rest.REST_HEADER_RESNAME, ""));
|
||||
int id = Integer.parseInt(req.getPathLastParam());
|
||||
service.asyncFindHello(resp.createAsyncHandler(HelloAsyncHandler.class), id);
|
||||
}
|
||||
|
||||
@@ -13,11 +13,10 @@ import org.redkale.service.RetResult;
|
||||
import org.redkale.source.Flipper;
|
||||
import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
@WebServlet(value = {"/hello/*"}, repair = true)
|
||||
/** @author zhangjx */
|
||||
@WebServlet(
|
||||
value = {"/hello/*"},
|
||||
repair = true)
|
||||
public class _DynHelloRestServlet2 extends SimpleRestServlet {
|
||||
|
||||
@Resource
|
||||
@@ -29,7 +28,9 @@ public class _DynHelloRestServlet2 extends SimpleRestServlet {
|
||||
@HttpMapping(url = "/hello/create", auth = false, comment = "创建Hello对象")
|
||||
@HttpParam(name = "bean", type = HelloEntity.class, comment = "Hello对象")
|
||||
public void create(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService2 service = _redkale_servicemap == null ? _redkale_service : _redkale_servicemap.get(req.getHeader(Rest.REST_HEADER_RESNAME, ""));
|
||||
HelloService2 service = _redkale_servicemap == null
|
||||
? _redkale_service
|
||||
: _redkale_servicemap.get(req.getHeader(Rest.REST_HEADER_RESNAME, ""));
|
||||
HelloEntity bean = req.getJsonParameter(HelloEntity.class, "bean");
|
||||
bean.setClientaddr(req.getRemoteAddr());
|
||||
bean.setResname(req.getHeader("hello-res"));
|
||||
@@ -43,7 +44,9 @@ public class _DynHelloRestServlet2 extends SimpleRestServlet {
|
||||
@HttpMapping(url = "/hello/delete/", auth = false, comment = "根据id删除Hello对象")
|
||||
@HttpParam(name = "#", type = int.class, comment = "Hello对象id")
|
||||
public void delete(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService2 service = _redkale_servicemap == null ? _redkale_service : _redkale_servicemap.get(req.getHeader(Rest.REST_HEADER_RESNAME, ""));
|
||||
HelloService2 service = _redkale_servicemap == null
|
||||
? _redkale_service
|
||||
: _redkale_servicemap.get(req.getHeader(Rest.REST_HEADER_RESNAME, ""));
|
||||
int id = Integer.parseInt(req.getPathLastParam());
|
||||
service.deleteHello(id);
|
||||
resp.finishJson(RetResult.success());
|
||||
@@ -52,7 +55,9 @@ public class _DynHelloRestServlet2 extends SimpleRestServlet {
|
||||
@HttpMapping(url = "/hello/update", auth = false, comment = "修改Hello对象")
|
||||
@HttpParam(name = "bean", type = HelloEntity.class, comment = "Hello对象")
|
||||
public void update(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService2 service = _redkale_servicemap == null ? _redkale_service : _redkale_servicemap.get(req.getHeader(Rest.REST_HEADER_RESNAME, ""));
|
||||
HelloService2 service = _redkale_servicemap == null
|
||||
? _redkale_service
|
||||
: _redkale_servicemap.get(req.getHeader(Rest.REST_HEADER_RESNAME, ""));
|
||||
HelloEntity bean = req.getJsonParameter(HelloEntity.class, "bean");
|
||||
bean.setClientaddr(req.getRemoteAddr());
|
||||
bean.setResname(req.getHeader("hello-res"));
|
||||
@@ -65,7 +70,9 @@ public class _DynHelloRestServlet2 extends SimpleRestServlet {
|
||||
@HttpMapping(url = "/hello/query", auth = false, comment = "查询Hello对象列表")
|
||||
@HttpParam(name = "bean", type = HelloBean.class, comment = "过滤条件")
|
||||
public void query(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService2 service = _redkale_servicemap == null ? _redkale_service : _redkale_servicemap.get(req.getHeader(Rest.REST_HEADER_RESNAME, ""));
|
||||
HelloService2 service = _redkale_servicemap == null
|
||||
? _redkale_service
|
||||
: _redkale_servicemap.get(req.getHeader(Rest.REST_HEADER_RESNAME, ""));
|
||||
HelloBean bean = req.getJsonParameter(HelloBean.class, "bean");
|
||||
bean.setClientaddr(req.getRemoteAddr());
|
||||
bean.setUseragent(req.getHeader("User-Agent"));
|
||||
@@ -79,7 +86,9 @@ public class _DynHelloRestServlet2 extends SimpleRestServlet {
|
||||
@HttpMapping(url = "/hello/find/", auth = false, comment = "根据id删除Hello对象")
|
||||
@HttpParam(name = "#", type = int.class, comment = "Hello对象id")
|
||||
public void find(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService2 service = _redkale_servicemap == null ? _redkale_service : _redkale_servicemap.get(req.getHeader(Rest.REST_HEADER_RESNAME, ""));
|
||||
HelloService2 service = _redkale_servicemap == null
|
||||
? _redkale_service
|
||||
: _redkale_servicemap.get(req.getHeader(Rest.REST_HEADER_RESNAME, ""));
|
||||
int id = Integer.parseInt(req.getPathLastParam());
|
||||
HelloEntity bean = service.findHello(id);
|
||||
resp.finishJson(bean);
|
||||
|
||||
@@ -3,14 +3,11 @@
|
||||
*/
|
||||
package org.redkale.test.schedule;
|
||||
|
||||
import org.redkale.schedule.Scheduled;
|
||||
import org.redkale.service.Service;
|
||||
import org.redkale.util.Times;
|
||||
import org.redkale.schedule.Scheduled;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class ScheduleService implements Service {
|
||||
|
||||
@Scheduled(cron = "0/1 * * * * ?")
|
||||
|
||||
@@ -7,10 +7,7 @@ import org.junit.jupiter.api.Test;
|
||||
import org.redkale.schedule.spi.ScheduleManagerService;
|
||||
import org.redkale.util.Utility;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class SchedulingTest {
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
@@ -28,5 +25,4 @@ public class SchedulingTest {
|
||||
manager.unschedule(service);
|
||||
manager.destroy(null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,10 +25,7 @@ import org.redkale.net.sncp.*;
|
||||
import org.redkale.service.Service;
|
||||
import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
@RestService(name = "abmain")
|
||||
public class ABMainService implements Service {
|
||||
|
||||
@@ -43,7 +40,8 @@ public class ABMainService implements Service {
|
||||
final AsyncIOGroup asyncGroup = new AsyncIOGroup(8192, 16);
|
||||
asyncGroup.start();
|
||||
InetSocketAddress sncpAddress = new InetSocketAddress("127.0.0.1", abport);
|
||||
final SncpClient client = new SncpClient("", asyncGroup, "0", sncpAddress, new ClientAddress(sncpAddress), "TCP", 16, 100);
|
||||
final SncpClient client =
|
||||
new SncpClient("", asyncGroup, "0", sncpAddress, new ClientAddress(sncpAddress), "TCP", 16, 100);
|
||||
final ResourceFactory resFactory = ResourceFactory.create();
|
||||
resFactory.register(JsonConvert.root());
|
||||
resFactory.register(BsonConvert.root());
|
||||
@@ -52,16 +50,16 @@ public class ABMainService implements Service {
|
||||
rpcGroups.computeIfAbsent("g88", "TCP").putAddress(new InetSocketAddress("127.0.0.1", 5588));
|
||||
rpcGroups.computeIfAbsent("g99", "TCP").putAddress(new InetSocketAddress("127.0.0.1", 5599));
|
||||
|
||||
//------------------------ 初始化 CService ------------------------------------
|
||||
// ------------------------ 初始化 CService ------------------------------------
|
||||
CService cservice = Sncp.createSimpleLocalService(CService.class, resFactory);
|
||||
SncpServer cserver = new SncpServer();
|
||||
cserver.getResourceFactory().register(application);
|
||||
//cserver.getLogger().setLevel(Level.WARNING);
|
||||
// cserver.getLogger().setLevel(Level.WARNING);
|
||||
cserver.addSncpServlet(cservice);
|
||||
cserver.init(AnyValueWriter.create("port", 5577));
|
||||
cserver.start();
|
||||
|
||||
//------------------------ 初始化 BCService ------------------------------------
|
||||
// ------------------------ 初始化 BCService ------------------------------------
|
||||
BCService bcservice = Sncp.createSimpleLocalService(BCService.class, resFactory);
|
||||
CService remoteCService = Sncp.createSimpleRemoteService(CService.class, resFactory, rpcGroups, client, "g77");
|
||||
if (remoteCService != null) {
|
||||
@@ -70,14 +68,15 @@ public class ABMainService implements Service {
|
||||
}
|
||||
SncpServer bcserver = new SncpServer();
|
||||
bcserver.getResourceFactory().register(application);
|
||||
//bcserver.getLogger().setLevel(Level.WARNING);
|
||||
// bcserver.getLogger().setLevel(Level.WARNING);
|
||||
bcserver.addSncpServlet(bcservice);
|
||||
bcserver.init(AnyValueWriter.create("port", 5588));
|
||||
bcserver.start();
|
||||
|
||||
//------------------------ 初始化 ABMainService ------------------------------------
|
||||
// ------------------------ 初始化 ABMainService ------------------------------------
|
||||
ABMainService service = Sncp.createSimpleLocalService(ABMainService.class, resFactory);
|
||||
BCService remoteBCService = Sncp.createSimpleRemoteService(BCService.class, resFactory, rpcGroups, client, "g88");
|
||||
BCService remoteBCService =
|
||||
Sncp.createSimpleRemoteService(BCService.class, resFactory, rpcGroups, client, "g88");
|
||||
if (remoteBCService != null) {
|
||||
resFactory.inject(remoteBCService);
|
||||
resFactory.register("", remoteBCService);
|
||||
@@ -89,7 +88,7 @@ public class ABMainService implements Service {
|
||||
|
||||
HttpServer server = new HttpServer();
|
||||
server.getResourceFactory().register(application);
|
||||
//server.getLogger().setLevel(Level.WARNING);
|
||||
// server.getLogger().setLevel(Level.WARNING);
|
||||
|
||||
server.init(AnyValueWriter.create("port", abport));
|
||||
server.addRestServlet(null, service, null, HttpServlet.class, "/pipes");
|
||||
@@ -97,21 +96,24 @@ public class ABMainService implements Service {
|
||||
Utility.sleep(100);
|
||||
System.out.println("开始请求");
|
||||
|
||||
//不声明一个新的HttpClient会导致Utility.postHttpContent操作
|
||||
//同一url在Utility里的httpClient会缓存导致调用是吧,应该是httpClient的bug
|
||||
// 不声明一个新的HttpClient会导致Utility.postHttpContent操作
|
||||
// 同一url在Utility里的httpClient会缓存导致调用是吧,应该是httpClient的bug
|
||||
java.net.http.HttpClient httpClient = java.net.http.HttpClient.newHttpClient();
|
||||
System.out.println("httpclient类: " + httpClient.getClass().getName());
|
||||
//同步方法
|
||||
// 同步方法
|
||||
String url = "http://127.0.0.1:" + abport + "/pipes/abmain/sab/张先生";
|
||||
System.out.println(Utility.postHttpContentAsync(httpClient, url, StandardCharsets.UTF_8, null).join());
|
||||
System.out.println(Utility.postHttpContentAsync(httpClient, url, StandardCharsets.UTF_8, null)
|
||||
.join());
|
||||
|
||||
//异步方法
|
||||
// 异步方法
|
||||
url = "http://127.0.0.1:" + abport + "/pipes/abmain/abc/张先生";
|
||||
System.out.println(Utility.postHttpContentAsync(httpClient, url, StandardCharsets.UTF_8, null).join());
|
||||
System.out.println(Utility.postHttpContentAsync(httpClient, url, StandardCharsets.UTF_8, null)
|
||||
.join());
|
||||
|
||||
//异步方法
|
||||
// 异步方法
|
||||
url = "http://127.0.0.1:" + abport + "/pipes/abmain/abc2/张先生";
|
||||
System.out.println(Utility.postHttpContentAsync(httpClient, url, StandardCharsets.UTF_8, null).join());
|
||||
System.out.println(Utility.postHttpContentAsync(httpClient, url, StandardCharsets.UTF_8, null)
|
||||
.join());
|
||||
|
||||
server.shutdown();
|
||||
bcserver.shutdown();
|
||||
@@ -145,20 +147,20 @@ public class ABMainService implements Service {
|
||||
Thread.sleep(100);
|
||||
|
||||
System.out.println("开始请求");
|
||||
//同步方法
|
||||
// 同步方法
|
||||
String url = "http://127.0.0.1:" + abport + "/pipes/abmain/sab/张先生";
|
||||
System.out.println(Utility.postHttpContent(url));
|
||||
|
||||
//异步方法
|
||||
// 异步方法
|
||||
url = "http://127.0.0.1:" + abport + "/pipes/abmain/abc/张先生";
|
||||
System.out.println(Utility.postHttpContent(url));
|
||||
|
||||
//异步方法
|
||||
// 异步方法
|
||||
url = "http://127.0.0.1:" + abport + "/pipes/abmain/abc2/张先生";
|
||||
System.out.println(Utility.postHttpContent(url));
|
||||
|
||||
server.shutdown();
|
||||
//远程模式
|
||||
// 远程模式
|
||||
remote(args);
|
||||
}
|
||||
|
||||
@@ -174,14 +176,19 @@ public class ABMainService implements Service {
|
||||
}
|
||||
|
||||
public static ObjectPool<ByteBuffer> newBufferPool() {
|
||||
return ObjectPool.createSafePool(new LongAdder(), new LongAdder(), 16,
|
||||
(Object... params) -> ByteBuffer.allocateDirect(8192), null, (e) -> {
|
||||
if (e == null || e.isReadOnly() || e.capacity() != 8192) {
|
||||
return false;
|
||||
}
|
||||
e.clear();
|
||||
return true;
|
||||
});
|
||||
return ObjectPool.createSafePool(
|
||||
new LongAdder(),
|
||||
new LongAdder(),
|
||||
16,
|
||||
(Object... params) -> ByteBuffer.allocateDirect(8192),
|
||||
null,
|
||||
(e) -> {
|
||||
if (e == null || e.isReadOnly() || e.capacity() != 8192) {
|
||||
return false;
|
||||
}
|
||||
e.clear();
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
@RestMapping(name = "sab")
|
||||
@@ -194,44 +201,49 @@ public class ABMainService implements Service {
|
||||
|
||||
@RestMapping(name = "abc")
|
||||
public void abCurrentTime(final CompletionHandler<String, Void> handler, @RestParam(name = "#") final String name) {
|
||||
bcService.bcCurrentTime2(Utility.createAsyncHandler((v, a) -> {
|
||||
System.out.println("执行了 ABMainService.abCurrentTime----异步方法");
|
||||
String rs = "异步abCurrentTime: " + v;
|
||||
if (handler != null) {
|
||||
handler.completed(rs, a);
|
||||
}
|
||||
}, (t, a) -> {
|
||||
if (handler != null) {
|
||||
handler.failed(t, a);
|
||||
}
|
||||
}), name);
|
||||
bcService.bcCurrentTime2(
|
||||
Utility.createAsyncHandler(
|
||||
(v, a) -> {
|
||||
System.out.println("执行了 ABMainService.abCurrentTime----异步方法");
|
||||
String rs = "异步abCurrentTime: " + v;
|
||||
if (handler != null) {
|
||||
handler.completed(rs, a);
|
||||
}
|
||||
},
|
||||
(t, a) -> {
|
||||
if (handler != null) {
|
||||
handler.failed(t, a);
|
||||
}
|
||||
}),
|
||||
name);
|
||||
}
|
||||
|
||||
@RestMapping(name = "abc2")
|
||||
public void abCurrentTime(final MyAsyncHandler<String, Void> handler, @RestParam(name = "#") final String name) {
|
||||
bcService.bcCurrentTime3(new MyAsyncHandler<String, Void>() {
|
||||
@Override
|
||||
public int id() {
|
||||
return 1;
|
||||
}
|
||||
bcService.bcCurrentTime3(
|
||||
new MyAsyncHandler<String, Void>() {
|
||||
@Override
|
||||
public int id() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void completed(String v, Void a) {
|
||||
System.out.println("执行了 ABMainService.abCurrentTime----异步方法2");
|
||||
String rs = "异步abCurrentTime: " + v;
|
||||
if (handler != null) {
|
||||
handler.completed(rs, a);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void completed(String v, Void a) {
|
||||
System.out.println("执行了 ABMainService.abCurrentTime----异步方法2");
|
||||
String rs = "异步abCurrentTime: " + v;
|
||||
if (handler != null) {
|
||||
handler.completed(rs, a);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failed(Throwable exc, Void attachment) {
|
||||
}
|
||||
@Override
|
||||
public void failed(Throwable exc, Void attachment) {}
|
||||
|
||||
@Override
|
||||
public int id2() {
|
||||
return 2;
|
||||
}
|
||||
}, name);
|
||||
@Override
|
||||
public int id2() {
|
||||
return 2;
|
||||
}
|
||||
},
|
||||
name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,10 +10,7 @@ import org.redkale.annotation.Resource;
|
||||
import org.redkale.service.*;
|
||||
import org.redkale.util.Utility;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class BCService implements Service {
|
||||
|
||||
@Resource
|
||||
@@ -41,43 +38,48 @@ public class BCService implements Service {
|
||||
}
|
||||
|
||||
public void bcCurrentTime2(final CompletionHandler<String, Void> handler, final String name) {
|
||||
cService.ccCurrentTime2(Utility.createAsyncHandler((v, a) -> {
|
||||
System.out.println("执行了 BCService.bcCurrentTime2----异步方法2");
|
||||
String rs = "异步bcCurrentTime2: " + (v == null ? null : v.getResult());
|
||||
if (handler != null) {
|
||||
handler.completed(rs, null);
|
||||
}
|
||||
}, (t, a) -> {
|
||||
if (handler != null) {
|
||||
handler.failed(t, a);
|
||||
}
|
||||
}), name);
|
||||
cService.ccCurrentTime2(
|
||||
Utility.createAsyncHandler(
|
||||
(v, a) -> {
|
||||
System.out.println("执行了 BCService.bcCurrentTime2----异步方法2");
|
||||
String rs = "异步bcCurrentTime2: " + (v == null ? null : v.getResult());
|
||||
if (handler != null) {
|
||||
handler.completed(rs, null);
|
||||
}
|
||||
},
|
||||
(t, a) -> {
|
||||
if (handler != null) {
|
||||
handler.failed(t, a);
|
||||
}
|
||||
}),
|
||||
name);
|
||||
}
|
||||
|
||||
public void bcCurrentTime3(final MyAsyncHandler<String, Void> handler, final String name) {
|
||||
cService.mcCurrentTime3(new MyAsyncHandler<RetResult<String>, Void>() {
|
||||
@Override
|
||||
public int id() {
|
||||
return 1;
|
||||
}
|
||||
cService.mcCurrentTime3(
|
||||
new MyAsyncHandler<RetResult<String>, Void>() {
|
||||
@Override
|
||||
public int id() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void completed(RetResult<String> v, Void a) {
|
||||
System.out.println("执行了 BCService.bcCurrentTime3----异步方法3");
|
||||
String rs = "异步bcCurrentTime3: " + (v == null ? null : v.getResult());
|
||||
if (handler != null) {
|
||||
handler.completed(rs, null);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void completed(RetResult<String> v, Void a) {
|
||||
System.out.println("执行了 BCService.bcCurrentTime3----异步方法3");
|
||||
String rs = "异步bcCurrentTime3: " + (v == null ? null : v.getResult());
|
||||
if (handler != null) {
|
||||
handler.completed(rs, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failed(Throwable exc, Void attachment) {
|
||||
}
|
||||
@Override
|
||||
public void failed(Throwable exc, Void attachment) {}
|
||||
|
||||
@Override
|
||||
public int id2() {
|
||||
return 2;
|
||||
}
|
||||
}, name);
|
||||
@Override
|
||||
public int id2() {
|
||||
return 2;
|
||||
}
|
||||
},
|
||||
name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,10 +10,7 @@ import org.redkale.annotation.Resource;
|
||||
import org.redkale.service.*;
|
||||
import org.redkale.util.Times;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class CService implements Service {
|
||||
|
||||
@Resource(name = "@name")
|
||||
@@ -41,7 +38,7 @@ public class CService implements Service {
|
||||
System.out.println("执行了 CService.ccCurrentTime2----异步方法2");
|
||||
if (handler != null) handler.completed(new RetResult(rs), null);
|
||||
}
|
||||
|
||||
|
||||
public void mcCurrentTime3(final MyAsyncHandler<RetResult<String>, Void> handler, final String name) {
|
||||
String rs = "异步mcCurrentTime3: " + name + ": " + Times.formatTime(System.currentTimeMillis());
|
||||
System.out.println("执行了 CService.mcCurrentTime3----异步方法3");
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
package org.redkale.test.service;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
* @param <V> V
|
||||
* @param <A> A
|
||||
@@ -14,5 +13,4 @@ package org.redkale.test.service;
|
||||
public abstract class MyAsyncHandler<V, A> extends MyAsyncInnerHandler<V, A> {
|
||||
|
||||
public abstract int id();
|
||||
|
||||
}
|
||||
|
||||
@@ -7,12 +7,8 @@ package org.redkale.test.service;
|
||||
|
||||
import java.nio.channels.CompletionHandler;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public abstract class MyAsyncInnerHandler<V, A> implements CompletionHandler<V, A> {
|
||||
|
||||
protected abstract int id2();
|
||||
|
||||
}
|
||||
|
||||
@@ -28,5 +28,4 @@ public class Person implements Serializable {
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,10 +5,5 @@
|
||||
*/
|
||||
package org.redkale.test.service;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public class TestBean {
|
||||
|
||||
}
|
||||
/** @author zhangjx */
|
||||
public class TestBean {}
|
||||
|
||||
@@ -11,18 +11,13 @@ import org.redkale.net.sncp.*;
|
||||
import org.redkale.service.*;
|
||||
import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class TestService implements Service {
|
||||
|
||||
// public boolean change(TestBean bean, String name, int id) {
|
||||
// return false;
|
||||
// }
|
||||
public void change(CompletionHandler<Boolean, TestBean> handler, TestBean bean, String name, int id) {
|
||||
|
||||
}
|
||||
// public boolean change(TestBean bean, String name, int id) {
|
||||
// return false;
|
||||
// }
|
||||
public void change(CompletionHandler<Boolean, TestBean> handler, TestBean bean, String name, int id) {}
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
final Application application = Application.create(true);
|
||||
|
||||
@@ -13,10 +13,7 @@ import org.redkale.net.client.*;
|
||||
import org.redkale.net.sncp.*;
|
||||
import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class SncpClientCodecTest {
|
||||
|
||||
private boolean main;
|
||||
@@ -32,7 +29,8 @@ public class SncpClientCodecTest {
|
||||
InetSocketAddress sncpAddress = new InetSocketAddress("127.0.0.1", 3389);
|
||||
InetSocketAddress remoteAddress = new InetSocketAddress("127.0.0.1", 3344);
|
||||
final AsyncIOGroup asyncGroup = new AsyncIOGroup(8192, 16);
|
||||
SncpClient client = new SncpClient("test", asyncGroup, "0", sncpAddress, new ClientAddress(remoteAddress), "TCP", Utility.cpus(), 16);
|
||||
SncpClient client = new SncpClient(
|
||||
"test", asyncGroup, "0", sncpAddress, new ClientAddress(remoteAddress), "TCP", Utility.cpus(), 16);
|
||||
SncpClientConnection conn = client.createClientConnection(asyncGroup.newTCPClientConnection());
|
||||
SncpClientCodec codec = new SncpClientCodec(conn);
|
||||
List respResults = new ArrayList();
|
||||
@@ -44,7 +42,7 @@ public class SncpClientCodecTest {
|
||||
e.printStackTrace();
|
||||
}
|
||||
ByteBuffer realBuf;
|
||||
//----------------------------------------------
|
||||
// ----------------------------------------------
|
||||
respResults.clear();
|
||||
{
|
||||
SncpHeader header = SncpHeader.create(sncpAddress, Uint128.ZERO, "", Uint128.ZERO, "");
|
||||
@@ -53,12 +51,14 @@ public class SncpClientCodecTest {
|
||||
request.prepare(header, 1, "aa", new byte[20]);
|
||||
request.writeTo(conn, writeArray1);
|
||||
System.out.println("request.1 = " + request);
|
||||
System.out.println("headerSize = " + SncpHeader.calcHeaderSize(request) + ", arraySzie = " + writeArray1.getBytes().length);
|
||||
System.out.println("headerSize = " + SncpHeader.calcHeaderSize(request) + ", arraySzie = "
|
||||
+ writeArray1.getBytes().length);
|
||||
ByteArray writeArray2 = new ByteArray();
|
||||
request.prepare(header, 2, "bb", new byte[25]);
|
||||
request.writeTo(conn, writeArray2);
|
||||
System.out.println("request.2 = " + request);
|
||||
System.out.println("headerSize = " + SncpHeader.calcHeaderSize(request) + ", arraySzie = " + writeArray2.getBytes().length);
|
||||
System.out.println("headerSize = " + SncpHeader.calcHeaderSize(request) + ", arraySzie = "
|
||||
+ writeArray2.getBytes().length);
|
||||
writeArray1.put(writeArray2);
|
||||
realBuf = ByteBuffer.wrap(writeArray1.getBytes());
|
||||
}
|
||||
@@ -66,7 +66,7 @@ public class SncpClientCodecTest {
|
||||
codec.decodeMessages(realBuf, new ByteArray());
|
||||
System.out.println("respResults.size = " + respResults.size());
|
||||
Assertions.assertEquals(2, respResults.size());
|
||||
//----------------------------------------------
|
||||
// ----------------------------------------------
|
||||
respResults.clear();
|
||||
{
|
||||
SncpHeader header = SncpHeader.create(sncpAddress, Uint128.ZERO, "", Uint128.ZERO, "");
|
||||
@@ -75,12 +75,14 @@ public class SncpClientCodecTest {
|
||||
request.prepare(header, 1, "", new byte[20]);
|
||||
request.writeTo(conn, writeArray1);
|
||||
System.out.println("request.1 = " + request);
|
||||
System.out.println("headerSize = " + SncpHeader.calcHeaderSize(request) + ", arraySzie = " + writeArray1.getBytes().length);
|
||||
System.out.println("headerSize = " + SncpHeader.calcHeaderSize(request) + ", arraySzie = "
|
||||
+ writeArray1.getBytes().length);
|
||||
ByteArray writeArray2 = new ByteArray();
|
||||
request.prepare(header, 2, "", new byte[25]);
|
||||
request.writeTo(conn, writeArray2);
|
||||
System.out.println("request.2 = " + request);
|
||||
System.out.println("headerSize = " + SncpHeader.calcHeaderSize(request) + ", arraySzie = " + writeArray2.getBytes().length);
|
||||
System.out.println("headerSize = " + SncpHeader.calcHeaderSize(request) + ", arraySzie = "
|
||||
+ writeArray2.getBytes().length);
|
||||
writeArray1.put(writeArray2);
|
||||
realBuf = ByteBuffer.wrap(writeArray1.getBytes());
|
||||
}
|
||||
|
||||
@@ -9,10 +9,7 @@ import java.util.Map;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.redkale.net.sncp.SncpAsyncHandler;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class SncpHandlerTest {
|
||||
|
||||
private boolean main;
|
||||
@@ -26,57 +23,53 @@ public class SncpHandlerTest {
|
||||
@Test
|
||||
public void run() throws Exception {
|
||||
SncpAsyncHandler.createHandler(CompletionHandler.class, new CompletionHandler() {
|
||||
@Override
|
||||
public void completed(Object result, Object attachment) {
|
||||
if (main) {
|
||||
System.out.println("handler result: " + result + ", attachment: " + attachment);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void completed(Object result, Object attachment) {
|
||||
if (main) {
|
||||
System.out.println("handler result: " + result + ", attachment: " + attachment);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failed(Throwable exc, Object attachment) {
|
||||
|
||||
}
|
||||
}).completed(1, 2);
|
||||
@Override
|
||||
public void failed(Throwable exc, Object attachment) {}
|
||||
})
|
||||
.completed(1, 2);
|
||||
|
||||
SncpAsyncHandler.createHandler(ITestHandler1.class, new CompletionHandler() {
|
||||
@Override
|
||||
public void completed(Object result, Object attachment) {
|
||||
System.out.println("handler1 result: " + result + ", attachment: " + attachment);
|
||||
}
|
||||
@Override
|
||||
public void completed(Object result, Object attachment) {
|
||||
System.out.println("handler1 result: " + result + ", attachment: " + attachment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failed(Throwable exc, Object attachment) {
|
||||
|
||||
}
|
||||
}).completed("name", "/user/");
|
||||
@Override
|
||||
public void failed(Throwable exc, Object attachment) {}
|
||||
})
|
||||
.completed("name", "/user/");
|
||||
|
||||
SncpAsyncHandler.createHandler(ITestHandler2.class, new CompletionHandler() {
|
||||
@Override
|
||||
public void completed(Object result, Object attachment) {
|
||||
System.out.println("handler2 result: " + result + ", attachment: " + attachment);
|
||||
}
|
||||
@Override
|
||||
public void completed(Object result, Object attachment) {
|
||||
System.out.println("handler2 result: " + result + ", attachment: " + attachment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failed(Throwable exc, Object attachment) {
|
||||
|
||||
}
|
||||
}).completed("aaa", "bbb");
|
||||
@Override
|
||||
public void failed(Throwable exc, Object attachment) {}
|
||||
})
|
||||
.completed("aaa", "bbb");
|
||||
|
||||
SncpAsyncHandler.createHandler(ITestHandler3.class, new CompletionHandler() {
|
||||
@Override
|
||||
public void completed(Object result, Object attachment) {
|
||||
System.out.println("handler3 result: " + result + ", attachment: " + attachment);
|
||||
}
|
||||
@Override
|
||||
public void completed(Object result, Object attachment) {
|
||||
System.out.println("handler3 result: " + result + ", attachment: " + attachment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failed(Throwable exc, Object attachment) {
|
||||
|
||||
}
|
||||
}).completed("key1", "val1");
|
||||
@Override
|
||||
public void failed(Throwable exc, Object attachment) {}
|
||||
})
|
||||
.completed("key1", "val1");
|
||||
}
|
||||
|
||||
public static abstract class ITestHandler1 implements CompletionHandler<String, File> {
|
||||
public abstract static class ITestHandler1 implements CompletionHandler<String, File> {
|
||||
|
||||
@Override
|
||||
public abstract void completed(String result, File attachment);
|
||||
@@ -87,11 +80,7 @@ public class SncpHandlerTest {
|
||||
public void close(T val);
|
||||
}
|
||||
|
||||
public static interface ITestHandler2 extends CompletionHandler<String, String>, IClose<File> {
|
||||
public static interface ITestHandler2 extends CompletionHandler<String, String>, IClose<File> {}
|
||||
|
||||
}
|
||||
|
||||
public static interface ITestHandler3 extends CompletionHandler<String, String>, Map<String, String> {
|
||||
|
||||
}
|
||||
public static interface ITestHandler3 extends CompletionHandler<String, String>, Map<String, String> {}
|
||||
}
|
||||
|
||||
@@ -13,10 +13,7 @@ import org.redkale.net.client.ClientAddress;
|
||||
import org.redkale.net.sncp.*;
|
||||
import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class SncpRequestParseTest {
|
||||
|
||||
private boolean main;
|
||||
@@ -32,7 +29,8 @@ public class SncpRequestParseTest {
|
||||
InetSocketAddress sncpAddress = new InetSocketAddress("127.0.0.1", 3389);
|
||||
InetSocketAddress remoteAddress = new InetSocketAddress("127.0.0.1", 3344);
|
||||
final AsyncIOGroup asyncGroup = new AsyncIOGroup(8192, 16);
|
||||
SncpClient client = new SncpClient("test", asyncGroup, "0", sncpAddress, new ClientAddress(remoteAddress), "TCP", Utility.cpus(), 16);
|
||||
SncpClient client = new SncpClient(
|
||||
"test", asyncGroup, "0", sncpAddress, new ClientAddress(remoteAddress), "TCP", Utility.cpus(), 16);
|
||||
SncpClientConnection conn = client.createClientConnection(asyncGroup.newTCPClientConnection());
|
||||
|
||||
SncpContext.SncpContextConfig config = new SncpContext.SncpContextConfig();
|
||||
@@ -53,16 +51,21 @@ public class SncpRequestParseTest {
|
||||
|
||||
SncpRequestTest request = new SncpRequestTest(context);
|
||||
Assertions.assertEquals(1, request.readHeader(ByteBuffer.wrap(Arrays.copyOfRange(bs, 0, 1)), null));
|
||||
Assertions.assertEquals(headerSize - 2, request.readHeader(ByteBuffer.wrap(Arrays.copyOfRange(bs, 1, 2)), null));
|
||||
Assertions.assertEquals(
|
||||
headerSize - 2, request.readHeader(ByteBuffer.wrap(Arrays.copyOfRange(bs, 1, 2)), null));
|
||||
Assertions.assertEquals(0, request.readHeader(ByteBuffer.wrap(Arrays.copyOfRange(bs, 2, bs.length)), null));
|
||||
Assertions.assertEquals("aa", request.getHeader().getTraceid());
|
||||
|
||||
System.out.println("测试第二段");
|
||||
request = new SncpRequestTest(context);
|
||||
Assertions.assertEquals(1, request.readHeader(ByteBuffer.wrap(Arrays.copyOfRange(bs, 0, 1)), null));
|
||||
Assertions.assertEquals(headerSize - 2, request.readHeader(ByteBuffer.wrap(Arrays.copyOfRange(bs, 1, 2)), null));
|
||||
Assertions.assertEquals(headerSize - headerSize / 2, request.readHeader(ByteBuffer.wrap(Arrays.copyOfRange(bs, 2, headerSize / 2)), null));
|
||||
Assertions.assertEquals(0, request.readHeader(ByteBuffer.wrap(Arrays.copyOfRange(bs, headerSize / 2, bs.length)), null));
|
||||
Assertions.assertEquals(
|
||||
headerSize - 2, request.readHeader(ByteBuffer.wrap(Arrays.copyOfRange(bs, 1, 2)), null));
|
||||
Assertions.assertEquals(
|
||||
headerSize - headerSize / 2,
|
||||
request.readHeader(ByteBuffer.wrap(Arrays.copyOfRange(bs, 2, headerSize / 2)), null));
|
||||
Assertions.assertEquals(
|
||||
0, request.readHeader(ByteBuffer.wrap(Arrays.copyOfRange(bs, headerSize / 2, bs.length)), null));
|
||||
Assertions.assertEquals("aa", request.getHeader().getTraceid());
|
||||
}
|
||||
|
||||
|
||||
@@ -8,36 +8,42 @@ import org.redkale.service.AbstractService;
|
||||
import org.redkale.util.Times;
|
||||
import org.redkale.util.Utility;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class SncpSleepService extends AbstractService {
|
||||
|
||||
public CompletableFuture<String> sleep200() {
|
||||
System.out.println(Times.nowMillis() + " " + Thread.currentThread().getName() + " 接收sleep200");
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
Utility.sleep(200);
|
||||
System.out.println(Times.nowMillis() + " " + Thread.currentThread().getName() + " 执行完sleep200");
|
||||
return "ok200";
|
||||
}, getExecutor());
|
||||
return CompletableFuture.supplyAsync(
|
||||
() -> {
|
||||
Utility.sleep(200);
|
||||
System.out.println(
|
||||
Times.nowMillis() + " " + Thread.currentThread().getName() + " 执行完sleep200");
|
||||
return "ok200";
|
||||
},
|
||||
getExecutor());
|
||||
}
|
||||
|
||||
public CompletableFuture<String> sleep300() {
|
||||
System.out.println(Times.nowMillis() + " " + Thread.currentThread().getName() + " 接收sleep300");
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
Utility.sleep(300);
|
||||
System.out.println(Times.nowMillis() + " " + Thread.currentThread().getName() + " 执行完sleep300");
|
||||
return "ok300";
|
||||
}, getExecutor());
|
||||
return CompletableFuture.supplyAsync(
|
||||
() -> {
|
||||
Utility.sleep(300);
|
||||
System.out.println(
|
||||
Times.nowMillis() + " " + Thread.currentThread().getName() + " 执行完sleep300");
|
||||
return "ok300";
|
||||
},
|
||||
getExecutor());
|
||||
}
|
||||
|
||||
public CompletableFuture<String> sleep500() {
|
||||
System.out.println(Times.nowMillis() + " " + Thread.currentThread().getName() + " 接收sleep500");
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
Utility.sleep(500);
|
||||
System.out.println(Times.nowMillis() + " " + Thread.currentThread().getName() + " 执行完sleep500");
|
||||
return "ok500";
|
||||
}, getExecutor());
|
||||
return CompletableFuture.supplyAsync(
|
||||
() -> {
|
||||
Utility.sleep(500);
|
||||
System.out.println(
|
||||
Times.nowMillis() + " " + Thread.currentThread().getName() + " 执行完sleep500");
|
||||
return "ok500";
|
||||
},
|
||||
getExecutor());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,10 +14,7 @@ import org.redkale.net.client.ClientAddress;
|
||||
import org.redkale.net.sncp.*;
|
||||
import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class SncpSleepTest {
|
||||
|
||||
private boolean main;
|
||||
@@ -40,7 +37,7 @@ public class SncpSleepTest {
|
||||
resFactory.register(JsonConvert.root());
|
||||
resFactory.register(BsonConvert.root());
|
||||
|
||||
//------------------------ 初始化 CService ------------------------------------
|
||||
// ------------------------ 初始化 CService ------------------------------------
|
||||
SncpSleepService service = Sncp.createSimpleLocalService(SncpSleepService.class, resFactory);
|
||||
resFactory.inject(service);
|
||||
SncpServer server = new SncpServer(application, System.currentTimeMillis(), null, resFactory);
|
||||
@@ -52,16 +49,16 @@ public class SncpSleepTest {
|
||||
int port = server.getSocketAddress().getPort();
|
||||
System.out.println("SNCP服务器启动端口: " + port);
|
||||
InetSocketAddress sncpAddress = new InetSocketAddress("127.0.0.1", port);
|
||||
final SncpClient client = new SncpClient("", asyncGroup, "0", sncpAddress, new ClientAddress(sncpAddress), "TCP", 16, 100);
|
||||
final SncpClient client =
|
||||
new SncpClient("", asyncGroup, "0", sncpAddress, new ClientAddress(sncpAddress), "TCP", 16, 100);
|
||||
final SncpRpcGroups rpcGroups = application.getSncpRpcGroups();
|
||||
rpcGroups.computeIfAbsent("cs", "TCP").putAddress(sncpAddress);
|
||||
SncpSleepService remoteCService = Sncp.createSimpleRemoteService(SncpSleepService.class, resFactory, rpcGroups, client, "cs");
|
||||
SncpSleepService remoteCService =
|
||||
Sncp.createSimpleRemoteService(SncpSleepService.class, resFactory, rpcGroups, client, "cs");
|
||||
long s = System.currentTimeMillis();
|
||||
CompletableFuture[] futures = new CompletableFuture[]{
|
||||
remoteCService.sleep200(),
|
||||
remoteCService.sleep300(),
|
||||
remoteCService.sleep500()
|
||||
};
|
||||
CompletableFuture[] futures =
|
||||
new CompletableFuture[] {remoteCService.sleep200(), remoteCService.sleep300(), remoteCService.sleep500()
|
||||
};
|
||||
CompletableFuture.allOf(futures).join();
|
||||
long e = System.currentTimeMillis() - s;
|
||||
System.out.println("耗时: " + e + " ms");
|
||||
|
||||
@@ -18,10 +18,7 @@ import org.redkale.net.sncp.*;
|
||||
import org.redkale.service.Service;
|
||||
import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class SncpTest {
|
||||
|
||||
private static final String myhost = "127.0.0.1";
|
||||
@@ -73,26 +70,44 @@ public class SncpTest {
|
||||
|
||||
private void runClient() throws Exception {
|
||||
InetSocketAddress addr = new InetSocketAddress(myhost, port);
|
||||
rpcGroups.computeIfAbsent("client", protocol.endsWith(".UDP") ? "UDP" : "TCP").putAddress(addr);
|
||||
rpcGroups
|
||||
.computeIfAbsent("client", protocol.endsWith(".UDP") ? "UDP" : "TCP")
|
||||
.putAddress(addr);
|
||||
if (port2 > 0) {
|
||||
rpcGroups.computeIfAbsent("client", protocol.endsWith(".UDP") ? "UDP" : "TCP").putAddress(new InetSocketAddress(myhost, port2));
|
||||
rpcGroups
|
||||
.computeIfAbsent("client", protocol.endsWith(".UDP") ? "UDP" : "TCP")
|
||||
.putAddress(new InetSocketAddress(myhost, port2));
|
||||
}
|
||||
final AsyncIOGroup asyncGroup = new AsyncIOGroup(clientCapacity, 16);
|
||||
asyncGroup.start();
|
||||
|
||||
InetSocketAddress sncpAddress = addr;
|
||||
final SncpClient client = new SncpClient("", asyncGroup, "0", sncpAddress, new ClientAddress(sncpAddress), protocol.endsWith(".UDP") ? "UDP" : "TCP", 16, 100);
|
||||
final SncpClient client = new SncpClient(
|
||||
"",
|
||||
asyncGroup,
|
||||
"0",
|
||||
sncpAddress,
|
||||
new ClientAddress(sncpAddress),
|
||||
protocol.endsWith(".UDP") ? "UDP" : "TCP",
|
||||
16,
|
||||
100);
|
||||
|
||||
final SncpTestIService service = Sncp.createSimpleRemoteService(SncpTestIService.class, factory, rpcGroups, client, "client");//Sncp.createSimpleRemoteService(SncpTestIService.class, null, transFactory, addr, "client");
|
||||
final SncpTestIService service = Sncp.createSimpleRemoteService(
|
||||
SncpTestIService.class,
|
||||
factory,
|
||||
rpcGroups,
|
||||
client,
|
||||
"client"); // Sncp.createSimpleRemoteService(SncpTestIService.class, null, transFactory, addr,
|
||||
// "client");
|
||||
factory.inject(service);
|
||||
|
||||
// SncpTestBean bean = new SncpTestBean();
|
||||
// StringBuilder sb = new StringBuilder();
|
||||
// for (int i = 0; i < 2000; i++) {
|
||||
// sb.append("_").append(i).append("_0123456789");
|
||||
// }
|
||||
// bean.setContent(sb.toString());
|
||||
// bean.setContent("hello sncp");
|
||||
// SncpTestBean bean = new SncpTestBean();
|
||||
// StringBuilder sb = new StringBuilder();
|
||||
// for (int i = 0; i < 2000; i++) {
|
||||
// sb.append("_").append(i).append("_0123456789");
|
||||
// }
|
||||
// bean.setContent(sb.toString());
|
||||
// bean.setContent("hello sncp");
|
||||
SncpTestBean callbean = new SncpTestBean();
|
||||
callbean.setId(1);
|
||||
callbean.setContent("数据X");
|
||||
@@ -112,7 +127,7 @@ public class SncpTest {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
//Thread.sleep(k);
|
||||
// Thread.sleep(k);
|
||||
SncpTestBean bean = new SncpTestBean();
|
||||
bean.setId(k);
|
||||
bean.setContent("数据: " + k);
|
||||
@@ -124,12 +139,13 @@ public class SncpTest {
|
||||
bean.setContent(sb.toString());
|
||||
|
||||
service.queryResult(bean);
|
||||
//service.updateBean(bean);
|
||||
// service.updateBean(bean);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
long a = ai.incrementAndGet();
|
||||
System.out.println("运行了 " + (a == 100 ? "--------------------------------------------------" : "") + a);
|
||||
System.out.println(
|
||||
"运行了 " + (a == 100 ? "--------------------------------------------------" : "") + a);
|
||||
cld.countDown();
|
||||
}
|
||||
}
|
||||
@@ -148,7 +164,8 @@ public class SncpTest {
|
||||
long s2 = System.currentTimeMillis();
|
||||
final CompletableFuture<String> future = service.queryResultAsync(callbean);
|
||||
future.whenComplete((v, e) -> {
|
||||
System.out.println("异步执行结果: " + v + ", 异常为: " + e + ", 耗时: " + (System.currentTimeMillis() - s2) / 1000.0 + "s");
|
||||
System.out.println(
|
||||
"异步执行结果: " + v + ", 异常为: " + e + ", 耗时: " + (System.currentTimeMillis() - s2) / 1000.0 + "s");
|
||||
cld2.countDown();
|
||||
});
|
||||
cld2.await();
|
||||
@@ -175,10 +192,15 @@ public class SncpTest {
|
||||
conf.addValue("maxbody", "" + (100 * 1024 * 1024));
|
||||
SncpServer server = new SncpServer(null, System.currentTimeMillis(), conf, factory);
|
||||
if (port2 > 0) {
|
||||
rpcGroups.computeIfAbsent("server", protocol.endsWith(".UDP") ? "UDP" : "TCP").putAddress(new InetSocketAddress(myhost, port2));
|
||||
rpcGroups
|
||||
.computeIfAbsent("server", protocol.endsWith(".UDP") ? "UDP" : "TCP")
|
||||
.putAddress(new InetSocketAddress(myhost, port2));
|
||||
}
|
||||
|
||||
SncpTestIService service = Sncp.createSimpleLocalService(SncpTestServiceImpl.class, factory); //Sncp.createSimpleLocalService(SncpTestServiceImpl.class, null, factory, transFactory, addr, "server");
|
||||
SncpTestIService service = Sncp.createSimpleLocalService(
|
||||
SncpTestServiceImpl.class,
|
||||
factory); // Sncp.createSimpleLocalService(SncpTestServiceImpl.class, null, factory,
|
||||
// transFactory, addr, "server");
|
||||
factory.inject(service);
|
||||
server.addSncpServlet(service);
|
||||
System.out.println(service);
|
||||
@@ -213,9 +235,14 @@ public class SncpTest {
|
||||
conf.addValue("protocol", protocol);
|
||||
conf.addValue("maxbody", "" + (100 * 1024 * 1024));
|
||||
SncpServer server = new SncpServer(null, System.currentTimeMillis(), conf, factory);
|
||||
rpcGroups.computeIfAbsent("server", protocol.endsWith(".UDP") ? "UDP" : "TCP").putAddress(new InetSocketAddress(myhost, port));
|
||||
rpcGroups
|
||||
.computeIfAbsent("server", protocol.endsWith(".UDP") ? "UDP" : "TCP")
|
||||
.putAddress(new InetSocketAddress(myhost, port));
|
||||
|
||||
Service service = Sncp.createSimpleLocalService(SncpTestServiceImpl.class, factory); //Sncp.createSimpleLocalService(SncpTestServiceImpl.class, null, factory, transFactory, addr, "server");
|
||||
Service service = Sncp.createSimpleLocalService(
|
||||
SncpTestServiceImpl.class,
|
||||
factory); // Sncp.createSimpleLocalService(SncpTestServiceImpl.class, null, factory,
|
||||
// transFactory, addr, "server");
|
||||
server.addSncpServlet(service);
|
||||
server.init(conf);
|
||||
server.start();
|
||||
@@ -228,5 +255,4 @@ public class SncpTest {
|
||||
}.start();
|
||||
cdl.await();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,10 +11,7 @@ import org.redkale.persistence.Id;
|
||||
import org.redkale.source.FilterBean;
|
||||
import org.redkale.util.Utility;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class SncpTestBean implements FilterBean {
|
||||
|
||||
@Id
|
||||
@@ -28,7 +25,10 @@ public class SncpTestBean implements FilterBean {
|
||||
System.out.println(bean);
|
||||
byte[] bs = BsonFactory.root().getConvert().convertTo(bean);
|
||||
Utility.println("---------", bs);
|
||||
System.out.println(BsonFactory.root().getConvert().convertFrom(SncpTestBean.class, bs).toString());
|
||||
System.out.println(BsonFactory.root()
|
||||
.getConvert()
|
||||
.convertFrom(SncpTestBean.class, bs)
|
||||
.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -51,5 +51,4 @@ public class SncpTestBean implements FilterBean {
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,10 +8,7 @@ package org.redkale.test.sncp;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import org.redkale.service.Service;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public interface SncpTestIService extends Service {
|
||||
|
||||
public String queryResult(SncpTestBean bean);
|
||||
|
||||
@@ -18,10 +18,7 @@ import org.redkale.net.sncp.*;
|
||||
import org.redkale.service.*;
|
||||
import org.redkale.util.Utility;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
@ResourceType(SncpTestIService.class)
|
||||
public class SncpTestServiceImpl implements SncpTestIService {
|
||||
|
||||
@@ -33,7 +30,8 @@ public class SncpTestServiceImpl implements SncpTestIService {
|
||||
public void run() {
|
||||
try {
|
||||
Utility.sleep(200);
|
||||
System.out.println(Thread.currentThread().getName() + " sleep 200ms后运行了异步方法-----------queryResultAsync方法");
|
||||
System.out.println(
|
||||
Thread.currentThread().getName() + " sleep 200ms后运行了异步方法-----------queryResultAsync方法");
|
||||
future.complete("异步 result: " + bean);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@@ -41,7 +39,6 @@ public class SncpTestServiceImpl implements SncpTestIService {
|
||||
}
|
||||
}.start();
|
||||
return future;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -67,7 +64,8 @@ public class SncpTestServiceImpl implements SncpTestIService {
|
||||
|
||||
@Override
|
||||
public String queryResult(SncpTestBean bean) {
|
||||
System.out.println(Thread.currentThread().getName() + " 运行了queryResult方法 content-length: " + bean.getContent().length());
|
||||
System.out.println(Thread.currentThread().getName() + " 运行了queryResult方法 content-length: "
|
||||
+ bean.getContent().length());
|
||||
return "result-content: " + bean.getContent();
|
||||
}
|
||||
|
||||
@@ -94,7 +92,8 @@ public class SncpTestServiceImpl implements SncpTestIService {
|
||||
final SncpRpcGroups rpcGroups = application.getSncpRpcGroups();
|
||||
InetSocketAddress sncpAddress = new InetSocketAddress("127.0.0.1", 7070);
|
||||
rpcGroups.computeIfAbsent("g70", "TCP").putAddress(sncpAddress);
|
||||
final SncpClient client = new SncpClient("", asyncGroup, "0", sncpAddress, new ClientAddress(sncpAddress), "TCP", 16, 100);
|
||||
final SncpClient client =
|
||||
new SncpClient("", asyncGroup, "0", sncpAddress, new ClientAddress(sncpAddress), "TCP", 16, 100);
|
||||
|
||||
Service service = Sncp.createSimpleLocalService(SncpTestServiceImpl.class, factory);
|
||||
for (Method method : service.getClass().getDeclaredMethods()) {
|
||||
|
||||
@@ -14,20 +14,17 @@ import org.redkale.service.Service;
|
||||
import org.redkale.test.util.TestBean;
|
||||
import org.redkale.util.Uint128;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public interface TestService extends Service {
|
||||
|
||||
public boolean change(TestBean bean, String name, int id);
|
||||
|
||||
public void insert(BooleanHandler handler, TestBean bean, String name, int id);
|
||||
|
||||
public void update(long show, short v2, CompletionHandler<Boolean, TestBean> handler, TestBean bean, String name, int id);
|
||||
public void update(
|
||||
long show, short v2, CompletionHandler<Boolean, TestBean> handler, TestBean bean, String name, int id);
|
||||
|
||||
public CompletableFuture<String> changeName(TestBean bean, String name, int id);
|
||||
|
||||
}
|
||||
|
||||
@ResourceType(TestService.class)
|
||||
@@ -38,16 +35,14 @@ class TestServiceImpl implements TestService {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void delete(TestBean bean) {
|
||||
}
|
||||
public void delete(TestBean bean) {}
|
||||
|
||||
@Override
|
||||
public void insert(BooleanHandler handler, TestBean bean, String name, int id) {
|
||||
}
|
||||
public void insert(BooleanHandler handler, TestBean bean, String name, int id) {}
|
||||
|
||||
@Override
|
||||
public void update(long show, short v2, CompletionHandler<Boolean, TestBean> handler, TestBean bean, String name, int id) {
|
||||
}
|
||||
public void update(
|
||||
long show, short v2, CompletionHandler<Boolean, TestBean> handler, TestBean bean, String name, int id) {}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<String> changeName(TestBean bean, String name, int id) {
|
||||
@@ -58,18 +53,21 @@ class TestServiceImpl implements TestService {
|
||||
class BooleanHandler implements CompletionHandler<Boolean, TestBean> {
|
||||
|
||||
@Override
|
||||
public void completed(Boolean result, TestBean attachment) {
|
||||
}
|
||||
public void completed(Boolean result, TestBean attachment) {}
|
||||
|
||||
@Override
|
||||
public void failed(Throwable exc, TestBean attachment) {
|
||||
}
|
||||
|
||||
public void failed(Throwable exc, TestBean attachment) {}
|
||||
}
|
||||
|
||||
class DynActionTestService_change extends SncpActionServlet {
|
||||
|
||||
public DynActionTestService_change(String resourceName, Class resourceType, Service service, Uint128 serviceid, Uint128 actionid, final Method method) {
|
||||
public DynActionTestService_change(
|
||||
String resourceName,
|
||||
Class resourceType,
|
||||
Service service,
|
||||
Uint128 serviceid,
|
||||
Uint128 actionid,
|
||||
final Method method) {
|
||||
super(resourceName, resourceType, service, serviceid, actionid, method);
|
||||
}
|
||||
|
||||
@@ -88,7 +86,13 @@ class DynActionTestService_change extends SncpActionServlet {
|
||||
|
||||
class DynActionTestService_insert extends SncpActionServlet {
|
||||
|
||||
public DynActionTestService_insert(String resourceName, Class resourceType, Service service, Uint128 serviceid, Uint128 actionid, final Method method) {
|
||||
public DynActionTestService_insert(
|
||||
String resourceName,
|
||||
Class resourceType,
|
||||
Service service,
|
||||
Uint128 serviceid,
|
||||
Uint128 actionid,
|
||||
final Method method) {
|
||||
super(resourceName, resourceType, service, serviceid, actionid, method);
|
||||
}
|
||||
|
||||
@@ -109,7 +113,13 @@ class DynActionTestService_insert extends SncpActionServlet {
|
||||
|
||||
class DynActionTestService_update extends SncpActionServlet {
|
||||
|
||||
public DynActionTestService_update(String resourceName, Class resourceType, Service service, Uint128 serviceid, Uint128 actionid, final Method method) {
|
||||
public DynActionTestService_update(
|
||||
String resourceName,
|
||||
Class resourceType,
|
||||
Service service,
|
||||
Uint128 serviceid,
|
||||
Uint128 actionid,
|
||||
final Method method) {
|
||||
super(resourceName, resourceType, service, serviceid, actionid, method);
|
||||
}
|
||||
|
||||
@@ -132,7 +142,13 @@ class DynActionTestService_update extends SncpActionServlet {
|
||||
|
||||
class DynActionTestService_changeName extends SncpActionServlet {
|
||||
|
||||
public DynActionTestService_changeName(String resourceName, Class resourceType, Service service, Uint128 serviceid, Uint128 actionid, final Method method) {
|
||||
public DynActionTestService_changeName(
|
||||
String resourceName,
|
||||
Class resourceType,
|
||||
Service service,
|
||||
Uint128 serviceid,
|
||||
Uint128 actionid,
|
||||
final Method method) {
|
||||
super(resourceName, resourceType, service, serviceid, actionid, method);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,12 +7,6 @@ package org.redkale.test.sncp;
|
||||
|
||||
import org.redkale.annotation.ResourceType;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
@ResourceType(SncpTestIService.class)
|
||||
public class _DynLocalSncpTestService extends SncpTestServiceImpl {
|
||||
|
||||
|
||||
}
|
||||
public class _DynLocalSncpTestService extends SncpTestServiceImpl {}
|
||||
|
||||
@@ -8,15 +8,11 @@ package org.redkale.test.source;
|
||||
import java.io.Serializable;
|
||||
import org.redkale.convert.json.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public abstract class BaseEntity implements Serializable {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonConvert.root().convertTo(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,10 +27,7 @@ import org.redkale.source.Flipper;
|
||||
import org.redkale.util.TypeToken;
|
||||
import org.redkale.util.Utility;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class CacheMemorySourceTest {
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
@@ -91,7 +88,8 @@ public class CacheMemorySourceTest {
|
||||
|
||||
Map<String, Flipper> flippermap = source.mgets(Flipper.class, "objitem1", "objitem2");
|
||||
System.out.println("[有值] MGET : " + flippermap);
|
||||
Assertions.assertTrue(Utility.equalsElement(Utility.ofMap("objitem1", new Flipper(10), "objitem2", new Flipper(20)), flippermap));
|
||||
Assertions.assertTrue(Utility.equalsElement(
|
||||
Utility.ofMap("objitem1", new Flipper(10), "objitem2", new Flipper(20)), flippermap));
|
||||
|
||||
source.del("key1", "key2", "300");
|
||||
source.setex("key1", 1000, String.class, "value1");
|
||||
@@ -179,7 +177,8 @@ public class CacheMemorySourceTest {
|
||||
source.sadd("stringmap", JsonConvert.TYPE_MAP_STRING_STRING, Utility.ofMap("c", "cc", "d", "dd"));
|
||||
col = source.smembers("stringmap", JsonConvert.TYPE_MAP_STRING_STRING);
|
||||
System.out.println("[两值] stringmap VALUES : " + col);
|
||||
Assertions.assertTrue(Utility.equalsElement(List.of(Utility.ofMap("c", "cc", "d", "dd"), Utility.ofMap("a", "aa", "b", "bb")), col));
|
||||
Assertions.assertTrue(Utility.equalsElement(
|
||||
List.of(Utility.ofMap("c", "cc", "d", "dd"), Utility.ofMap("a", "aa", "b", "bb")), col));
|
||||
|
||||
source.del("sets3");
|
||||
source.del("sets4");
|
||||
@@ -247,7 +246,10 @@ public class CacheMemorySourceTest {
|
||||
}
|
||||
});
|
||||
mapcol.putAll(news);
|
||||
Assertions.assertEquals(Utility.ofMap("sets3", List.of("setvals2"), "sets4", List.of("setvals1", "setvals2")).toString(), mapcol.toString());
|
||||
Assertions.assertEquals(
|
||||
Utility.ofMap("sets3", List.of("setvals2"), "sets4", List.of("setvals1", "setvals2"))
|
||||
.toString(),
|
||||
mapcol.toString());
|
||||
|
||||
source.del("sets3");
|
||||
source.del("sets4");
|
||||
@@ -282,7 +284,8 @@ public class CacheMemorySourceTest {
|
||||
Assertions.assertIterableEquals(interanswer, interset);
|
||||
|
||||
source.del("sets6");
|
||||
Set<String> unionanswer = new TreeSet<>(Set.of("setvals1", "setvals2", "setvals3", "setvals4", "setvals5", "setvals6", "setvals7", "setvals8"));
|
||||
Set<String> unionanswer = new TreeSet<>(
|
||||
Set.of("setvals1", "setvals2", "setvals3", "setvals4", "setvals5", "setvals6", "setvals7", "setvals8"));
|
||||
Set<String> unionset = new TreeSet<>(source.sunionString("sets3", "sets4", "sets5"));
|
||||
System.out.println("sunion: " + unionset);
|
||||
Assertions.assertIterableEquals(unionanswer, unionset);
|
||||
@@ -349,12 +352,14 @@ public class CacheMemorySourceTest {
|
||||
}
|
||||
});
|
||||
mapcol.putAll(news2);
|
||||
Assertions.assertEquals(Utility.ofMap("myaddrs", List.of(addr99), "myaddrs2", List.of(addr88, addr99)).toString(), mapcol.toString());
|
||||
Assertions.assertEquals(
|
||||
Utility.ofMap("myaddrs", List.of(addr99), "myaddrs2", List.of(addr88, addr99))
|
||||
.toString(),
|
||||
mapcol.toString());
|
||||
|
||||
System.out.println("------------------------------------");
|
||||
source.del("myaddrs");
|
||||
Type mapType = new TypeToken<Map<String, Integer>>() {
|
||||
}.getType();
|
||||
Type mapType = new TypeToken<Map<String, Integer>>() {}.getType();
|
||||
Map<String, Integer> paramap = new HashMap<>();
|
||||
paramap.put("a", 1);
|
||||
paramap.put("b", 2);
|
||||
@@ -369,17 +374,31 @@ public class CacheMemorySourceTest {
|
||||
Assertions.assertIterableEquals(List.of("111", "222"), source.hvals("hmapall", String.class));
|
||||
Assertions.assertIterableEquals(List.of("111", "222"), source.hvalsString("hmapall"));
|
||||
Assertions.assertIterableEquals(List.of(111L, 222L), source.hvalsLong("hmapall"));
|
||||
Assertions.assertIterableEquals(List.of("111", "222"), source.hvalsAsync("hmapall", String.class).join());
|
||||
Assertions.assertIterableEquals(List.of("111", "222"), source.hvalsStringAsync("hmapall").join());
|
||||
Assertions.assertIterableEquals(List.of(111L, 222L), source.hvalsLongAsync("hmapall").join());
|
||||
Assertions.assertIterableEquals(
|
||||
List.of("111", "222"),
|
||||
source.hvalsAsync("hmapall", String.class).join());
|
||||
Assertions.assertIterableEquals(
|
||||
List.of("111", "222"), source.hvalsStringAsync("hmapall").join());
|
||||
Assertions.assertIterableEquals(
|
||||
List.of(111L, 222L), source.hvalsLongAsync("hmapall").join());
|
||||
Assertions.assertEquals(Utility.ofMap("k1", "111", "k2", "222"), source.hgetall("hmapall", String.class));
|
||||
Assertions.assertEquals(Utility.ofMap("k1", "111", "k2", "222"), source.hgetallString("hmapall"));
|
||||
Assertions.assertEquals(JsonConvert.root().convertTo(Utility.ofMap("k1", 111L, "k2", 222L)), JsonConvert.root().convertTo(source.hgetallLong("hmapall")));
|
||||
Assertions.assertEquals(JsonConvert.root().convertTo(Utility.ofMap("k1", "111", "k2", "222")), JsonConvert.root().convertTo(source.hgetallAsync("hmapall", String.class).join()));
|
||||
Assertions.assertEquals(JsonConvert.root().convertTo(Utility.ofMap("k1", "111", "k2", "222")), JsonConvert.root().convertTo(source.hgetallStringAsync("hmapall").join()));
|
||||
Assertions.assertEquals(JsonConvert.root().convertTo(Utility.ofMap("k1", 111L, "k2", 222L)), JsonConvert.root().convertTo(source.hgetallLongAsync("hmapall").join()));
|
||||
Assertions.assertEquals(
|
||||
JsonConvert.root().convertTo(Utility.ofMap("k1", 111L, "k2", 222L)),
|
||||
JsonConvert.root().convertTo(source.hgetallLong("hmapall")));
|
||||
Assertions.assertEquals(
|
||||
JsonConvert.root().convertTo(Utility.ofMap("k1", "111", "k2", "222")),
|
||||
JsonConvert.root()
|
||||
.convertTo(source.hgetallAsync("hmapall", String.class).join()));
|
||||
Assertions.assertEquals(
|
||||
JsonConvert.root().convertTo(Utility.ofMap("k1", "111", "k2", "222")),
|
||||
JsonConvert.root()
|
||||
.convertTo(source.hgetallStringAsync("hmapall").join()));
|
||||
Assertions.assertEquals(
|
||||
JsonConvert.root().convertTo(Utility.ofMap("k1", 111L, "k2", 222L)),
|
||||
JsonConvert.root().convertTo(source.hgetallLongAsync("hmapall").join()));
|
||||
|
||||
//h
|
||||
// h
|
||||
source.del("hmap");
|
||||
source.hincr("hmap", "key1");
|
||||
num = source.hgetLong("hmap", "key1", -1);
|
||||
@@ -449,7 +468,7 @@ public class CacheMemorySourceTest {
|
||||
cursor = new AtomicLong();
|
||||
Map<String, String> smap = source.hscan("hmap", String.class, cursor, 5);
|
||||
System.out.println("hmap.hscan 长度 : " + smap.size() + ", cursor: " + cursor + ", 内容: " + smap);
|
||||
//smap.size 是不确定的,可能是全量,也可能比5多,也可能比5少
|
||||
// smap.size 是不确定的,可能是全量,也可能比5多,也可能比5少
|
||||
Assertions.assertFalse(smap.isEmpty());
|
||||
if (smap.size() == ccc) {
|
||||
Assertions.assertTrue(cursor.get() == 0);
|
||||
@@ -477,12 +496,14 @@ public class CacheMemorySourceTest {
|
||||
Assertions.assertEquals(1L, source.zrevrank("sortset", "key400"));
|
||||
Assertions.assertEquals(List.of("key100", "key200", "key300"), source.zrange("sortset", 0, 2));
|
||||
cursor = new AtomicLong();
|
||||
Assertions.assertEquals(List.of(CacheScoredValue.create(100, "key100"),
|
||||
CacheScoredValue.create(200, "key200"),
|
||||
CacheScoredValue.create(300, "key300"),
|
||||
CacheScoredValue.create(400, "key400"),
|
||||
CacheScoredValue.create(500, "key500")
|
||||
), source.zscanInteger("sortset", cursor, -1));
|
||||
Assertions.assertEquals(
|
||||
List.of(
|
||||
CacheScoredValue.create(100, "key100"),
|
||||
CacheScoredValue.create(200, "key200"),
|
||||
CacheScoredValue.create(300, "key300"),
|
||||
CacheScoredValue.create(400, "key400"),
|
||||
CacheScoredValue.create(500, "key500")),
|
||||
source.zscanInteger("sortset", cursor, -1));
|
||||
|
||||
size = source.zcard("sortset");
|
||||
Assertions.assertEquals(5, size);
|
||||
@@ -511,7 +532,7 @@ public class CacheMemorySourceTest {
|
||||
cursor = new AtomicLong();
|
||||
Set<String> sset = source.sscan("popset", String.class, cursor, 3);
|
||||
System.out.println("popset.sscan 长度 : " + sset.size() + ", cursor: " + cursor + ", 内容: " + sset);
|
||||
//smap.size 是不确定的,可能是全量,也可能比5多,也可能比5少
|
||||
// smap.size 是不确定的,可能是全量,也可能比5多,也可能比5少
|
||||
Assertions.assertFalse(sset.isEmpty());
|
||||
if (sset.size() == 5) {
|
||||
Assertions.assertTrue(cursor.get() == 0);
|
||||
@@ -560,7 +581,8 @@ public class CacheMemorySourceTest {
|
||||
|
||||
cursor = new AtomicLong();
|
||||
List<String> keys = source.scan(cursor, 5);
|
||||
System.out.println("scan 长度 : " + keys.size() + ", dbsize: " + source.dbsize() + ", cursor: " + cursor + ", 内容: " + keys);
|
||||
System.out.println(
|
||||
"scan 长度 : " + keys.size() + ", dbsize: " + source.dbsize() + ", cursor: " + cursor + ", 内容: " + keys);
|
||||
Assertions.assertFalse(keys.isEmpty());
|
||||
if (keys.size() == source.dbsize()) {
|
||||
Assertions.assertTrue(cursor.get() == 0);
|
||||
@@ -573,7 +595,7 @@ public class CacheMemorySourceTest {
|
||||
|
||||
long dbsize = source.dbsize();
|
||||
System.out.println("keys总数量 : " + dbsize);
|
||||
//清除
|
||||
// 清除
|
||||
long rs = source.del("stritem1");
|
||||
System.out.println("删除stritem1个数: " + rs);
|
||||
source.del("popset");
|
||||
@@ -622,7 +644,7 @@ public class CacheMemorySourceTest {
|
||||
System.out.println("订阅结束");
|
||||
source.publish(channel, content);
|
||||
System.out.println("发布结束");
|
||||
if (!source.getClass().getName().contains("Redisson")) { //Redisson不支持
|
||||
if (!source.getClass().getName().contains("Redisson")) { // Redisson不支持
|
||||
List<String> channels = source.pubsubChannels(null);
|
||||
Assertions.assertEquals(List.of(channel), channels);
|
||||
}
|
||||
@@ -638,5 +660,4 @@ public class CacheMemorySourceTest {
|
||||
source.unsubscribe(listener, channel);
|
||||
System.out.println("取消订阅结束");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,10 +14,7 @@ import org.redkale.persistence.*;
|
||||
import org.redkale.persistence.VirtualEntity;
|
||||
import org.redkale.source.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
@VirtualEntity(loader = CacheTestBean.DefaultBeanLoader.class)
|
||||
public class CacheTestBean {
|
||||
|
||||
@@ -29,9 +26,11 @@ public class CacheTestBean {
|
||||
private long price;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
Method method = EntityInfo.class.getDeclaredMethod("load", Class.class, boolean.class, Properties.class, DataSource.class, BiFunction.class);
|
||||
Method method = EntityInfo.class.getDeclaredMethod(
|
||||
"load", Class.class, boolean.class, Properties.class, DataSource.class, BiFunction.class);
|
||||
method.setAccessible(true);
|
||||
final EntityInfo<CacheTestBean> info = (EntityInfo<CacheTestBean>) method.invoke(null, CacheTestBean.class, true, new Properties(), null, new CacheTestBean.DefaultBeanLoader());
|
||||
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.fullLoadAsync();
|
||||
|
||||
@@ -50,8 +49,7 @@ public class CacheTestBean {
|
||||
System.out.println(cache.querySheet(null, null, FilterNodes.igNotLike(CacheTestBean::getName, "B")));
|
||||
}
|
||||
|
||||
public CacheTestBean() {
|
||||
}
|
||||
public CacheTestBean() {}
|
||||
|
||||
public CacheTestBean(long pkgid, String name, long price) {
|
||||
this.pkgid = pkgid;
|
||||
@@ -99,6 +97,5 @@ public class CacheTestBean {
|
||||
list.add(new CacheTestBean(2, "bb", 60));
|
||||
return CompletableFuture.completedFuture(list);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
*/
|
||||
package org.redkale.test.source;
|
||||
|
||||
import static org.redkale.source.FilterExpress.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@@ -16,11 +18,8 @@ import org.redkale.persistence.Entity;
|
||||
import org.redkale.persistence.Id;
|
||||
import org.redkale.persistence.Transient;
|
||||
import org.redkale.source.*;
|
||||
import static org.redkale.source.FilterExpress.*;
|
||||
|
||||
/**
|
||||
* @author zhangjx
|
||||
*/
|
||||
/** @author zhangjx */
|
||||
public class FilterNodeTest {
|
||||
|
||||
private static Function<Class, EntityInfo> func;
|
||||
@@ -36,16 +35,38 @@ public class FilterNodeTest {
|
||||
@BeforeAll
|
||||
public static void init() throws Exception {
|
||||
final Properties props = new Properties();
|
||||
final BiFunction<DataSource, EntityInfo, CompletableFuture<List>> fullloader = (s, t) -> CompletableFuture.completedFuture(new ArrayList());
|
||||
final BiFunction<DataSource, EntityInfo, CompletableFuture<List>> fullloader =
|
||||
(s, t) -> CompletableFuture.completedFuture(new ArrayList());
|
||||
func = (Class t) -> loadEntityInfo(t, false, props, null, fullloader);
|
||||
carEntity = loadEntityInfo(CarTestTable.class, false, props, null, (s, t) -> CompletableFuture.completedFuture(CarTestTable.createList()));
|
||||
final EntityInfo<UserTestTable> userEntity = loadEntityInfo(UserTestTable.class, false, props, null, (s, t) -> CompletableFuture.completedFuture(UserTestTable.createList()));
|
||||
final EntityInfo<CarTypeTable> typeEntity = loadEntityInfo(CarTypeTable.class, false, props, null, (s, t) -> CompletableFuture.completedFuture(CarTypeTable.createList()));
|
||||
carEntity = loadEntityInfo(
|
||||
CarTestTable.class,
|
||||
false,
|
||||
props,
|
||||
null,
|
||||
(s, t) -> CompletableFuture.completedFuture(CarTestTable.createList()));
|
||||
final EntityInfo<UserTestTable> userEntity = loadEntityInfo(
|
||||
UserTestTable.class,
|
||||
false,
|
||||
props,
|
||||
null,
|
||||
(s, t) -> CompletableFuture.completedFuture(UserTestTable.createList()));
|
||||
final EntityInfo<CarTypeTable> typeEntity = loadEntityInfo(
|
||||
CarTypeTable.class,
|
||||
false,
|
||||
props,
|
||||
null,
|
||||
(s, t) -> CompletableFuture.completedFuture(CarTypeTable.createList()));
|
||||
}
|
||||
|
||||
private static <T> EntityInfo<T> loadEntityInfo(Class<T> clazz, final boolean cacheForbidden, final Properties conf, DataSource source, BiFunction<DataSource, EntityInfo, CompletableFuture<List>> fullloader) {
|
||||
private static <T> EntityInfo<T> loadEntityInfo(
|
||||
Class<T> clazz,
|
||||
final boolean cacheForbidden,
|
||||
final Properties conf,
|
||||
DataSource source,
|
||||
BiFunction<DataSource, EntityInfo, CompletableFuture<List>> fullloader) {
|
||||
try {
|
||||
Method loadMethod = EntityInfo.class.getDeclaredMethod("load", Class.class, boolean.class, Properties.class, DataSource.class, BiFunction.class);
|
||||
Method loadMethod = EntityInfo.class.getDeclaredMethod(
|
||||
"load", Class.class, boolean.class, Properties.class, DataSource.class, BiFunction.class);
|
||||
loadMethod.setAccessible(true);
|
||||
return (EntityInfo) loadMethod.invoke(null, clazz, cacheForbidden, conf, source, fullloader);
|
||||
} catch (Exception e) {
|
||||
@@ -63,9 +84,16 @@ public class FilterNodeTest {
|
||||
}
|
||||
}
|
||||
|
||||
private static <T> CharSequence createSQLJoin(FilterNode node, Function<Class, EntityInfo> func, final boolean update, final Map<Class, String> joinTabalis, final Set<String> haset, final EntityInfo<T> info) {
|
||||
private static <T> CharSequence createSQLJoin(
|
||||
FilterNode node,
|
||||
Function<Class, EntityInfo> func,
|
||||
final boolean update,
|
||||
final Map<Class, String> joinTabalis,
|
||||
final Set<String> haset,
|
||||
final EntityInfo<T> info) {
|
||||
try {
|
||||
Method method = FilterNode.class.getDeclaredMethod("createSQLJoin", Function.class, boolean.class, Map.class, Set.class, EntityInfo.class);
|
||||
Method method = FilterNode.class.getDeclaredMethod(
|
||||
"createSQLJoin", Function.class, boolean.class, Map.class, Set.class, EntityInfo.class);
|
||||
method.setAccessible(true);
|
||||
return (CharSequence) method.invoke(node, func, update, joinTabalis, haset, info);
|
||||
} catch (Exception e) {
|
||||
@@ -73,9 +101,14 @@ public class FilterNodeTest {
|
||||
}
|
||||
}
|
||||
|
||||
private static <T> CharSequence createSQLExpress(FilterNode node, AbstractDataSqlSource source, final EntityInfo<T> info, final Map<Class, String> joinTabalis) {
|
||||
private static <T> CharSequence createSQLExpress(
|
||||
FilterNode node,
|
||||
AbstractDataSqlSource source,
|
||||
final EntityInfo<T> info,
|
||||
final Map<Class, String> joinTabalis) {
|
||||
try {
|
||||
Method method = FilterNode.class.getDeclaredMethod("createSQLExpress", AbstractDataSqlSource.class, EntityInfo.class, Map.class);
|
||||
Method method = FilterNode.class.getDeclaredMethod(
|
||||
"createSQLExpress", AbstractDataSqlSource.class, EntityInfo.class, Map.class);
|
||||
method.setAccessible(true);
|
||||
return (CharSequence) method.invoke(node, source, info, joinTabalis);
|
||||
} catch (Exception e) {
|
||||
@@ -106,14 +139,20 @@ public class FilterNodeTest {
|
||||
@Test
|
||||
public void run() throws Exception {
|
||||
final CarTestBean bean = CarTestBean.create();
|
||||
FilterNode joinNode1 = FilterNodes.joinInner(UserTestTable.class, new String[]{"userid", "username"}, "username", LIKE, bean.username)
|
||||
.or(FilterNodes.joinInner(UserTestTable.class, new String[]{"userid", "username"}, "createtime", GT, bean.createtime));
|
||||
FilterNode joinNode1 = FilterNodes.joinInner(
|
||||
UserTestTable.class, new String[] {"userid", "username"}, "username", LIKE, bean.username)
|
||||
.or(FilterNodes.joinInner(
|
||||
UserTestTable.class, new String[] {"userid", "username"}, "createtime", GT, bean.createtime));
|
||||
FilterNode joinNode2 = FilterNodes.joinInner(CarTypeTable.class, "cartype", "typename", LIKE, bean.typename);
|
||||
final FilterNode node = CarTestBean.caridTransient() ? (joinNode2.or(joinNode1)) : FilterNodes.gt("carid", bean.carid).and(joinNode1).or(joinNode2);
|
||||
final FilterNode node = CarTestBean.caridTransient()
|
||||
? (joinNode2.or(joinNode1))
|
||||
: FilterNodes.gt("carid", bean.carid).and(joinNode1).or(joinNode2);
|
||||
final FilterNode beanNode = FilterNodeBean.createFilterNode(bean);
|
||||
System.out.println("node.string = " + node);
|
||||
System.out.println("bean.string = " + beanNode);
|
||||
Assertions.assertEquals("(CarTypeTable.typename LIKE '%法拉利%' OR (UserTestTable.username LIKE '%用户1%' OR UserTestTable.createtime > 500))", node.toString());
|
||||
Assertions.assertEquals(
|
||||
"(CarTypeTable.typename LIKE '%法拉利%' OR (UserTestTable.username LIKE '%用户1%' OR UserTestTable.createtime > 500))",
|
||||
node.toString());
|
||||
Assertions.assertEquals(node.toString(), beanNode.toString());
|
||||
Map<Class, String> nodeJoinTabalis = getJoinTabalis(node);
|
||||
Map<Class, String> beanJoinTabalis = getJoinTabalis(beanNode);
|
||||
@@ -123,9 +162,14 @@ public class FilterNodeTest {
|
||||
CharSequence beanJoinsql = createSQLJoin(beanNode, func, false, beanJoinTabalis, new HashSet<>(), carEntity);
|
||||
CharSequence nodeWhere = createSQLExpress(node, null, carEntity, nodeJoinTabalis);
|
||||
CharSequence beanWhere = createSQLExpress(beanNode, null, carEntity, beanJoinTabalis);
|
||||
String expect = "SELECT a.* FROM cartesttable a INNER JOIN cartypetable ctt ON a.cartype = ctt.cartype INNER JOIN usertesttable utt ON a.userid = utt.userid AND a.username = utt.username WHERE (ctt.typename LIKE '%法拉利%' OR (utt.username LIKE '%用户1%' OR utt.createtime > 500))";
|
||||
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);
|
||||
String expect =
|
||||
"SELECT a.* FROM cartesttable a INNER JOIN cartypetable ctt ON a.cartype = ctt.cartype INNER JOIN usertesttable utt ON a.userid = utt.userid AND a.username = utt.username WHERE (ctt.typename LIKE '%法拉利%' OR (utt.username LIKE '%用户1%' OR utt.createtime > 500))";
|
||||
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 = isCacheUseable(node, func);
|
||||
Assertions.assertTrue(r1);
|
||||
if (!r1) {
|
||||
@@ -149,17 +193,23 @@ public class FilterNodeTest {
|
||||
|
||||
@FilterGroup("[OR].[AND]a.[OR]c")
|
||||
@FilterColumn(express = LIKE)
|
||||
@FilterJoinColumn(table = UserTestTable.class, columns = {"userid", "username"})
|
||||
@FilterJoinColumn(
|
||||
table = UserTestTable.class,
|
||||
columns = {"userid", "username"})
|
||||
public String username;
|
||||
|
||||
@FilterGroup("[OR].[AND]a.[OR]c")
|
||||
@FilterColumn(express = GT)
|
||||
@FilterJoinColumn(table = UserTestTable.class, columns = {"userid", "username"})
|
||||
@FilterJoinColumn(
|
||||
table = UserTestTable.class,
|
||||
columns = {"userid", "username"})
|
||||
public long createtime;
|
||||
|
||||
@FilterGroup("[OR]")
|
||||
@FilterColumn(express = LIKE)
|
||||
@FilterJoinColumn(table = CarTypeTable.class, columns = {"cartype"})
|
||||
@FilterJoinColumn(
|
||||
table = CarTypeTable.class,
|
||||
columns = {"cartype"})
|
||||
public String typename;
|
||||
|
||||
@Override
|
||||
@@ -220,9 +270,7 @@ public class FilterNodeTest {
|
||||
|
||||
private String cartitle;
|
||||
|
||||
public CarTestTable() {
|
||||
|
||||
}
|
||||
public CarTestTable() {}
|
||||
|
||||
public CarTestTable(long carid, int cartype, int userid, String cartitle) {
|
||||
this.carid = carid;
|
||||
@@ -276,7 +324,6 @@ public class FilterNodeTest {
|
||||
public String toString() {
|
||||
return JsonConvert.root().convertTo(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@AutoLoad
|
||||
@@ -304,9 +351,7 @@ public class FilterNodeTest {
|
||||
|
||||
private String typename;
|
||||
|
||||
public CarTypeTable() {
|
||||
|
||||
}
|
||||
public CarTypeTable() {}
|
||||
|
||||
public CarTypeTable(int cartype, String typename) {
|
||||
this.cartype = cartype;
|
||||
@@ -333,7 +378,6 @@ public class FilterNodeTest {
|
||||
public void setTypename(String typename) {
|
||||
this.typename = typename;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@AutoLoad
|
||||
@@ -356,8 +400,7 @@ public class FilterNodeTest {
|
||||
|
||||
private long createtime;
|
||||
|
||||
public UserTestTable() {
|
||||
}
|
||||
public UserTestTable() {}
|
||||
|
||||
public UserTestTable(int userid, String username, long createtime) {
|
||||
this.userid = userid;
|
||||
@@ -393,6 +436,5 @@ public class FilterNodeTest {
|
||||
public void setCreatetime(long createtime) {
|
||||
this.createtime = createtime;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,11 +13,8 @@ import org.redkale.persistence.Id;
|
||||
import org.redkale.source.*;
|
||||
import org.redkale.util.AnyValueWriter;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
//@Cacheable
|
||||
/** @author zhangjx */
|
||||
// @Cacheable
|
||||
public class JsonRecord {
|
||||
|
||||
@SourceConvert
|
||||
@@ -64,7 +61,9 @@ public class JsonRecord {
|
||||
public static void main(String[] args) throws Throwable {
|
||||
AnyValueWriter conf = AnyValueWriter.create();
|
||||
conf.addValue("name", "");
|
||||
conf.addValue("url", "jdbc:mysql://localhost:3306/center?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true");
|
||||
conf.addValue(
|
||||
"url",
|
||||
"jdbc:mysql://localhost:3306/center?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true");
|
||||
conf.addValue("user", "root");
|
||||
conf.addValue("password", "");
|
||||
DataJdbcSource source = new DataJdbcSource();
|
||||
@@ -73,7 +72,8 @@ public class JsonRecord {
|
||||
source.insert(record);
|
||||
source.updateColumn(JsonRecord.class, record.getRecordid(), ColumnValue.set("recordname", "my name 2"));
|
||||
record.getRmap().put("haha", 2222);
|
||||
source.updateColumn(JsonRecord.class, record.getRecordid(), ColumnValue.set("rmap", (Serializable) (Object) record.getRmap()));
|
||||
source.updateColumn(JsonRecord.class, record.getRecordid(), ColumnValue.set("rmap", (Serializable)
|
||||
(Object) record.getRmap()));
|
||||
System.out.println(source.find(JsonRecord.class, record.getRecordid()));
|
||||
System.out.println(source.findColumn(JsonRecord.class, "rmap", record.getRecordid()));
|
||||
}
|
||||
@@ -122,5 +122,4 @@ public class JsonRecord {
|
||||
public void setRset(Set<String> rset) {
|
||||
this.rset = rset;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user