com.alipay.remoting.Url Java Examples
The following examples show how to use
com.alipay.remoting.Url.
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: ReconnectManagerTest.java From sofa-bolt with Apache License 2.0 | 6 votes |
@Test public void testCancelReConnection() throws InterruptedException, RemotingException { doInit(false, true); client.enableReconnectSwitch(); String addr = "127.0.0.1:2014?zone=RZONE&_CONNECTIONNUM=1"; Url url = addressParser.parse(addr); client.getConnection(url, 1000); Assert.assertEquals(0, clientDisConnectProcessor.getDisConnectTimes()); Assert.assertEquals(1, clientConnectProcessor.getConnectTimes()); client.closeConnection(url); Thread.sleep(1000); Assert.assertEquals(1, clientDisConnectProcessor.getDisConnectTimes()); Assert.assertEquals(1, clientConnectProcessor.getConnectTimes()); }
Example #2
Source File: RpcClientRemoting.java From sofa-bolt with Apache License 2.0 | 6 votes |
/** * Get connection and set init invokeContext if invokeContext not {@code null} * * @param url target url * @param invokeContext invoke context to set * @return connection */ protected Connection getConnectionAndInitInvokeContext(Url url, InvokeContext invokeContext) throws RemotingException, InterruptedException { long start = System.currentTimeMillis(); Connection conn; try { conn = this.connectionManager.getAndCreateIfAbsent(url); } finally { if (null != invokeContext) { invokeContext.putIfAbsent(InvokeContext.CLIENT_CONN_CREATETIME, (System.currentTimeMillis() - start)); } } return conn; }
Example #3
Source File: ScheduledDisconnectStrategyTest.java From sofa-bolt with Apache License 2.0 | 6 votes |
@Test public void testCloseFreshSelectConnections_byUserSetting() throws RemotingException, InterruptedException { System.setProperty(Configs.RETRY_DETECT_PERIOD, "500"); System.setProperty(Configs.CONN_MONITOR_INITIAL_DELAY, "2000"); System.setProperty(Configs.CONN_MONITOR_PERIOD, "100"); System.setProperty(Configs.CONN_THRESHOLD, "0"); doInit(false, true); String addr = "127.0.0.1:" + port + "?zone=RZONE&_CONNECTIONNUM=1"; Url url = addressParser.parse(addr); final Connection connection = client.getConnection(url, 1000); connection.addInvokeFuture(new DefaultInvokeFuture(1, null, null, RpcCommandType.REQUEST, null)); Thread.sleep(2100); Assert.assertTrue(0 == clientDisConnectProcessor.getDisConnectTimes()); Assert.assertEquals(1, clientConnectProcessor.getConnectTimes()); connection.removeInvokeFuture(1); /* Monitor task sleep 500ms*/ Thread.sleep(100); Assert.assertEquals(1, clientDisConnectProcessor.getDisConnectTimes()); Thread.sleep(500); Assert.assertTrue(0 <= clientDisConnectProcessor.getDisConnectTimes()); }
Example #4
Source File: ScheduledDisconnectStrategyTest.java From sofa-bolt with Apache License 2.0 | 6 votes |
@Test public void testCloseFreshSelectConnections_bySystemSetting() throws RemotingException, InterruptedException { System.setProperty(Configs.RETRY_DETECT_PERIOD, "500"); System.setProperty(Configs.CONN_MONITOR_INITIAL_DELAY, "2000"); System.setProperty(Configs.CONN_MONITOR_PERIOD, "100"); System.setProperty(Configs.CONN_THRESHOLD, "0"); doInit(true, false); String addr = "127.0.0.1:" + port + "?zone=RZONE&_CONNECTIONNUM=1"; Url url = addressParser.parse(addr); final Connection connection = client.getConnection(url, 1000); connection.addInvokeFuture(new DefaultInvokeFuture(1, null, null, RpcCommandType.REQUEST, null)); Thread.sleep(2100); Assert.assertTrue(0 == clientDisConnectProcessor.getDisConnectTimes()); Assert.assertEquals(1, clientConnectProcessor.getConnectTimes()); connection.removeInvokeFuture(1); /* Monitor task sleep 500ms*/ Thread.sleep(100); Assert.assertTrue(0 <= clientDisConnectProcessor.getDisConnectTimes()); Thread.sleep(500); Assert.assertTrue(0 <= clientDisConnectProcessor.getDisConnectTimes()); }
Example #5
Source File: ReconnectManagerTest.java From sofa-bolt with Apache License 2.0 | 6 votes |
@Test public void testReconnectionByUserSetting() throws InterruptedException, RemotingException { doInit(false, true); client.enableReconnectSwitch(); String addr = "127.0.0.1:2014?zone=RZONE&_CONNECTIONNUM=1"; Url url = addressParser.parse(addr); Connection connection = client.getConnection(url, 1000); Assert.assertEquals(0, clientDisConnectProcessor.getDisConnectTimes()); Assert.assertEquals(1, clientConnectProcessor.getConnectTimes()); connection.close(); Thread.sleep(2000); Assert.assertEquals(1, clientDisConnectProcessor.getDisConnectTimes()); Assert.assertEquals(2, clientConnectProcessor.getConnectTimes()); }
Example #6
Source File: BoltClientTransport.java From sofa-rpc with Apache License 2.0 | 6 votes |
/** * For convert provider to bolt url. * * @param transportConfig ClientTransportConfig * @param providerInfo ProviderInfo * @return Bolt Url */ protected Url convertProviderToUrl(ClientTransportConfig transportConfig, ProviderInfo providerInfo) { // Url的第一个参数,如果不用事件的话,其实无所谓 Url boltUrl = new Url(providerInfo.toString(), providerInfo.getHost(), providerInfo.getPort()); boltUrl.setConnectTimeout(transportConfig.getConnectTimeout()); // 默认初始化connNum个长连接,为了slb和vip的情况 final int connectionNum = transportConfig.getConnectionNum(); if (connectionNum > 0) { boltUrl.setConnNum(connectionNum); } else { boltUrl.setConnNum(1); } boltUrl.setConnWarmup(false); // true的话 if (RpcConstants.PROTOCOL_TYPE_BOLT.equals(providerInfo.getProtocolType())) { boltUrl.setProtocol(RemotingConstants.PROTOCOL_BOLT); } else { boltUrl.setProtocol(RemotingConstants.PROTOCOL_TR); } return boltUrl; }
Example #7
Source File: AloneBoltClientConnectionManager.java From sofa-rpc with Apache License 2.0 | 6 votes |
/** * 通过配置获取长连接 * * @param rpcClient bolt客户端 * @param transportConfig 传输层配置 * @param url 传输层地址 * @return 长连接 */ public Connection getConnection(RpcClient rpcClient, ClientTransportConfig transportConfig, Url url) { if (rpcClient == null || transportConfig == null || url == null) { return null; } Connection connection; try { connection = rpcClient.getConnection(url, url.getConnectTimeout()); } catch (InterruptedException | RemotingException e) { throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_GET_CONNECTION),e); } if (connection == null) { return null; } return connection; }
Example #8
Source File: ConcurrentCreateConnectionTest.java From sofa-bolt with Apache License 2.0 | 6 votes |
@Test public void testGetAndCheckConnection() throws InterruptedException { final Url addr = new Url(ip, port); final int connNum = 1; final boolean warmup = false; for (int i = 0; i < 10; ++i) { MyThread thread = new MyThread(addr, connNum, warmup); new Thread(thread).start(); } try { Thread.sleep(1000); } catch (InterruptedException e) { logger.error("", e); } Assert.assertEquals(1, serverConnectProcessor.getConnectTimes()); }
Example #9
Source File: RpcAddressParser_SOFTREF_Test.java From sofa-bolt with Apache License 2.0 | 6 votes |
public void testParserNonProtocol() throws RemotingException { String url = "127.0.0.1:1111?_TIMEOUT=3000&_SERIALIZETYPE=hessian2"; RpcAddressParser parser = new RpcAddressParser(); int MAX = 1000000; printMemory(); long start1 = System.currentTimeMillis(); for (int i = 0; i < MAX; ++i) { Url btUrl = parser.parse(url); Assert.assertEquals(btUrl.getUniqueKey(), "127.0.0.1:1111"); } long end1 = System.currentTimeMillis(); long time1 = end1 - start1; System.out.println("time1:" + time1); printMemory(); }
Example #10
Source File: RpcConnectionManagerTest.java From sofa-bolt with Apache License 2.0 | 6 votes |
@Test public void testConnectionCloseAndConnectionManagerRemove() throws RemotingException, InterruptedException { final Url addr = new Url(ip, port); this.addressParser.initUrlArgs(addr); Connection conn = null; try { conn = cm.getAndCreateIfAbsent(addr); } catch (InterruptedException e) { Assert.fail("InterruptedException!"); } Assert.assertEquals(1, cm.count(addr.getUniqueKey())); conn.close(); Thread.sleep(100); Assert.assertEquals(0, cm.count(addr.getUniqueKey())); }
Example #11
Source File: UrlTest.java From sofa-bolt with Apache License 2.0 | 6 votes |
@Test public void testUrlArgsEquals() { RpcAddressParser parser = new RpcAddressParser(); String urlA = "localhost:3333?key1=value1"; Url urlObjA = parser.parse(urlA); String urlB = "localhost:3333?key1=value1"; Url urlObjB = parser.parse(urlB); String urlC = "localhost:3333?key1=value2"; Url urlObjC = parser.parse(urlC); Assert.assertEquals(urlObjA, urlObjB); Assert.assertEquals(urlObjA.hashCode(), urlObjB.hashCode()); Assert.assertFalse(urlObjA.equals(urlObjC)); Assert.assertFalse(urlObjA.hashCode() == urlObjC.hashCode()); }
Example #12
Source File: BoltClient.java From sofa-registry with Apache License 2.0 | 6 votes |
protected Connection getBoltConnection(RpcClient rpcClient, URL url) throws RemotingException { Url boltUrl = createBoltUrl(url); try { Connection connection = rpcClient.getConnection(boltUrl, connectTimeout); if (connection == null || !connection.isFine()) { if (connection != null) { connection.close(); } throw new RemotingException("Get bolt connection failed for boltUrl: " + boltUrl); } return connection; } catch (InterruptedException e) { throw new RuntimeException( "BoltClient rpcClient.getConnection InterruptedException! target boltUrl:" + boltUrl, e); } }
Example #13
Source File: ConcurrentCreateConnectionTest.java From sofa-bolt with Apache License 2.0 | 6 votes |
@Test public void testGetAndCheckConnectionMulti() throws InterruptedException { final Url addr = new Url(ip, port); final int connNum = 10; final boolean warmup = true; for (int i = 0; i < 10; ++i) { MyThread thread = new MyThread(addr, connNum, warmup);// warmup in one thread, the other threads will try lock failed. new Thread(thread).start(); } try { Thread.sleep(3000); } catch (InterruptedException e) { logger.error("", e); } Assert.assertEquals(10, serverConnectProcessor.getConnectTimes()); }
Example #14
Source File: RpcClient.java From sofa-bolt with Apache License 2.0 | 5 votes |
@Override public Object invokeSync(final Url url, final Object request, final InvokeContext invokeContext, final int timeoutMillis) throws RemotingException, InterruptedException { return this.rpcRemoting.invokeSync(url, request, invokeContext, timeoutMillis); }
Example #15
Source File: RpcClient.java From sofa-bolt with Apache License 2.0 | 5 votes |
@Override public RpcResponseFuture invokeWithFuture(final Url url, final Object request, final InvokeContext invokeContext, final int timeoutMillis) throws RemotingException, InterruptedException { return this.rpcRemoting.invokeWithFuture(url, request, invokeContext, timeoutMillis); }
Example #16
Source File: ReuseBoltClientConnectionManager.java From sofa-rpc with Apache License 2.0 | 5 votes |
/** * 关闭长连接 * * @param rpcClient bolt客户端 * @param transportConfig 传输层配置 * @param url 传输层地址 */ @Override public void closeConnection(RpcClient rpcClient, ClientTransportConfig transportConfig, Url url) { if (rpcClient == null || transportConfig == null || url == null) { return; } // 先删除 Connection connection = urlConnectionMap.remove(transportConfig); if (connection == null) { return; } // 再判断是否需要关闭 boolean needDestroy; AtomicInteger integer = connectionRefCounter.get(connection); if (integer == null) { needDestroy = true; } else { // 当前连接引用数 int currentCount = integer.decrementAndGet(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Client transport {} of {} , current ref count is: {}", url.toString(), NetUtils.channelToString(connection.getLocalAddress(), connection.getRemoteAddress()), currentCount); } if (currentCount <= 0) { // 此长连接无任何引用,可以销毁 connectionRefCounter.remove(connection); needDestroy = true; } else { needDestroy = false; } } if (needDestroy) { rpcClient.closeStandaloneConnection(connection); } }
Example #17
Source File: ScheduledDisconnectStrategyTest.java From sofa-bolt with Apache License 2.0 | 5 votes |
@Test public void testConnectionMonitorBySystemSetting() throws InterruptedException, RemotingException { System.setProperty(Configs.CONN_MONITOR_INITIAL_DELAY, "2000"); System.setProperty(Configs.CONN_MONITOR_PERIOD, "100"); doInit(true, false); String addr = "127.0.0.1:" + port + "?zone=RZONE&_CONNECTIONNUM=8&_CONNECTIONWARMUP=false"; Url url = addressParser.parse(addr); for (int i = 0; i < 8; ++i) { client.getConnection(url, 1000); } Thread.sleep(2150); Assert.assertTrue(1 <= clientDisConnectProcessor.getDisConnectTimes()); Assert.assertEquals(9, clientConnectProcessor.getConnectTimes()); Thread.sleep(200); Assert.assertTrue(2 <= clientDisConnectProcessor.getDisConnectTimes()); Assert.assertTrue(9 <= clientConnectProcessor.getConnectTimes()); Thread.sleep(400); Assert.assertTrue(4 <= clientDisConnectProcessor.getDisConnectTimes()); Assert.assertTrue(9 <= clientConnectProcessor.getConnectTimes()); Thread.sleep(200); Assert.assertTrue(5 <= clientDisConnectProcessor.getDisConnectTimes()); Thread.sleep(200); Assert.assertTrue(5 <= clientDisConnectProcessor.getDisConnectTimes()); Thread.sleep(100); Assert.assertTrue(6 <= clientDisConnectProcessor.getDisConnectTimes()); Assert.assertTrue(10 <= clientConnectProcessor.getConnectTimes()); }
Example #18
Source File: ScheduledDisconnectStrategyTest.java From sofa-bolt with Apache License 2.0 | 5 votes |
@Test public void testConnectionMonitorByUserSetting() throws InterruptedException, RemotingException { System.setProperty(Configs.CONN_MONITOR_INITIAL_DELAY, "2000"); System.setProperty(Configs.CONN_MONITOR_PERIOD, "100"); doInit(false, true); String addr = "127.0.0.1:" + port + "?zone=RZONE&_CONNECTIONNUM=8&_CONNECTIONWARMUP=false"; Url url = addressParser.parse(addr); for (int i = 0; i < 8; ++i) { client.getConnection(url, 1000); } Thread.sleep(2150); Assert.assertTrue(1 <= clientDisConnectProcessor.getDisConnectTimes()); Assert.assertEquals(9, clientConnectProcessor.getConnectTimes()); Thread.sleep(200); Assert.assertTrue(2 <= clientDisConnectProcessor.getDisConnectTimes()); Assert.assertTrue(9 <= clientConnectProcessor.getConnectTimes()); Thread.sleep(400); Assert.assertTrue(4 <= clientDisConnectProcessor.getDisConnectTimes()); Assert.assertTrue(9 <= clientConnectProcessor.getConnectTimes()); Thread.sleep(200); Assert.assertTrue(5 <= clientDisConnectProcessor.getDisConnectTimes()); Thread.sleep(200); Assert.assertTrue(5 <= clientDisConnectProcessor.getDisConnectTimes()); Thread.sleep(100); Assert.assertTrue(6 <= clientDisConnectProcessor.getDisConnectTimes()); Assert.assertTrue(10 <= clientConnectProcessor.getConnectTimes()); }
Example #19
Source File: RpcClientRemoting.java From sofa-bolt with Apache License 2.0 | 5 votes |
/** * @see com.alipay.remoting.rpc.RpcRemoting#oneway(com.alipay.remoting.Url, java.lang.Object, InvokeContext) */ @Override public void oneway(Url url, Object request, InvokeContext invokeContext) throws RemotingException, InterruptedException { final Connection conn = getConnectionAndInitInvokeContext(url, invokeContext); this.connectionManager.check(conn); this.oneway(conn, request, invokeContext); }
Example #20
Source File: RpcClient.java From sofa-bolt with Apache License 2.0 | 5 votes |
@Override public void invokeWithCallback(final Url url, final Object request, final InvokeCallback invokeCallback, final int timeoutMillis) throws RemotingException, InterruptedException { this.rpcRemoting.invokeWithCallback(url, request, null, invokeCallback, timeoutMillis); }
Example #21
Source File: RpcClient.java From sofa-bolt with Apache License 2.0 | 5 votes |
@Override public void invokeWithCallback(final Url url, final Object request, final InvokeContext invokeContext, final InvokeCallback invokeCallback, final int timeoutMillis) throws RemotingException, InterruptedException { this.rpcRemoting.invokeWithCallback(url, request, invokeContext, invokeCallback, timeoutMillis); }
Example #22
Source File: RpcAddressParserTest.java From sofa-bolt with Apache License 2.0 | 5 votes |
@Test public void testParserConnectTimeout() throws RemotingException { String url = "127.0.0.1:1111?_CONNECTTIMEOUT=2000&_TIMEOUT=3000&_SERIALIZETYPE=hessian2&_PROTOCOL=1"; RpcAddressParser parser = new RpcAddressParser(); Url btUrl = parser.parse(url); Assert.assertEquals("127.0.0.1", btUrl.getIp()); Assert.assertEquals(1111, btUrl.getPort()); Assert.assertEquals("1", btUrl.getProperty(RpcConfigs.URL_PROTOCOL)); Assert.assertEquals("2000", btUrl.getProperty(RpcConfigs.CONNECT_TIMEOUT_KEY)); }
Example #23
Source File: RpcClient.java From sofa-bolt with Apache License 2.0 | 5 votes |
@Override public boolean checkConnection(String address) { Url url = this.addressParser.parse(address); Connection conn = this.connectionManager.get(url.getUniqueKey()); try { this.connectionManager.check(conn); } catch (Exception e) { logger.warn("check failed. connection: {}", conn, e); return false; } return true; }
Example #24
Source File: RpcClient.java From sofa-bolt with Apache License 2.0 | 5 votes |
/** * Close all connections of a address * * @param addr */ public void closeConnection(String addr) { Url url = this.addressParser.parse(addr); if (switches().isOn(GlobalSwitch.CONN_RECONNECT_SWITCH) && reconnectManager != null) { reconnectManager.disableReconnect(url); } this.connectionManager.remove(url.getUniqueKey()); }
Example #25
Source File: RpcClient.java From sofa-bolt with Apache License 2.0 | 5 votes |
@Override public void closeConnection(Url url) { if (switches().isOn(GlobalSwitch.CONN_RECONNECT_SWITCH) && reconnectManager != null) { reconnectManager.disableReconnect(url); } this.connectionManager.remove(url.getUniqueKey()); }
Example #26
Source File: RpcAddressParserTest.java From sofa-bolt with Apache License 2.0 | 5 votes |
@Test public void testParserWithProtocol() throws RemotingException { String url = "127.0.0.1:1111?_TIMEOUT=3000&_SERIALIZETYPE=hessian2&_PROTOCOL=1"; RpcAddressParser parser = new RpcAddressParser(); Url btUrl = parser.parse(url); Assert.assertEquals("127.0.0.1", btUrl.getIp()); Assert.assertEquals(1111, btUrl.getPort()); Assert.assertEquals("1", btUrl.getProperty(RpcConfigs.URL_PROTOCOL)); url = "127.0.0.1:1111?protocol=1"; Assert.assertEquals("127.0.0.1", btUrl.getIp()); Assert.assertEquals(1111, btUrl.getPort()); Assert.assertEquals("1", btUrl.getProperty(RpcConfigs.URL_PROTOCOL)); }
Example #27
Source File: RpcAddressParserTest.java From sofa-bolt with Apache License 2.0 | 5 votes |
@Test public void testParserNonProtocol() throws RemotingException { String url = "127.0.0.1:1111?_TIMEOUT=3000&_SERIALIZETYPE=hessian2"; RpcAddressParser parser = new RpcAddressParser(); Url btUrl = parser.parse(url); Assert.assertEquals("127.0.0.1", btUrl.getIp()); Assert.assertEquals(1111, btUrl.getPort()); Assert.assertEquals(null, btUrl.getProperty(RpcConfigs.URL_PROTOCOL)); url = "127.0.0.1:1111"; btUrl = parser.parse(url); Assert.assertEquals("127.0.0.1", btUrl.getIp()); Assert.assertEquals(1111, btUrl.getPort()); Assert.assertEquals(null, btUrl.getProperty(RpcConfigs.URL_PROTOCOL)); }
Example #28
Source File: AbstractConnectionFactory.java From sofa-bolt with Apache License 2.0 | 5 votes |
@Override public Connection createConnection(String targetIP, int targetPort, byte version, int connectTimeout) throws Exception { Channel channel = doCreateConnection(targetIP, targetPort, connectTimeout); Connection conn = new Connection(channel, ProtocolCode.fromBytes(RpcProtocolV2.PROTOCOL_CODE), version, new Url(targetIP, targetPort)); channel.pipeline().fireUserEventTriggered(ConnectionEventType.CONNECT); return conn; }
Example #29
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 #30
Source File: AbstractConnectionFactory.java From sofa-bolt with Apache License 2.0 | 5 votes |
@Override public Connection createConnection(Url url) throws Exception { Channel channel = doCreateConnection(url.getIp(), url.getPort(), url.getConnectTimeout()); Connection conn = new Connection(channel, ProtocolCode.fromBytes(url.getProtocol()), url.getVersion(), url); channel.pipeline().fireUserEventTriggered(ConnectionEventType.CONNECT); return conn; }