12
12
import org .springframework .context .ApplicationContext ;
13
13
14
14
import com .aol .micro .server .config .Config ;
15
- import com .aol .micro .server .config .Configurer ;
16
15
import com .aol .micro .server .config .MicroserverConfigurer ;
17
16
import com .aol .micro .server .module .Module ;
18
17
import com .aol .micro .server .servers .ApplicationRegister ;
24
23
import com .google .common .collect .Lists ;
25
24
26
25
/**
27
- *
28
26
* Startup class for Microserver instance
29
27
*
30
28
* @author johnmcclean
31
- *
32
29
*/
33
30
public class MicroserverApp {
34
31
35
32
private final Logger logger = LoggerFactory .getLogger (this .getClass ());
36
33
private final List <Module > modules ;
34
+
37
35
private final CompletableFuture end = new CompletableFuture ();
38
- private final ExceptionSoftener softener = ExceptionSoftener .singleton .factory
39
- .getInstance ();
36
+ private final ExceptionSoftener softener = ExceptionSoftener .singleton .factory .getInstance ();
40
37
41
38
@ Getter
42
39
private final ApplicationContext springContext ;
43
40
44
41
/**
45
- * This will construct a Spring context for this Microserver instance.
46
- * The calling class will be used to determine the base package to auto-scan from for Spring Beans
47
- * It will attempt to pick up an @Microservice annotation first, if not present the package of the calling class
48
- * will be used.
42
+ * This will construct a Spring context for this Microserver instance. The calling class will be used to determine the base package to auto-scan
43
+ * from for Spring Beans It will attempt to pick up an @Microservice annotation first, if not present the package of the calling class will be
44
+ * used.
49
45
*
50
- * @param modules Multiple Microservice end points that can be deployed within a single Spring context
46
+ * @param modules
47
+ * Multiple Microservice end points that can be deployed within a single Spring context
51
48
*/
52
49
public MicroserverApp (Module ... modules ) {
53
50
this .modules = Lists .newArrayList (modules );
54
- springContext = new SpringContextFactory (new MicroserverConfigurer ().buildConfig (
55
- extractClass ()), extractClass (),
56
- modules [0 ].getSpringConfigurationClasses ())
57
- .createSpringContext ();
51
+ springContext = new SpringContextFactory (new MicroserverConfigurer ().buildConfig (extractClass ()), extractClass (),
52
+ modules [0 ].getSpringConfigurationClasses ()).createSpringContext ();
58
53
59
54
}
60
55
61
56
/**
62
- * This will construct a Spring context for this Microserver instance.
63
- * The provided class will be used to determine the base package to auto-scan from for Spring Beans
64
- * It will attempt to pick up an @Microservice annotation first, if not present the package of the provided class
65
- * will be used.
57
+ * This will construct a Spring context for this Microserver instance. The provided class will be used to determine the base package to auto-scan
58
+ * from for Spring Beans It will attempt to pick up an @Microservice annotation first, if not present the package of the provided class will be
59
+ * used.
66
60
*
67
- * @param c Class used to configure Spring
68
- * @param modules Multiple Microservice end points that can be deployed within a single Spring context
61
+ * @param c
62
+ * Class used to configure Spring
63
+ * @param modules
64
+ * Multiple Microservice end points that can be deployed within a single Spring context
69
65
*/
70
66
public MicroserverApp (Class c , Module ... modules ) {
71
67
72
68
this .modules = Lists .newArrayList (modules );
73
- springContext = new SpringContextFactory (
74
- new MicroserverConfigurer ().buildConfig (c ), c ,
75
- modules [0 ].getSpringConfigurationClasses ())
69
+ springContext = new SpringContextFactory (new MicroserverConfigurer ().buildConfig (c ), c , modules [0 ].getSpringConfigurationClasses ())
76
70
.createSpringContext ();
77
71
78
72
}
79
73
80
74
/**
81
- * This will construct a Spring context for this Microserver instance.
82
- * The provided Config object will be used to configure Spring
75
+ * This will construct a Spring context for this Microserver instance. The provided Config object will be used to configure Spring
83
76
*
84
- * @param config Spring configuration
85
- * @param modules Multiple Microservice end points that can be deployed within a single Spring context
77
+ * @param config
78
+ * Spring configuration
79
+ * @param modules
80
+ * Multiple Microservice end points that can be deployed within a single Spring context
86
81
*/
87
82
public MicroserverApp (Config config , Module ... modules ) {
88
83
89
84
this .modules = Lists .newArrayList (modules );
90
85
config .set ();
91
- springContext = new SpringContextFactory (config ,
92
- modules [0 ].getSpringConfigurationClasses ())
93
- .createSpringContext ();
86
+ springContext = new SpringContextFactory (config , modules [0 ].getSpringConfigurationClasses ()).createSpringContext ();
94
87
95
88
}
96
-
97
-
98
89
99
90
private Class extractClass () {
100
91
try {
101
- return Class .forName (new Exception ().getStackTrace ()[2 ]
102
- .getClassName ());
92
+ return Class .forName (new Exception ().getStackTrace ()[2 ].getClassName ());
103
93
} catch (ClassNotFoundException e ) {
104
94
softener .throwSoftenedException (e );
105
95
}
106
96
return null ; // unreachable normally
107
97
}
108
98
109
-
110
-
111
99
public void stop () {
112
100
113
101
end .complete (true );
@@ -121,15 +109,12 @@ public void run() {
121
109
122
110
public List <Thread > start () {
123
111
124
- List <ServerApplication > apps = modules
125
- .stream ()
126
- .map (module -> createServer (module )).collect (Collectors .toList ());
112
+ List <ServerApplication > apps = modules .stream ().map (module -> createServer (module )).collect (Collectors .toList ());
127
113
128
114
ServerRunner runner ;
129
115
try {
130
116
131
- runner = new ServerRunner (
132
- springContext .getBean (ApplicationRegister .class ), apps , end );
117
+ runner = new ServerRunner (springContext .getBean (ApplicationRegister .class ), apps , end );
133
118
} catch (BeansException e ) {
134
119
runner = new ServerRunner (apps , end );
135
120
}
@@ -138,10 +123,9 @@ public List<Thread> start() {
138
123
}
139
124
140
125
private ServerApplication createServer (Module module ) {
141
- ServerApplication app = new GrizzlyApplicationFactory (springContext ,
142
- module ).createApp ();
143
-
144
- if (Config .instance ().getSslProperties ()!=null )
126
+ ServerApplication app = new GrizzlyApplicationFactory (springContext , module ).createApp ();
127
+
128
+ if (Config .instance ().getSslProperties () != null )
145
129
return app .withSSLProperties (Config .instance ().getSslProperties ());
146
130
else
147
131
return app ;
0 commit comments