Search in sources :

Example 1 with UserServiceServerImpl

use of rpc.turbo.benchmark.service.UserServiceServerImpl in project turbo-rpc by hank-whu.

the class RpcServerBenchmark method main.

public static void main(String[] args) throws Exception {
    ResourceLeakDetector.setLevel(Level.DISABLED);
    try (TurboServer server = new TurboServer("shop", "auth")) {
        Map<Class<?>, Object> services = Map.of(UserService.class, new UserServiceServerImpl());
        server.registerService(services);
        /*
			 * server.addFirst(new RpcServerFilter() {
			 * 
			 * @Override public void onSend(Request request, Response response) { try {
			 * Tracer tracer = request.getTracer();
			 * 
			 * if (tracer != null) { response.setTracer(tracer); }
			 * 
			 * } catch (Exception e) { e.printStackTrace(); } }
			 * 
			 * @Override public boolean onRecive(Request request) { try { Tracer tracer =
			 * request.getTracer();
			 * 
			 * if (tracer != null) { RemoteContext.getClientAddress().toString();
			 * RemoteContext.getServerAddress().toString();
			 * RemoteContext.getServiceMethodName();
			 * 
			 * TracerContext.setTracer(tracer); } } catch (Exception e) {
			 * e.printStackTrace(); }
			 * 
			 * return true; }
			 * 
			 * @Override public void onError(Request request, Response response, Throwable
			 * throwable) { } });
			 */
        server.startRpcServer(new HostPort("127.0.0.1", 8080));
        server.waitUntilShutdown();
    }
}
Also used : TurboServer(rpc.turbo.server.TurboServer) UserServiceServerImpl(rpc.turbo.benchmark.service.UserServiceServerImpl) HostPort(rpc.turbo.config.HostPort)

Example 2 with UserServiceServerImpl

use of rpc.turbo.benchmark.service.UserServiceServerImpl in project turbo-rpc by hank-whu.

the class KryoByteBufTest method main.

public static void main(String[] args) {
    Kryo kryo = new Kryo();
    // kryo.setWarnUnregisteredClasses(true);
    // kryo.setReferences(false);
    kryo.register(IntObj.class);
    kryo.register(StringUTF8Obj.class);
    kryo.register(LocalDateTimeObj.class);
    kryo.register(ComplexObj.class);
    kryo.register(int[].class);
    kryo.register(ArrayList.class);
    kryo.register(ArrayListObj.class);
    ByteBufAllocator allocator = new PooledByteBufAllocator(true);
    ByteBuf buffer = allocator.directBuffer(2, 1024 * 1024 * 8);
    System.out.println("buffer.nioBufferCount: " + buffer.nioBufferCount());
    System.out.println(buffer.nioBuffer(0, buffer.capacity()));
    ByteBufOutput output = new ByteBufOutput(buffer);
    UserService userService = new UserServiceServerImpl();
    User user = userService.getUser(Long.MAX_VALUE).join();
    while (true) {
        buffer.clear();
        output.setBuffer(buffer);
        kryo.writeObject(output, user);
        ByteBufInput input = new ByteBufInput(buffer);
        User u = kryo.readObject(input, User.class);
        System.out.println(u);
    }
// buffer.clear();
// output.setBuffer(buffer);
// kryo.writeObject(output, user);
// System.out.println("user writeObject: " + output.total());
// 
// ByteBufInput input = new ByteBufInput(buffer);
// System.out.println("user readableBytes: " + buffer.readableBytes());
// System.out.println("user readerIndex: " + buffer.readerIndex());
// System.out.println(kryo.readObject(input, User.class));
}
Also used : ByteBufAllocator(io.netty.buffer.ByteBufAllocator) PooledByteBufAllocator(io.netty.buffer.PooledByteBufAllocator) UserServiceServerImpl(rpc.turbo.benchmark.service.UserServiceServerImpl) User(rpc.turbo.benchmark.bean.User) ByteBufOutput(rpc.turbo.serialization.kryo.ByteBufOutput) UserService(rpc.turbo.benchmark.service.UserService) ByteBufInput(rpc.turbo.serialization.kryo.ByteBufInput) ByteBuf(io.netty.buffer.ByteBuf) Kryo(com.esotericsoftware.kryo.Kryo) PooledByteBufAllocator(io.netty.buffer.PooledByteBufAllocator)

