@Test public void testOverridePayloadSerialize() { final Object customPayload = new Object(); Map<String, Object> endPoints = ImmutableMap.of("id", customPayload); HostDiscoverySource source = new ConfiguredFixedHostDiscoverySource<Object>(endPoints) { @Override protected String serialize(String serviceName, String id, Object payload) { assertEquals("service", serviceName); assertEquals("id", id); assertEquals(customPayload, payload); return "custom-payload"; } }; HostDiscovery hostDiscovery = source.forService("service"); assertNotNull(hostDiscovery); List<ServiceEndPoint> hosts = Lists.newArrayList(hostDiscovery.getHosts()); assertEquals("custom-payload", hosts.get(0).getPayload()); }
@Override public HostDiscovery forService(String serviceName) { if (_endPoints.isEmpty()) { return null; } List<ServiceEndPoint> endPoints = Lists.newArrayListWithCapacity(_endPoints.size()); for (Map.Entry<String, Payload> entry : _endPoints.entrySet()) { String id = entry.getKey(); Payload payload = entry.getValue(); endPoints.add(new ServiceEndPointBuilder() .withServiceName(serviceName) .withId(id) .withPayload(serialize(serviceName, id, payload)) .build()); } return new FixedHostDiscovery(endPoints); }
ConfiguredFixedHostDiscoverySource implements HostDiscoverySource { @Override public HostDiscovery forService(String serviceName) { if (_endPoints.isEmpty()) { return null; } List<ServiceEndPoint> endPoints = Lists.newArrayListWithCapacity(_endPoints.size()); for (Map.Entry<String, Payload> entry : _endPoints.entrySet()) { String id = entry.getKey(); Payload payload = entry.getValue(); endPoints.add(new ServiceEndPointBuilder() .withServiceName(serviceName) .withId(id) .withPayload(serialize(serviceName, id, payload)) .build()); } return new FixedHostDiscovery(endPoints); } }
ConfiguredFixedHostDiscoverySource implements HostDiscoverySource { @Override public HostDiscovery forService(String serviceName) { if (_endPoints.isEmpty()) { return null; } List<ServiceEndPoint> endPoints = Lists.newArrayListWithCapacity(_endPoints.size()); for (Map.Entry<String, Payload> entry : _endPoints.entrySet()) { String id = entry.getKey(); Payload payload = entry.getValue(); endPoints.add(new ServiceEndPointBuilder() .withServiceName(serviceName) .withId(id) .withPayload(serialize(serviceName, id, payload)) .build()); } return new FixedHostDiscovery(endPoints); } ConfiguredFixedHostDiscoverySource();  ConfiguredFixedHostDiscoverySource(Map<String, Payload> endPoints); }
ConfiguredFixedHostDiscoverySource implements HostDiscoverySource { @Override public HostDiscovery forService(String serviceName) { if (_endPoints.isEmpty()) { return null; } List<ServiceEndPoint> endPoints = Lists.newArrayListWithCapacity(_endPoints.size()); for (Map.Entry<String, Payload> entry : _endPoints.entrySet()) { String id = entry.getKey(); Payload payload = entry.getValue(); endPoints.add(new ServiceEndPointBuilder() .withServiceName(serviceName) .withId(id) .withPayload(serialize(serviceName, id, payload)) .build()); } return new FixedHostDiscovery(endPoints); } ConfiguredFixedHostDiscoverySource();  ConfiguredFixedHostDiscoverySource(Map<String, Payload> endPoints); @Override HostDiscovery forService(String serviceName); @Override String toString(); }
ConfiguredFixedHostDiscoverySource implements HostDiscoverySource { @Override public HostDiscovery forService(String serviceName) { if (_endPoints.isEmpty()) { return null; } List<ServiceEndPoint> endPoints = Lists.newArrayListWithCapacity(_endPoints.size()); for (Map.Entry<String, Payload> entry : _endPoints.entrySet()) { String id = entry.getKey(); Payload payload = entry.getValue(); endPoints.add(new ServiceEndPointBuilder() .withServiceName(serviceName) .withId(id) .withPayload(serialize(serviceName, id, payload)) .build()); } return new FixedHostDiscovery(endPoints); } ConfiguredFixedHostDiscoverySource();  ConfiguredFixedHostDiscoverySource(Map<String, Payload> endPoints); @Override HostDiscovery forService(String serviceName); @Override String toString();  }