Build service.

@param registeredService the registered service
@param context           the context
@param useServiceHeader  the use service header
@return the service
483365
public Service buildService(final OAuthRegisteredService registeredService, final J2EContext context, final boolean useServiceHeader) {
        var id = StringUtils.EMPTY;
        if (useServiceHeader) {
            id = OAuth20Utils.getServiceRequestHeaderIfAny(context.getRequest());
            LOGGER.debug("Located service based on request header is [{}]", id);
        }
        if (StringUtils.isBlank(id)) {
            id = registeredService.getClientId();
        }
        return webApplicationServiceServiceFactory.createService(id);
    }
1174154
protected TextService getServiceInstance(Map<String,String> headers) throws ServiceException {
        try {
            String requestPath = headers.get(Listener.METAINFO_REQUEST_PATH);
            String[] pathSegments = requestPath != null ? requestPath.split("/") : null;
            if (pathSegments == null)
                throw new ServiceException(ServiceException.INTERNAL_ERROR, "Unable to find a service or handler for request path: " + requestPath);
            String contentType = headers.get(Listener.METAINFO_CONTENT_TYPE);
            String serviceClassName = MDW_REST_SERVICE_PROVIDER_PACKAGE + "." + pathSegments[0];
            try {
                // normal classloader -- built-in service
                Class<? extends TextService> serviceClass = Class.forName(serviceClassName).asSubclass(TextService.class);
                return serviceClass.newInstance();
            }
            catch (ClassNotFoundException ex) {
                // try dynamic based on annotations eg: api/Users/dxoakes
                Class<? extends RegisteredService> serviceType = Listener.CONTENT_TYPE_JSON.equals(contentType) ? JsonService.class : XmlService.class;
                MdwServiceRegistry registry = MdwServiceRegistry.getInstance();
                String pkgName = null;
                for (int i = 0; i < pathSegments.length; i++) {
                    String pathSegment = pathSegments[i];
                    if (i == 0)
                        pkgName = pathSegment;
                    else
                        pkgName += "." + pathSegment;
                    Package pkg = PackageCache.getPackage(pkgName);
                    if (pkg != null) {
                        // try without any subpath first (@Path="/")
                        TextService service = (TextService)registry.getDynamicServiceForPath(pkg, serviceType, "/");
                        if (service == null && i < pathSegments.length - 1) {
                            service = (TextService)registry.getDynamicServiceForPath(pkg, serviceType, "/" + pathSegments[i + 1]);
                        }
                        if (service != null)
                            return service;
                    }
                }

                // lastly, try process invoker mapping
                AssetRequest processRequest = ProcessRequests.getRequest(headers.get(Listener.METAINFO_HTTP_METHOD), requestPath);
                if (processRequest != null) {
                    return new ProcessInvoker(processRequest);
                }

                return null;
            }
        }
        catch (Exception ex) {
            throw new ServiceException(ServiceException.INTERNAL_ERROR, ex.getMessage(), ex);
        }
    }
1112369
protected Context createContext() throws DurableDataLogException {
        val serviceConfig = getServiceConfig();
        val bkConfig = getCommandArgs().getState().getConfigBuilder()
                                       .include(BookKeeperConfig.builder().with(BookKeeperConfig.ZK_ADDRESS, serviceConfig.getZkURL()))
                                       .build().getConfig(BookKeeperConfig::builder);
        val zkClient = createZKClient();
        val factory = new BookKeeperLogFactory(bkConfig, zkClient, getCommandArgs().getState().getExecutor());
        try {
            factory.initialize();
        } catch (DurableDataLogException ex) {
            zkClient.close();
            throw ex;
        }

        val bkAdmin = new BookKeeperAdmin(factory.getBookKeeperClient());
        return new Context(serviceConfig, bkConfig, zkClient, factory, bkAdmin);
    }
548481
private <T> ServiceRegistration<T> registerMBean(ObjectName on, Class<T> type, T o) {
        Dictionary<String, Object> props = new Hashtable<String, Object>();
        props.put("jmx.objectname", on.toString());
        return context.registerService(type, o, props);
    }
472386
public CacheManagerBuilder<T> using(Service service) {
    Set<Service> newServices = new HashSet<>(services);
    newServices.add(service);
    return new CacheManagerBuilder<>(this, newServices);
  }
42164
private void registerService(BundleContext bc, String name, Object serviceInstance) {
        Dictionary<String, Object> properties = new Hashtable<String, Object>();
        properties.put("service.vendor", "IBM");
        bc.registerService(name, serviceInstance, properties);
    }
498174
@Override
    public void registerService(ServiceInstance<T> service) throws Exception
    {
        Entry<T> newEntry = new Entry<T>(service);
        Entry<T> oldEntry = services.putIfAbsent(service.getId(), newEntry);
        Entry<T> useEntry = (oldEntry != null) ? oldEntry : newEntry;
        synchronized(useEntry)
        {
            if ( useEntry == newEntry ) // i.e. is new
            {
                useEntry.cache = makeNodeCache(service);
            }
            internalRegisterService(service);
        }
    }
