>references(t).get().instance(id, factory, request); // assumes a specific kind of reduction; see #reducible
}
diff --git a/src/main/java/org/microbean/scopelet/Scopelet.java b/src/main/java/org/microbean/scopelet/Scopelet.java
index 8a8015a..40154d9 100644
--- a/src/main/java/org/microbean/scopelet/Scopelet.java
+++ b/src/main/java/org/microbean/scopelet/Scopelet.java
@@ -13,7 +13,6 @@
*/
package org.microbean.scopelet;
-import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodHandles.Lookup;
import java.lang.invoke.VarHandle;
@@ -25,8 +24,10 @@
import org.microbean.attributes.Value;
import org.microbean.bean.Bean;
+import org.microbean.bean.Creation;
import org.microbean.bean.Factory;
-import org.microbean.bean.Request;
+
+import static java.lang.invoke.MethodHandles.lookup;
import static org.microbean.assign.Qualifiers.primordialQualifier;
import static org.microbean.assign.Qualifiers.qualifier;
@@ -37,6 +38,8 @@
* @param the {@link Scopelet} subtype extending this class
*
* @author Laird Nelson
+ *
+ * @see #instance(Object, Factory, Creation)
*/
public abstract class Scopelet> implements AutoCloseable, Factory {
@@ -51,7 +54,7 @@ public abstract class Scopelet> implements AutoCloseable,
private static final VarHandle ME;
static {
- final Lookup lookup = MethodHandles.lookup();
+ final Lookup lookup = lookup();
try {
CLOSED = lookup.findVarHandle(Scopelet.class, "closed", boolean.class);
ME = lookup.findVarHandle(Scopelet.class, "me", Scopelet.class);
@@ -128,7 +131,7 @@ protected Scopelet() {
*/
@Override // Factory
@SuppressWarnings("unchecked")
- public final S create(final Request r) {
+ public final S create(final Creation r) {
if (ME.compareAndSet(this, null, this)) { // volatile write
if (r != null) {
// TODO: emit initialized event
@@ -138,12 +141,12 @@ public final S create(final Request r) {
}
/**
- * Returns this {@link Scopelet} if it has been created via the {@link #create(Request)} method, or {@code null} if
+ * Returns this {@link Scopelet} if it has been created via the {@link #create(Creation)} method, or {@code null} if
* that method has not yet been invoked.
*
- * @return this {@link Scopelet} if it has been "{@linkplain #create(Request) created}"; {@code null} otherwise
+ * @return this {@link Scopelet} if it has been "{@linkplain #create(Creation) created}"; {@code null} otherwise
*
- * @see #create(Request)
+ * @see #create(Creation)
*/
@Override // Factory
public final S singleton() {
@@ -152,13 +155,13 @@ public final S singleton() {
/**
* Returns {@code true} when invoked to indicate that {@link Scopelet} implementations {@linkplain
- * Factory#destroy(Object, Request) destroy} what they {@linkplain #create(Request) create}.
+ * Factory#destroy(Object, org.microbean.bean.Destruction) destroy} what they {@linkplain #create(Creation) create}.
*
* @return {@code true} when invoked
*
- * @see Factory#destroy(Object, Request)
+ * @see Factory#destroy(Object, org.microbean.bean.Destruction)
*
- * @see #create(Request)
+ * @see #create(Creation)
*/
@Override // Factory
public final boolean destroys() {
@@ -185,94 +188,10 @@ public boolean active() {
return !this.closed(); // volatile read
}
- /**
- * Checks to see if this {@link Scopelet} {@linkplain #active() is active} and then returns {@code true} if and only
- * if, at the moment of an invocation, this {@link Scopelet} {@linkplain #active() is active} and already contains an
- * object identified by the supplied {@link Object}.
- *
- * The default implementation of this method checks to see if this {@link Scopelet} {@linkplain #active() is
- * active}, and then {@code true} if and only if the result of invoking the {@link #instance(Object, Factory,
- * Request)} method with the supplied {@code id}, {@code null}, and {@code null} is not {@code null}.
- *
- * Subclasses are encouraged to override this method to be more efficient or to use a different algorithm.
- *
- * @param id the {@link Object} serving as an identifier; may be {@code null} in certain pathological cases
- *
- * @return {@code true} if and only if, at the moment of an invocation, this {@link Scopelet} {@linkplain #active() is
- * active} and contains a preexisting object identified by the supplied {@link Object}
- *
- * @exception InactiveScopeletException if this {@link Scopelet} {@linkplain #active() is not active}
- *
- * @see #active()
- *
- * @see #instance(Object, Factory, Request)
- */
- // @Deprecated // This method is not actually used but would need to exist for design flaws in CDI
- public boolean containsId(final Object id) {
- return (id instanceof Request> r ? this.instance(r) : this.instance(id, null, null)) != null;
- }
-
- /**
- * Checks to see if this {@link Scopelet} {@linkplain #active() is active}, and then returns the preexisting
- * contextual instance identified by the supplied {@link Object}, or {@code null} if no such instance exists.
- *
- * This convenience method checks to see if this {@link Scopelet} {@linkplain #active() is active}, and then, if
- * the supplied {@link Object} is not a {@link Request}, calls the {@link #instance(Object, Factory, Request)} method
- * with the supplied {@code id}, {@code null}, and {@code null}, and returns its result.
- *
- * If the supplied {@link Object} is a {@link Request}, this method calls the {@link #instance(Request)}
- * method with the supplied (cast) {@code id} and returns its result.
- *
- * @param the type of contextual instance
- *
- * @param id an {@link Object} serving as an identifier; may be {@code null} in certain pathological cases
- *
- * @return the contextual instance identified by the supplied {@link Object}, or {@code null} if no such instance
- * exists
- *
- * @exception InactiveScopeletException if this {@link Scopelet} {@linkplain #active() is not active}
- *
- * @see #instance(Object, Factory, Request)
- *
- * @see #instance(Request)
- */
- // id is nullable.
- @SuppressWarnings("unchecked")
- public final I get(final Object id) {
- return id instanceof Request> r ? this.instance((Request)r) : this.instance(id, null, null);
- }
-
- /**
- * Checks to see if this {@link Scopelet} {@linkplain #active() is active} and then eturns a contextual instance
- * identified by the {@linkplain Request#beanReduction() identifying information} present within the supplied {@link
- * Request}, creating the instance and associating it with the {@linkplain Request#beanReduction() identifying
- * information} present within the supplied {@link Request} if necessary.
- *
- * @param the type of contextual instance
- *
- * @param request a {@link Request}; may be {@code null} in which case the return value of an invocation of {@link
- * #instance(Object, Factory, Request)} with {@code null} supplied for all three arguments will be returned instead
- *
- * @return an appropriate contextual instance, or {@code null}
- *
- * @exception InactiveScopeletException if this {@link Scopelet} {@linkplain #active() is not active}
- *
- * @see Request#beanReduction()
- *
- * @see #instance(Object, Factory, Request)
- */
- public final I instance(final Request request) {
- if (request == null || request.primordial()) {
- return this.instance(null, null, request);
- }
- final Bean bean = request.beanReduction().bean();
- return this.instance(bean.id(), bean.factory(), request);
- }
-
/**
* Checks to see if this {@link Scopelet} {@linkplain #active() is active} and then returns a pre-existing or
* created-on-demand contextual instance suitable for the combination of identifier, {@link Factory} and {@link
- * Request}.
+ * Creation}, or {@code null}
*
* @param the type of contextual instance
*
@@ -280,15 +199,19 @@ public final I instance(final Request request) {
*
* @param factory a {@link Factory}; may be {@code null}
*
- * @param request a {@link Request}, typically the one in effect that is causing this method to be invoked in the
+ * @param creation a {@link Creation}, typically the one in effect that is causing this method to be invoked in the
* first place; may be {@code null}
*
* @return a contextual instance, possibly pre-existing, or possibly created just in time, or {@code null}
*
* @exception InactiveScopeletException if this {@link Scopelet} {@linkplain #active() is not active}
+ *
+ * @exception ClassCastException if {@code creation} is non-{@code null} and does not implement {@link
+ * org.microbean.bean.Destruction}, a requirement of its contract
+ *
+ * @see Creation
*/
- // All parameters are nullable, perhaps pathologically. This helps permit super early bootstrapping.
- public abstract I instance(final Object id, final Factory factory, final Request request);
+ public abstract I instance(final Object id, final Factory factory, final Creation creation);
/**
* Checks to see if this {@link Scopelet} {@linkplain #active() is active} and then removes any contextual instance
@@ -303,7 +226,6 @@ public final I instance(final Request request) {
*
* @exception InactiveScopeletException if this {@link Scopelet} {@linkplain #active() is not active}
*/
- // id is nullable.
public boolean remove(final Object id) {
if (!this.active()) {
throw new InactiveScopeletException();
@@ -315,15 +237,13 @@ public boolean remove(final Object id) {
* Irrevocably closes this {@link Scopelet}, and, by doing so, notionally makes it irrevocably {@linkplain #closed()
* closed} and {@linkplain #active() inactive}.
*
- * Overrides of this method must call {@link Scopelet#close() super.close()} as part of their implementation or
- * undefined behavior may result.
+ * Overrides of this method must call {@link Scopelet#close() super.close()} as part of their
+ * implementation or undefined behavior may result.
*
* @see #closed()
*
* @see #active()
*/
- // Most scopelets will want to override this to do additional work. They must call super.close() to ensure #closed()
- // returns an appropriate value.
@Override // AutoCloseable
public void close() {
CLOSED.compareAndSet(this, false, true); // volatile write
diff --git a/src/main/java/org/microbean/scopelet/SingletonScopelet.java b/src/main/java/org/microbean/scopelet/SingletonScopelet.java
index 9831622..8a0933b 100644
--- a/src/main/java/org/microbean/scopelet/SingletonScopelet.java
+++ b/src/main/java/org/microbean/scopelet/SingletonScopelet.java
@@ -19,11 +19,8 @@
import java.lang.constant.DynamicConstantDesc;
import java.lang.constant.MethodHandleDesc;
-import java.util.Objects;
import java.util.Optional;
-import org.microbean.construct.Domain;
-
import static java.lang.constant.ConstantDescs.BSM_INVOKE;
/**
@@ -33,27 +30,18 @@
*/
public class SingletonScopelet extends MapBackedScopelet implements Constable {
- private final Domain domain;
-
/**
* Creates a new {@link SingletonScopelet}.
- *
- * @param domain a {@link Domain}; must not be {@code null}
- *
- * @exception NullPointerException if {@code domain} is {@code null}
*/
- public SingletonScopelet(final Domain domain) {
+ public SingletonScopelet() {
super();
- this.domain = Objects.requireNonNull(domain, "domain");
}
@Override // Constable
public Optional extends ConstantDesc> describeConstable() {
- return (this.domain instanceof Constable c ? c.describeConstable() : Optional.empty())
- .map(domainDesc -> DynamicConstantDesc.of(BSM_INVOKE,
- MethodHandleDesc.ofConstructor(ClassDesc.of(this.getClass().getName()),
- ClassDesc.of(Domain.class.getName())),
- domainDesc));
+ return
+ Optional.of(DynamicConstantDesc.of(BSM_INVOKE,
+ MethodHandleDesc.ofConstructor(ClassDesc.of(this.getClass().getName()))));
}
}