@@ -26,6 +26,10 @@ public class JobScopedContextImpl implements Context {
26
26
private JobScopedContextImpl () {
27
27
}
28
28
29
+ public static JobScopedContextImpl getInstance () {
30
+ return INSTANCE ;
31
+ }
32
+
29
33
@ Override
30
34
public Class <? extends Annotation > getScope () {
31
35
return JobScoped .class ;
@@ -61,6 +65,10 @@ public boolean isActive() {
61
65
return ArtifactCreationContext .getCurrentArtifactCreationContext ().jobContext != null ;
62
66
}
63
67
68
+ public void destroy (Contextual <?> contextual ) {
69
+ JobScopedContextImpl .ScopedInstance .destroy (getJobScopedBeans (), contextual );
70
+ }
71
+
64
72
private ConcurrentMap <Contextual <?>, ScopedInstance <?>> getJobScopedBeans () {
65
73
final JobContextImpl jobContext = ArtifactCreationContext .getCurrentArtifactCreationContext ().jobContext ;
66
74
return jobContext .getScopedBeans ();
@@ -75,15 +83,27 @@ public ScopedInstance(final T instance, final CreationalContext<T> creationalCon
75
83
this .creationalContext = creationalContext ;
76
84
}
77
85
78
- @ SuppressWarnings ("unchecked" )
79
86
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 ) {
84
105
((Contextual ) contextual ).destroy (value .instance , value .creationalContext );
85
106
}
86
- scopedBeans .clear ();
87
107
}
88
108
}
89
109
}
0 commit comments