Move the configuration handling over to Java

This commit is contained in:
R. Tyler Croy 2015-04-03 08:07:07 -07:00
parent aa84bad7b9
commit 666769e9f6
3 changed files with 38 additions and 24 deletions

View File

@ -1,7 +1,6 @@
package com.github.lookout.whoas
package com.github.lookout.whoas;
import io.dropwizard.Configuration
import io.dropwizard.Configuration;
/**
* The interface to create the whoas factory based on configuration
@ -9,5 +8,5 @@ import io.dropwizard.Configuration
* @param < T > Configuration class that extends dropwizard configuration
*/
public interface WhoasConfiguration<T extends Configuration> {
WhoasFactory getWhoasFactory(T configuration)
}
public WhoasFactory getWhoasFactory(T configuration);
}

View File

@ -1,7 +1,11 @@
package com.github.lookout.whoas
package com.github.lookout.whoas;
import com.fasterxml.jackson.annotation.JsonProperty
import org.hibernate.validator.constraints.NotEmpty
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.hibernate.validator.constraints.NotEmpty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* This factory will allow clients of whoas to build
@ -9,12 +13,13 @@ import org.hibernate.validator.constraints.NotEmpty
* like sequential.
*/
public class WhoasFactory {
protected Logger logger = LoggerFactory.getLogger(WhoasFactory.class);
/**
* Queue configuration
*/
@JsonProperty(value = "queue")
WhoasQueueConfig queueConfig = new WhoasQueueConfig()
public WhoasQueueConfig queueConfig = new WhoasQueueConfig();
/**
* Type of runner to create in whoas.
@ -22,7 +27,7 @@ public class WhoasFactory {
* Default runner in whoas is SequentialHookRunner
*/
@JsonProperty
String runnerType = "com.github.lookout.whoas.SequentialHookRunner"
public String runnerType = "com.github.lookout.whoas.SequentialHookRunner";
/**
* Allocate and return the queue based on stored queue type.
@ -36,9 +41,14 @@ public class WhoasFactory {
* or if the instantiation fails for some other reason.
* @return allocated queue
*/
public AbstractHookQueue buildQueue() {
return Class.forName(this.queueConfig.type).getConstructor(WhoasQueueConfig.class).
newInstance(queueConfig)
public AbstractHookQueue buildQueue() throws ClassNotFoundException,
NoSuchMethodException,
InstantiationException,
IllegalAccessException,
InvocationTargetException {
Class queueClass = Class.forName(this.queueConfig.type);
Constructor<AbstractHookQueue> builder = queueClass.getDeclaredConstructor(WhoasQueueConfig.class);
return builder.newInstance(this.queueConfig);
}
/**
@ -54,8 +64,13 @@ public class WhoasFactory {
* @param hookQueue queue to associate with allocated runner
* @return
*/
public AbstractHookRunner buildRunner(AbstractHookQueue hookQueue) {
return Class.forName(this.runnerType).getConstructor(AbstractHookQueue.class).
newInstance(hookQueue)
public AbstractHookRunner buildRunner(AbstractHookQueue hookQueue) throws ClassNotFoundException,
NoSuchMethodException,
InstantiationException,
IllegalAccessException,
InvocationTargetException {
Class runnerClass = Class.forName(this.runnerType);
Constructor<AbstractHookRunner> builder = runnerClass.getDeclaredConstructor(AbstractHookQueue.class);
return builder.newInstance(hookQueue);
}
}
}

View File

@ -1,6 +1,6 @@
package com.github.lookout.whoas
package com.github.lookout.whoas;
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* Whoas Queue Configuration
@ -13,7 +13,7 @@ public class WhoasQueueConfig {
* Default queue in whoas is InMemoryQueue
*/
@JsonProperty
String type = "com.github.lookout.whoas.InMemoryQueue"
public String type = "com.github.lookout.whoas.InMemoryQueue";
/**
* key to idenitfy the distributed queue
@ -21,7 +21,7 @@ public class WhoasQueueConfig {
* Default key is "queue"
*/
@JsonProperty
String key = "queue"
public String key = "queue";
/**
* Hostname of the distributed queue server
@ -29,7 +29,7 @@ public class WhoasQueueConfig {
* Default hostname is localhost
*/
@JsonProperty
String hostname = "localhost"
public String hostname = "localhost";
/**
* Port number of the distributed queue server
@ -37,6 +37,6 @@ public class WhoasQueueConfig {
* Default port is 6379 (i.e. redis)
*/
@JsonProperty
Integer port = 6379
public Integer port = 6379;
}
}