/*
Service Lifecycle Related Methods
326721
@Override
    public void start(StartContext startContext) throws StartException {
        try {
            LdapKeyStore.Builder builder = LdapKeyStore.builder()
                    .setDirContextSupplier(dirContextSupplierInjector.getValue())
                    .setSearchPath(searchPath);

            if (filterAlias != null) builder.setFilterAlias(filterAlias);
            if (filterCertificate != null) builder.setFilterCertificate(filterCertificate);
            if (filterIterate != null) builder.setFilterIterate(filterIterate);
            if (createPath != null) builder.setCreatePath(createPath);
            if (createRdn != null) builder.setCreateRdn(createRdn);
            if (createAttributes != null) builder.setCreateAttributes(createAttributes);
            if (aliasAttribute != null) builder.setAliasAttribute(aliasAttribute);
            if (certificateAttribute != null) builder.setCertificateAttribute(certificateAttribute);
            if (certificateType != null) builder.setCertificateType(certificateType);
            if (certificateChainAttribute != null) builder.setCertificateChainAttribute(certificateChainAttribute);
            if (certificateChainEncoding != null) builder.setCertificateChainEncoding(certificateChainEncoding);
            if (keyAttribute != null) builder.setKeyAttribute(keyAttribute);
            if (keyType != null) builder.setKeyType(keyType);

            KeyStore keyStore = builder.build();
            keyStore.load(null); // initialize
            this.modifiableKeyStore = keyStore;
            this.unmodifiableKeyStore = UnmodifiableKeyStore.unmodifiableKeyStore(keyStore);
        } catch (GeneralSecurityException | IOException e) {
            throw ROOT_LOGGER.unableToStartService(e);
        }
    }
1191205
public void setLifecycleEvents(java.util.Collection<LifecycleEvent> lifecycleEvents) {
        if (lifecycleEvents == null) {
            this.lifecycleEvents = null;
            return;
        }

        this.lifecycleEvents = new com.amazonaws.internal.SdkInternalList<LifecycleEvent>(lifecycleEvents);
    }
1038955
public void setProperties(ServiceReference<FilterFactory> reference) {
        { // set the lifecycle property
            Object property = reference.getProperty(FilterFactory.MAINTAIN_LIFECYCLE);
            if (property != null) {
                maintainLifeCycle = Boolean.parseBoolean(property.toString());
            } else {
                maintainLifeCycle = true;
            }
            serviceRanking = getInteger(reference.getProperty(Constants.SERVICE_RANKING), 0);
            priority = getInteger(reference.getProperty(FilterFactory.FILTER_PRIORITY), 0);
            serviceID = getInteger(reference.getProperty(Constants.SERVICE_ID), 0);
        }
    }
809822
private <T extends OrchidService> void initializeService(Class<T> serviceClass, T service) {
        services.put(serviceClass, service);
    }
1097906
public void setLifecycleOwner(@Nullable LifecycleOwner lifecycleOwner) {
        this.lifecycleOwner = lifecycleOwner;
        for (View view : views) {
            ViewDataBinding binding = DataBindingUtil.getBinding(view);
            if (binding != null) {
                binding.setLifecycleOwner(lifecycleOwner);
            }
        }
    }
585410
public function validateLifecycleCallbacks(ReflectionService $reflectionService) : void
    {
        foreach ($this->lifecycleCallbacks as $callbacks) {
            /** @var array $callbacks */
            foreach ($callbacks as $callbackFuncName) {
                if (! $reflectionService->hasPublicMethod($this->className, $callbackFuncName)) {
                    throw MappingException::lifecycleCallbackMethodNotFound($this->className, $callbackFuncName);
                }
            }
        }
    }
498581
public void setContextLifecycleListeners(
			Collection<? extends LifecycleListener> contextLifecycleListeners) {
		Assert.notNull(contextLifecycleListeners,
				"ContextLifecycleListeners must not be null");
		this.contextLifecycleListeners = new ArrayList<>(contextLifecycleListeners);
	}
440768
@Reference(service = EventEngine.class,
               cardinality = ReferenceCardinality.MANDATORY)
    protected void setEventService(EventEngine service) {
        this.eventService = service;
    }
