Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JBERET-561 Change visibility of scopes implementations #432

Merged
merged 1 commit into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public class JobScopedContextImpl implements Context {
private JobScopedContextImpl() {
}

public static JobScopedContextImpl getInstance() {
return INSTANCE;
}

@Override
public Class<? extends Annotation> getScope() {
return JobScoped.class;
Expand Down Expand Up @@ -61,6 +65,10 @@ public boolean isActive() {
return ArtifactCreationContext.getCurrentArtifactCreationContext().jobContext != null;
}

public void destroy(Contextual<?> contextual) {
JobScopedContextImpl.ScopedInstance.destroy(getJobScopedBeans(), contextual);
}

private ConcurrentMap<Contextual<?>, ScopedInstance<?>> getJobScopedBeans() {
final JobContextImpl jobContext = ArtifactCreationContext.getCurrentArtifactCreationContext().jobContext;
return jobContext.getScopedBeans();
Expand All @@ -75,15 +83,27 @@ public ScopedInstance(final T instance, final CreationalContext<T> creationalCon
this.creationalContext = creationalContext;
}

@SuppressWarnings("unchecked")
public static void destroy(final ConcurrentMap<Contextual<?>, JobScopedContextImpl.ScopedInstance<?>> scopedBeans) {
if (scopedBeans.size() > 0) {
for (final Map.Entry<Contextual<?>, JobScopedContextImpl.ScopedInstance<?>> e : scopedBeans.entrySet()) {
final Contextual<?> contextual = e.getKey();
final ScopedInstance<?> value = e.getValue();
destroy(scopedBeans, null);
}

@SuppressWarnings({"rawtypes", "unchecked"})
public static void destroy(final ConcurrentMap<Contextual<?>, JobScopedContextImpl.ScopedInstance<?>> scopedBeans,
final Contextual<?> contextual) {
if (contextual == null) {
if (scopedBeans.size() > 0) {
for (final Map.Entry<Contextual<?>, JobScopedContextImpl.ScopedInstance<?>> e : scopedBeans.entrySet()) {
final Contextual<?> key = e.getKey();
final ScopedInstance<?> value = e.getValue();
((Contextual) key).destroy(value.instance, value.creationalContext);
}
scopedBeans.clear();
}
} else {
final ScopedInstance<?> value = scopedBeans.remove(contextual);
if (value != null) {
((Contextual) contextual).destroy(value.instance, value.creationalContext);
}
scopedBeans.clear();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public class PartitionScopedContextImpl implements Context {
private PartitionScopedContextImpl() {
}

public static PartitionScopedContextImpl getInstance() {
return INSTANCE;
}

@Override
public Class<? extends Annotation> getScope() {
return PartitionScoped.class;
Expand Down Expand Up @@ -61,6 +65,10 @@ public boolean isActive() {
return stepContext != null && stepContext.getPartitionScopedBeans() != null;
}

public void destroy(Contextual<?> contextual) {
JobScopedContextImpl.ScopedInstance.destroy(getPartitionScopedBeans(), contextual);
}

private ConcurrentMap<Contextual<?>, JobScopedContextImpl.ScopedInstance<?>> getPartitionScopedBeans() {
final StepContextImpl stepContext = ArtifactCreationContext.getCurrentArtifactCreationContext().stepContext;
return stepContext.getPartitionScopedBeans();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public class StepScopedContextImpl implements Context {
private StepScopedContextImpl() {
}

public static StepScopedContextImpl getInstance() {
return INSTANCE;
}

@Override
public Class<? extends Annotation> getScope() {
return StepScoped.class;
Expand Down Expand Up @@ -60,6 +64,10 @@ public boolean isActive() {
return ArtifactCreationContext.getCurrentArtifactCreationContext().stepContext != null;
}

public void destroy(Contextual<?> contextual) {
JobScopedContextImpl.ScopedInstance.destroy(getStepScopedBeans(), contextual);
}

private ConcurrentMap<Contextual<?>, JobScopedContextImpl.ScopedInstance<?>> getStepScopedBeans() {
final StepContextImpl stepContext = ArtifactCreationContext.getCurrentArtifactCreationContext().stepContext;
return stepContext.getScopedBeans();
Expand Down