com.alipay.remoting.rpc.protocol.RpcProtocol Java Examples
The following examples show how to use
com.alipay.remoting.rpc.protocol.RpcProtocol.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HeartBeatDisableTest.java From sofa-bolt with Apache License 2.0 | 6 votes |
@Test public void testClientHeartBeatNotTrigger() throws InterruptedException { server.getRpcServer().registerProcessor(RpcProtocol.PROTOCOL_CODE, CommonCommandCode.HEARTBEAT, heartBeatProcessor); try { client.createStandaloneConnection(addr, 1000); } catch (RemotingException e) { logger.error("", e); } Thread.sleep(500); Assert.assertEquals(0, heartBeatProcessor.getHeartBeatTimes()); Assert.assertEquals(1, clientConnectProcessor.getConnectTimes()); Assert.assertEquals(1, serverConnectProcessor.getConnectTimes()); Assert.assertEquals(0, clientDisConnectProcessor.getDisConnectTimes());// not closed,because heartbeat disabled Assert.assertEquals(0, serverDisConnectProcessor.getDisConnectTimes());// not closed,because heartbeat disabled }
Example #2
Source File: HeartBeatDisableTest.java From sofa-bolt with Apache License 2.0 | 6 votes |
@Test public void testClientHeartBeatTriggerExceed3Times() throws InterruptedException { server.getRpcServer().registerProcessor(RpcProtocol.PROTOCOL_CODE, CommonCommandCode.HEARTBEAT, heartBeatProcessor); try { client.createStandaloneConnection(addr, 1000); } catch (RemotingException e) { logger.error("", e); } Thread.sleep(1000); Assert.assertEquals(0, heartBeatProcessor.getHeartBeatTimes()); Assert.assertEquals(1, clientConnectProcessor.getConnectTimes()); Assert.assertEquals(1, serverConnectProcessor.getConnectTimes()); Assert.assertEquals(0, clientDisConnectProcessor.getDisConnectTimes());// not closed,because heartbeat disabled Assert.assertEquals(0, serverDisConnectProcessor.getDisConnectTimes());// not closed,because heartbeat disabled }
Example #3
Source File: RuntimeClientHeartBeatTest.java From sofa-bolt with Apache License 2.0 | 6 votes |
@Test public void testRuntimeCloseAndEnableHeartbeat() throws InterruptedException { server.getRpcServer().registerProcessor(RpcProtocol.PROTOCOL_CODE, CommonCommandCode.HEARTBEAT, heartBeatProcessor); try { client.getConnection(addr, 1000); } catch (RemotingException e) { logger.error("", e); } Thread.sleep(1500); logger.warn("before disable: " + heartBeatProcessor.getHeartBeatTimes()); Assert.assertTrue(heartBeatProcessor.getHeartBeatTimes() > 0); client.disableConnHeartbeat(addr); heartBeatProcessor.reset(); Thread.sleep(1500); logger.warn("after disable: " + heartBeatProcessor.getHeartBeatTimes()); Assert.assertTrue(heartBeatProcessor.getHeartBeatTimes() == 0); client.enableConnHeartbeat(addr); heartBeatProcessor.reset(); Thread.sleep(1500); logger.warn("after enable: " + heartBeatProcessor.getHeartBeatTimes()); Assert.assertTrue(heartBeatProcessor.getHeartBeatTimes() > 0); }
Example #4
Source File: ClientHeartBeatTest.java From sofa-bolt with Apache License 2.0 | 6 votes |
/** * test heartbeat no response, close the connection from client side */ @Test public void testClientHeartBeatTriggerExceed3Times() throws InterruptedException { server.getRpcServer().registerProcessor(RpcProtocol.PROTOCOL_CODE, CommonCommandCode.HEARTBEAT, heartBeatProcessor); try { client.createStandaloneConnection(addr, 1000); } catch (RemotingException e) { logger.error("", e); } Thread.sleep(3000); Assert.assertTrue(heartBeatProcessor.getHeartBeatTimes() > 1); Assert.assertEquals(1, clientConnectProcessor.getConnectTimes()); Assert.assertEquals(1, serverConnectProcessor.getConnectTimes()); Assert.assertEquals(1, clientDisConnectProcessor.getDisConnectTimes()); Assert.assertEquals(1, serverDisConnectProcessor.getDisConnectTimes()); }
Example #5
Source File: SofaRpcSerialization.java From sofa-rpc with Apache License 2.0 | 6 votes |
/** * 客户端记录序列化请求的耗时和 * * @param requestCommand 请求对象 */ protected void recordSerializeRequest(RequestCommand requestCommand, InvokeContext invokeContext) { if (!RpcInternalContext.isAttachmentEnable()) { return; } RpcInternalContext context = null; if (invokeContext != null) { // 客户端异步调用的情况下,上下文会放在InvokeContext中传递 context = invokeContext.get(RemotingConstants.INVOKE_CTX_RPC_CTX); } if (context == null) { context = RpcInternalContext.getContext(); } int cost = context.getStopWatch().tick().read(); int requestSize = RpcProtocol.getRequestHeaderLength() + requestCommand.getClazzLength() + requestCommand.getContentLength() + requestCommand.getHeaderLength(); // 记录请求序列化大小和请求序列化耗时 context.setAttachment(RpcConstants.INTERNAL_KEY_REQ_SIZE, requestSize); context.setAttachment(RpcConstants.INTERNAL_KEY_REQ_SERIALIZE_TIME, cost); }
Example #6
Source File: SofaRpcSerialization.java From sofa-rpc with Apache License 2.0 | 6 votes |
/** * 客户端记录响应反序列化大小和响应反序列化耗时 * * @param responseCommand 响应体 */ private void recordDeserializeResponse(RpcResponseCommand responseCommand, InvokeContext invokeContext) { if (!RpcInternalContext.isAttachmentEnable()) { return; } RpcInternalContext context = null; if (invokeContext != null) { // 客户端异步调用的情况下,上下文会放在InvokeContext中传递 context = invokeContext.get(RemotingConstants.INVOKE_CTX_RPC_CTX); } if (context == null) { context = RpcInternalContext.getContext(); } int cost = context.getStopWatch().tick().read(); int respSize = RpcProtocol.getResponseHeaderLength() + responseCommand.getClazzLength() + responseCommand.getContentLength() + responseCommand.getHeaderLength(); // 记录响应反序列化大小和响应反序列化耗时 context.setAttachment(RpcConstants.INTERNAL_KEY_RESP_SIZE, respSize); context.setAttachment(RpcConstants.INTERNAL_KEY_RESP_DESERIALIZE_TIME, cost); }
Example #7
Source File: BoltClient.java From sofa-registry with Apache License 2.0 | 5 votes |
protected Url createBoltUrl(URL url) { Url boltUrl = new Url(url.getIpAddress(), url.getPort()); boltUrl.setProtocol(RpcProtocol.PROTOCOL_CODE); boltUrl.setConnNum(connNum); boltUrl.setConnWarmup(true); return boltUrl; }
Example #8
Source File: AbstractConnectionFactory.java From sofa-bolt with Apache License 2.0 | 5 votes |
@Override public Connection createConnection(String targetIP, int targetPort, int connectTimeout) throws Exception { Channel channel = doCreateConnection(targetIP, targetPort, connectTimeout); Connection conn = new Connection(channel, ProtocolCode.fromBytes(RpcProtocol.PROTOCOL_CODE), RpcProtocolV2.PROTOCOL_VERSION_1, new Url(targetIP, targetPort)); channel.pipeline().fireUserEventTriggered(ConnectionEventType.CONNECT); return conn; }
Example #9
Source File: ClientHeartBeatTest.java From sofa-bolt with Apache License 2.0 | 5 votes |
/** * test heartbeat trigger */ @Test public void testClientHeartBeatTrigger() throws InterruptedException { server.getRpcServer().registerProcessor(RpcProtocol.PROTOCOL_CODE, CommonCommandCode.HEARTBEAT, heartBeatProcessor); try { client.createStandaloneConnection(addr, 1000); } catch (RemotingException e) { logger.error("", e); } Thread.sleep(500); Assert.assertTrue(heartBeatProcessor.getHeartBeatTimes() > 1); Assert.assertEquals(1, clientConnectProcessor.getConnectTimes()); Assert.assertEquals(1, serverConnectProcessor.getConnectTimes()); }
Example #10
Source File: SofaRpcSerialization.java From sofa-rpc with Apache License 2.0 | 5 votes |
/** * 服务端记录反序列化请求的大小和耗时 * * @param requestCommand 请求对象 */ private void recordDeserializeRequest(RequestCommand requestCommand) { if (!RpcInternalContext.isAttachmentEnable()) { return; } RpcInternalContext context = RpcInternalContext.getContext(); int cost = context.getStopWatch().tick().read(); int requestSize = RpcProtocol.getRequestHeaderLength() + requestCommand.getClazzLength() + requestCommand.getContentLength() + requestCommand.getHeaderLength(); // 记录请求反序列化大小和请求反序列化耗时 context.setAttachment(RpcConstants.INTERNAL_KEY_REQ_SIZE, requestSize); context.setAttachment(RpcConstants.INTERNAL_KEY_REQ_DESERIALIZE_TIME, cost); }
Example #11
Source File: SofaRpcSerialization.java From sofa-rpc with Apache License 2.0 | 5 votes |
/** * 服务端记录序列化响应的大小和耗时 * * @param responseCommand 响应体 */ private void recordSerializeResponse(RpcResponseCommand responseCommand) { if (!RpcInternalContext.isAttachmentEnable()) { return; } RpcInternalContext context = RpcInternalContext.getContext(); int cost = context.getStopWatch().tick().read(); int respSize = RpcProtocol.getResponseHeaderLength() + responseCommand.getClazzLength() + responseCommand.getContentLength() + responseCommand.getHeaderLength(); // 记录响应序列化大小和请求序列化耗时 context.setAttachment(RpcConstants.INTERNAL_KEY_RESP_SIZE, respSize); context.setAttachment(RpcConstants.INTERNAL_KEY_RESP_SERIALIZE_TIME, cost); }
Example #12
Source File: RpcAddressParser.java From sofa-bolt with Apache License 2.0 | 4 votes |
/** * @see com.alipay.remoting.RemotingAddressParser#initUrlArgs(Url) */ @Override public void initUrlArgs(Url url) { String connTimeoutStr = url.getProperty(RpcConfigs.CONNECT_TIMEOUT_KEY); int connTimeout = Configs.DEFAULT_CONNECT_TIMEOUT; if (StringUtils.isNotBlank(connTimeoutStr)) { if (StringUtils.isNumeric(connTimeoutStr)) { connTimeout = Integer.parseInt(connTimeoutStr); } else { throw new IllegalArgumentException( "Url args illegal value of key [" + RpcConfigs.CONNECT_TIMEOUT_KEY + "] must be positive integer! The origin url is [" + url.getOriginUrl() + "]"); } } url.setConnectTimeout(connTimeout); String protocolStr = url.getProperty(RpcConfigs.URL_PROTOCOL); byte protocol = RpcProtocol.PROTOCOL_CODE; if (StringUtils.isNotBlank(protocolStr)) { if (StringUtils.isNumeric(protocolStr)) { protocol = Byte.parseByte(protocolStr); } else { throw new IllegalArgumentException( "Url args illegal value of key [" + RpcConfigs.URL_PROTOCOL + "] must be positive integer! The origin url is [" + url.getOriginUrl() + "]"); } } url.setProtocol(protocol); String versionStr = url.getProperty(RpcConfigs.URL_VERSION); byte version = RpcProtocolV2.PROTOCOL_VERSION_1; if (StringUtils.isNotBlank(versionStr)) { if (StringUtils.isNumeric(versionStr)) { version = Byte.parseByte(versionStr); } else { throw new IllegalArgumentException( "Url args illegal value of key [" + RpcConfigs.URL_VERSION + "] must be positive integer! The origin url is [" + url.getOriginUrl() + "]"); } } url.setVersion(version); String connNumStr = url.getProperty(RpcConfigs.CONNECTION_NUM_KEY); int connNum = Configs.DEFAULT_CONN_NUM_PER_URL; if (StringUtils.isNotBlank(connNumStr)) { if (StringUtils.isNumeric(connNumStr)) { connNum = Integer.parseInt(connNumStr); } else { throw new IllegalArgumentException( "Url args illegal value of key [" + RpcConfigs.CONNECTION_NUM_KEY + "] must be positive integer! The origin url is [" + url.getOriginUrl() + "]"); } } url.setConnNum(connNum); String connWarmupStr = url.getProperty(RpcConfigs.CONNECTION_WARMUP_KEY); boolean connWarmup = false; if (StringUtils.isNotBlank(connWarmupStr)) { connWarmup = Boolean.parseBoolean(connWarmupStr); } url.setConnWarmup(connWarmup); }
Example #13
Source File: RpcCommand.java From sofa-bolt with Apache License 2.0 | 4 votes |
@Override public ProtocolCode getProtocolCode() { return ProtocolCode.fromBytes(RpcProtocol.PROTOCOL_CODE); }