/*
private ProvidedServiceInstance toProvidedInstance(ModelServiceInstance mInstance) {
return new ProvidedServiceInstance(mInstance.getServiceName(), mInstance.getAddress(),
mInstance.getUri(), mInstance.getStatus(),
mInstance.getMetadata());
}
348208
private static String objHashStr(Object o) {
        return o.getClass().getSimpleName() + "@" + Integer.toHexString(o.hashCode());
    }
1246639
private CachedProviderServiceInstance getCachedServiceInstance(
            String serviceName, String providerId) {
        try {
            read.lock();
            ServiceInstanceId id = new ServiceInstanceId(serviceName, providerId);
            return getCacheServiceInstances().get(id);
        } finally {
            read.unlock();
        }
    }
1095521
private ProvidedServiceInstance jsonToProvidedServiceInstance(String jsonString) throws JsonParseException, JsonMappingException, IOException{
        return deserialize(jsonString.getBytes(), ProvidedServiceInstance.class);
    }
15513
protected static AbatisService getInstance(Context context, String dbName, int version) {
      if (instance == null) {
         instance = new AbatisService(context, dbName, version);
      }
      return instance;
   }
260310
private void createManagedService(final BundleContext context) {
		ManagedService service = this::scheduleUpdateConfig;
		final Dictionary<String, String> props = new Hashtable<>();
		props.put(Constants.SERVICE_PID, org.ops4j.pax.web.service.WebContainerConstants.PID);
		context.registerService(ManagedService.class, service, props);

		// If ConfigurationAdmin service is not available, then do a default configuration.
		// In other cases, ConfigurationAdmin service will always call the ManagedService.
		if (context.getServiceReference(ConfigurationAdmin.class.getName()) == null) {
			try {
				service.updated(null);
			} catch (ConfigurationException ignore) {
				// this should never happen
				LOG.error("Internal error. Cannot set initial configuration resolver.", ignore);
			}
		}
	}
995922
public ModelServiceInstance getModelServiceInstance(String serviceName, String instanceId){
        ModelService service = getModelService(serviceName);
        if(service != null && service.getServiceInstances() != null ){
            for(ModelServiceInstance instance : service.getServiceInstances()){
                if(instance.getInstanceId().equals(instanceId)){
                    return instance;
                }
            }
        }
        return null;
    }
792034
public static Factory newInstance() {
        ScheduledExecutorService scheduler = newSingleThreadScheduledExecutor(new ThreadFactory() {
            public Thread newThread(Runnable r) {
                Thread result = new Thread(r);
                result.setDaemon(true);
                return result;
            }
        });
        Properties props = new Properties();
        return new DefaultFactory(scheduler, props);
    }
513061
public static <T> Provider<T> ofInstance(final T instance) {
		return new Provider<T>() {
			@Override
			public T get() {
				return instance;
			}
		};
	}
695395
protected T createInstance() {
        try {
            Constructor<T> ctor = clazz.getDeclaredConstructor();
            ctor.setAccessible(true);
            return ctor.newInstance();
        } catch (InstantiationException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        } catch (SecurityException e) {
            throw new RuntimeException(e);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        } catch (IllegalArgumentException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        }
    }
782646
public ServiceInstance<T> build()
    {
        return new ServiceInstance<T>(name, id, address, port, sslPort, payload, registrationTimeUTC, serviceType, uriSpec, enabled);
    }
1122423
private Class<?> retrieveRealServiceClass(Object service) {
        Class<?> serviceClass = service.getClass();
        Method realTypeMethod = null;
        try {
            realTypeMethod = serviceClass.getMethod("getRealUnproxiedType");
        } catch (NoSuchMethodException e) {
            // no problem this method does not have to exist
        }
        if (realTypeMethod != null) {
            try {
                serviceClass = (Class<?>) realTypeMethod.invoke(service);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return serviceClass;
    }
432947
function StartableModel(model,instance) {
    if(!model) {
        throw new Error('model is required')
    }
    if(!instance) {
        throw new Error('instance is required')
    }
    if(!(this instanceof StartableModel)) {
        return new StartableModel(model,instance,index)
    }
    this.model = model
    this.key = model.key
    this.instance= instance
    this.fn = instance[model.startable]
    if(!this.fn) {
        throw new Error('The instance of ' +
                        this.key +
                        ' does not have a method ' +
                        model.startable +
                       ' which is required for starting this service.')
    }
    this.inject = (this.fn.inject || [])
    this.hasDeps = (this.inject.length > 0)
}
965687
private void editCachedServiceInstance(ProvidedServiceInstance instance) {
        try {
            write.lock();
            ServiceInstanceId id = new ServiceInstanceId(instance.getServiceName(),
                    instance.getProviderId());
            CachedProviderServiceInstance cachedInstance = getCacheServiceInstances().get(id);
            if(cachedInstance != null){
                cachedInstance.setMonitorEnabled(instance.isMonitorEnabled());
                cachedInstance.setStatus(instance.getStatus());
            }
            
            LOGGER.debug("update cached ProvidedServiceInstance: {}.", cachedInstance.toString());

        } finally {
            write.unlock();
        }
    }
259885
private Object getJavaObjectInstance(Context c, Hashtable<?, ?> envmt, String className, String bindingName, ResourceInfo resourceRefInfo, IndirectReference ref) throws Exception {
        // Return null if we don't find a binding so that the caller can
        // use JNDI if enabled.
        Object resource = null;

        NamingConstants.JavaColonNamespace namespace = NamingConstants.JavaColonNamespace.match(bindingName);
        if (namespace != null) {
            ComponentMetaData cmd = ComponentMetaDataAccessorImpl.getComponentMetaDataAccessor().getComponentMetaData();
            if (cmd != null) {
                OSGiInjectionScopeData isd = injectionEngine.getInjectionScopeData(cmd, namespace);
                if (isd != null) {
                    String name = namespace.unprefix(bindingName);

                    InjectionBinding<?> binding = isd.getInjectionBinding(namespace, name);
                    if (binding == null && isd.processDeferredReferenceData()) {
                        // Try again after processing deferred reference data.
                        binding = isd.getInjectionBinding(namespace, name);
                    }

                    if (binding != null) {
                        resource = getBindingObjectInstance(c, envmt, className, resourceRefInfo, ref, binding);
                    }
                }
            }

            if (resource == null && namespace == NamingConstants.JavaColonNamespace.COMP) {
                resource = getDefaultJavaCompObjectInstance(namespace, bindingName, resourceRefInfo);
            }

            // If not found and the customer did not provide a binding, then try and
            // auto-link to a resource that matches on name in the service registry.
            if (resource == null && ref.defaultBinding && !ref.name.startsWith("java:")) {
                resource = createResource(ref.name, className, ref.name, resourceRefInfo);
            }
        }

        return resource;
    }
936963
static ManagedChannelServiceConfig fromServiceConfig(
      Map<String, ?> serviceConfig,
      boolean retryEnabled,
      int maxRetryAttemptsLimit,
      int maxHedgedAttemptsLimit,
      @Nullable Object loadBalancingConfig) {
    Throttle retryThrottling = null;
    if (retryEnabled) {
      retryThrottling = ServiceConfigUtil.getThrottlePolicy(serviceConfig);
    }
    Map<String, MethodInfo> serviceMethodMap = new HashMap<>();
    Map<String, MethodInfo> serviceMap = new HashMap<>();

    // Try and do as much validation here before we swap out the existing configuration.  In case
    // the input is invalid, we don't want to lose the existing configuration.
    List<Map<String, ?>> methodConfigs =
        ServiceConfigUtil.getMethodConfigFromServiceConfig(serviceConfig);

    if (methodConfigs == null) {
      // this is surprising, but possible.
      return new ManagedChannelServiceConfig(
          serviceMethodMap, serviceMap, retryThrottling, loadBalancingConfig);
    }

    for (Map<String, ?> methodConfig : methodConfigs) {
      MethodInfo info = new MethodInfo(
          methodConfig, retryEnabled, maxRetryAttemptsLimit, maxHedgedAttemptsLimit);

      List<Map<String, ?>> nameList =
          ServiceConfigUtil.getNameListFromMethodConfig(methodConfig);

      checkArgument(
          nameList != null && !nameList.isEmpty(), "no names in method config %s", methodConfig);
      for (Map<String, ?> name : nameList) {
        String serviceName = ServiceConfigUtil.getServiceFromName(name);
        checkArgument(!Strings.isNullOrEmpty(serviceName), "missing service name");
        String methodName = ServiceConfigUtil.getMethodFromName(name);
        if (Strings.isNullOrEmpty(methodName)) {
          // Service scoped config
          checkArgument(
              !serviceMap.containsKey(serviceName), "Duplicate service %s", serviceName);
          serviceMap.put(serviceName, info);
        } else {
          // Method scoped config
          String fullMethodName = MethodDescriptor.generateFullMethodName(serviceName, methodName);
          checkArgument(
              !serviceMethodMap.containsKey(fullMethodName),
              "Duplicate method name %s",
              fullMethodName);
          serviceMethodMap.put(fullMethodName, info);
        }
      }
    }

    return new ManagedChannelServiceConfig(
        serviceMethodMap, serviceMap, retryThrottling, loadBalancingConfig);
  }
791466
public static ServiceDependencyBuilder copyOf(final ServiceDependency prototype) {
        return new ServiceDependencyBuilder()
                .withName(prototype.getName())
                .withDescription(prototype.getDescription())
                .withUrl(prototype.getUrl())
                .withType(prototype.getType())
                .withSubtype(prototype.getSubtype())
                .withMethods(prototype.getMethods())
                .withMediaTypes(prototype.getMediaTypes())
                .withAuthentication(prototype.getAuthentication())
                .withCriticality(prototype.getCriticality())
                .withExpectations(prototype.getExpectations());
    }
1001604
@SuppressWarnings("unchecked")
  public static <T> T newInstance(Class<T> theClass, Configuration conf,
      boolean supportJobConf) {
    T result;
    try {
      Constructor<T> meth = (Constructor<T>) CONSTRUCTOR_CACHE.get(theClass);
      if (meth == null) {
        meth = theClass.getDeclaredConstructor(EMPTY_ARRAY);
        meth.setAccessible(true);
        CONSTRUCTOR_CACHE.put(theClass, meth);
      }
      result = meth.newInstance();
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
    setConf(result, conf, supportJobConf);
    return result;
  }