-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add ArcContainer.getContexts() - remove ArcContainer.normalScopedInstance() - rename InjectableContext.getOrCreate() to getIfActive() - add ClientProxies util class
- Loading branch information
Showing
9 changed files
with
161 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/ClientProxies.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package io.quarkus.arc.impl; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.arc.InjectableBean; | ||
import io.quarkus.arc.InjectableContext; | ||
import javax.enterprise.context.ContextNotActiveException; | ||
import javax.enterprise.context.spi.Contextual; | ||
|
||
public final class ClientProxies { | ||
|
||
private ClientProxies() { | ||
} | ||
|
||
public static <T> T getApplicationScopedDelegate(InjectableContext applicationContext, InjectableBean<T> bean) { | ||
T result = applicationContext.get(bean); | ||
if (result == null) { | ||
result = applicationContext.get(bean, newCreationalContext(bean)); | ||
} | ||
return result; | ||
} | ||
|
||
public static <T> T getDelegate(InjectableBean<T> bean) { | ||
Iterable<InjectableContext> contexts = Arc.container().getContexts(bean.getScope()); | ||
T result = null; | ||
InjectableContext selectedContext = null; | ||
for (InjectableContext context : contexts) { | ||
if (result != null) { | ||
if (context.isActive()) { | ||
throw new IllegalArgumentException( | ||
"More than one context object for the given scope: " + selectedContext + " " + context); | ||
} | ||
} else { | ||
result = context.getIfActive(bean, ClientProxies::newCreationalContext); | ||
if (result != null) { | ||
selectedContext = context; | ||
} | ||
} | ||
} | ||
if (result == null) { | ||
throw new ContextNotActiveException(); | ||
} | ||
return result; | ||
} | ||
|
||
private static <T> CreationalContextImpl<T> newCreationalContext(Contextual<T> contextual) { | ||
return new CreationalContextImpl<>(contextual); | ||
} | ||
|
||
} |
Oops, something went wrong.