264250
function(service)
    {
        var moduleName = this.moduleName = 'I' + service.serviceName;
        this.append('module.exports = ' + moduleName +
            ' = require(\'typedef\')');
        this.addBreak(2);
        this.addDisclaimer();
        this.addBreak();
        this.addComment(service.description);
        this.append('.interface(\'' + moduleName + '\') .define({');
        this.addBreak();

	    var processedMethods = [];
        service.methods.forEach(function(method, index) {
	        if (processedMethods.indexOf(method.name) >= 0) {
		        return;
	        }
	        processedMethods.push(method.name);
            if (index) this.code += ',\n';
            this.addMethod(method);
        }.bind(this));

        this.addBreak(2);
        this.append('});');
    }
479632
@Override
    public ModelService getModelService(String serviceName){
        ModelServiceClientCache cache = getCache().get(serviceName);
        ModelService lookup;
        if (cache == null) {
            // cache has not never been created, initialize an new one.
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("service has not been cached, try to cache the service {} ", serviceName);
            }
            lookup = super.getModelService(serviceName);
            if (lookup!=null) {
                getCache().putIfAbsent(serviceName, new ModelServiceClientCache(lookup));
                cache = getCache().get(serviceName);
                addInstanceChangeListener(serviceName, cache);
            }
        } else {
            // service cached has been removed
            if (cache.getData() == null) {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("cached service={} is obsoleted, try to get service from server", serviceName);
                }
                lookup = super.getModelService(serviceName);
                if (lookup != null) {
                    // replace old cached service by new one
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug("try to replace the obsoleted cached service={} by service from server {}", serviceName,lookup.getServiceInstances());
                    }
                    removeInstanceChangeListener(serviceName, cache);
                    boolean replaced = getCache().replace(serviceName, cache, new ModelServiceClientCache(lookup));
                    if (replaced) {
                        addInstanceChangeListener(serviceName, getCache().get(serviceName));

                    } else {
                        LOGGER.error("fail to replace the obsoleted cached service={}", serviceName);
                    }
                }else{
                    LOGGER.error("fail to lookup service={} from server",serviceName);
                }
            }
            // use the use cached service
            else {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("service={} has been cached, get service from cache. {}", serviceName,cache.getData().getServiceInstances());
                }
                lookup = cache.getData();
            }
        }
        return lookup;
    }
713122
public void addContextLifecycleListeners(
			LifecycleListener... contextLifecycleListeners) {
		Assert.notNull(contextLifecycleListeners,
				"ContextLifecycleListeners must not be null");
		this.contextLifecycleListeners.addAll(Arrays.asList(contextLifecycleListeners));
	}
1062147
function (args) {
            var modules = args.modules;
            for (var i = 0; i < modules.length; i += 1) {
                var services = modules[i].services, refpath = modules[i].refpath, moduleInstance = this._utils.resolvePath(refpath, this);
                if (services) {
                    for (var service in services) {
                        if (services.hasOwnProperty(service) && !this.json.isMetadata(service)) {
                            if (this.services[service]) {
                                this.$logWarn(this.SERVICE_ALREADY_DEFINED, service);
                            }
                            if (ariaUtilsType.isFunction(moduleInstance[services[service]])) {
                                this.services[service] = ariaUtilsFunction.bind(moduleInstance[services[service]], moduleInstance);
                                if (this._serviceList[refpath]) {
                                    this._serviceList[refpath].push(service);
                                } else {
                                    this._serviceList[refpath] = [service];
                                }
                            } else {
                                this.$logError(this.SERVICE_METHOD_NOT_FOUND, [services[service],
                                        moduleInstance.$classpath]);
                            }
                        }
                    }
                }
            }
            this.connectBindings(args);
        }
