This commit is contained in:
地平线
2015-06-21 10:50:51 +08:00
parent ba514cfdc1
commit 496ff9833b
29 changed files with 1937 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="" transaction-type="RESOURCE_LOCAL">
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<shared-cache-mode>ALL</shared-cache-mode>
<validation-mode>NONE</validation-mode>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://127.0.0.1:3306/test?autoReconnect=true&amp;autoReconnectForPools=true&amp;characterEncoding=utf8"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.password" value="1234"/>
</properties>
</persistence-unit>
</persistence>

View File

@@ -0,0 +1,21 @@
/*
* 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);
}
}

View File

@@ -0,0 +1,41 @@
/*
* 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.BsonConvert;
import com.wentch.redkale.convert.bson.BsonFactory;
import com.wentch.redkale.convert.json.*;
import java.io.Serializable;
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(TestEntry2.class, entry);
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);
System.out.println(convert.convertFrom(TestComplextBean.class, bytes2).toString());
}
}

View File

@@ -0,0 +1,31 @@
/*
* 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.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));
}
}

View File

@@ -0,0 +1,391 @@
/*
* 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;
}
}

View File

@@ -0,0 +1,129 @@
/*
* 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;
}
}

View File

@@ -0,0 +1,114 @@
/*
* 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 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});
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;
}
}

View File

@@ -0,0 +1,45 @@
/*
* 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.*;
/**
*
* @author zhangjx
*/
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});
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;
}
}

View File

@@ -0,0 +1,114 @@
/*
* 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;
}
}

View File

@@ -0,0 +1,89 @@
/*
* 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;
}
}

View File

@@ -0,0 +1,48 @@
/*
* 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\"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;文件1: <input type=\"file\" name=\"filepath1\"/><br/><br/>"
+ "描述: <input name=\"desc2\"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;文件2: <input type=\"file\" name=\"filepath2\"/><br/><br/>"
+ "描述: <input name=\"desc3\"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;文件3: <input type=\"file\" name=\"filepath3\"/><br/><br/>"
+ "描述: <input name=\"desc4\"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/><br/>"
+ "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<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);
}
}

View File

@@ -0,0 +1,28 @@
/*
* 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;
import com.wentch.redkale.service.Service;
/**
*
* @author zhangjx
*/
public class IMService implements Service {
@Override
public String toString() {
return "[" + this.getClass().getSimpleName() + "]";
}
public void send(String text) {
onSend(text);
}
public void onSend(String text) {
System.out.println("接收到消息: " + text);
}
}

View File

@@ -0,0 +1,27 @@
/*
* 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;
import com.wentch.redkale.net.http.WebSocketServlet;
import com.wentch.redkale.net.http.WebSocket;
import java.util.Map;
import javax.annotation.Resource;
/**
*
* @author zhangjx
*/
public class IMServlet extends WebSocketServlet {
@Resource(name = "^IMNODE.+$")
private Map<String, IMService> nodemaps;
@Override
protected WebSocket createWebSocket() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}

View File

@@ -0,0 +1,32 @@
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;
}
}

View File

