Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * #%L
   * Service Locator Client for CXF
   * %%
   * Copyright (C) 2011 Talend Inc.
   * %%
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  * #L%
 package org.talend.esb.locator;
 import java.util.List;
This class should be used by Service Locator consumers. It is able to retrieve the list of available endpoints for a given service. Only a random selection strategy to select a single endpoint out of the list uses. When creating an object, you must specify Name of service for which to get the endpoints and the hosts where ZooKeeper started.


  • For a given Service get the list of existing providers from the SL.
  • Select from the list the endpoint to be used.
  • Keep the list of endpoints for subsequent requests.
  • Refresh (reload) the list of endpoints from SL.
  • Returns a proxy of specified service endpoint interface.
 public class EndpointRetriever {
 	private static final Logger LOG = Logger.getLogger(EndpointRetriever.class
 	private List<StringendpointsList;
 	private QName serviceName;
 	public void init() throws ServiceLocatorExceptionInterruptedException ,
 		if ( == null)
 			throw new NullPointerException("Service name can not be null");
 		if ( == null)
 			throw new NullPointerException("Service locator can not be null");
 		.log(."Creating EndpointRetriever object for "
 				+ .toString() + " service...");
 		if (!isEmptyList()) {
 						"Endpoint Retriever was initialized successfully.");
 		} else if (.isLoggable(.)) {
 					"Endpoint Retriever was initialized with empty list of endpoints.");
 	public boolean isEmptyList() {
 		return ( == null) || .isEmpty();
 	public List<StringgetEndpointsList() {
 		if (.isLoggable(.)) {
 					"List of endpoints: " + .toString());
 		return ;

List of endpoins replaced by new data from the ServiceLocator.
 	public void refreshEndpointsList() {
 		try {
 			if ( == null) {
 				.log(."Cannot receive list of endpoints");
 		} catch (ServiceLocatorException e) {
						"Cannot refresh list of endpoints due to ServiceLocatorException"e);
catch (InterruptedException e) {
						"Cannot refresh list of endpoints due to InterruptedException"e);
catch (IOException e) {
						"Cannot refresh list of endpoints due to IOException"e);
		return new ServiceLocator();
	public void setServiceLocator(ServiceLocator serviceLocator) {
		this. = serviceLocator;
	public void setServiceName(QName serviceName) {
		this. = serviceName;

Establish a connection to the Service Locator, using ServiceLocator instance. Lookup endpoints for Service Name, specified specified in constructor. Disconnects from a Service Locator server.

all endpoints that currently registered at the Service Locator Service.
		List<StringendpointsList = null;
		endpointsList = .lookup(this.);
		.log(."For service " +  + " received list of endpoints: "
		return endpointsList;
New to GrepCode? Check out our FAQ X