Example 3 with UserServiceServerImpl

use of rpc.turbo.benchmark.service.UserServiceServerImpl in project turbo-rpc by hank-whu.

the class ProtostuffSerializerTest method main.

public static void main(String[] args) throws IOException {
    ProtostuffSerializer serializer = new ProtostuffSerializer();
    UserService userService = new UserServiceServerImpl();
    ByteBufAllocator allocator = new UnpooledByteBufAllocator(true);
    ByteBuf byteBuf = allocator.directBuffer(16, 1024 * 1024 * 8);
    Request request = new Request();
    request.setRequestId(123);
    request.setServiceId(8);
    // request.setParams(new Object[] { Integer.valueOf(1), LocalDate.now(), userService.getUser(999).join() });
    serializer.writeRequest(byteBuf, request);
    byteBuf.readerIndex(4);
    System.out.println(serializer.readRequest(byteBuf));
    byteBuf.clear();
    Response response = new Response();
    response.setRequestId(321);
    response.setStatusCode((byte) 1);
    response.setResult(userService.listUser(0).join());
    serializer.writeResponse(byteBuf, response);
    byteBuf.readerIndex(4);
    System.out.println(serializer.readResponse(byteBuf));
}
Also used : Response(rpc.turbo.protocol.Response) UnpooledByteBufAllocator(io.netty.buffer.UnpooledByteBufAllocator) ByteBufAllocator(io.netty.buffer.ByteBufAllocator) UserServiceServerImpl(rpc.turbo.benchmark.service.UserServiceServerImpl) UnpooledByteBufAllocator(io.netty.buffer.UnpooledByteBufAllocator) UserService(rpc.turbo.benchmark.service.UserService) Request(rpc.turbo.protocol.Request) ByteBuf(io.netty.buffer.ByteBuf) ProtostuffSerializer(rpc.turbo.serialization.protostuff.ProtostuffSerializer)

Example 4 with UserServiceServerImpl

use of rpc.turbo.benchmark.service.UserServiceServerImpl in project turbo-rpc by hank-whu.

the class RestServerBenchmark method main.

public static void main(String[] args) throws Exception {
    ResourceLeakDetector.setLevel(Level.DISABLED);
    try (TurboServer server = new TurboServer("shop", "auth")) {
        Map<Class<?>, Object> services = Map.of(UserService.class, new UserServiceServerImpl());
        server.registerService(services);
        server.startRestServer(new HostPort("0.0.0.0", 8080));
        server.waitUntilShutdown();
    }
}
Also used : TurboServer(rpc.turbo.server.TurboServer) UserServiceServerImpl(rpc.turbo.benchmark.service.UserServiceServerImpl) HostPort(rpc.turbo.config.HostPort)

Aggregations

UserServiceServerImpl (rpc.turbo.benchmark.service.UserServiceServerImpl)4 ByteBuf (io.netty.buffer.ByteBuf)2 ByteBufAllocator (io.netty.buffer.ByteBufAllocator)2 UserService (rpc.turbo.benchmark.service.UserService)2 HostPort (rpc.turbo.config.HostPort)2 TurboServer (rpc.turbo.server.TurboServer)2 Kryo (com.esotericsoftware.kryo.Kryo)1 PooledByteBufAllocator (io.netty.buffer.PooledByteBufAllocator)1 UnpooledByteBufAllocator (io.netty.buffer.UnpooledByteBufAllocator)1 User (rpc.turbo.benchmark.bean.User)1 Request (rpc.turbo.protocol.Request)1 Response (rpc.turbo.protocol.Response)1 ByteBufInput (rpc.turbo.serialization.kryo.ByteBufInput)1 ByteBufOutput (rpc.turbo.serialization.kryo.ByteBufOutput)1 ProtostuffSerializer (rpc.turbo.serialization.protostuff.ProtostuffSerializer)1