Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2014 Cisco Systems, 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 http://www.apache.org/licenses/LICENSE-2.0 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.
 
 
 
 
 
 package com.cisco.oss.foundation.directory.impl;
 
 
 
 
 import static com.cisco.oss.foundation.directory.ServiceDirectory.getServiceDirectoryConfig;

The ServiceDirectory context class. This class initializes RegistrationManager, LookupManager, and ServiceDirectoryService with the getter methods.
 
 public class ServiceDirectoryImpl {
 
     public static final Logger LOGGER = LoggerFactory.getLogger(ServiceDirectoryImpl.class);

    
The customer ServiceDirectoryManagerFactory implementation class name property name.
 
     public static final String SD_API_SERVICE_DIRECTORY_MANAGER_FACTORY_PROVIDER_PROPERTY = "com.cisco.oss.foundation.directory.manager.factory.provider";

    
ServiceDirectoryManagerFactory.
 
The singleton instance.
 
     private final static ServiceDirectoryImpl instance = new ServiceDirectoryImpl();
 
     private boolean isShutdown = false;
 
     private final String version;
 
     // Singleton, private the constructor.
     private ServiceDirectoryImpl() {
         String version = "Unknown";
         try {
             InputStream input = ServiceDirectoryImpl.class.getClassLoader()
                     .getResourceAsStream("version.txt");
             if (input != null) {
                 Properties prop = new Properties();
                 prop.load(input);
                 input.close();
 
                 if (prop.containsKey("version")) {
                     version = prop.getProperty("version");
                 }
             }
         } catch (IOException e) {
         }
         this. = version;
 
         String custProvider = getServiceDirectoryConfig()
 
         if (!StringUtils.isEmpty(custProvider)) {
             try {
                 Class<?> provider = Class.forName(custProvider);
                 if (ServiceDirectoryManagerFactory.class
                         .isAssignableFrom(provider)) {
                      = (ServiceDirectoryManagerFactoryprovider
                             .newInstance();
                     .info(
                             "Initialize the ServiceDirectoryManager with customer implementation {}.",
                             custProvider);
                }
            } catch (Exception e) {
                .error(
                        "Initialize ServiceDirectoryManagerFactory from {} failed.",
                        custProvidere);
            }
        }
        if ( == null) {
            .info("Initialize the ServiceDirectoryManager with default implementation.");
        }
    }

    
Get the ServiceDirectoryImpl singleton instance.

Returns:
the ServiceDirectoryImpl instance.
    public static ServiceDirectoryImpl getInstance(){
        return ;
    }

    
Get RegistrationManager from ServiceDirectoryManagerFactory.

Returns:
the RegistrationManager instance.
Throws:
com.cisco.oss.foundation.directory.exception.ServiceException
    }

    
get LookupManager from ServiceDirectoryManagerFactory.

Returns:
the LookupManager instance.
Throws:
com.cisco.oss.foundation.directory.exception.ServiceException
    }


    
Get the Service Directory API version

Returns:
the Service Directory API version
    public String getVersion() {
        return this.;
    }

    
Set the ServiceDirectoryManagerFactory.

Parameters:
factory the ServiceDirectoryManagerFactory.
Throws:
com.cisco.oss.foundation.directory.exception.ServiceException
        if (factory == null) {
                     ..getMessageTemplate(),
                    "ServiceDirectoryManagerFactory");
        }
        synchronized(this){
            if(){
                throw new ServiceException(.);
            }
            if (this. != null) {
                .stop();
                .info(
                        "Resetting ServiceDirectoryManagerFactory, old={}, new={}.",
                        this..getClass().getName(),
                        factory.getClass().getName());
                this. = factory;
            } else {
                this. = factory;
                .info("Setting ServiceDirectoryManagerFactory, factory={}.",
                        factory.getClass().getName());
            }
            .start();
        }
    }

    
        if () {
            throw new ServiceException(.);
        }
    }

    
Shut down the ServiceDirectory client and the ServiceDirectoryManagerFactory.
    public synchronized void shutdown(){
        if ( != null) {
            .stop();
        }
        this. = true;
    }

    
not properly implemented, just works as an opposite part with shutdown() method since the shutdown() is not implemented properly
    public synchronized void restart(){
        if ( != null) {
            .start();
        }
         = false;
    }

    
Get the ServiceDirectoryManagerFactory. It looks up the configuration "com.cisco.oss.foundation.directory.manager.factory.provider". If the configuration is null or the provider instantiation fails, it will instantiate the DefaultServiceDirectoryManagerFactory.

Returns:
the ServiceDirectoryManagerFactory instance.
        if(){
            throw new ServiceException(.);
        }
        if( == null){
            // should not allow to return a null
            // TODO, make directoryManagerFactory is immutable.
            // TODO. remove the initialize and reinit method in ServiceDirectoryManagerFactory and ServiceDirectory
                    ..getMessageTemplate(),
                    "ServiceDirectoryManagerFactory");
        }
        return ;
    }
New to GrepCode? Check out our FAQ X