Proxy creator function.

@param serviceClazz service interface.
@param errorMapper error mapper.
@param <T> type of service interface.
@return proxied service object.
198302
public <T> T forService(Class<T> serviceClazz, ClientErrorMapper errorMapper) {
    // noinspection unchecked
    return (T)
        proxyMap.computeIfAbsent(
            serviceClazz,
            (clazz) -> {
              Map<Method, MethodInfo> methods = Reflect.methodsInfo(serviceClazz);
              return Proxy.newProxyInstance(
                  serviceClazz.getClassLoader(),
                  new Class[] {serviceClazz},
                  new RemoteInvocationHandler(transport, methods, codec, errorMapper));
            }
356718
public ServerBuilder annotatedService(String pathPrefix, Object service,
                                          Iterable<?> exceptionHandlersAndConverters) {
        return annotatedService(pathPrefix, service, Function.identity(), exceptionHandlersAndConverters);
    }
332209
private ServerEventHandler createServerEventHandler(
			SFSEventType type, Class<?> clazz) {
		try {
			return (ServerEventHandler)
					ReflectClassUtil.newInstance(
					clazz, BaseAppContext.class, context);
		} catch (ExtensionException e) {
		    getLogger().error("Error when create server event handlers", e);
			throw new RuntimeException("Can not create event handler of class "
					+ clazz, e);
		}
	}
1360606
@Override
    public Class<?> getProxyClass() {
        if (proxyClass != null) {
            return proxyClass;
        }
        if (generic) {
            return GenericService.class;
        }
        try {
            if (StringUtils.isNotBlank(interfaceId)) {
                this.proxyClass = ClassUtils.forName(interfaceId);
                if (!proxyClass.isInterface()) {
                    throw ExceptionUtils.buildRuntime("consumer.interface",
                        interfaceId, "interfaceId must set interface class, not implement class");
                }
            } else {
                throw ExceptionUtils.buildRuntime("consumer.interface",
                    "null", "interfaceId must be not null");
            }
        } catch (RuntimeException t) {
            throw new IllegalStateException(t.getMessage(), t);
        }
        return proxyClass;
    }
772455
@Override
    public <T> PluggableProviderService<T> createPluginService(Class<T> type, final String serviceName) {
        //load provider service implementation via java ServiceLoader if available
        PluggableProviderService<T> pluginProviderService = ServiceTypes.getPluginProviderService(type, serviceName, this);
        if (null != pluginProviderService) {
            return pluginProviderService;
        }

        //otherwise construct default service implementation
        BasePluginProviderService<T> basePluginProviderService = new BasePluginProviderService<T>(
                serviceName,
                type
        );
        basePluginProviderService.setRundeckServerServiceProviderLoader(this);
        return basePluginProviderService;
    }
167883
@Override
    public T build() {
        return build(new ProxyCreatedCallback<T>() {

            @Override
            public void onProxyCreationFinished(T result) {
                logger.trace("proxy created: interface: {} domains: {}", interfaceName, domains);
            }

            @Override
            public void onProxyCreationError(JoynrRuntimeException error) {
                logger.error("error creating proxy: interface: {} domains: {}, error: {}",
                             interfaceName,
                             domains,
                             error.getMessage());
            }
        });
    }
617241
public <T extends InteractionAwareFixture> T create(Class<T> clazz) {
        return create(clazz, null, null);
    }
603045
public static <TYPE> Provider<TYPE> of(final Class<TYPE> clazz)
    {
        return new ConfigProvider<TYPE>(null, clazz, null);
    }
1312314
public ServerBuilder annotatedService(String pathPrefix, Object service,
                                          Function<Service<HttpRequest, HttpResponse>,
                                                  ? extends Service<HttpRequest, HttpResponse>> decorator,
                                          Iterable<?> exceptionHandlersAndConverters) {
        requireNonNull(pathPrefix, "pathPrefix");
        requireNonNull(service, "service");
        requireNonNull(decorator, "decorator");
        requireNonNull(exceptionHandlersAndConverters, "exceptionHandlersAndConverters");

        defaultVirtualHostBuilderUpdated();
        defaultVirtualHostBuilder.annotatedService(pathPrefix, service, decorator,
                                                   exceptionHandlersAndConverters);
        return this;
    }
66208
@SuppressWarnings("unchecked")
    public <P> P as(final Class<P> proxyType) {
        final boolean isMap = (object instanceof Map);
        final InvocationHandler handler = new InvocationHandler() {
            @Override
            @SuppressWarnings("null")
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                String name = method.getName();

                // Actual method name matches always come first
                try {
                    return on(type, object).call(name, args).get();
                }

                // [#14] Emulate POJO behaviour on wrapped map objects
                catch (ReflectException e) {
                    if (isMap) {
                        Map<String, Object> map = (Map<String, Object>) object;
                        int length = (args == null ? 0 : args.length);

                        if (length == 0 && name.startsWith("get")) {
                            return map.get(property(name.substring(3)));
                        }
                        else if (length == 0 && name.startsWith("is")) {
                            return map.get(property(name.substring(2)));
                        }
                        else if (length == 1 && name.startsWith("set")) {
                            map.put(property(name.substring(3)), args[0]);
                            return null;
                        }
                    }

























                    throw e;
                }
            }
        };

        return (P) Proxy.newProxyInstance(proxyType.getClassLoader(), new Class[] { proxyType }, handler);
    }
396560
@Override
    public ServiceProviderBuilder<T> serviceProviderBuilder()
    {
        return new ServiceProviderBuilderImpl<T>(this)
            .providerStrategy(new RoundRobinStrategy<T>())
            .threadFactory(ThreadUtils.newThreadFactory("ServiceProvider"));
    }
617585
@SuppressWarnings("unchecked")
  public static <T extends Annotation> T createAnnotationFromMap(Class<T> annotationClass,
      Map<String, Object> valuesMap) {
    Map<String, Object> map = getAnnotationDefaultMap(annotationClass);
    map.putAll(valuesMap);
    return AccessController
        .doPrivileged((PrivilegedAction<T>) () -> (T) Proxy.newProxyInstance(
            annotationClass.getClassLoader(),
            new Class[] { annotationClass },
            uncheck(
                () -> (InvocationHandler) AnnotationInvocationHandler_constructor.newInstance(annotationClass, map))));
  }
682581
public static void main(String[] args) throws InterruptedException {
    Microservices ms1 =
        Microservices.builder()
            .discovery(ScalecubeServiceDiscovery::new)
            .transport(ServiceTransports::rsocketServiceTransport)
            .defaultErrorMapper(new ServiceAProviderErrorMapper()) // default mapper for whole node
            .services(
                ServiceInfo.fromServiceInstance(new ServiceAImpl())
                    .errorMapper(new ServiceAProviderErrorMapper()) // mapper per service instance
                    .build())
            .startAwait();

    System.err.println("ms1 started: " + ms1.serviceAddress());

    Microservices ms2 =
        Microservices.builder()
            .discovery(serviceEndpoint -> serviceDiscovery(serviceEndpoint, ms1))
            .transport(ServiceTransports::rsocketServiceTransport)
            .services(
                call -> {
                  ServiceA serviceA =
                      call.errorMapper(
                              new ServiceAClientErrorMapper()) // service client error mapper
                          .api(ServiceA.class);

                  ServiceB serviceB = new ServiceBImpl(serviceA);

                  return Collections.singleton(ServiceInfo.fromServiceInstance(serviceB).build());
                })
            .startAwait();

    System.err.println("ms2 started: " + ms2.serviceAddress());

    ms2.call()
        .api(ServiceB.class)
        .doAnotherStuff(0)
        .subscribe(
            System.out::println,
            th ->
                System.err.println(
                    "No service client mapper is defined for ServiceB, "
                        + "so default scalecube mapper is used! -> "
                        + th),
            () -> System.out.println("Completed!"));

    Thread.currentThread().join();
  }
647538
@SuppressWarnings("unchecked")
    public static <T> ThreadLocalProxy<T> createThreadLocalProxy(Class<T> type) {
        ThreadLocalProxy<?> proxy = null;
        if (UriInfo.class.isAssignableFrom(type)) {
            proxy = new ThreadLocalUriInfo();
        } else if (HttpHeaders.class.isAssignableFrom(type)) {
            proxy = new ThreadLocalHttpHeaders();
        } else if (ProtocolHeaders.class.isAssignableFrom(type)) {
            proxy = new ThreadLocalProtocolHeaders();
        } else if (SecurityContext.class.isAssignableFrom(type)) {
            proxy = new ThreadLocalSecurityContext();
        } else if (ContextResolver.class.isAssignableFrom(type)) {
            proxy = new ThreadLocalContextResolver<>();
        } else if (Request.class.isAssignableFrom(type)) {
            proxy = new ThreadLocalRequest();
        } else if (Providers.class.isAssignableFrom(type)) {
            proxy = new ThreadLocalProviders();
        } else if (MessageContext.class.isAssignableFrom(type)) {
            proxy = new ThreadLocalMessageContext();
// Liberty Change for CXF Begin
        } else if (type.getName().equals(MessageContext.class.getName())) {
            MessageContextProxyClassLoader loader = new MessageContextProxyClassLoader(getClassLoader(Proxy.class), getClassLoader(type), getClassLoader(ThreadLocalProxy.class));
            proxy = (ThreadLocalProxy<T>) Proxy.newProxyInstance(loader,
                                                                 new Class[] { type, ThreadLocalProxy.class },
                                                                 new ProxyInvocationHandler(new ThreadLocalMessageContext()));
// Liberty Change for CXF Begin
        }

        if (proxy == null && isServletApiContext(type.getName())) {
            proxy = createThreadLocalServletApiContext(type.getName());
        }
        if (proxy == null) {
            ClassLoader loader
                = proxyClassLoaderCache.getProxyClassLoader(Proxy.class.getClassLoader(), 
                                                            new Class<?>[]{Proxy.class, ThreadLocalProxy.class, type}); 
            if (!canSeeAllClasses(loader, new Class<?>[]{Proxy.class, ThreadLocalProxy.class, type})) {
                // Liberty change start - (LOG to Tr)
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "find a loader from ProxyClassLoader cache," 
                        + " but can't see all interfaces");
                
                    Tr.debug(tc, "create a new one with parent  " + Proxy.class.getClassLoader());
                }
                //Liberty change end
                proxyClassLoaderCache.removeStaleProxyClassLoader(type);
                proxyClassLoaderCache.getProxyClassLoader(Proxy.class.getClassLoader(), 
                                                          new Class<?>[]{Proxy.class, ThreadLocalProxy.class, type}); 
            }
            return (ThreadLocalProxy<T>)Proxy.newProxyInstance(loader,
                                                     new Class[] {type, ThreadLocalProxy.class },
                                                     new ThreadLocalInvocationHandler<T>());
        }

        return (ThreadLocalProxy<T>) proxy;
    }
