@Test public void testGetWeight() { ProviderInfo provider = ProviderHelper .toProviderInfo("bolt: long warmupTime = Long.parseLong(provider.getStaticAttr(ProviderInfoAttrs.ATTR_WARMUP_TIME)); provider.setDynamicAttr(ProviderInfoAttrs.ATTR_WARMUP_WEIGHT, Integer.parseInt(provider.getStaticAttr(ProviderInfoAttrs.ATTR_WARMUP_WEIGHT))); provider.setDynamicAttr(ProviderInfoAttrs.ATTR_WARMUP_TIME, warmupTime); provider.setDynamicAttr(ProviderInfoAttrs.ATTR_WARM_UP_END_TIME, System.currentTimeMillis() + warmupTime); provider.setStatus(ProviderStatus.WARMING_UP); Assert.assertTrue(RpcConstants.PROTOCOL_TYPE_BOLT.equals(provider.getProtocolType())); Assert.assertTrue(RpcConstants.SERIALIZE_HESSIAN2.equals(provider.getSerializationType())); Assert.assertTrue("10.15.232.229".equals(provider.getHost())); Assert.assertTrue(provider.getPort() == 12222); Assert.assertTrue("test-server".equals(provider.getAttr(ProviderInfoAttrs.ATTR_APP_NAME))); Assert.assertTrue("1".equals(provider.getAttr(ProviderInfoAttrs.ATTR_CONNECTIONS))); Assert.assertEquals("3333", provider.getStaticAttr(ProviderInfoAttrs.ATTR_TIMEOUT)); Assert.assertEquals(5, provider.getDynamicAttr(ProviderInfoAttrs.ATTR_WARMUP_WEIGHT)); Assert.assertTrue(provider.getDynamicAttr(ProviderInfoAttrs.ATTR_WARM_UP_END_TIME) != null); Assert.assertEquals("5", provider.getStaticAttr(ProviderInfoAttrs.ATTR_WARMUP_WEIGHT)); Assert.assertEquals("6", provider.getStaticAttr(ProviderInfoAttrs.ATTR_WARMUP_TIME)); Assert.assertEquals(ProviderStatus.WARMING_UP, provider.getStatus()); Assert.assertEquals(5, provider.getWeight()); try { Thread.sleep(10); } catch (Exception e) { } Assert.assertTrue(provider.getWeight() == 2000); Assert.assertTrue(provider.getStatus() == ProviderStatus.AVAILABLE); Assert.assertTrue(provider.getDynamicAttr(ProviderInfoAttrs.ATTR_WARM_UP_END_TIME) == null); }
public int getWeight() { ProviderStatus status = getStatus(); if (status == ProviderStatus.WARMING_UP) { try { Integer warmUpWeight = (Integer) getDynamicAttr(ProviderInfoAttrs.ATTR_WARMUP_WEIGHT); if (warmUpWeight != null) { return warmUpWeight; } } catch (Exception e) { return weight; } } return weight; }
ProviderInfo implements Serializable { public int getWeight() { ProviderStatus status = getStatus(); if (status == ProviderStatus.WARMING_UP) { try { Integer warmUpWeight = (Integer) getDynamicAttr(ProviderInfoAttrs.ATTR_WARMUP_WEIGHT); if (warmUpWeight != null) { return warmUpWeight; } } catch (Exception e) { return weight; } } return weight; } }
ProviderInfo implements Serializable { public int getWeight() { ProviderStatus status = getStatus(); if (status == ProviderStatus.WARMING_UP) { try { Integer warmUpWeight = (Integer) getDynamicAttr(ProviderInfoAttrs.ATTR_WARMUP_WEIGHT); if (warmUpWeight != null) { return warmUpWeight; } } catch (Exception e) { return weight; } } return weight; } ProviderInfo();  ProviderInfo(String host, int port);  ProviderInfo(String host, int port, String originUrl); }
ProviderInfo implements Serializable { public int getWeight() { ProviderStatus status = getStatus(); if (status == ProviderStatus.WARMING_UP) { try { Integer warmUpWeight = (Integer) getDynamicAttr(ProviderInfoAttrs.ATTR_WARMUP_WEIGHT); if (warmUpWeight != null) { return warmUpWeight; } } catch (Exception e) { return weight; } } return weight; } ProviderInfo();  ProviderInfo(String host, int port);  ProviderInfo(String host, int port, String originUrl); @Deprecated static ProviderInfo valueOf(String url); @Deprecated String toUrl(); @Override boolean equals(Object o); @Override int hashCode(); String getOriginUrl(); ProviderInfo setOriginUrl(String originUrl); String getProtocolType(); ProviderInfo setProtocolType(String protocolType); String getHost(); ProviderInfo setHost(String host); int getPort(); ProviderInfo setPort(int port); String getPath(); ProviderInfo setPath(String path); String getSerializationType(); ProviderInfo setSerializationType(String serializationType); int getWeight(); ProviderInfo setWeight(int weight); int getRpcVersion(); ProviderInfo setRpcVersion(int rpcVersion); ProviderStatus getStatus(); ProviderInfo setStatus(ProviderStatus status); ConcurrentMap<String, String> getStaticAttrs(); ProviderInfo setStaticAttrs(Map<String, String> staticAttrs); ConcurrentMap<String, Object> getDynamicAttrs(); ProviderInfo setDynamicAttrs(Map<String, Object> dynamicAttrs); String getStaticAttr(String staticAttrKey); ProviderInfo setStaticAttr(String staticAttrKey, String staticAttrValue); Object getDynamicAttr(String dynamicAttrKey); ProviderInfo setDynamicAttr(String dynamicAttrKey, Object dynamicAttrValue); @Override String toString(); String getAttr(String key); }
ProviderInfo implements Serializable { public int getWeight() { ProviderStatus status = getStatus(); if (status == ProviderStatus.WARMING_UP) { try { Integer warmUpWeight = (Integer) getDynamicAttr(ProviderInfoAttrs.ATTR_WARMUP_WEIGHT); if (warmUpWeight != null) { return warmUpWeight; } } catch (Exception e) { return weight; } } return weight; } ProviderInfo();  ProviderInfo(String host, int port);  ProviderInfo(String host, int port, String originUrl); @Deprecated static ProviderInfo valueOf(String url); @Deprecated String toUrl(); @Override boolean equals(Object o); @Override int hashCode(); String getOriginUrl(); ProviderInfo setOriginUrl(String originUrl); String getProtocolType(); ProviderInfo setProtocolType(String protocolType); String getHost(); ProviderInfo setHost(String host); int getPort(); ProviderInfo setPort(int port); String getPath(); ProviderInfo setPath(String path); String getSerializationType(); ProviderInfo setSerializationType(String serializationType); int getWeight(); ProviderInfo setWeight(int weight); int getRpcVersion(); ProviderInfo setRpcVersion(int rpcVersion); ProviderStatus getStatus(); ProviderInfo setStatus(ProviderStatus status); ConcurrentMap<String, String> getStaticAttrs(); ProviderInfo setStaticAttrs(Map<String, String> staticAttrs); ConcurrentMap<String, Object> getDynamicAttrs(); ProviderInfo setDynamicAttrs(Map<String, Object> dynamicAttrs); String getStaticAttr(String staticAttrKey); ProviderInfo setStaticAttr(String staticAttrKey, String staticAttrValue); Object getDynamicAttr(String dynamicAttrKey); ProviderInfo setDynamicAttr(String dynamicAttrKey, Object dynamicAttrValue); @Override String toString(); String getAttr(String key);  }