Skip to content

Commit 75d2e50

Browse files
author
Castigliego, Marco
committed
test
1 parent 0e570dc commit 75d2e50

File tree

1 file changed

+29
-45
lines changed

1 file changed

+29
-45
lines changed

micro-core/src/main/java/com/aol/micro/server/MicroserverApp.java

Lines changed: 29 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.springframework.context.ApplicationContext;
1313

1414
import com.aol.micro.server.config.Config;
15-
import com.aol.micro.server.config.Configurer;
1615
import com.aol.micro.server.config.MicroserverConfigurer;
1716
import com.aol.micro.server.module.Module;
1817
import com.aol.micro.server.servers.ApplicationRegister;
@@ -24,90 +23,79 @@
2423
import com.google.common.collect.Lists;
2524

2625
/**
27-
*
2826
* Startup class for Microserver instance
2927
*
3028
* @author johnmcclean
31-
*
3229
*/
3330
public class MicroserverApp {
3431

3532
private final Logger logger = LoggerFactory.getLogger(this.getClass());
3633
private final List<Module> modules;
34+
3735
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();
4037

4138
@Getter
4239
private final ApplicationContext springContext;
4340

4441
/**
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.
4945
*
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
5148
*/
5249
public MicroserverApp(Module... modules) {
5350
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();
5853

5954
}
6055

6156
/**
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.
6660
*
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
6965
*/
7066
public MicroserverApp(Class c, Module... modules) {
7167

7268
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())
7670
.createSpringContext();
7771

7872
}
7973

8074
/**
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
8376
*
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
8681
*/
8782
public MicroserverApp(Config config, Module... modules) {
8883

8984
this.modules = Lists.newArrayList(modules);
9085
config.set();
91-
springContext = new SpringContextFactory(config,
92-
modules[0].getSpringConfigurationClasses())
93-
.createSpringContext();
86+
springContext = new SpringContextFactory(config, modules[0].getSpringConfigurationClasses()).createSpringContext();
9487

9588
}
96-
97-
9889

9990
private Class extractClass() {
10091
try {
101-
return Class.forName(new Exception().getStackTrace()[2]
102-
.getClassName());
92+
return Class.forName(new Exception().getStackTrace()[2].getClassName());
10393
} catch (ClassNotFoundException e) {
10494
softener.throwSoftenedException(e);
10595
}
10696
return null; // unreachable normally
10797
}
10898

109-
110-
11199
public void stop() {
112100

113101
end.complete(true);
@@ -121,15 +109,12 @@ public void run() {
121109

122110
public List<Thread> start() {
123111

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());
127113

128114
ServerRunner runner;
129115
try {
130116

131-
runner = new ServerRunner(
132-
springContext.getBean(ApplicationRegister.class), apps, end);
117+
runner = new ServerRunner(springContext.getBean(ApplicationRegister.class), apps, end);
133118
} catch (BeansException e) {
134119
runner = new ServerRunner(apps, end);
135120
}
@@ -138,10 +123,9 @@ public List<Thread> start() {
138123
}
139124

140125
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)
145129
return app.withSSLProperties(Config.instance().getSslProperties());
146130
else
147131
return app;

0 commit comments

Comments
 (0)