Skip to content

Commit

Permalink
javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmcclean committed Mar 4, 2015
1 parent 7c9cfe6 commit 115a1b1
Show file tree
Hide file tree
Showing 6 changed files with 183 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,42 @@
public @interface Microboot{


/**
* @return Spring auto-scan base packages
*/
String[] basePackages() default {};

/**
* @return Classes to be passed to initial Spring context
* e.g. Classes that have Spring @Configuration or @Component annotation
*
*/
Class[] classes() default {};

/**
* @return Preconfigured collections of classes to be passed to initial Spring context
* They configure various useful pieces of functionality - such as property file loading,
* datasources, scheduling etc
*/
Classes[] springClasses() default {};

/**
* @return Property file name
* default value is 'application.properties'
*/
String propertiesName() default "application.properties";

/**
* @return Hibernate entity scan packages
*/
String[] entityScan() default {};

/**
* @return Properties to be injected into spring format is
* key,value,key,value comma separated list
*/
String[] properties() default {};
boolean isSpringBoot() default false;


}

Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@ public class MicrobootApp {
@Getter
private final ApplicationContext springContext;


/**
* This will construct a Spring context, using Spring Boot for this Microboot instance.
* The calling class will be used to determine the base package to auto-scan 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 used.
*
* @param modules Multiple Microservice end points that can be deployed within a single Spring context
*/
public MicrobootApp(Module...modules){
this.modules = Lists.newArrayList(modules);
springContext = new SpringContextFactory(new MicrobootConfigurator().buildConfig(extractClass()),extractClass(),
Expand All @@ -45,6 +52,16 @@ public MicrobootApp(Module...modules){

}


/**
* This will construct a Spring context, using Spring Boot for this Microboot instance.
* The provided class will be used to determine the base package to auto-scan 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 used.
*
* @param c Class used to configure Spring
* @param modules Multiple Microservice end points that can be deployed within a single Spring context
*/
public MicrobootApp(Class c, Module... modules) {

this.modules = Lists.newArrayList(modules);
Expand All @@ -53,6 +70,13 @@ public MicrobootApp(Class c, Module... modules) {

}

/**
* This will construct a Spring context, using Spring Boot for this Microboot instance.
* The provided Config object will be used to configure Spring
*
* @param config Spring configuration
* @param modules Multiple Microservice end points that can be deployed within a single Spring context
*/
public MicrobootApp(Config config, Module... modules) {

this.modules = Lists.newArrayList(modules);
Expand Down
61 changes: 46 additions & 15 deletions micro-core/src/main/java/com/aol/micro/server/MicroserverApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
import com.aol.simple.react.exceptions.ExceptionSoftener;
import com.google.common.collect.Lists;

/**
*
* Startup class for Microserver instance
*
* @author johnmcclean
*
*/
public class MicroserverApp {

private final Logger logger = LoggerFactory.getLogger(this.getClass());
Expand All @@ -34,29 +41,32 @@ public class MicroserverApp {
@Getter
private final ApplicationContext springContext;

/**
* This will construct a Spring context for this Microserver instance.
* The calling class will be used to determine the base package to auto-scan 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 used.
*
* @param modules Multiple Microservice end points that can be deployed within a single Spring context
*/
public MicroserverApp(Module... modules) {
this.modules = Lists.newArrayList(modules);
springContext = new SpringContextFactory(getConfigurer().buildConfig(
springContext = new SpringContextFactory(new MicroserverConfigurer().buildConfig(
extractClass()), extractClass(),
modules[0].getSpringConfigurationClasses())
.createSpringContext();

}

public Configurer getConfigurer() {
return new MicroserverConfigurer();
}

private Class extractClass() {
try {
return Class.forName(new Exception().getStackTrace()[2]
.getClassName());
} catch (ClassNotFoundException e) {
softener.throwSoftenedException(e);
}
return null; // unreachable normally
}

/**
* This will construct a Spring context for this Microserver instance.
* The provided class will be used to determine the base package to auto-scan 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 used.
*
* @param c Class used to configure Spring
* @param modules Multiple Microservice end points that can be deployed within a single Spring context
*/
public MicroserverApp(Class c, Module... modules) {

this.modules = Lists.newArrayList(modules);
Expand All @@ -67,6 +77,13 @@ public MicroserverApp(Class c, Module... modules) {

}

/**
* This will construct a Spring context for this Microserver instance.
* The provided Config object will be used to configure Spring
*
* @param config Spring configuration
* @param modules Multiple Microservice end points that can be deployed within a single Spring context
*/
public MicroserverApp(Config config, Module... modules) {

this.modules = Lists.newArrayList(modules);
Expand All @@ -76,6 +93,20 @@ public MicroserverApp(Config config, Module... modules) {
.createSpringContext();

}



private Class extractClass() {
try {
return Class.forName(new Exception().getStackTrace()[2]
.getClassName());
} catch (ClassNotFoundException e) {
softener.throwSoftenedException(e);
}
return null; // unreachable normally
}



public void stop() {

Expand Down
14 changes: 14 additions & 0 deletions micro-core/src/main/java/com/aol/micro/server/config/Classes.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,22 @@
import com.aol.micro.server.spring.metrics.CodahaleMetricsConfigurer;
import com.aol.micro.server.spring.properties.PropertyFileConfig;

/**
*
* Collections of Spring configuration classes (Classes annotated with @Configuration)
* that configure various useful pieces of functionality - such as property file loading,
* datasources, scheduling etc
*
* @author johnmcclean
*
*/
public enum Classes {

/**
* CORE CLASSES are the Core Microserver Spring Configuration classes
* Property support, Guava Event Bus, Spring AOP & Scheduling
* Codahale Metrics, Event tracking etc
*/
CORE_CLASSES(PropertyFileConfig.class,
MiscellaneousConfig.class, AopConfig.class, CodahaleMetricsConfigurer.class,
ConfigureActiveJobsAspect.class, ScheduleAndAsyncConfig.class,ConfigureResources.class),
Expand Down
36 changes: 36 additions & 0 deletions micro-core/src/main/java/com/aol/micro/server/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@



/**
*
* Class for configuring a Spring Context for Microserver
*
* @author johnmcclean
*
*/
@AllArgsConstructor
@Getter
@Wither
Expand Down Expand Up @@ -66,13 +73,27 @@ public Config withEntityScanDataSource(String dataSource,String... packages){
newMap.put(dataSource,Arrays.asList(packages));
return this.withDataSources(ImmutableMap.copyOf(newMap));
}
/**
* Define the packages that hibernate should scan for Hibernate entities
* Should be used in conjunction Microserver Spring Configuration classes @See Classes#HIBERNATE_CLASSES
*
* @param packages Packages to scan for hibernate entities
* @return New Config object, with configured packages
*/
public Config withEntityScan(String... packages){
Map<String,List<String>> newMap = new HashMap<>(dataSources);
newMap.put(defaultDataSourceName,Arrays.asList(packages));
return this.withDataSources(ImmutableMap.copyOf(newMap));
}


/**
* Add the provided Classes to initial Spring Context as well as
* @see Classes#DATASOURCE_CLASSES
*
* @param c Array of additional Spring configuration classes
* @return New Config object, with configured packages
*/
public Config withDefaultDataSource(Class... c){
List<Class> result =Lists.newArrayList(Classes.DATASOURCE_CLASSES.getClasses());
if(classes!=null)
Expand All @@ -82,6 +103,14 @@ public Config withDefaultDataSource(Class... c){
}


/**
*
* Add the provided Classes to initial Spring Context as well as
* @see Classes#JDBC_CLASSES
*
* @param c Array of additional Spring configuration classes
* @return New Config object, with configured packages
*/
public Config withJdbcClasses(Class... c){
List<Class> result = Lists.newArrayList(Classes.JDBC_CLASSES.getClasses());
result.addAll(Arrays.asList(Classes.SPRING_DATA_CLASSES.getClasses()));
Expand All @@ -91,6 +120,13 @@ public Config withJdbcClasses(Class... c){
return this.withClasses(ImmutableSet.copyOf(result));
}

/**
* Add the provided Classes to initial Spring Context as well as
* @see Classes#SPRING_DATA_CLASSES
*
* @param c Array of additional Spring configuration classes
* @return New Config object, with configured packages
*/
public Config withHibernateClasses(Class... c){
Set<Class> result = Sets.newHashSet(Classes.HIBERNATE_CLASSES.getClasses());
result.addAll(Arrays.asList(Classes.SPRING_DATA_CLASSES.getClasses()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,41 @@
public @interface Microserver {


/**
* @return Spring auto-scan base packages
*/
String[] basePackages() default {};

/**
* @return Classes to be passed to initial Spring context
* e.g. Classes that have Spring @Configuration or @Component annotation
*
*/
Class[] classes() default {};

/**
* @return Preconfigured collections of classes to be passed to initial Spring context
* They configure various useful pieces of functionality - such as property file loading,
* datasources, scheduling etc
*/
Classes[] springClasses() default {};

/**
* @return Property file name
*/
String propertiesName() default "application.properties";

/**
* @return Hibernate entity scan packages
*/
String[] entityScan() default {};

/**
* @return Properties to be injected into spring format is
* key,value,key,value comma separated list
*/
String[] properties() default {};
boolean isSpringBoot() default false;



}

0 comments on commit 115a1b1

Please sign in to comment.