/** * Unwrap HK2 proxy to ConfigBeanProxy. * @param ConfigBeanProxy probably proxied by HK2. * @return actual ConfigBeanProxy. * @throws MultiException If there was an error resolving the proxy. */ @SuppressWarnings("unchecked") public static <T extends ConfigBeanProxy> T revealProxy(T proxy) { if (proxy instanceof ProxyCtl) { ProxyCtl proxyCtl = (ProxyCtl) proxy; proxy = (T) proxyCtl.__make(); } return proxy; }
/** * Unwrap HK2 proxy to ConfigBeanProxy. * @param ConfigBeanProxy probably proxied by HK2. * @return actual ConfigBeanProxy. * @throws MultiException If there was an error resolving the proxy. */ @SuppressWarnings("unchecked") public static <T extends ConfigBeanProxy> T revealProxy(T proxy) { if (proxy instanceof ProxyCtl) { ProxyCtl proxyCtl = (ProxyCtl) proxy; proxy = (T) proxyCtl.__make(); } return proxy; }
/** * Unwrap HK2 proxy to ConfigBeanProxy. * @param ConfigBeanProxy probably proxied by HK2. * @return actual ConfigBeanProxy. * @throws MultiException If there was an error resolving the proxy. */ @SuppressWarnings("unchecked") public static <T extends ConfigBeanProxy> T revealProxy(T proxy) { if (proxy instanceof ProxyCtl) { ProxyCtl proxyCtl = (ProxyCtl) proxy; proxy = (T) proxyCtl.__make(); } return proxy; }
@Override @SuppressWarnings("unchecked") public T get() { // HK2 by default proxy instances to delay actual instance creation, which could harm guice scopes logic // for example: if guice request scope transfer used ServletScopes.transferRequest and we try to obtain // it will try to use proxy instance in separate thread which will perform HK2 checks for request scope // and fail. Instead, we always resolve actual instance and let guice properly control scoping final T res = injector.get().getInstance(ServiceLocator.class).getService(type); return res instanceof ProxyCtl ? (T) ((ProxyCtl) res).__make() : res; }
@Override @SuppressWarnings("unchecked") public T get() { // HK2 by default proxy instances to delay actual instance creation, which could harm guice scopes logic // for example: if guice request scope transfer used ServletScopes.transferRequest and we try to obtain // it will try to use proxy instance in separate thread which will perform HK2 checks for request scope // and fail. Instead, we always resolve actual instance and let guice properly control scoping final T res = injector.get().getInstance(ServiceLocator.class).getService(type); return res instanceof ProxyCtl ? (T) ((ProxyCtl) res).__make() : res; }
private Object internalInvoke(Object target, Method method, Method proceed, Object[] params) throws Throwable { Context<?> context; Object service; context = locator.resolveContext(descriptor.getScopeAnnotation()); service = context.findOrCreate(descriptor, root); if (service == null) { throw new MultiException(new IllegalStateException("Proxiable context " + context + " findOrCreate returned a null for descriptor " + descriptor + " and handle " + root)); } if (method.getName().equals(PROXY_MORE_METHOD_NAME)) { // We did what we came here to do return service; } if (isEquals(method) && (params.length == 1) && (params[0] != null) && (params[0] instanceof ProxyCtl)) { ProxyCtl equalsProxy = (ProxyCtl) params[0]; params = new Object[1]; params[0] = equalsProxy.__make(); } return ReflectionHelper.invoke(service, method, params, locator.getNeutralContextClassLoader()); }
private Object internalInvoke(Object target, Method method, Method proceed, Object[] params) throws Throwable { Context<?> context; Object service; context = locator.resolveContext(descriptor.getScopeAnnotation()); service = context.findOrCreate(descriptor, root); if (service == null) { throw new MultiException(new IllegalStateException("Proxiable context " + context + " findOrCreate returned a null for descriptor " + descriptor + " and handle " + root)); } if (method.getName().equals(PROXY_MORE_METHOD_NAME)) { // We did what we came here to do return service; } if (isEquals(method) && (params.length == 1) && (params[0] != null) && (params[0] instanceof ProxyCtl)) { ProxyCtl equalsProxy = (ProxyCtl) params[0]; params = new Object[1]; params[0] = equalsProxy.__make(); } return ReflectionHelper.invoke(service, method, params, locator.getNeutralContextClassLoader()); }
private Object internalInvoke(Object target, Method method, Method proceed, Object[] params) throws Throwable { Context<?> context; Object service; context = locator.resolveContext(descriptor.getScopeAnnotation()); service = context.findOrCreate(descriptor, root); if (service == null) { throw new MultiException(new IllegalStateException("Proxiable context " + context + " findOrCreate returned a null for descriptor " + descriptor + " and handle " + root)); } if (method.getName().equals(PROXY_MORE_METHOD_NAME)) { // We did what we came here to do return service; } if (isEquals(method) && (params.length == 1) && (params[0] != null) && (params[0] instanceof ProxyCtl)) { ProxyCtl equalsProxy = (ProxyCtl) params[0]; params = new Object[1]; params[0] = equalsProxy.__make(); } return ReflectionHelper.invoke(service, method, params, locator.getNeutralContextClassLoader()); }
private Object internalInvoke(Object target, Method method, Method proceed, Object[] params) throws Throwable { Context<?> context; Object service; context = locator.resolveContext(descriptor.getScopeAnnotation()); service = context.findOrCreate(descriptor, root); if (service == null) { throw new MultiException(new IllegalStateException("Proxiable context " + context + " findOrCreate returned a null for descriptor " + descriptor + " and handle " + root)); } if (method.getName().equals(PROXY_MORE_METHOD_NAME)) { // We did what we came here to do return service; } if (isEquals(method) && (params.length == 1) && (params[0] != null) && (params[0] instanceof ProxyCtl)) { ProxyCtl equalsProxy = (ProxyCtl) params[0]; params = new Object[1]; params[0] = equalsProxy.__make(); } return ReflectionHelper.invoke(service, method, params, locator.getNeutralContextClassLoader()); }