/** * Gets the service object. If not retrieved, call {@link #retrieve()}, otherwise returned the cached value. * * @return the service object */ @Override public synchronized <X> X get() { if (service == null) { service = retrieve(); } return cached(); }
/** * Gets the service object. If not retrieved, call {@link #retrieve()}, otherwise returned the cached value. * * @return the service object */ @Override public synchronized <X> X get() { if (service == null) { service = retrieve(); } return cached(); }
/** * GGets the service object if already retrieved. It won't try to acquire the service object if not retrieved yet. Unlike * {@link #cached()} this method let you configure the type of object you want to retrieve. This parameter must match * the expected service type, and must pass the "polyglot" version of the class. * * @param x the * @return the object to access the service */ @Override public <X> X cachedAs(Class<X> x) { Object svc = cached(); if (svc == null) { return null; } if (x == null || x.isInstance(svc)) { return (X) svc; } else { return ClassLoaderUtils.createWithDelegate(x, svc); } }
/** * GGets the service object if already retrieved. It won't try to acquire the service object if not retrieved yet. Unlike * {@link #cached()} this method let you configure the type of object you want to retrieve. This parameter must match * the expected service type, and must pass the "polyglot" version of the class. * * @param x the * @return the object to access the service */ @Override public <X> X cachedAs(Class<X> x) { Object svc = cached(); if (svc == null) { return null; } if (x == null || x.isInstance(svc)) { return (X) svc; } else { return ClassLoaderUtils.createWithDelegate(x, svc); } }