884962
private void initializeServiceRefMetadata(int serviceLocationOffset, int serviceOffsetIndex) {
        metaDataBuffer.putInt(serviceLocationOffset, serviceRefSection + serviceOffsetIndex * BitUtil.SIZE_OF_INT);

        // service reference section
        metaDataBuffer.putInt(serviceRefSection + serviceOffsetIndex * BitUtil.SIZE_OF_INT, 0);
        metaDataBuffer.putInt(serviceRefSection + (serviceOffsetIndex + 1) * BitUtil.SIZE_OF_INT,
                SERVICE_COUNTER_LABELS_BUFFER_LENGTH);
        metaDataBuffer.putInt(serviceRefSection + (serviceOffsetIndex + 2) * BitUtil.SIZE_OF_INT, 0);
        metaDataBuffer.putInt(serviceRefSection + (serviceOffsetIndex + 3) * BitUtil.SIZE_OF_INT,
                SERVICE_COUNTER_VALUES_BUFFER_LENGTH);
    }
1340790
private void doStart() throws LifecycleException {
        tomcat.getServer().addLifecycleListener(new TomcatLifecycleListener());
        logger.info("Deploying application to [" + getConfig().getDeployUrl() + "]");
        tomcat.start();

        // Let's set the port that was used to actually start the application if necessary
        if (getConfig().getPort() == EmbedVaadinConfig.DEFAULT_PORT) {
            getConfig().setPort(getTomcat().getConnector().getLocalPort());
        }

        logger.info("Application has been deployed to [" + getConfig().getDeployUrl() + "]");
        if (config.shouldOpenBrowser()) {
            BrowserUtils.openBrowser(getConfig().getOpenBrowserUrl());
        }
        if (isWaiting()) {
            tomcat.getServer().await();
        }
    }
731280
public final void addLifecycleListener(@NonNull LifecycleListener lifecycleListener) {
        if (!lifecycleListeners.contains(lifecycleListener)) {
            lifecycleListeners.add(lifecycleListener);
        }
    }
565924
@Override
    @Subscribe
    public void handleServiceCreated(ServiceCreatedEvent event) {
        log.debug("Processing Service Created Event {}", event);
        this.fetchModelsForService(event.getService());
    }
195012
@Override
	public void addListeners(String serviceName, Service service) {

		// Service name with version
		String name = (serviceName == null || serviceName.isEmpty()) ? service.getName() : serviceName;
		Class<? extends Service> clazz = service.getClass();
		Field[] fields = clazz.getFields();

		boolean hasListener = false;
		writeLock.lock();
		try {

			// Initialize listeners in service
			for (Field field : fields) {

				// Register event listener
				if (Listener.class.isAssignableFrom(field.getType())) {
					hasListener = true;

					// Name of the action (eg. "service.action")
					String listenerName = nameOf(name, field);

					// Process "Subscribe" annotation
					Subscribe s = field.getAnnotation(Subscribe.class);
					String subscribe = null;
					if (s != null) {
						subscribe = s.value();
					}
					if (subscribe == null || subscribe.isEmpty()) {
						subscribe = listenerName;
					}

					// Process "Group" annotation
					String group = null;
					Group g = field.getAnnotation(Group.class);
					if (g != null) {
						group = g.value();
					}
					if (group == null || group.isEmpty()) {
						group = name;
					}

					// Register listener in EventBus
					field.setAccessible(true);
					Listener listener = (Listener) field.get(service);

					// Get or create group map
					HashMap<String, Strategy<ListenerEndpoint>> groups = listeners.get(subscribe);
					if (groups == null) {
						groups = new HashMap<String, Strategy<ListenerEndpoint>>();
						listeners.put(subscribe, groups);
					}

					// Get or create strategy
					Strategy<ListenerEndpoint> strategy = groups.get(group);
					if (strategy == null) {
						strategy = this.strategy.create();
						groups.put(group, strategy);
					}

					// Add endpoint to strategy
					strategy.addEndpoint(new LocalListenerEndpoint(executor, nodeID, name, group, subscribe, listener,
							asyncLocalInvocation));
				}
			}
		} catch (Exception cause) {
			logger.error("Unable to register local listener!", cause);
		} finally {

			// Clear caches
			if (hasListener) {
				emitterCache.clear();
				broadcasterCache.clear();
				localBroadcasterCache.clear();
			}

			// Unlock reader threads
			writeLock.unlock();
		}
	}