/** * This method will add the ability to use the {@link PerThread} scope to * the given locator. If the locator already has a {@link Context} implementation * that handles the {@link PerThread} scope this method does nothing. * * @param locator The non-null locator to enable the PerThread scope on * @throws MultiException if there were errors when committing the service */ public static void enablePerThreadScope(ServiceLocator locator) { try { addClasses(locator, true, PerThreadContext.class); } catch (MultiException me) { if (!isDupException(me)) throw me; } }
/** * This method will add the ability to use the {@link InheritableThread} * scope to the given locator. If the locator already has a {@link Context} * implementation that handles the {@link InheritableThread} scope this * method does nothing. * * @param locator The non-null locator to enable the PerThread scope on * @throws MultiException if there were errors when committing the service */ public static void enableInheritableThreadScope(ServiceLocator locator) { try { addClasses(locator, true, InheritableThreadContext.class); } catch (MultiException me) { if (!isDupException(me)) throw me; } }
/** * Enables greedy service resolution in this service locator by * adding the {@link GredyResolver} into the service locator. This * method is idempotent. * <p> * WARNING: Use of greedy resolution may cause classes that were not * intended to be instantiated by hk2 to be instantiated by hk2. Please * use this with care * * @param locator The locator to enable for greedy resolution */ public static void enableGreedyResolution(ServiceLocator locator) { if (locator == null) throw new IllegalArgumentException(); try { addClasses(locator, true, GreedyResolver.class); } catch (MultiException me) { if (!isDupException(me)) throw me; } }
/** * This method will cause lookup operations to throw exceptions when * exceptions are encountered in underlying operations such as * classloading. This method is idempotent. This method works * by adding {@link RethrowErrorService} to the service registry * <p> * Do not use this methods in secure applications where callers to lookup * should not be given the information that they do NOT have access * to a service * * @param locator The service locator to enable lookup exceptions on. May not be null */ public static void enableLookupExceptions(ServiceLocator locator) { if (locator == null) throw new IllegalArgumentException(); try { addClasses(locator, true, RethrowErrorService.class); } catch (MultiException me) { if (!isDupException(me)) throw me; } }
/** * This method will add the ability to use the {@link Immediate} scope to * the given locator. If the locator already has a {@link Context} implementation * that handles the {@link Immediate} scope this method does nothing. The Immediate * scope will start in the suspended state, allowing the caller to customize the * Immediate scope using the {@link ImmediateController} * <p> * * @param locator The non-null locator to enable the Immediate scope on * @return The ImmediateController that can be used to further configure * the Immediate scope * @throws MultiException if there were errors when committing the service */ public static ImmediateController enableImmediateScopeSuspended(ServiceLocator locator) { try { addClasses(locator, true, ImmediateContext.class, ImmediateHelper.class); } catch (MultiException me) { if (!isDupException(me)) throw me; } return locator.getService(ImmediateController.class); }