845986
public Object getService( final Bundle bundle, ServiceRegistration registration )
    {
        class ManagedPaxLoggingService
            implements PaxLoggingService, LogService, ManagedService
        {
            private final String fqcn = getClass().getName();

            public void log( int level, String message )
            {
                PaxLoggingServiceImpl.this.log(bundle, level, message, null, fqcn);
            }

            public void log( int level, String message, Throwable exception )
            {
                PaxLoggingServiceImpl.this.log(bundle, level, message, exception, fqcn);
            }

            public void log( ServiceReference sr, int level, String message )
            {
                Bundle b = bundle == null && sr != null ? sr.getBundle() : bundle;
                PaxLoggingServiceImpl.this.log(b, level, message, null, fqcn);
            }

            public void log( ServiceReference sr, int level, String message, Throwable exception )
            {
                Bundle b = bundle == null && sr != null ? sr.getBundle() : bundle;
                PaxLoggingServiceImpl.this.log(b, level, message, exception, fqcn);
            }

            public int getLogLevel()
            {
                return PaxLoggingServiceImpl.this.getLogLevel();
            }

            public PaxLogger getLogger( Bundle myBundle, String category, String fqcn )
            {
                return PaxLoggingServiceImpl.this.getLogger( myBundle, category, fqcn );
            }

            public void updated( Dictionary<String, ?> configuration )
                throws ConfigurationException
            {
                PaxLoggingServiceImpl.this.updated( configuration );
            }

            public PaxContext getPaxContext()
            {
                return PaxLoggingServiceImpl.this.getPaxContext();
            }
        }

        return new ManagedPaxLoggingService();
    }
1295438
public ModelService getService(String serviceName, Watcher watcher){
        WatcherRegistration wcb = null;
        if (watcher != null) {
            wcb = new WatcherRegistration(serviceName, watcher);
        }

        ProtocolHeader header = new ProtocolHeader();
        header.setType(ProtocolType.GetService);

        GetServiceProtocol p = new GetServiceProtocol(serviceName);
        p.setWatcher(watcher != null);
        GetServiceResponse resp ;
        resp = (GetServiceResponse) connection.submitRequest(header, p,  wcb);
        return resp.getService();
    }
895519
public CorsService build(Service<HttpRequest, HttpResponse> delegate) {
        if (delegate.as(CorsService.class).isPresent()) {
            throw new IllegalArgumentException(
                    "decorated with a " + CorsService.class.getSimpleName() + " already: " +
                    delegate);
        }

        return new CorsService(delegate, new CorsConfig(this));
    }
1166020
@SuppressWarnings("unchecked")
    public final List<RegisteredService> loadServices() {
        logger.info("Loading Registered Services from: [ {} ]...", this.servicesConfigFile);
        final List<RegisteredService> resolvedServices = new ArrayList<RegisteredService>();
        
        try {
            
            final Map<String, List> m = unmarshalServicesRegistryResourceIntoMap();
            
            if (m != null) {
              final Iterator<Map> i = m.get(SERVICES_KEY).iterator();
              while (i.hasNext()) {
                  final Map<?, ?> record = i.next();
                  final String svcId = ((String) record.get(SERVICES_ID_KEY));
                  final RegisteredService svc = getRegisteredServiceInstance(svcId);
                  if (svc != null) {
                      resolvedServices.add(this.objectMapper.convertValue(record, svc.getClass()));
                      logger.debug("Unmarshaled {}: {}", svc.getClass().getSimpleName(), record);
                  }
              }
  
              synchronized (this.mutexMonitor) {
                  this.delegateServiceRegistryDao.setRegisteredServices(resolvedServices);
              }
            }
        } catch (final Throwable e) {
            throw new RuntimeException(e);
        }
        return resolvedServices;
    }
613774
public static RegisteredService of(String name, URI url, Optional<String> portName) {
        return new RegisteredService(name, url, portName);
    }
129826
public ClassLoader buildClassLoader(ClassLoader serviceLoader)
  {
    synchronized (_loaderMap) {
      SoftReference<ClassLoader> extLoaderRef = _loaderMap.get(serviceLoader);
      
      if (extLoaderRef != null) {
        ClassLoader extLoader = extLoaderRef.get();
        
        if (extLoader != null) {
          return extLoader;
        }
      }
    }
    
    String parentId = EnvLoader.getEnvironmentName(serviceLoader);
    
    String id = _id + "!" + parentId;
    
    //DynamicClassLoader extLoader = new PodExtClassLoader(serviceLoader, id);
    DynamicClassLoader extLoader = null;

    /*
    LibraryLoader libLoader
      = new LibraryLoader(extLoader, getRootDirectory().lookup("lib"));
    libLoader.init();
    
    CompilingLoader compLoader
      = new CompilingLoader(extLoader, getRootDirectory().lookup("classes"));
    compLoader.init();
    
    synchronized (_loaderMap) {
      SoftReference<ClassLoader> extLoaderRef = _loaderMap.get(serviceLoader);
      
      if (extLoaderRef != null) {
        ClassLoader extLoaderOld = extLoaderRef.get();
        
        if (extLoaderOld != null) {
          return extLoaderOld;
        }
      }
      
      _loaderMap.put(serviceLoader, new SoftReference<>(extLoader));
    }
    */
    
    return extLoader;
  }
347496
@Override
    protected ServiceRegistration<D> addService(S service, ServiceProperties props) {
        D decorator = createDecorator(service, props);
        if (decorator == null) {
            return null;
        }
        Dictionary<String, ?> decoratorServiceProps = decoratorServiceProps(props);
        getLogger().info("Registering decorator service {} with properties {}", decoratorType.getSimpleName(), decoratorServiceProps);
        return getBundleContext().registerService(decoratorType, decorator, decoratorServiceProps);
    }
1233514
public static boolean isServiceRunning(Context context, Class<? extends Service> service) {
        return isServiceRunning(context, service, Integer.MAX_VALUE);
    }
1294889
public GrpcServiceBuilder addServices(BindableService... bindableServices) {
        requireNonNull(bindableServices, "bindableServices");
        return addServices(ImmutableList.copyOf(bindableServices));
    }
412918
public GrpcServerBuilder addService(ServiceType serviceType, GrpcService serviceDefinition) {
    mServices.add(serviceType);
    return addService(serviceDefinition);
  }