@Override public void unregister() throws ComponentRegistrationException { try { serviceDiscovery.unregisterService(registeredInstance); registeredInstance = null; registered = false; } catch (Exception e) { // TODO Auto-generated catch block throw new ComponentRegistrationException(e); } }
@Override public ComponentRegistration createRegistration(Component component) throws ComponentRegistrationException { try { return new ZookeeperComponentRegistration(serviceDiscovery, component); } catch (Exception e) { throw new ComponentRegistrationException(e); } }
@Override public void update() throws ComponentRegistrationException { try { if (registered) { registeredInstance = createServiceInstance(registeredComponent); serviceDiscovery.updateService(registeredInstance); } } catch (Exception e) { throw new ComponentRegistrationException(e); } }
@Override public void register() throws ComponentRegistrationException { try { registeredInstance = createServiceInstance(registeredComponent); serviceDiscovery.registerService(registeredInstance); registered = true; } catch (Exception e) { throw new ComponentRegistrationException(e); } }
private ServiceInstance<ComponentInfo> createServiceInstance(Component component) throws ComponentRegistrationException { // in a real application, you'd have a convention of some kind for the URI // layout UriSpec uriSpec = new UriSpec("{scheme}://{hostName}:{port}"); ComponentInfo componentInfo = component.getComponentInfo(); try { ServiceInstance<ComponentInfo> inst = ServiceInstance.<ComponentInfo>builder() .name(component.getCategory().getName()) .id(component.getId()) .payload(componentInfo) .port((int) (65535 * Math.random())) // in a real application, you'd use a common port .uriSpec(uriSpec).build(); componentInfo.setHostName(inst.getAddress()); //componentInfo.setUriSpec(uriSpec.toString()); return inst; } catch (Exception e) { throw new ComponentRegistrationException(e); } }