Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2013-2014 by Cisco Systems, Inc. All rights reserved.
  
  package com.cisco.oss.foundation.directory.impl;
  
  import java.util.List;
 
 
The default LookupManager implementation to access the remote ServiceDirectory node.

Author(s):
zuxiang
 
 public class LookupManagerImpl implements LookupManagerClosable {
 	
 	private static final Logger LOGGER = LoggerFactory.getLogger(LookupManagerImpl.class);

The LookupManager cache enabled property.
 
 	public static final String SD_API_CACHE_ENABLED_PROPERTY = "cache.enabled";

The default cache enabled property value.
 
 	public static final boolean SD_API_CACHE_ENABLED_DEFAULT = true;

The remote ServiceDirectory node client.
 
The loadbalancer map for Services.
 
 	private final LoadBalancerManager lbManager;

The LookupService.
 
Mark component started or not
 
 	private boolean isStarted=false;

Constructor.
 
 	public LookupManagerImpl(DirectoryServiceClientManager directoryServiceClientManager){
 		this. = directoryServiceClientManager;
 	}

Start the LookupManagerImpl. it is idempotent, it can be invoked multiple times while in same state and is not thread safe.
 
 	public void start(){
 		if(!){
 			synchronized (this) {
 				if (!) {
 					 = true;
 				}
 			}
 		}
 	}

Stop the LookupManagerImpl it is idempotent, it can be invoked multiple times while in same state and is not thread safe.
	public void stop(){
			synchronized (this) {
				if () {
					if (getLookupService() instanceof Closable) {
					}
					 = false;
				}
			}
		}
	}

	public ServiceInstance lookupInstance(String serviceName)
		if(! ){
			throw new ServiceException(error);
		}
		if(serviceName == null || serviceName.isEmpty()){
			throw new IllegalArgumentException("The serviceName argument is null or empty.");
		}
		try{
			return lb.vote();
			throw new ServiceException(e);
		}
	}

		if(! ){
			throw new ServiceException(error);
		}
		if(serviceName == null || serviceName.isEmpty()){
			throw new IllegalArgumentException("The serviceName argument is null or empty.");
		}
		try{
			if(modelSvc == null || modelSvc.isEmpty()){
				return Collections.emptyList();
			}else{
				for(ModelServiceInstance modelInstance : modelSvc){
					instances.add(ServiceInstanceUtils.transferFromModelServiceInstance(modelInstance));
				}
				return instances;
			}
			throw new ServiceException(e);
		}
	}

		if(! ){
			throw new ServiceException(error);
		}
		if(serviceName == null || serviceName.isEmpty()){
			throw new IllegalArgumentException("The serviceName argument is null or empty.");
		}
		if(query == null){
			throw new IllegalArgumentException("The ServiceInstanceQuery is null.");
		}
		try{
			return lb.vote();
			throw new ServiceException(e);
		}
	}

		if(! ){
			throw new ServiceException(error);
		}
		if(serviceName == null || serviceName.isEmpty()){
			throw new IllegalArgumentException("The serviceName argument is null or empty.");
		}
		if(query == null){
			throw new IllegalArgumentException("The ServiceInstanceQuery is null.");
		}
		try{
			if(modelSvc != null && ! modelSvc.isEmpty()){
				List<ModelServiceInstancefilteredInstances = ServiceInstanceQueryHelper.filter(querymodelSvc);
				if(filteredInstances.size() > 0){
					for(ModelServiceInstance model : filteredInstances){
						instances.add(ServiceInstanceUtils.transferFromModelServiceInstance(model));
					}
					return instances;
				}
			}
			return Collections.emptyList();
			throw new ServiceException(e);
		}
	}

		if(! ){
			throw new ServiceException(error);
		}
		if(query == null){
			throw new IllegalArgumentException("The ServiceInstanceQuery is null.");
		}
		try{
			return lb.vote();
			throw new ServiceException(e);
		}
	}

		if(! ){
			throw new ServiceException(error);
		}
		if(query == null){
			throw new IllegalArgumentException("The ServiceInstanceQuery is null.");
		}
		try{
			List<ServiceInstanceinstances = null;
			String keyName = null;
			if (query.getCriteria().size() > 0) {
				keyName = query.getCriteria().get(0).getMetadataKey();
			}
			if (keyName != null && !keyName.isEmpty()) {
				List<ModelServiceInstancefilteredInstances = ServiceInstanceQueryHelper
						.filter(querymodelInstances);
				if (filteredInstances.size() > 0) {
					if (instances == null) {
						instances = new ArrayList<ServiceInstance>();
					}
					for (ModelServiceInstance model : filteredInstances) {
						instances.add(ServiceInstanceUtils
					}
				}
			}
			if (instances != null) {
				return instances;
else {
				return Collections.emptyList();
			}
			throw new ServiceException(e);
		}
	}

	public ServiceInstance getInstance(String serviceNameString instanceId)
		if(! ){
			throw new ServiceException(error);
		}
		if(instanceId == null || instanceId.isEmpty()){
			throw new IllegalArgumentException("The instanceId argument is null or empty.");
		}
		if(serviceName == null || serviceName.isEmpty()){
			throw new IllegalArgumentException("The serviceName argument is null or empty.");
		}
		try{
			ModelServiceInstance instance = getLookupService().getModelServiceInstance(serviceNameinstanceId);
			if(instance != null){
				return ServiceInstanceUtils.transferFromModelServiceInstance(instance);
			}
			throw new ServiceException(e);
		}
		return null;
	}

		if(! ){
			throw new ServiceException(error);
		}
		if(serviceName == null || serviceName.isEmpty()){
			throw new IllegalArgumentException("The serviceName argument is null or empty.");
		}
		try{
			if(modelSvc == null || modelSvc.isEmpty()){
				return Collections.emptyList();
			}else{
				for(ModelServiceInstance modelInstance : modelSvc){
					instances.add(ServiceInstanceUtils.transferFromModelServiceInstance(modelInstance));
				}
				return instances;
			}
			throw new ServiceException(e);
		}
	}

		if(! ){
			throw new ServiceException(error);
		}
		if(query == null){
			throw new IllegalArgumentException("The ServiceInstanceQuery argument is null.");
		}
		if(serviceName == null || serviceName.isEmpty()){
			throw new IllegalArgumentException("The serviceName argument is null or empty.");
		}
		try{
			if(modelSvc != null && ! modelSvc.isEmpty()){
				List<ModelServiceInstancefilteredInstances = ServiceInstanceQueryHelper.filter(querymodelSvc);
				if(filteredInstances.size() > 0){
					for(ModelServiceInstance model : filteredInstances){
						instances.add(ServiceInstanceUtils.transferFromModelServiceInstance(model));
					}
					return instances;
				}
			}
			return Collections.emptyList();
			throw new ServiceException(e);
		}
	}

		if(! ){
			throw new ServiceException(error);
		}
		if(query == null){
			throw new IllegalArgumentException("The ServiceInstanceQuery argument is null.");
		}
		try{
			List<ServiceInstanceinstances = null;
			String keyName = null;
			if (query.getCriteria().size() > 0) {
				keyName = query.getCriteria().get(0).getMetadataKey();
			}
			if (keyName != null && !keyName.isEmpty()) {
				List<ModelServiceInstancefilteredInstances = ServiceInstanceQueryHelper
						.filter(querymodelInstances);
				if (filteredInstances.size() > 0) {
					if (instances == null) {
						instances = new ArrayList<ServiceInstance>();
					}
					for (ModelServiceInstance model : filteredInstances) {
						instances.add(ServiceInstanceUtils
					}
				}
			}
			if (instances != null) {
				return instances;
else {
				return Collections.emptyList();
			}
			throw new ServiceException(e);
		}
	}

		if(! ){
			throw new ServiceException(error);
		}
		List<ServiceInstanceinstances = null;
		try{
			for(ModelServiceInstance serviceInstance : allInstances){
				if(instances == null){
					instances = new ArrayList<ServiceInstance>();
				}
				instances.add(ServiceInstanceUtils.transferFromModelServiceInstance(serviceInstance));
			}
			throw new ServiceException(e);
		}
		if(instances == null){
			return Collections.emptyList();
		}
		return instances;
	}

Get the DirectoryLookupService to do the lookup. It is thread safe and lazy initialized.

Returns:
the LookupService.
		if( == null){
			synchronized(this){
				if( == null){
					boolean cacheEnabled = Configurations.getBoolean(,
					if(cacheEnabled){
						service.start();
						 = service;
						.info("Created the CachedDirectoryLookupService in LookupManager");
else {
						.info("Created the DirectoryLookupService in LookupManager");
					}
				}
			}
		}
	}

Validate the ServiceInstanceQuery for the queryInstanceByKey, queryInstancesByKey and getAllInstancesByKey method. For those methods, the ContainQueryCriterion and NotContainQueryCriterion are not supported.

Parameters:
query the ServiceInstanceQuery to validate.
Throws:
com.cisco.oss.foundation.directory.exception.ServiceException when the ServiceInstanceQuery has ContainQueryCriterion or NotContainQueryCriterion.
		for(QueryCriterion criterion : query.getCriteria()){
			if(criterion instanceof ContainQueryCriterion || criterion instanceof NotContainQueryCriterion){
				throw new ServiceException(error);
			}
		}
	}
New to GrepCode? Check out our FAQ X