/** * Same as {@link #release()}, here to implement {@link AutoCloseable}. */ @Override public void close() { release(); }
/** * If the service object has been retrieved, calls {@link #onClose} and release the reference. Otherwise, does nothing. */ @Override public synchronized void release() { ((DiscoveryImpl) discovery).unbind(this); if (service != null) { onClose(); service = null; } }
/** * Gets the service object. It can be a proxy, a client or whatever object depending on the service type. Unlike * {@link #get()} 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 getAs(Class<X> x) { Object svc = get(); 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); } }
/** * If the service object has been retrieved, calls {@link #onClose} and release the reference. Otherwise, does nothing. */ @Override public synchronized void release() { ((DiscoveryImpl) discovery).unbind(this); if (service != null) { onClose(); service = null; } }
/** * Gets the service object. It can be a proxy, a client or whatever object depending on the service type. Unlike * {@link #get()} 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 getAs(Class<X> x) { Object svc = get(); 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); } }
/** * Same as {@link #release()}, here to implement {@link AutoCloseable}. */ @Override public void close() { release(); }