Skip to content

Commit 81fad9b

Browse files
committed
JBERET-561 Change visibility of scopes implementations
1 parent c6d30f8 commit 81fad9b

File tree

3 files changed

+42
-6
lines changed

3 files changed

+42
-6
lines changed

jberet-core/src/main/java/org/jberet/creation/JobScopedContextImpl.java

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ public class JobScopedContextImpl implements Context {
2626
private JobScopedContextImpl() {
2727
}
2828

29+
public static JobScopedContextImpl getInstance() {
30+
return INSTANCE;
31+
}
32+
2933
@Override
3034
public Class<? extends Annotation> getScope() {
3135
return JobScoped.class;
@@ -61,6 +65,10 @@ public boolean isActive() {
6165
return ArtifactCreationContext.getCurrentArtifactCreationContext().jobContext != null;
6266
}
6367

68+
public void destroy(Contextual<?> contextual) {
69+
JobScopedContextImpl.ScopedInstance.destroy(getJobScopedBeans(), contextual);
70+
}
71+
6472
private ConcurrentMap<Contextual<?>, ScopedInstance<?>> getJobScopedBeans() {
6573
final JobContextImpl jobContext = ArtifactCreationContext.getCurrentArtifactCreationContext().jobContext;
6674
return jobContext.getScopedBeans();
@@ -75,15 +83,27 @@ public ScopedInstance(final T instance, final CreationalContext<T> creationalCon
7583
this.creationalContext = creationalContext;
7684
}
7785

78-
@SuppressWarnings("unchecked")
7986
public static void destroy(final ConcurrentMap<Contextual<?>, JobScopedContextImpl.ScopedInstance<?>> scopedBeans) {
80-
if (scopedBeans.size() > 0) {
81-
for (final Map.Entry<Contextual<?>, JobScopedContextImpl.ScopedInstance<?>> e : scopedBeans.entrySet()) {
82-
final Contextual<?> contextual = e.getKey();
83-
final ScopedInstance<?> value = e.getValue();
87+
destroy(scopedBeans, null);
88+
}
89+
90+
@SuppressWarnings({"rawtypes", "unchecked"})
91+
public static void destroy(final ConcurrentMap<Contextual<?>, JobScopedContextImpl.ScopedInstance<?>> scopedBeans,
92+
final Contextual<?> contextual) {
93+
if (contextual == null) {
94+
if (scopedBeans.size() > 0) {
95+
for (final Map.Entry<Contextual<?>, JobScopedContextImpl.ScopedInstance<?>> e : scopedBeans.entrySet()) {
96+
final Contextual<?> key = e.getKey();
97+
final ScopedInstance<?> value = e.getValue();
98+
((Contextual) key).destroy(value.instance, value.creationalContext);
99+
}
100+
scopedBeans.clear();
101+
}
102+
} else {
103+
final ScopedInstance<?> value = scopedBeans.remove(contextual);
104+
if (value != null) {
84105
((Contextual) contextual).destroy(value.instance, value.creationalContext);
85106
}
86-
scopedBeans.clear();
87107
}
88108
}
89109
}

jberet-core/src/main/java/org/jberet/creation/PartitionScopedContextImpl.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ public class PartitionScopedContextImpl implements Context {
2525
private PartitionScopedContextImpl() {
2626
}
2727

28+
public static PartitionScopedContextImpl getInstance() {
29+
return INSTANCE;
30+
}
31+
2832
@Override
2933
public Class<? extends Annotation> getScope() {
3034
return PartitionScoped.class;
@@ -61,6 +65,10 @@ public boolean isActive() {
6165
return stepContext != null && stepContext.getPartitionScopedBeans() != null;
6266
}
6367

68+
public void destroy(Contextual<?> contextual) {
69+
JobScopedContextImpl.ScopedInstance.destroy(getPartitionScopedBeans(), contextual);
70+
}
71+
6472
private ConcurrentMap<Contextual<?>, JobScopedContextImpl.ScopedInstance<?>> getPartitionScopedBeans() {
6573
final StepContextImpl stepContext = ArtifactCreationContext.getCurrentArtifactCreationContext().stepContext;
6674
return stepContext.getPartitionScopedBeans();

jberet-core/src/main/java/org/jberet/creation/StepScopedContextImpl.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ public class StepScopedContextImpl implements Context {
2525
private StepScopedContextImpl() {
2626
}
2727

28+
public static StepScopedContextImpl getInstance() {
29+
return INSTANCE;
30+
}
31+
2832
@Override
2933
public Class<? extends Annotation> getScope() {
3034
return StepScoped.class;
@@ -60,6 +64,10 @@ public boolean isActive() {
6064
return ArtifactCreationContext.getCurrentArtifactCreationContext().stepContext != null;
6165
}
6266

67+
public void destroy(Contextual<?> contextual) {
68+
JobScopedContextImpl.ScopedInstance.destroy(getStepScopedBeans(), contextual);
69+
}
70+
6371
private ConcurrentMap<Contextual<?>, JobScopedContextImpl.ScopedInstance<?>> getStepScopedBeans() {
6472
final StepContextImpl stepContext = ArtifactCreationContext.getCurrentArtifactCreationContext().stepContext;
6573
return stepContext.getScopedBeans();

0 commit comments

Comments
 (0)