Skip to content

Commit

Permalink
Feature:添加了FastJson序列化,还是有bug,不可使用。
Browse files Browse the repository at this point in the history
  • Loading branch information
songxinjianqwe committed Aug 23, 2018
1 parent a811185 commit fb919f0
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ public static void main(String[] args) throws InterruptedException {

@Override
public void run(String... strings) throws Exception {
int threads = Integer.parseInt(strings[0]);
int requestTotal = Integer.parseInt(strings[1]);
int measurementIterations = Integer.parseInt(strings[2]);
client.run(threads, requestTotal,measurementIterations);
// client.run(1,1,1);
// int threads = Integer.parseInt(strings[0]);
// int requestTotal = Integer.parseInt(strings[1]);
// int measurementIterations = Integer.parseInt(strings[2]);
// client.run(threads, requestTotal,measurementIterations);
client.run(1,1,1);
System.exit(0);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
rpc.application.name=benchmark_consumer
rpc.application.serialize=protostuff
rpc.application.serialize=json
rpc.application.proxy=javassist
rpc.protocol.type=toy
rpc.protocol.executor.server.type=threadpool
rpc.protocol.executor.client.type=threadpool
#rpc.registry.address=127.0.0.1:2181
rpc.registry.address=192.168.1.117:2181
rpc.registry.address=127.0.0.1:2181
#rpc.registry.address=192.168.1.117:2181
rpc.cluster.loadbalance=consistent_hash
rpc.cluster.faulttolerance=failover
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
rpc.application.name=benchmark_provider
rpc.application.serialize=protostuff
rpc.application.serialize=json
rpc.application.proxy=javassist
rpc.protocol.type=toy
rpc.protocol.port=8000
Expand Down
6 changes: 6 additions & 0 deletions toy-rpc-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,11 @@
<artifactId>hessian</artifactId>
<version>4.0.38</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.49</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.sinjinsong.toy.serialize.api.Serializer;
import com.sinjinsong.toy.serialize.hessian.HessianSerializer;
import com.sinjinsong.toy.serialize.jdk.JdkSerializer;
import com.sinjinsong.toy.serialize.json.JsonSerializer;
import com.sinjinsong.toy.serialize.protostuff.ProtostuffSerializer;

/**
Expand All @@ -13,7 +14,8 @@
public enum SerializerType implements ExtensionBaseType<Serializer> {
PROTOSTUFF(new ProtostuffSerializer()),
JDK(new JdkSerializer()),
HESSIAN(new HessianSerializer());
HESSIAN(new HessianSerializer()),
JSON(new JsonSerializer());

private Serializer serializer;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.sinjinsong.toy.serialize.json;

import com.alibaba.fastjson.JSONObject;
import com.sinjinsong.toy.common.exception.RPCException;
import com.sinjinsong.toy.serialize.api.Serializer;

/**
* @author sinjinsong
* @date 2018/8/23
*/
public class JsonSerializer implements Serializer {
@Override
public <T> byte[] serialize(T obj) throws RPCException {
return JSONObject.toJSONBytes(obj);
}

@Override
public <T> T deserialize(byte[] data, Class<T> cls) throws RPCException {
return JSONObject.parseObject(data, cls);
}
}

0 comments on commit fb919f0

Please sign in to comment.