1
1
/*
2
- * Copyright 2015-2023 the original author or authors.
2
+ * Copyright 2015-2025 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
31
31
import java .util .Map .Entry ;
32
32
import java .util .Properties ;
33
33
import java .util .Set ;
34
+ import java .util .concurrent .atomic .AtomicBoolean ;
34
35
import java .util .concurrent .locks .ReentrantLock ;
35
36
import java .util .stream .Stream ;
36
37
47
48
import org .springframework .context .ApplicationEvent ;
48
49
import org .springframework .context .ApplicationListener ;
49
50
import org .springframework .context .ConfigurableApplicationContext ;
51
+ import org .springframework .context .SmartLifecycle ;
50
52
import org .springframework .context .annotation .AnnotationConfigApplicationContext ;
51
53
import org .springframework .context .support .GenericApplicationContext ;
52
54
import org .springframework .core .convert .converter .Converter ;
78
80
* @author Byungjun You
79
81
* @author Omer Celik
80
82
*/
81
- public class DefaultBinderFactory implements BinderFactory , DisposableBean , ApplicationContextAware {
83
+ public class DefaultBinderFactory implements BinderFactory , DisposableBean , ApplicationContextAware , SmartLifecycle {
82
84
83
85
protected final Log logger = LogFactory .getLog (getClass ());
84
86
@@ -94,6 +96,8 @@ public class DefaultBinderFactory implements BinderFactory, DisposableBean, Appl
94
96
95
97
private final BinderCustomizer binderCustomizer ;
96
98
99
+ private final AtomicBoolean running = new AtomicBoolean ();
100
+
97
101
private volatile ConfigurableApplicationContext context ;
98
102
99
103
private Collection <Listener > listeners ;
@@ -144,6 +148,27 @@ public void destroy() {
144
148
this .defaultBinderForBindingTargetType .clear ();
145
149
}
146
150
151
+ @ Override
152
+ public void start () {
153
+ // This is essentially used when CRaC checkpoint is restored
154
+ if (this .running .compareAndSet (false , true )) {
155
+ this .binderInstanceCache .values ().stream ().map (Entry ::getValue ).forEach (ConfigurableApplicationContext ::start );
156
+ }
157
+ }
158
+
159
+ @ Override
160
+ public void stop () {
161
+ // Makes sense for CRaC checkpoint
162
+ if (this .running .compareAndSet (true , false )) {
163
+ this .binderInstanceCache .values ().stream ().map (Entry ::getValue ).forEach (ConfigurableApplicationContext ::stop );
164
+ }
165
+ }
166
+
167
+ @ Override
168
+ public boolean isRunning () {
169
+ return this .running .get ();
170
+ }
171
+
147
172
@ SuppressWarnings ({ "unchecked" , "rawtypes" })
148
173
@ Override
149
174
public <T > Binder <T , ?, ?> getBinder (String name , Class <? extends T > bindingTargetType ) {
0 commit comments