Package net.hasor.rsf.protocol.message

Examples of net.hasor.rsf.protocol.message.RequestMsg


            });
            //发起100万次调用.
            ChannelFuture f = b.connect(host, port).sync();
            {
                for (int i = 0; i < 1000000; i++) {
                    RequestMsg req = getData();
                    f.channel().writeAndFlush(req).await();
                }
            }
            // Wait until the connection is closed.
            f.channel().closeFuture().sync();
View Full Code Here


    //
    //
    private static int reqID = 0;
    private RequestMsg getData() throws IOException {
        Hessian_DecoderEncoder de = new Hessian_DecoderEncoder();
        RequestMsg request = new RequestMsg();
        request.setVersion(ProtocolVersion.V_1_0.value());
        request.setRequestID(reqID++);
        //
        request.setServiceName("net.hasor.rsf._test.TestServices");
        request.setServiceVersion("1.0.0");
        request.setServiceGroup("default");
        request.setTargetMethod("sayHello");//String item, int index
        request.setSerializeType("Hessian");
        //
        request.addParameter("java.lang.String", de.encode("你好..."));
        //
        request.addOption("sync", "true");
        //
        return request;
    }
View Full Code Here

    //
    //
    private static int reqID = 0;
    private RequestMsg getData() throws IOException {
        Hessian_DecoderEncoder de = new Hessian_DecoderEncoder();
        RequestMsg request = new RequestMsg();
        request.setVersion(ProtocolVersion.V_1_0.value());
        request.setRequestID(reqID++);
        //
        request.setServiceName("net.hasor.rsf._test.TestServices");
        request.setServiceVersion("1.0.0");
        request.setServiceGroup("default");
        request.setTargetMethod("sayHello");//String item, int index
        request.setSerializeType("Hessian");
        //
        request.addParameter("java.lang.String", de.encode("你好..."));
        //
        request.addOption("sync", "true");
        //
        sendCount++;
        return request;
    }
View Full Code Here

        super.channelActive(ctx);
    }
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        if (msg instanceof RequestMsg == false)
            return;
        RequestMsg requestMsg = (RequestMsg) msg;
        requestMsg.setReceiveTime(System.currentTimeMillis());
        //
        try {
            Executor exe = this.rsfContext.getCallExecute(requestMsg.getServiceName());
            exe.execute(new InnerInvokeHandler(this.rsfContext, requestMsg, ctx.channel()));
            //
            ResponseMsg pack = TransferUtils.buildStatus(//
                    requestMsg.getVersion(), //协议版本
                    requestMsg.getRequestID(),//请求ID
                    ProtocolStatus.Accepted);//回应ACK
            ctx.pipeline().writeAndFlush(pack);
        } catch (RejectedExecutionException e) {
            ResponseMsg pack = TransferUtils.buildStatus(//
                    requestMsg.getVersion(), //协议版本
                    requestMsg.getRequestID(),//请求ID
                    ProtocolStatus.ChooseOther);//服务器资源紧张
            ctx.pipeline().writeAndFlush(pack);
        }
    }
View Full Code Here

    //
    //
    /**将{@link RequestSocketBlock}转换为{@link RequestMsg}消息。*/
    public static RequestMsg requestToMessage(RequestSocketBlock block) {
        //1.基本参数
        RequestMsg reqMetaData = new RequestMsg();
        reqMetaData.setVersion(block.getVersion());//协议版本
        reqMetaData.setRequestID(block.getRequestID());//请求ID
        reqMetaData.setServiceName(getString(block, block.getServiceName()));//远程服务名
        reqMetaData.setServiceGroup(getString(block, block.getServiceGroup()));//远程服务分组
        reqMetaData.setServiceVersion(getString(block, block.getServiceVersion()));//远程服务版本
        reqMetaData.setTargetMethod(getString(block, block.getTargetMethod()));//远程服务方法名
        reqMetaData.setSerializeType(getString(block, block.getSerializeType()));//序列化策略
        reqMetaData.setClientTimeout(block.getClientTimeout());//远程客户端超时时间
        //2.调用参数
        short[] pTypes = block.getParameterTypes();
        short[] pValues = block.getParameterValues();
        for (int i = 0; i < pTypes.length; i++) {
            String paramType = getString(block, pTypes[i]);
            byte[] rawData = block.readPool(pValues[i]);
            //
            reqMetaData.addParameter(paramType, rawData);
        }
        //3.Opt参数
        short[] oTypes = block.getOptionKeys();
        short[] oValues = block.getOptionValues();
        for (int i = 0; i < oTypes.length; i++) {
            String optKey = getString(block, oTypes[i]);
            String optVar = getString(block, oValues[i]);
            //
            reqMetaData.addOption(optKey, optVar);
        }
        return reqMetaData;
    };
View Full Code Here

        if (pType == ProtocolType.Request) {
            //request
            Protocol<RequestSocketBlock> requestProtocol = ProtocolUtils.requestProtocol(version);
            if (requestProtocol != null) {
                RequestSocketBlock block = requestProtocol.decode(frame);
                RequestMsg reqMetaData = TransferUtils.requestToMessage(block);
                ctx.fireChannelRead(reqMetaData);
                return null;/*正常处理后返回*/
            }
        }
        if (pType == ProtocolType.Response) {
View Full Code Here

TOP

Related Classes of net.hasor.rsf.protocol.message.RequestMsg

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.