@@ -0,0 +1,14 @@
/*
* 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 {
}

View File

@@ -0,0 +1,69 @@
/*
* 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.net.*;
import com.wentch.redkale.net.sncp.*;
import com.wentch.redkale.util.*;
import com.wentch.redkale.watch.*;
import java.net.*;
import java.util.concurrent.*;
/**
*
* @author zhangjx
*/
public class SncpTest {
private static final String serviceName = "";
private static final int port = 7070;
public static void main(String[] args) throws Exception {
runServer();
runClient();
}
private static void runClient() throws Exception {
ResourceFactory.root().register("", BsonConvert.class, BsonFactory.root().getConvert());
Transport transport = new Transport("testsncp", "UDP", WatchFactory.root(), 100, new InetSocketAddress("127.0.0.1", port));
ResourceFactory.root().register("testsncp", Transport.class, transport);
SncpTestService service = Sncp.createRemoteService(serviceName, SncpTestService.class, "testsncp");
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());
System.out.println(service.queryResult(bean));
}
private static void runServer() throws Exception {
final CountDownLatch cdl = new CountDownLatch(1);
new Thread() {
@Override
public void run() {
try {
SncpServer server = new SncpServer();
server.addService(new ServiceEntry(SncpTestService.class, new SncpTestService(), null, serviceName));
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();
}
}

View File

@@ -0,0 +1,42 @@
/*
* 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.json.*;
import com.wentch.redkale.source.*;
/**
*
* @author zhangjx
*/
public class SncpTestBean implements FilterBean {
private long id;
private String content;
@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;
}
}

View File

@@ -0,0 +1,20 @@
/*
* 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.service.*;
/**
*
* @author zhangjx
*/
public class SncpTestService implements Service {
public String queryResult(SncpTestBean bean) {
System.out.println("运行了方法");
return "result: " + bean;
}
}

View File

@@ -0,0 +1,78 @@
/*
* 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.*;
/**
*
* @author zhangjx
*/
public class CacheTestBean {
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(CacheTestBean.class, Creator.create(CacheTestBean.class), idattr, null);
cache.fullLoad(list);
System.out.println(cache.getMapResult(idattr, Reckon.COUNT, nameattr, null));
System.out.println(cache.getMapResult(idattr, Reckon.DISTINCTCOUNT, nameattr, null));
System.out.println(cache.getMapResult(idattr, Reckon.AVG, priceattr, null));
System.out.println(cache.getMapResult(idattr, Reckon.SUM, priceattr, null));
System.out.println(cache.getMapResult(idattr, Reckon.MAX, priceattr, null));
System.out.println(cache.getMapResult(idattr, Reckon.MIN, priceattr, 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;
}
}

View File

@@ -0,0 +1,43 @@
/*
* 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.DataSource;
import com.wentch.redkale.source.DataSourceFactory;
/**
*
* @author zhangjx
*/
public class JDBCTest {
public static void main(String[] args) throws Exception {
System.setProperty("persist.type", "jdbc");
DataSource source = DataSourceFactory.create(); //耗时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);
}
}

View File

@@ -0,0 +1,26 @@
/*
* 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;
}
}

View File

@@ -0,0 +1,96 @@
/*
* 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;
}
}

View File

@@ -0,0 +1,38 @@
/*
* 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.*;
/**
*
* @author zhangjx
*/
public class Test {
public static void main(String args[]) {
List<String> list = new ArrayList<String>();
test1(list);
System.out.println(list.size()); // 1处
test2(list);
System.out.println(list.size()); // 2处
test3(list);
System.out.println(list.size()); // 3处
}
public static void test1(List list) {
list = null;
}
public static void test2(List list) {
list.add("3wyc");
}
public static void test3(List list) {
list.add(new StringBuilder("3wyc"));
}
}

View File

@@ -0,0 +1,46 @@
/*
* 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 {
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;
}
}

View File

@@ -0,0 +1,15 @@
/*
* 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{
}

View File

@@ -0,0 +1,101 @@
/*
* 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");
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.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();
}
}

View File

@@ -0,0 +1,68 @@
/*
* 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 static java.lang.Thread.sleep;
import java.text.*;
import java.util.concurrent.atomic.*;
/**
*
* @author zhangjx
*/
@WebServlet("/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));
}
};
}
}

View File

@@ -0,0 +1,29 @@
/*
* 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());
}
}

View File

@@ -0,0 +1,128 @@
/*
* 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.util.*;
import java.util.concurrent.CountDownLatch;
/**
*
* @author zhangjx
*/
@WebServlet({"/listen/*"})
public class VideoWebSocketServlet extends WebSocketServlet {
private final Map<String, Entry> sessions = new java.util.concurrent.ConcurrentHashMap<>();
private final Map<String, String> users = new HashMap<>();
private static final class Entry {
public WebSocket socket;
public String username;
public String 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<String, 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);
});
}
};
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();
}
}