278594
@Override
	protected Class<?>[] getHandlerInterfaces(String serviceName) {
		Class<?> remoteInterface = interfaceMap.get(serviceName);
		if (remoteInterface != null) {
			return new Class<?>[]{remoteInterface};
		} else if (Proxy.isProxyClass(getHandler(serviceName).getClass())) {
			return getHandler(serviceName).getClass().getInterfaces();
		} else {
			return new Class<?>[]{getHandler(serviceName).getClass()};
		}
	}
1342062
protected static <P extends AbstractDecoderProxy<T>, T> Object newInstance(
        final Class<P> proxyType, final Class<T> decoderType, final T decoder) {

        if (proxyType == null) {
            throw new NullPointerException("proxyType");
        }

        if (!StringDecoderProxy.class.isAssignableFrom(proxyType)) {
            throw new IllegalArgumentException(
                "proxyType(" + proxyType + ") is not assignable to "
                + StringDecoderProxy.class);
        }

        return newInstance(DECODER.getClassLoader(), new Class<?>[]{DECODER},
                           proxyType, decoderType, decoder);
    }
109338
<T> T createProxy(Class<T> interfaceClass, C adsServiceClient) {
    Set<Class<?>> interfaces = Sets.newHashSet(adsServiceClient.getClass().getInterfaces());
    interfaces.add(interfaceClass);
    Object proxy = Proxy.newProxyInstance(
        adsServiceClient.getSoapClient().getClass().getClassLoader(),
        interfaces.toArray(new Class[] {}), adsServiceClient);
    return interfaceClass.cast(proxy);
  }