This commit is contained in:
@@ -1,302 +0,0 @@
|
||||
/*
|
||||
* 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 com.wentch.redkale.source;
|
||||
|
||||
import com.wentch.redkale.convert.json.*;
|
||||
import static com.wentch.redkale.source.FilterExpress.*;
|
||||
import com.wentch.redkale.util.*;
|
||||
import java.util.*;
|
||||
import java.util.function.*;
|
||||
import javax.persistence.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public class FilterNodeTest {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
final Function<Class, List> fullloader = (Class t) -> new ArrayList();
|
||||
final Function<Class, EntityInfo> func = (Class t) -> EntityInfo.load(t, 0, false, fullloader);
|
||||
final EntityInfo<CarTestTable> carEntity = EntityInfo.load(CarTestTable.class, 0, false, (t) -> CarTestTable.createList());
|
||||
final EntityInfo<UserTestTable> userEntity = EntityInfo.load(UserTestTable.class, 0, false, (t) -> UserTestTable.createList());
|
||||
final EntityInfo<CarTypeTestTable> typeEntity = EntityInfo.load(CarTypeTestTable.class, 0, false, (t) -> CarTypeTestTable.createList());
|
||||
|
||||
final CarTestBean bean = new CarTestBean();
|
||||
bean.carid = 70002;
|
||||
bean.username = "用户1";
|
||||
bean.createtime = 500;
|
||||
bean.typename = "法拉利";
|
||||
FilterNode joinNode1 = FilterJoinNode.create(UserTestTable.class, new String[]{"userid", "username"}, "username", LIKE, bean.username)
|
||||
.or(FilterJoinNode.create(UserTestTable.class, new String[]{"userid", "username"}, "createtime", GREATERTHAN, bean.createtime));
|
||||
FilterNode joinNode2 = FilterJoinNode.create(CarTypeTestTable.class, "cartype", "typename", LIKE, bean.typename);
|
||||
FilterNode node = CarTestBean.caridTransient() ? (joinNode2.or(joinNode1)) : FilterNode.create("carid", GREATERTHAN, bean.carid).and(joinNode1).or(joinNode2);
|
||||
FilterNode beanNode = FilterNodeBean.createFilterNode(bean);
|
||||
System.out.println("node.string = " + node);
|
||||
System.out.println("bean.string = " + beanNode);
|
||||
Map<Class, String> nodeJoinTabalis = node.getJoinTabalis();
|
||||
Map<Class, String> beanJoinTabalis = beanNode.getJoinTabalis();
|
||||
CharSequence nodeJoinsql = node.createSQLJoin(func, nodeJoinTabalis, carEntity);
|
||||
CharSequence beanJoinsql = beanNode.createSQLJoin(func, beanJoinTabalis, carEntity);
|
||||
CharSequence nodeWhere = node.createSQLExpress(carEntity, nodeJoinTabalis);
|
||||
CharSequence beanWhere = beanNode.createSQLExpress(carEntity, beanJoinTabalis);
|
||||
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);
|
||||
assert node.isCacheUseable(func) : "isCacheUseable 应该是true";
|
||||
assert beanNode.isCacheUseable(func) : "isCacheUseable 应该是true";
|
||||
System.out.println("node.Predicate = " + node.createPredicate(carEntity.getCache()));
|
||||
System.out.println("bean.Predicate = " + beanNode.createPredicate(carEntity.getCache()));
|
||||
System.out.println("node.sheet = " +carEntity.getCache().querySheet(null, new Flipper(), node));
|
||||
System.out.println("bean.sheet = " +carEntity.getCache().querySheet(null, new Flipper(), beanNode));
|
||||
}
|
||||
|
||||
public static class CarTestBean implements FilterBean {
|
||||
|
||||
@FilterGroup("[OR].[AND]a")
|
||||
@FilterColumn(express = GREATERTHAN)
|
||||
@Transient
|
||||
public long carid;
|
||||
|
||||
@FilterGroup("[OR].[AND]a.[OR]c")
|
||||
@FilterColumn(express = LIKE)
|
||||
@FilterJoinColumn(table = UserTestTable.class, columns = {"userid", "username"})
|
||||
public String username;
|
||||
|
||||
@FilterGroup("[OR].[AND]a.[OR]c")
|
||||
@FilterColumn(express = GREATERTHAN)
|
||||
@FilterJoinColumn(table = UserTestTable.class, columns = {"userid", "username"})
|
||||
public long createtime;
|
||||
|
||||
@FilterGroup("[OR]")
|
||||
@FilterColumn(express = LIKE)
|
||||
@FilterJoinColumn(table = CarTypeTestTable.class, columns = {"cartype"})
|
||||
public String typename;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonFactory.root().getConvert().convertTo(this);
|
||||
}
|
||||
|
||||
public static boolean caridTransient() {
|
||||
try {
|
||||
return CarTestBean.class.getDeclaredField("carid").getAnnotation(Transient.class) != null;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@AutoLoad
|
||||
@Cacheable
|
||||
public static class CarTestTable {
|
||||
|
||||
public static List<CarTestTable> createList() {
|
||||
List<CarTestTable> list = new ArrayList<>();
|
||||
|
||||
list.add(new CarTestTable(70001, 101, 1000011, "我的车"));
|
||||
list.add(new CarTestTable(70002, 102, 1000012, "我的车"));
|
||||
list.add(new CarTestTable(70003, 103, 1000013, "我的车"));
|
||||
list.add(new CarTestTable(70004, 104, 1000014, "我的车"));
|
||||
list.add(new CarTestTable(70005, 105, 1000015, "我的车"));
|
||||
|
||||
list.add(new CarTestTable(70201, 201, 1000031, "我的车"));
|
||||
list.add(new CarTestTable(70202, 202, 1000032, "我的车"));
|
||||
list.add(new CarTestTable(70203, 203, 1000033, "我的车"));
|
||||
list.add(new CarTestTable(70204, 204, 1000034, "我的车"));
|
||||
list.add(new CarTestTable(70205, 205, 1000035, "我的车"));
|
||||
list.add(new CarTestTable(70505, 301, 1008000, "我的车"));
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@Id
|
||||
private long carid;
|
||||
|
||||
private int cartype;
|
||||
|
||||
private int userid;
|
||||
|
||||
private String username;
|
||||
|
||||
private String cartitle;
|
||||
|
||||
public CarTestTable() {
|
||||
|
||||
}
|
||||
|
||||
public CarTestTable(long carid, int cartype, int userid, String cartitle) {
|
||||
this.carid = carid;
|
||||
this.cartype = cartype;
|
||||
this.userid = userid;
|
||||
this.username = "用户" + userid % 1000;
|
||||
this.cartitle = cartitle;
|
||||
}
|
||||
|
||||
public long getCarid() {
|
||||
return carid;
|
||||
}
|
||||
|
||||
public void setCarid(long carid) {
|
||||
this.carid = carid;
|
||||
}
|
||||
|
||||
public int getUserid() {
|
||||
return userid;
|
||||
}
|
||||
|
||||
public void setUserid(int userid) {
|
||||
this.userid = userid;
|
||||
}
|
||||
|
||||
public String getCartitle() {
|
||||
return cartitle;
|
||||
}
|
||||
|
||||
public void setCartitle(String cartitle) {
|
||||
this.cartitle = cartitle;
|
||||
}
|
||||
|
||||
public int getCartype() {
|
||||
return cartype;
|
||||
}
|
||||
|
||||
public void setCartype(int cartype) {
|
||||
this.cartype = cartype;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonFactory.root().getConvert().convertTo(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@AutoLoad
|
||||
@Cacheable
|
||||
public static class CarTypeTestTable {
|
||||
|
||||
public static List<CarTypeTestTable> createList() {
|
||||
List<CarTypeTestTable> list = new ArrayList<>();
|
||||
list.add(new CarTypeTestTable(101, "奥迪A1"));
|
||||
list.add(new CarTypeTestTable(102, "奥迪A2"));
|
||||
list.add(new CarTypeTestTable(103, "奥迪A3"));
|
||||
list.add(new CarTypeTestTable(104, "奥迪A4"));
|
||||
list.add(new CarTypeTestTable(105, "奥迪A5"));
|
||||
list.add(new CarTypeTestTable(201, "奔驰S1"));
|
||||
list.add(new CarTypeTestTable(202, "奔驰S2"));
|
||||
list.add(new CarTypeTestTable(203, "奔驰S3"));
|
||||
list.add(new CarTypeTestTable(204, "奔驰S4"));
|
||||
list.add(new CarTypeTestTable(205, "奔驰S5"));
|
||||
list.add(new CarTypeTestTable(301, "法拉利"));
|
||||
return list;
|
||||
}
|
||||
|
||||
@Id
|
||||
private int cartype;
|
||||
|
||||
private String typename;
|
||||
|
||||
public CarTypeTestTable() {
|
||||
|
||||
}
|
||||
|
||||
public CarTypeTestTable(int cartype, String typename) {
|
||||
this.cartype = cartype;
|
||||
this.typename = typename;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonFactory.root().getConvert().convertTo(this);
|
||||
}
|
||||
|
||||
public int getCartype() {
|
||||
return cartype;
|
||||
}
|
||||
|
||||
public void setCartype(int cartype) {
|
||||
this.cartype = cartype;
|
||||
}
|
||||
|
||||
public String getTypename() {
|
||||
return typename;
|
||||
}
|
||||
|
||||
public void setTypename(String typename) {
|
||||
this.typename = typename;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@AutoLoad
|
||||
@Cacheable
|
||||
public static class UserTestTable {
|
||||
|
||||
public static List<UserTestTable> createList() {
|
||||
List<UserTestTable> list = new ArrayList<>();
|
||||
for (int i = 11; i <= 50; i++) {
|
||||
list.add(new UserTestTable(1000000 + i, "用户" + i, i * 20));
|
||||
}
|
||||
list.add(new UserTestTable(1008000, "车主A", 20));
|
||||
return list;
|
||||
}
|
||||
|
||||
@Id
|
||||
private int userid;
|
||||
|
||||
private String username;
|
||||
|
||||
private long createtime;
|
||||
|
||||
public UserTestTable() {
|
||||
}
|
||||
|
||||
public UserTestTable(int userid, String username, long createtime) {
|
||||
this.userid = userid;
|
||||
this.username = username;
|
||||
this.createtime = createtime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonFactory.root().getConvert().convertTo(this);
|
||||
}
|
||||
|
||||
public int getUserid() {
|
||||
return userid;
|
||||
}
|
||||
|
||||
public void setUserid(int userid) {
|
||||
this.userid = userid;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public long getCreatetime() {
|
||||
return createtime;
|
||||
}
|
||||
|
||||
public void setCreatetime(long createtime) {
|
||||
this.createtime = createtime;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
/*
|
||||
* 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 com.wentch.redkale.test.convert;
|
||||
|
||||
import com.wentch.redkale.convert.json.JsonFactory;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public abstract class BasedEntity implements Serializable {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonFactory.root().getConvert().convertTo(this);
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* 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 com.wentch.redkale.test.convert;
|
||||
|
||||
import com.wentch.redkale.convert.bson.*;
|
||||
import com.wentch.redkale.convert.json.*;
|
||||
import com.wentch.redkale.util.*;
|
||||
import java.io.Serializable;
|
||||
import java.nio.*;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public class BsonTestMain {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
Serializable[] sers = new Serializable[]{"aaa",4};
|
||||
final BsonConvert convert = BsonFactory.root().getConvert();
|
||||
byte[] bytes = convert.convertTo(sers);
|
||||
Serializable[] a = convert.convertFrom(Serializable[].class, bytes);
|
||||
System.out.println(Arrays.toString(a));
|
||||
main2(args);
|
||||
}
|
||||
public static void main2(String[] args) throws Exception {
|
||||
final BsonConvert convert = BsonFactory.root().getConvert();
|
||||
TestEntry2 entry = TestEntry2.create();
|
||||
byte[] bytes = convert.convertTo(TestEntry.class, entry);
|
||||
Utility.println(null,bytes);
|
||||
System.out.println(JsonFactory.root().getConvert().convertTo(entry));
|
||||
TestEntry rs = convert.convertFrom(TestEntry.class, bytes);
|
||||
System.out.println(rs.toString());
|
||||
System.out.println(JsonFactory.root().getConvert().convertTo(rs));
|
||||
|
||||
TestComplextBean bean = new TestComplextBean();
|
||||
byte[] bytes2 = convert.convertTo(Object.class, bean);
|
||||
final int len = bytes2.length;
|
||||
BsonByteBufferWriter writer = convert.pollBsonWriter(()-> ByteBuffer.allocate(len/2));
|
||||
convert.convertTo(writer, bean);
|
||||
bytes2 = writer.toArray();
|
||||
System.out.println(convert.convertFrom(TestComplextBean.class, bytes2).toString());
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* 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 com.wentch.redkale.test.convert;
|
||||
|
||||
import com.wentch.redkale.convert.json.*;
|
||||
import com.wentch.redkale.util.*;
|
||||
import java.lang.reflect.*;
|
||||
import java.nio.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public class JsonTestMain {
|
||||
|
||||
private static final Type MAPTYPE = new TypeToken<Map<String, String>>() {
|
||||
}.getType();
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
JsonFactory factory = JsonFactory.root();
|
||||
factory.setTiny(true);
|
||||
final JsonConvert convert = JsonFactory.root().getConvert();
|
||||
String json = "{\"access_token\":\"vVX2bIjN5P9TMOphDkStM96eNWapAehTuWAlVDO74aFaYxLwj2b-9-T9p_W2mfr9\",\"expires_in\":7200, \"aa\":\"\"}";
|
||||
Map<String, String> map = convert.convertFrom(MAPTYPE, json);
|
||||
System.out.println(map);
|
||||
System.out.println(convert.convertTo(map));
|
||||
ByteBuffer[] buffers = convert.convertTo(() -> ByteBuffer.allocate(1024), map);
|
||||
byte[] bs = new byte[buffers[0].remaining()];
|
||||
buffers[0].get(bs);
|
||||
System.out.println(new String(bs));
|
||||
}
|
||||
}
|
||||
@@ -1,391 +0,0 @@
|
||||
/*
|
||||
* 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 com.wentch.redkale.test.convert;
|
||||
|
||||
import java.util.List;
|
||||
import javax.persistence.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public class TestComplextBean extends BasedEntity{
|
||||
|
||||
@Id
|
||||
private int userid;
|
||||
|
||||
private String chname = "";
|
||||
|
||||
private int organid;
|
||||
|
||||
private String photos = "";
|
||||
|
||||
private String introvideourl = "";
|
||||
|
||||
private String introduction = "";
|
||||
|
||||
private String linkemail = "";
|
||||
|
||||
private String telephone = "";
|
||||
|
||||
private String skype = "";
|
||||
|
||||
private String weixin = "";
|
||||
|
||||
private String jego = "";
|
||||
|
||||
private String city = ""; //'导师所在城市',
|
||||
|
||||
private String states = ""; //导师所在洲名
|
||||
|
||||
private String country = ""; //导师所在国家
|
||||
|
||||
private int zones;// 导师所在时区
|
||||
|
||||
private int lac;// 1东北部,2西部,4中西部,8南部
|
||||
|
||||
private short hyproficient;
|
||||
|
||||
private long createtime;
|
||||
|
||||
private long updatetime;
|
||||
|
||||
private int edutype;
|
||||
|
||||
private int major;
|
||||
|
||||
private short iecalevel; //IECA会员或者认证:1、IECA会员一级 ;2、IECA会员二级 ;3、IECA会员三级 ;4、IECA认证一级;5、IECA认证二级;6、IECA认证三级;7、非会员非认证导师'
|
||||
|
||||
private int workyear;
|
||||
|
||||
private int rateservice;//'服务态度评分(总分)',
|
||||
|
||||
private int ratemajor;//'咨询专业评分(总分)',
|
||||
|
||||
private int ratenum;//'导师评分人次数(总评价人次)',
|
||||
|
||||
private int successnum;//'服务过多少名申请学生',
|
||||
|
||||
private int successrate; //'申请的成功率: 9500,表示成功率为95%',
|
||||
|
||||
private int successhotrate; //'常青藤学校比例: 6000,表示比例为60%',
|
||||
|
||||
private long hots;
|
||||
|
||||
private int starlevel;
|
||||
|
||||
private String degreestr = "";
|
||||
|
||||
private String searchflag="";
|
||||
|
||||
private String searchkey = "";
|
||||
|
||||
@Transient
|
||||
private boolean baseinfoAll = true;//基本信息是否完整
|
||||
|
||||
@Transient
|
||||
private List<UserMentorPrize> prizes;
|
||||
|
||||
@Transient
|
||||
private UserInfo user;
|
||||
|
||||
public List<UserMentorPrize> getPrizes() {
|
||||
return prizes;
|
||||
}
|
||||
|
||||
public void setPrizes(List<UserMentorPrize> prizes) {
|
||||
this.prizes = prizes;
|
||||
}
|
||||
|
||||
public boolean isBaseinfoAll() {
|
||||
return baseinfoAll;
|
||||
}
|
||||
|
||||
public void setBaseinfoAll(boolean baseinfoAll) {
|
||||
this.baseinfoAll = baseinfoAll;
|
||||
}
|
||||
|
||||
public UserInfo getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(UserInfo user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public int getUserid() {
|
||||
return userid;
|
||||
}
|
||||
|
||||
public void setUserid(int userid) {
|
||||
this.userid = userid;
|
||||
}
|
||||
|
||||
public String getChname() {
|
||||
return chname;
|
||||
}
|
||||
|
||||
public void setChname(String chname) {
|
||||
this.chname = chname;
|
||||
}
|
||||
|
||||
public int getOrganid() {
|
||||
return organid;
|
||||
}
|
||||
|
||||
public void setOrganid(int organid) {
|
||||
this.organid = organid;
|
||||
}
|
||||
|
||||
public String getPhotos() {
|
||||
return photos;
|
||||
}
|
||||
|
||||
public void setPhotos(String photos) {
|
||||
this.photos = photos;
|
||||
}
|
||||
|
||||
public String getIntrovideourl() {
|
||||
return introvideourl;
|
||||
}
|
||||
|
||||
public void setIntrovideourl(String introvideourl) {
|
||||
this.introvideourl = introvideourl;
|
||||
}
|
||||
|
||||
public String getIntroduction() {
|
||||
return introduction;
|
||||
}
|
||||
|
||||
public void setIntroduction(String introduction) {
|
||||
this.introduction = introduction;
|
||||
}
|
||||
|
||||
public String getLinkemail() {
|
||||
return linkemail;
|
||||
}
|
||||
|
||||
public void setLinkemail(String linkemail) {
|
||||
this.linkemail = linkemail;
|
||||
}
|
||||
|
||||
public String getTelephone() {
|
||||
return telephone;
|
||||
}
|
||||
|
||||
public void setTelephone(String telephone) {
|
||||
this.telephone = telephone;
|
||||
}
|
||||
|
||||
public String getSkype() {
|
||||
return skype;
|
||||
}
|
||||
|
||||
public void setSkype(String skype) {
|
||||
this.skype = skype;
|
||||
}
|
||||
|
||||
public String getWeixin() {
|
||||
return weixin;
|
||||
}
|
||||
|
||||
public void setWeixin(String weixin) {
|
||||
this.weixin = weixin;
|
||||
}
|
||||
|
||||
public String getJego() {
|
||||
return jego;
|
||||
}
|
||||
|
||||
public void setJego(String jego) {
|
||||
this.jego = jego;
|
||||
}
|
||||
|
||||
public String getCity() {
|
||||
return city;
|
||||
}
|
||||
|
||||
public void setCity(String city) {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
public String getStates() {
|
||||
return states;
|
||||
}
|
||||
|
||||
public void setStates(String states) {
|
||||
this.states = states;
|
||||
}
|
||||
|
||||
public String getCountry() {
|
||||
return country;
|
||||
}
|
||||
|
||||
public void setCountry(String country) {
|
||||
this.country = country;
|
||||
}
|
||||
|
||||
public int getZones() {
|
||||
return zones;
|
||||
}
|
||||
|
||||
public void setZones(int zones) {
|
||||
this.zones = zones;
|
||||
}
|
||||
|
||||
public int getLac() {
|
||||
return lac;
|
||||
}
|
||||
|
||||
public void setLac(int lac) {
|
||||
this.lac = lac;
|
||||
}
|
||||
|
||||
public short getHyproficient() {
|
||||
return hyproficient;
|
||||
}
|
||||
|
||||
public void setHyproficient(short hyproficient) {
|
||||
this.hyproficient = hyproficient;
|
||||
}
|
||||
|
||||
public long getCreatetime() {
|
||||
return createtime;
|
||||
}
|
||||
|
||||
public void setCreatetime(long createtime) {
|
||||
this.createtime = createtime;
|
||||
}
|
||||
|
||||
public long getUpdatetime() {
|
||||
return updatetime;
|
||||
}
|
||||
|
||||
public void setUpdatetime(long updatetime) {
|
||||
this.updatetime = updatetime;
|
||||
}
|
||||
|
||||
public int getEdutype() {
|
||||
return edutype;
|
||||
}
|
||||
|
||||
public void setEdutype(int edutype) {
|
||||
this.edutype = edutype;
|
||||
}
|
||||
|
||||
public int getMajor() {
|
||||
return major;
|
||||
}
|
||||
|
||||
public void setMajor(int major) {
|
||||
this.major = major;
|
||||
}
|
||||
|
||||
public short getIecalevel() {
|
||||
return iecalevel;
|
||||
}
|
||||
|
||||
public void setIecalevel(short iecalevel) {
|
||||
this.iecalevel = iecalevel;
|
||||
}
|
||||
|
||||
public int getWorkyear() {
|
||||
return workyear;
|
||||
}
|
||||
|
||||
public void setWorkyear(int workyear) {
|
||||
this.workyear = workyear;
|
||||
}
|
||||
|
||||
public int getRateservice() {
|
||||
return rateservice;
|
||||
}
|
||||
|
||||
public void setRateservice(int rateservice) {
|
||||
this.rateservice = rateservice;
|
||||
}
|
||||
|
||||
public int getRatemajor() {
|
||||
return ratemajor;
|
||||
}
|
||||
|
||||
public void setRatemajor(int ratemajor) {
|
||||
this.ratemajor = ratemajor;
|
||||
}
|
||||
|
||||
public int getRatenum() {
|
||||
return ratenum;
|
||||
}
|
||||
|
||||
public void setRatenum(int ratenum) {
|
||||
this.ratenum = ratenum;
|
||||
}
|
||||
|
||||
public int getSuccessnum() {
|
||||
return successnum;
|
||||
}
|
||||
|
||||
public void setSuccessnum(int successnum) {
|
||||
this.successnum = successnum;
|
||||
}
|
||||
|
||||
public int getSuccessrate() {
|
||||
return successrate;
|
||||
}
|
||||
|
||||
public void setSuccessrate(int successrate) {
|
||||
this.successrate = successrate;
|
||||
}
|
||||
|
||||
public int getSuccesshotrate() {
|
||||
return successhotrate;
|
||||
}
|
||||
|
||||
public void setSuccesshotrate(int successhotrate) {
|
||||
this.successhotrate = successhotrate;
|
||||
}
|
||||
|
||||
public long getHots() {
|
||||
return hots;
|
||||
}
|
||||
|
||||
public void setHots(long hots) {
|
||||
this.hots = hots;
|
||||
}
|
||||
|
||||
public int getStarlevel() {
|
||||
return starlevel;
|
||||
}
|
||||
|
||||
public void setStarlevel(int starlevel) {
|
||||
this.starlevel = starlevel;
|
||||
}
|
||||
|
||||
public String getDegreestr() {
|
||||
return degreestr;
|
||||
}
|
||||
|
||||
public void setDegreestr(String degreestr) {
|
||||
this.degreestr = degreestr;
|
||||
}
|
||||
|
||||
public String getSearchflag() {
|
||||
return searchflag;
|
||||
}
|
||||
|
||||
public void setSearchflag(String searchflag) {
|
||||
this.searchflag = searchflag;
|
||||
}
|
||||
|
||||
public String getSearchkey() {
|
||||
return searchkey;
|
||||
}
|
||||
|
||||
public void setSearchkey(String searchkey) {
|
||||
this.searchkey = searchkey;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,129 +0,0 @@
|
||||
/*
|
||||
* 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 com.wentch.redkale.test.convert;
|
||||
|
||||
import com.wentch.redkale.util.Sheet;
|
||||
import com.wentch.redkale.util.TypeToken;
|
||||
import com.wentch.redkale.convert.bson.BsonFactory;
|
||||
import com.wentch.redkale.convert.json.JsonFactory;
|
||||
import java.lang.reflect.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
* @param <T>
|
||||
* @param <K>
|
||||
* @param <V>
|
||||
*/
|
||||
public class TestConvertBean<T, K, V> {
|
||||
|
||||
public static class Entry {
|
||||
|
||||
private String id;
|
||||
|
||||
private String remark;
|
||||
|
||||
public Entry(){
|
||||
|
||||
}
|
||||
public Entry(String id, String remark) {
|
||||
this.id = id;
|
||||
this.remark = remark;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Entry{" + "id=" + id + ", remark=" + remark + '}';
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getRemark() {
|
||||
return remark;
|
||||
}
|
||||
|
||||
public void setRemark(String remark) {
|
||||
this.remark = remark;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private T name;
|
||||
|
||||
private List<? extends K> list;
|
||||
|
||||
private Map<K, V> map;
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
TestConvertBean<Long, String, Entry> bean = new TestConvertBean<>();
|
||||
bean.setName(1234567890L);
|
||||
List<String> list = new ArrayList<>();
|
||||
list.add("你好");
|
||||
bean.setList(list);
|
||||
Map<String, Entry> map = new HashMap<>();
|
||||
map.put("myvalue", new Entry("myid", ""));
|
||||
bean.setMap(map);
|
||||
final Type type = new TypeToken<TestConvertBean<Long, String, Entry>>() {
|
||||
}.getType();
|
||||
JsonFactory.root().setTiny(true);
|
||||
String json = JsonFactory.root().getConvert().convertTo(type, bean);
|
||||
System.out.println(json);
|
||||
System.out.println( JsonFactory.root().getConvert().convertFrom(type, json).toString());
|
||||
// JsonFactory child = JsonFactory.root().createChild();
|
||||
// System.out.println(child.register(TestConvertBean.class, "name", new ConvertColumnEntry("name", true)));
|
||||
// child.register(TestConvertBean.class, child.createEncoder(type));
|
||||
// System.out.println(child.getConvert().convertTo(type, bean));
|
||||
if(true) return;
|
||||
|
||||
Sheet<Entry> sheet = new Sheet<>();
|
||||
sheet.setTotal(20);
|
||||
List<Entry> list2 = new ArrayList<>();
|
||||
list2.add(new Entry("myid", "描述"));
|
||||
sheet.setRows(list2);
|
||||
final Type type2 = new TypeToken<Sheet<Entry>>() {
|
||||
}.getType();
|
||||
System.out.println(JsonFactory.root().getConvert().convertTo(type2, sheet));
|
||||
sheet = BsonFactory.root().getConvert().convertFrom(type2, BsonFactory.root().getConvert().convertTo(type2, sheet));
|
||||
System.out.println(JsonFactory.root().getConvert().convertTo(type2, sheet));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TestConvertBean{" + "name=" + name + ", list=" + list + ", map=" + map + '}';
|
||||
}
|
||||
|
||||
public T getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(T name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public List<? extends K> getList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
public void setList(List<? extends K> list) {
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
public Map<K, V> getMap() {
|
||||
return map;
|
||||
}
|
||||
|
||||
public void setMap(Map<K, V> map) {
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,125 +0,0 @@
|
||||
/*
|
||||
* 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 com.wentch.redkale.test.convert;
|
||||
|
||||
import com.wentch.redkale.convert.json.JsonFactory;
|
||||
import com.wentch.redkale.util.Creator;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public class TestEntry {
|
||||
|
||||
private String name;
|
||||
|
||||
private String desc="";
|
||||
|
||||
private int id = (int) System.currentTimeMillis();
|
||||
|
||||
private int[] addrs;
|
||||
|
||||
private List<String> lists;
|
||||
|
||||
private String[] strings;
|
||||
|
||||
private Map<String, Integer> map;
|
||||
|
||||
public static TestEntry create() {
|
||||
TestEntry v = new TestEntry();
|
||||
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"});
|
||||
List<String> list = new ArrayList<>();
|
||||
list.add("aaaa");
|
||||
list.add("bbbb");
|
||||
list.add("cccc");
|
||||
v.setLists(list);
|
||||
Map<String, Integer> map = new HashMap<>();
|
||||
map.put("AAA", 111);
|
||||
map.put("BBB", 222);
|
||||
map.put("CCC", 333);
|
||||
v.setMap(map);
|
||||
return v;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
System.out.println(JsonFactory.root().getConvert().convertTo(create()));
|
||||
Creator<TestEntry> creator = Creator.create(TestEntry.class); //Creator.create(10, TestEntry.class);
|
||||
TestEntry entry = creator.create();
|
||||
System.out.println(entry);
|
||||
for(int i =0; i < 10000000; i++){
|
||||
creator.create();
|
||||
}
|
||||
System.gc();
|
||||
Thread.sleep(2000) ;
|
||||
System.out.println(creator.create());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonFactory.root().getConvert().convertTo(this);
|
||||
}
|
||||
|
||||
public int[] getAddrs() {
|
||||
return addrs;
|
||||
}
|
||||
|
||||
public void setAddrs(int[] addrs) {
|
||||
this.addrs = addrs;
|
||||
}
|
||||
|
||||
public List<String> getLists() {
|
||||
return lists;
|
||||
}
|
||||
|
||||
public void setLists(List<String> lists) {
|
||||
this.lists = lists;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Map<String, Integer> getMap() {
|
||||
return map;
|
||||
}
|
||||
|
||||
public void setMap(Map<String, Integer> map) {
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
public void setDesc(String desc) {
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public String[] getStrings() {
|
||||
return strings;
|
||||
}
|
||||
|
||||
public void setStrings(String[] strings) {
|
||||
this.strings = strings;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
* 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 com.wentch.redkale.test.convert;
|
||||
|
||||
import com.wentch.redkale.convert.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
@ConvertEntity("myname")
|
||||
public class TestEntry2 extends TestEntry {
|
||||
|
||||
private String extend;
|
||||
|
||||
public static TestEntry2 create() {
|
||||
TestEntry2 v = new TestEntry2();
|
||||
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"});
|
||||
List<String> list = new ArrayList<>();
|
||||
list.add("aaaa");
|
||||
list.add("bbbb");
|
||||
list.add("cccc");
|
||||
v.setLists(list);
|
||||
Map<String, Integer> map = new HashMap<>();
|
||||
map.put("AAA", 111);
|
||||
map.put("BBB", 222);
|
||||
map.put("CCC", 333);
|
||||
v.setMap(map);
|
||||
v.setExtend("hahaha");
|
||||
return v;
|
||||
}
|
||||
|
||||
public String getExtend() {
|
||||
return extend;
|
||||
}
|
||||
|
||||
public void setExtend(String extend) {
|
||||
this.extend = extend;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,114 +0,0 @@
|
||||
/*
|
||||
* 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 com.wentch.redkale.test.convert;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public class UserInfo extends BasedEntity {
|
||||
|
||||
private int userid;
|
||||
|
||||
private String namekey;
|
||||
|
||||
private String nickname;
|
||||
|
||||
private String chname;
|
||||
|
||||
private String password;
|
||||
|
||||
private String mobile;
|
||||
|
||||
private String email;
|
||||
|
||||
private short type;
|
||||
|
||||
private short status;
|
||||
|
||||
private int gmt = 8;
|
||||
|
||||
public int getUserid() {
|
||||
return userid;
|
||||
}
|
||||
|
||||
public void setUserid(int userid) {
|
||||
this.userid = userid;
|
||||
}
|
||||
|
||||
public String getNamekey() {
|
||||
return namekey;
|
||||
}
|
||||
|
||||
public void setNamekey(String namekey) {
|
||||
this.namekey = namekey;
|
||||
}
|
||||
|
||||
public String getNickname() {
|
||||
return nickname;
|
||||
}
|
||||
|
||||
public void setNickname(String nickname) {
|
||||
this.nickname = nickname;
|
||||
}
|
||||
|
||||
public String getChname() {
|
||||
return chname;
|
||||
}
|
||||
|
||||
public void setChname(String chname) {
|
||||
this.chname = chname;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getMobile() {
|
||||
return mobile;
|
||||
}
|
||||
|
||||
public void setMobile(String mobile) {
|
||||
this.mobile = mobile;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public short getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(short type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public short getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(short status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public int getGmt() {
|
||||
return gmt;
|
||||
}
|
||||
|
||||
public void setGmt(int gmt) {
|
||||
this.gmt = gmt;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
/*
|
||||
* 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 com.wentch.redkale.test.convert;
|
||||
|
||||
import com.wentch.redkale.source.DistributeGenerator;
|
||||
import javax.persistence.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public class UserMentorPrize extends BasedEntity implements Comparable<UserMentorPrize> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
@DistributeGenerator(initialValue = 10001)
|
||||
private long mentorprizeid;
|
||||
|
||||
private int userid;
|
||||
|
||||
private String prizename;
|
||||
|
||||
private int happenday;
|
||||
|
||||
@Column(updatable = false)
|
||||
private long createtime = System.currentTimeMillis();
|
||||
|
||||
private long updatetime;
|
||||
|
||||
public UserMentorPrize() {
|
||||
}
|
||||
|
||||
public long getMentorprizeid() {
|
||||
return mentorprizeid;
|
||||
}
|
||||
|
||||
public void setMentorprizeid(long mentorprizeid) {
|
||||
this.mentorprizeid = mentorprizeid;
|
||||
}
|
||||
|
||||
public int getUserid() {
|
||||
return userid;
|
||||
}
|
||||
|
||||
public void setUserid(int userid) {
|
||||
this.userid = userid;
|
||||
}
|
||||
|
||||
public String getPrizename() {
|
||||
return prizename;
|
||||
}
|
||||
|
||||
public void setPrizename(String prizename) {
|
||||
this.prizename = prizename;
|
||||
}
|
||||
|
||||
public int getHappenday() {
|
||||
return happenday;
|
||||
}
|
||||
|
||||
public void setHappenday(int happenday) {
|
||||
this.happenday = happenday;
|
||||
}
|
||||
|
||||
public long getCreatetime() {
|
||||
return createtime;
|
||||
}
|
||||
|
||||
public void setCreatetime(long createtime) {
|
||||
this.createtime = createtime;
|
||||
}
|
||||
|
||||
public long getUpdatetime() {
|
||||
return updatetime;
|
||||
}
|
||||
|
||||
public void setUpdatetime(long updatetime) {
|
||||
this.updatetime = updatetime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(UserMentorPrize o) {
|
||||
return this.happenday - o.happenday;
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
* 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 com.wentch.redkale.test.net;
|
||||
|
||||
import com.wentch.redkale.net.http.*;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
//@WebServlet({"/uploadtest/form", "/uploadtest/send"})
|
||||
public class UploadTestServlet extends HttpServlet {
|
||||
|
||||
@Override
|
||||
public void execute(HttpRequest request, HttpResponse response) throws IOException {
|
||||
if (request.getRequestURI().contains("/uploadtest/send")) {
|
||||
send(request, response);
|
||||
} else {
|
||||
form(request, response);
|
||||
}
|
||||
}
|
||||
|
||||
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>"
|
||||
+ "<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/>"
|
||||
+ "描述: <input name=\"desc3\"/> 文件3: <input type=\"file\" name=\"filepath3\"/><br/><br/>"
|
||||
+ "描述: <input name=\"desc4\"/> <br/><br/>"
|
||||
+ " <input type=\"submit\" value=\"Submit\"/></form></div>"
|
||||
+ "</html>");
|
||||
}
|
||||
|
||||
public void send(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
MultiContext context = req.getMultiContext();
|
||||
for (MultiPart entry : context.listMultiPart()) {
|
||||
entry.skip();
|
||||
System.out.println(entry);
|
||||
}
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package com.wentch.redkale.test.service;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Person implements Serializable {
|
||||
|
||||
private byte[] b = new byte[1024 * 2];
|
||||
|
||||
private String name;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{name=" + name + ", b =" + (b == null ? "null" : "[length=" + b.length + "]") + "}";
|
||||
}
|
||||
|
||||
public byte[] getB() {
|
||||
return b;
|
||||
}
|
||||
|
||||
public void setB(byte[] b) {
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
/*
|
||||
* 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 com.wentch.redkale.test.service;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public class TestBean {
|
||||
|
||||
}
|
||||
@@ -1,176 +0,0 @@
|
||||
/*
|
||||
* 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 com.wentch.redkale.test.sncp;
|
||||
|
||||
import com.wentch.redkale.boot.*;
|
||||
import com.wentch.redkale.convert.bson.*;
|
||||
import com.wentch.redkale.net.*;
|
||||
import com.wentch.redkale.net.sncp.*;
|
||||
import com.wentch.redkale.service.*;
|
||||
import com.wentch.redkale.util.*;
|
||||
import com.wentch.redkale.watch.*;
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.atomic.*;
|
||||
import java.util.logging.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public class SncpTest {
|
||||
|
||||
private static final String serviceName = "";
|
||||
|
||||
private static final String myhost = Utility.localInetAddress().getHostAddress();
|
||||
|
||||
private static final int port = 4040;
|
||||
|
||||
private static final int port2 = 0; // 4240;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
final PrintStream ps = new PrintStream(out);
|
||||
ps.println("handlers = java.util.logging.ConsoleHandler");
|
||||
ps.println(".handlers = java.util.logging.ConsoleHandler");
|
||||
ps.println(".level = FINEST");
|
||||
ps.println("java.util.logging.ConsoleHandler.level = FINEST");
|
||||
LogManager.getLogManager().readConfiguration(new ByteArrayInputStream(out.toByteArray()));
|
||||
ResourceFactory.root().register("", BsonConvert.class, BsonFactory.root().getConvert());
|
||||
if (System.getProperty("client") == null) {
|
||||
runServer();
|
||||
if (port2 > 0) runServer2();
|
||||
}
|
||||
if (System.getProperty("server") == null) {
|
||||
runClient();
|
||||
}
|
||||
if (System.getProperty("server") != null) {
|
||||
System.in.read();
|
||||
}
|
||||
}
|
||||
|
||||
private static void runClient() throws Exception {
|
||||
InetSocketAddress addr = new InetSocketAddress(myhost, port);
|
||||
Set<InetSocketAddress> set = new LinkedHashSet<>();
|
||||
set.add(addr);
|
||||
if (port2 > 0) set.add(new InetSocketAddress(myhost, port2));
|
||||
final Transport transport = new Transport("", WatchFactory.root(), 50, set);
|
||||
final SncpTestService service = Sncp.createRemoteService(serviceName, null, SncpTestService.class, null, new LinkedHashSet<>(), transport);
|
||||
ResourceFactory.root().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 callbean = new SncpTestBean();
|
||||
callbean.setId(1);
|
||||
callbean.setContent("数据X");
|
||||
|
||||
service.insert(callbean);
|
||||
System.out.println("bean.id应该会被修改: " + callbean);
|
||||
System.out.println("---------------------------------------------------");
|
||||
final int count = 10;
|
||||
final CountDownLatch cld = new CountDownLatch(count);
|
||||
final AtomicInteger ai = new AtomicInteger();
|
||||
for (int i = 0; i < count; i++) {
|
||||
final int k = i + 1;
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Thread.sleep(k);
|
||||
SncpTestBean bean = new SncpTestBean();
|
||||
bean.setId(k);
|
||||
bean.setContent("数据: " + (k < 10 ? "0" : "") + k);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(k).append("------");
|
||||
for (int i = 0; i < 1200; i++) {
|
||||
sb.append("_").append(i).append("_").append(k).append("_0123456789");
|
||||
}
|
||||
bean.setContent(sb.toString());
|
||||
|
||||
service.queryResult(bean);
|
||||
//service.updateBean(bean);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
long a = ai.incrementAndGet();
|
||||
System.out.println("运行了 " + (a == 100 ? "--------------------------------------------------" : "") + a);
|
||||
cld.countDown();
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
cld.await();
|
||||
System.out.println("---全部运行完毕---");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
private static void runServer() throws Exception {
|
||||
InetSocketAddress addr = new InetSocketAddress(myhost, port);
|
||||
final CountDownLatch cdl = new CountDownLatch(1);
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
SncpServer server = new SncpServer();
|
||||
Set<InetSocketAddress> set = new LinkedHashSet<>();
|
||||
if (port2 > 0) set.add(new InetSocketAddress(myhost, port2));
|
||||
Transport transport = new Transport("", WatchFactory.root(), 50, set);
|
||||
List<Transport> sameTransports = new ArrayList<>();
|
||||
if (port2 > 0) sameTransports.add(transport);
|
||||
SncpTestService service = Sncp.createLocalService("", null, SncpTestService.class, addr, new LinkedHashSet<>(), sameTransports, null);
|
||||
ResourceFactory.root().inject(service);
|
||||
server.addService(new ServiceWrapper(SncpTestService.class, service, "", new ClassFilter.FilterEntry(SncpTestService.class, null)));
|
||||
System.out.println(service);
|
||||
AnyValue.DefaultAnyValue conf = new AnyValue.DefaultAnyValue();
|
||||
conf.addValue("host", "0.0.0.0");
|
||||
conf.addValue("port", "" + port);
|
||||
server.init(conf);
|
||||
server.start();
|
||||
cdl.countDown();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
cdl.await();
|
||||
}
|
||||
|
||||
private static void runServer2() throws Exception {
|
||||
InetSocketAddress addr = new InetSocketAddress(myhost, port2);
|
||||
final CountDownLatch cdl = new CountDownLatch(1);
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
SncpServer server = new SncpServer();
|
||||
Set<InetSocketAddress> set = new LinkedHashSet<>();
|
||||
set.add(new InetSocketAddress(myhost, port));
|
||||
Transport transport = new Transport("", WatchFactory.root(), 50, set);
|
||||
List<Transport> sameTransports = new ArrayList<>();
|
||||
sameTransports.add(transport);
|
||||
Service service = Sncp.createLocalService("", null, SncpTestService.class, addr, new LinkedHashSet<>(), sameTransports, null);
|
||||
server.addService(new ServiceWrapper(SncpTestService.class, service, "", new ClassFilter.FilterEntry(SncpTestService.class, null)));
|
||||
AnyValue.DefaultAnyValue conf = new AnyValue.DefaultAnyValue();
|
||||
conf.addValue("host", "0.0.0.0");
|
||||
conf.addValue("port", "" + port2);
|
||||
server.init(conf);
|
||||
server.start();
|
||||
cdl.countDown();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
cdl.await();
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* 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 com.wentch.redkale.test.sncp;
|
||||
|
||||
import com.wentch.redkale.convert.bson.*;
|
||||
import com.wentch.redkale.convert.json.*;
|
||||
import com.wentch.redkale.source.*;
|
||||
import com.wentch.redkale.util.*;
|
||||
import javax.persistence.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public class SncpTestBean implements FilterBean {
|
||||
|
||||
@Id
|
||||
private long id;
|
||||
|
||||
private String content;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
SncpTestBean bean = JsonFactory.root().getConvert().convertFrom(SncpTestBean.class, "{\"content\":\"数据: 01\",\"id\":1}");
|
||||
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());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonFactory.root().getConvert().convertTo(this);
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
* 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 com.wentch.redkale.test.sncp;
|
||||
|
||||
import com.wentch.redkale.net.sncp.*;
|
||||
import com.wentch.redkale.service.*;
|
||||
import com.wentch.redkale.source.*;
|
||||
import com.wentch.redkale.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public class SncpTestService implements Service {
|
||||
|
||||
public static class CallAttribute implements Attribute<SncpTestBean, Long> {
|
||||
|
||||
@Override
|
||||
public Class<? extends Long> type() {
|
||||
return long.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<SncpTestBean> declaringClass() {
|
||||
return SncpTestBean.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String field() {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long get(SncpTestBean obj) {
|
||||
System.out.println("返回ID: " + obj.getId());
|
||||
return obj.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(SncpTestBean obj, Long value) {
|
||||
System.out.println("设置ID: " + value);
|
||||
obj.setId(value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void insert(@SncpCall(DataCallArrayAttribute.class) SncpTestBean... beans) {
|
||||
for (SncpTestBean bean : beans) {
|
||||
bean.setId(System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
|
||||
public String queryResult(SncpTestBean bean) {
|
||||
System.out.println(Thread.currentThread().getName() + " 运行了queryResult方法");
|
||||
return "result: " + bean;
|
||||
}
|
||||
|
||||
@MultiRun
|
||||
public String updateBean(@SncpCall(CallAttribute.class) SncpTestBean bean) {
|
||||
bean.setId(System.currentTimeMillis());
|
||||
System.out.println(Thread.currentThread().getName() + " 运行了updateBean方法");
|
||||
return "result: " + bean;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
/*
|
||||
* 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 com.wentch.redkale.test.source;
|
||||
|
||||
import com.wentch.redkale.source.*;
|
||||
import com.wentch.redkale.source.DataSource.Reckon;
|
||||
import com.wentch.redkale.util.*;
|
||||
import java.util.*;
|
||||
import javax.persistence.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public class CacheTestBean {
|
||||
|
||||
@Id
|
||||
private long pkgid;
|
||||
|
||||
private String name;
|
||||
|
||||
private long price;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
final List<CacheTestBean> list = new ArrayList<>();
|
||||
list.add(new CacheTestBean(1, "a", 12));
|
||||
list.add(new CacheTestBean(1, "a", 18));
|
||||
list.add(new CacheTestBean(2, "b", 20));
|
||||
list.add(new CacheTestBean(2, "bb", 60));
|
||||
Attribute idattr = Attribute.create(CacheTestBean.class, "pkgid");
|
||||
Attribute nameattr = Attribute.create(CacheTestBean.class, "name");
|
||||
Attribute priceattr = Attribute.create(CacheTestBean.class, "price");
|
||||
EntityCache<CacheTestBean> cache = new EntityCache(EntityInfo.load(CacheTestBean.class, 0, true, null));
|
||||
cache.fullLoad(list);
|
||||
|
||||
System.out.println(cache.getMapResult("pkgid", Reckon.COUNT, "name", null));
|
||||
System.out.println(cache.getMapResult("pkgid", Reckon.DISTINCTCOUNT, "name", null));
|
||||
System.out.println(cache.getMapResult("pkgid", Reckon.AVG, "price", null));
|
||||
System.out.println(cache.getMapResult("pkgid", Reckon.SUM, "price", null));
|
||||
System.out.println(cache.getMapResult("pkgid", Reckon.MAX, "price", null));
|
||||
System.out.println(cache.getMapResult("pkgid", Reckon.MIN, "price", null));
|
||||
}
|
||||
|
||||
public CacheTestBean() {
|
||||
}
|
||||
|
||||
public CacheTestBean(long pkgid, String name, long price) {
|
||||
this.pkgid = pkgid;
|
||||
this.name = name;
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public long getPkgid() {
|
||||
return pkgid;
|
||||
}
|
||||
|
||||
public void setPkgid(long pkgid) {
|
||||
this.pkgid = pkgid;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public long getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public void setPrice(long price) {
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* 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 com.wentch.redkale.test.source;
|
||||
|
||||
import com.wentch.redkale.source.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public class JDBCTest {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
System.setProperty("persist.type", "jdbc");
|
||||
DataSource source = new DataDefaultSource(); //耗时:37415
|
||||
int count = 1000;
|
||||
LoginTestRecord last = null;
|
||||
long s = System.currentTimeMillis();
|
||||
int c = 0;
|
||||
try {
|
||||
for (int i = 0; i < count; i++) {
|
||||
LoginTestRecord record = new LoginTestRecord();
|
||||
record.setSessionid(Long.toHexString(System.nanoTime()));
|
||||
record.setLoginagent("win7");
|
||||
record.setLogintime(System.currentTimeMillis());
|
||||
record.setLoginip("127.0.0.1");
|
||||
record.setUserid(i);
|
||||
source.insert(record);
|
||||
last = record;
|
||||
c = i;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("异常了: " + c);
|
||||
e.printStackTrace();
|
||||
}
|
||||
long e = System.currentTimeMillis() - s;
|
||||
System.out.println("耗时:" + e);
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* 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 com.wentch.redkale.test.source;
|
||||
|
||||
import com.wentch.redkale.source.FilterBean;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public class LoginTestBean implements FilterBean {
|
||||
|
||||
private String sessionid;
|
||||
|
||||
public String getSessionid() {
|
||||
return sessionid;
|
||||
}
|
||||
|
||||
public void setSessionid(String sessionid) {
|
||||
this.sessionid = sessionid;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
/*
|
||||
* 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 com.wentch.redkale.test.source;
|
||||
|
||||
import com.wentch.redkale.convert.json.JsonFactory;
|
||||
import javax.persistence.*;
|
||||
import static javax.persistence.GenerationType.SEQUENCE;
|
||||
|
||||
/**
|
||||
* CREATE TABLE `LoginTestRecord` (
|
||||
* `sessionid` VARCHAR(64) NOT NULL COMMENT '登陆会话ID',
|
||||
* `userid` INT(11) NOT NULL COMMENT '登陆用户ID',
|
||||
* `loginagent` VARCHAR(128) NOT NULL COMMENT '登陆端信息',
|
||||
* `loginip` VARCHAR(255) NOT NULL COMMENT '登陆IP',
|
||||
* `logintime` BIGINT(20) NOT NULL COMMENT '登陆时间',
|
||||
* `logouttime` BIGINT(20) NOT NULL COMMENT '注销时间',
|
||||
* PRIMARY KEY (`sessionid`)
|
||||
* ) ENGINE=INNODB DEFAULT CHARSET=utf8;
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
@Entity
|
||||
public class LoginTestRecord {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = SEQUENCE, generator = "SEQ")
|
||||
//@SequenceGenerator(name = "SEQ", initialValue = 100001, allocationSize = 1000)
|
||||
private String sessionid;
|
||||
|
||||
private int userid;
|
||||
|
||||
private String loginagent;
|
||||
|
||||
private String loginip;
|
||||
|
||||
private long logintime;
|
||||
|
||||
private long logouttime;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonFactory.root().getConvert().convertTo(this);
|
||||
}
|
||||
|
||||
public String getSessionid() {
|
||||
return sessionid;
|
||||
}
|
||||
|
||||
public void setSessionid(String sessionid) {
|
||||
this.sessionid = sessionid;
|
||||
}
|
||||
|
||||
public int getUserid() {
|
||||
return userid;
|
||||
}
|
||||
|
||||
public void setUserid(int userid) {
|
||||
this.userid = userid;
|
||||
}
|
||||
|
||||
public String getLoginagent() {
|
||||
return loginagent;
|
||||
}
|
||||
|
||||
public void setLoginagent(String loginagent) {
|
||||
this.loginagent = loginagent;
|
||||
}
|
||||
|
||||
public String getLoginip() {
|
||||
return loginip;
|
||||
}
|
||||
|
||||
public void setLoginip(String loginip) {
|
||||
this.loginip = loginip;
|
||||
}
|
||||
|
||||
public long getLogintime() {
|
||||
return logintime;
|
||||
}
|
||||
|
||||
public void setLogintime(long logintime) {
|
||||
this.logintime = logintime;
|
||||
}
|
||||
|
||||
public long getLogouttime() {
|
||||
return logouttime;
|
||||
}
|
||||
|
||||
public void setLogouttime(long logouttime) {
|
||||
this.logouttime = logouttime;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,126 +0,0 @@
|
||||
/*
|
||||
* 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 com.wentch.redkale.test.source;
|
||||
|
||||
import com.wentch.redkale.convert.json.*;
|
||||
import com.wentch.redkale.source.*;
|
||||
import com.wentch.redkale.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import javax.persistence.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public class TestSourceCache {
|
||||
|
||||
public static class TestEntityBean implements FilterBean {
|
||||
|
||||
@FilterColumn(express = FilterExpress.GREATERTHAN)
|
||||
public int userid;
|
||||
|
||||
@FilterColumn(express = FilterExpress.LIKE)
|
||||
public String username;
|
||||
|
||||
public TestEntityBean(int userid, String username) {
|
||||
this.userid = userid;
|
||||
this.username = username;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
final EntityInfo<TestEntity> info = EntityInfo.load(TestEntity.class, 0, false, null);
|
||||
TestEntity[] entitys = new TestEntity[10_0000];
|
||||
for (int i = 0; i < entitys.length; i++) {
|
||||
entitys[i] = new TestEntity(i + 1, "用户_" + (i + 1));
|
||||
}
|
||||
long s = System.currentTimeMillis();
|
||||
for (TestEntity en : entitys) {
|
||||
info.getCache().insert(en);
|
||||
}
|
||||
long e = System.currentTimeMillis() - s;
|
||||
System.out.println("插入十万条记录耗时: " + e / 1000.0 + " 秒");
|
||||
|
||||
s = System.currentTimeMillis();
|
||||
TestEntity one = info.getCache().find(9999);
|
||||
e = System.currentTimeMillis() - s;
|
||||
System.out.println("十万条数据中查询一条记录耗时: " + e / 1000.0 + " 秒 " + one);
|
||||
|
||||
final Flipper flipper = new Flipper(2);
|
||||
flipper.setSort("userid DESC, createtime DESC");
|
||||
final FilterNode node = FilterNode.create("userid", FilterExpress.GREATERTHAN, 1000).and("username", FilterExpress.LIKE, "用户");
|
||||
System.out.println("node = " + node);
|
||||
Sheet<TestEntity> sheet = info.getCache().querySheet(null, flipper, node);
|
||||
System.out.println(sheet);
|
||||
System.out.println(info.getCache().querySheet(null, flipper, FilterNodeBean.createFilterNode(new TestEntityBean(1000, "用户"))));
|
||||
final CountDownLatch cdl = new CountDownLatch(100);
|
||||
s = System.currentTimeMillis();
|
||||
for (int i = 0; i < 100; i++) {
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (int k = 0; k < 10; k++) {
|
||||
info.getCache().querySheet(true, null, flipper, node);
|
||||
}
|
||||
cdl.countDown();
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
cdl.await();
|
||||
e = System.currentTimeMillis() - s;
|
||||
System.out.println("十万条数据中查询一页记录耗时: " + e / 1000.0 + " 秒 " + sheet); // CopyOnWriteArrayList 0.798 ConcurrentLinkedQueue 1.063
|
||||
}
|
||||
|
||||
@VirtualEntity
|
||||
@Cacheable
|
||||
public static class TestEntity {
|
||||
|
||||
@Id
|
||||
private int userid;
|
||||
|
||||
private String username;
|
||||
|
||||
private long createtime = System.currentTimeMillis();
|
||||
|
||||
public TestEntity() {
|
||||
|
||||
}
|
||||
|
||||
public TestEntity(int userid, String username) {
|
||||
this.userid = userid;
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public int getUserid() {
|
||||
return userid;
|
||||
}
|
||||
|
||||
public void setUserid(int userid) {
|
||||
this.userid = userid;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public long getCreatetime() {
|
||||
return createtime;
|
||||
}
|
||||
|
||||
public void setCreatetime(long createtime) {
|
||||
this.createtime = createtime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonFactory.root().getConvert().convertTo(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
/*
|
||||
* 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 com.wentch.redkale.test.util;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public class TestABean {
|
||||
public long time;
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* 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 com.wentch.redkale.test.util;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public class TestBean extends TestABean {
|
||||
|
||||
private String name;
|
||||
|
||||
private int id;
|
||||
|
||||
private Map<String, String> map;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Map<String, String> getMap() {
|
||||
return map;
|
||||
}
|
||||
|
||||
public void setMap(Map<String, String> map) {
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
/*
|
||||
* 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 com.wentch.redkale.test.util;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public class TestXBean extends TestBean{
|
||||
|
||||
}
|
||||
@@ -1,103 +0,0 @@
|
||||
/*
|
||||
* 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 com.wentch.redkale.test.util;
|
||||
|
||||
import com.wentch.redkale.util.Reproduce;
|
||||
import com.wentch.redkale.util.Attribute;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public class UntilTestMain {
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
reproduce(args);
|
||||
attribute(args);
|
||||
}
|
||||
|
||||
public static void reproduce(String[] args) throws Throwable {
|
||||
final TestBean bean = new TestBean();
|
||||
bean.setId(123456);
|
||||
bean.setName("zhangjx");
|
||||
bean.time = 2000;
|
||||
final TestXBean beanx = new TestXBean();
|
||||
Reproduce<TestXBean, TestBean> action1 = Reproduce.create(TestXBean.class, TestBean.class);
|
||||
Reproduce<TestXBean, TestBean> action2 = new Reproduce<TestXBean, TestBean>() {
|
||||
|
||||
@Override
|
||||
public TestXBean copy(TestXBean dest, TestBean src) {
|
||||
dest.time = src.time;
|
||||
dest.setId(src.getId());
|
||||
dest.setName(src.getName());
|
||||
dest.setMap(src.getMap());
|
||||
return dest;
|
||||
}
|
||||
};
|
||||
final int count = 1_000_000;
|
||||
long s = System.nanoTime();
|
||||
for (int i = 0; i < count; i++) {
|
||||
action2.copy(beanx, bean);
|
||||
}
|
||||
long e = System.nanoTime() - s;
|
||||
System.out.println("静态Reproduce耗时: " + e);
|
||||
s = System.nanoTime();
|
||||
for (int i = 0; i < count; i++) {
|
||||
action1.copy(beanx, bean);
|
||||
}
|
||||
e = System.nanoTime() - s;
|
||||
System.out.println("动态Reproduce耗时: " + e);
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
public static void attribute(String[] args) throws Throwable {
|
||||
final TestBean bean = new TestBean();
|
||||
bean.setId(123456);
|
||||
bean.setName("zhangjx");
|
||||
Attribute<TestBean, String> action1 = Attribute.create(TestBean.class.getDeclaredField("name"));
|
||||
Attribute<TestBean, String> action2 = new Attribute<TestBean, String>() {
|
||||
|
||||
@Override
|
||||
public String field() {
|
||||
return "name";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get(TestBean obj) {
|
||||
return obj.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(TestBean obj, String value) {
|
||||
obj.setName(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class type() {
|
||||
return String.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class declaringClass() {
|
||||
return TestBean.class;
|
||||
}
|
||||
};
|
||||
final int count = 1_000_000;
|
||||
long s = System.nanoTime();
|
||||
for (int i = 0; i < count; i++) {
|
||||
action2.set(bean, "zhangjx2");
|
||||
}
|
||||
long e = System.nanoTime() - s;
|
||||
System.out.println("静态Attribute耗时: " + e);
|
||||
s = System.nanoTime();
|
||||
for (int i = 0; i < count; i++) {
|
||||
action1.set(bean, "zhangjx2");
|
||||
}
|
||||
e = System.nanoTime() - s;
|
||||
System.out.println("动态Attribute耗时: " + e);
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
* 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 com.wentch.redkale.test.websocket;
|
||||
|
||||
import com.wentch.redkale.net.http.WebServlet;
|
||||
import com.wentch.redkale.net.http.WebSocketServlet;
|
||||
import com.wentch.redkale.net.http.WebSocket;
|
||||
import java.io.*;
|
||||
import static java.lang.Thread.sleep;
|
||||
import java.text.*;
|
||||
import java.util.concurrent.atomic.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
@WebServlet("/ws/chat")
|
||||
public class ChatWebSocketServlet extends WebSocketServlet {
|
||||
|
||||
private final AtomicLong counter = new AtomicLong();
|
||||
|
||||
private final AtomicLong icounter = new AtomicLong();
|
||||
|
||||
private final boolean debug;
|
||||
|
||||
public ChatWebSocketServlet() {
|
||||
debug = "true".equalsIgnoreCase(System.getProperty("debug", "false"));
|
||||
Thread t = new Thread() {
|
||||
|
||||
private final DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
{
|
||||
setName("Debug-ChatWebSocket-ShowCount-Thread");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while (true) {
|
||||
try {
|
||||
sleep(60 * 1000);
|
||||
} catch (Exception e) {
|
||||
return;
|
||||
}
|
||||
System.out.println(format.format(new java.util.Date()) + ": 消息总数: " + counter.get() + ",间隔消息数: " + icounter.getAndSet(0));
|
||||
}
|
||||
}
|
||||
};
|
||||
t.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected WebSocket createWebSocket() {
|
||||
|
||||
return new WebSocket() {
|
||||
|
||||
@Override
|
||||
public void onMessage(String text) {
|
||||
icounter.incrementAndGet();
|
||||
counter.incrementAndGet();
|
||||
if (debug) System.out.println("收到消息: " + text);
|
||||
super.getWebSocketGroup().getWebSockets().forEach(x -> x.send(text));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Serializable createGroupid() {
|
||||
return "";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* 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 com.wentch.redkale.test.websocket;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.net.Socket;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public class Flash843 {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
Socket socket = new Socket("113.105.88.229", 843);
|
||||
socket.getOutputStream().write("<policy-file-request/>".getBytes());
|
||||
socket.getOutputStream().flush();
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
byte[] bytes = new byte[1024];
|
||||
int pos;
|
||||
while ((pos = socket.getInputStream().read(bytes)) != -1) {
|
||||
out.write(bytes, 0, pos);
|
||||
}
|
||||
System.out.println(out.toString());
|
||||
}
|
||||
}
|
||||
@@ -1,134 +0,0 @@
|
||||
/*
|
||||
* 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 com.wentch.redkale.test.websocket;
|
||||
|
||||
import com.wentch.redkale.net.http.WebServlet;
|
||||
import com.wentch.redkale.net.http.WebSocketServlet;
|
||||
import com.wentch.redkale.net.http.HttpRequest;
|
||||
import com.wentch.redkale.net.http.WebSocket;
|
||||
import com.wentch.redkale.net.http.HttpServer;
|
||||
import com.wentch.redkale.util.TypeToken;
|
||||
import com.wentch.redkale.util.AnyValue;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
@WebServlet({"/ws/listen"})
|
||||
public class VideoWebSocketServlet extends WebSocketServlet {
|
||||
|
||||
private final Map<Serializable, Entry> sessions = new java.util.concurrent.ConcurrentHashMap<>();
|
||||
|
||||
private final Map<Serializable, String> users = new HashMap<>();
|
||||
|
||||
private static final class Entry {
|
||||
|
||||
public WebSocket socket;
|
||||
|
||||
public String username;
|
||||
|
||||
public Serializable userid;
|
||||
|
||||
}
|
||||
|
||||
public VideoWebSocketServlet() {
|
||||
super();
|
||||
users.put("zhangjx", "xxxx");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected WebSocket createWebSocket() {
|
||||
WebSocket socket = new WebSocket() {
|
||||
|
||||
private final TypeToken<Map<String, String>> mapToken = new TypeToken<Map<String, String>>() {
|
||||
};
|
||||
|
||||
private boolean repeat = false;
|
||||
|
||||
@Override
|
||||
public String onOpen(final HttpRequest request) {
|
||||
String uri = request.getRequestURI();
|
||||
int pos = uri.indexOf("/listen/");
|
||||
uri = uri.substring(pos + "/listen/".length());
|
||||
this.repeat = sessions.get(uri) != null;
|
||||
if (!this.repeat) this.repeat = users.get(uri) == null;
|
||||
String sessionid = Long.toString(System.nanoTime());
|
||||
if (uri.indexOf('\'') >= 0 || uri.indexOf('"') >= 0) return null;
|
||||
if (!repeat) sessionid = uri;
|
||||
return sessionid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnected() {
|
||||
if (repeat) {
|
||||
super.close();
|
||||
} else {
|
||||
Entry entry = new Entry();
|
||||
entry.userid = this.getSessionid();
|
||||
entry.username = users.get(entry.userid);
|
||||
sessions.put(this.getSessionid(), entry);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Map.Entry<Serializable, Entry> en : sessions.entrySet()) {
|
||||
if (sb.length() > 0) sb.append(',');
|
||||
sb.append("{'userid':'").append(en.getKey()).append("','username':'").append(en.getValue().username).append("'}");
|
||||
}
|
||||
super.send(("{'type':'user_list','users':[" + sb + "]}").replace('\'', '"'));
|
||||
String msg = ("{'type':'discover_user','user':{'userid':'" + this.getSessionid() + "','username':'" + users.get(this.getSessionid()) + "'}}").replace('\'', '"');
|
||||
super.getWebSocketGroup().getWebSockets().filter(x -> x != this).forEach(x -> {
|
||||
x.send(msg);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(String text) {
|
||||
//System.out.println("接收到消息: " + text);
|
||||
super.getWebSocketGroup().getWebSockets().filter(x -> x != this).forEach(x -> {
|
||||
x.send(text);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(int code, String reason) {
|
||||
sessions.remove(this.getSessionid());
|
||||
String msg = ("{'type':'remove_user','user':{'userid':'" + this.getSessionid() + "','username':'" + users.get(this.getSessionid()) + "'}}").replace('\'', '"');
|
||||
super.getWebSocketGroup().getWebSockets().filter(x -> x != this).forEach(x -> {
|
||||
x.send(msg);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Serializable createGroupid() {
|
||||
return "";
|
||||
}
|
||||
};
|
||||
return socket;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
CountDownLatch cdl = new CountDownLatch(1);
|
||||
AnyValue.DefaultAnyValue config = new AnyValue.DefaultAnyValue();
|
||||
config.addValue("threads", System.getProperty("threads"));
|
||||
config.addValue("bufferPoolSize", System.getProperty("bufferPoolSize"));
|
||||
config.addValue("responsePoolSize", System.getProperty("responsePoolSize"));
|
||||
config.addValue("host", System.getProperty("host", "0.0.0.0"));
|
||||
config.addValue("port", System.getProperty("port", "8070"));
|
||||
config.addValue("root", System.getProperty("root", "./root3/"));
|
||||
AnyValue.DefaultAnyValue resConf = new AnyValue.DefaultAnyValue();
|
||||
resConf.setValue("cacheMaxLength", "200M");
|
||||
resConf.setValue("cacheMaxItemLength", "10M");
|
||||
config.setValue("ResourceServlet", resConf);
|
||||
HttpServer server = new HttpServer();
|
||||
server.addHttpServlet(new VideoWebSocketServlet(), null, "/pipes/listen/*");
|
||||
server.init(config);
|
||||
server.start();
|
||||
cdl.await();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user