killbill-aplcache
Details
server/pom.xml 150(+56 -94)
diff --git a/server/pom.xml b/server/pom.xml
index 6352893..8b16df1 100644
--- a/server/pom.xml
+++ b/server/pom.xml
@@ -9,7 +9,7 @@
the specific language governing permissions and limitations ~ under the License. -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.ning.billing</groupId>
@@ -23,57 +23,52 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <skeleton.version>0.0.20</skeleton.version>
+ <guice.version>3.0</guice.version>
+ <jersey.version>1.12</jersey.version>
+ <jetty.version>8.1.2.v20120308</jetty.version>
+ <logback.version>1.0.1</logback.version>
+ <metrics.version>2.1.1</metrics.version>
+ <slf4j.version>1.6.4</slf4j.version>
+ <skeleton.version>0.1.0-SNAPSHOT</skeleton.version>
</properties>
<dependencies>
-
-
-
-
-
<!-- NOT in master POM; include version as well -->
-
<dependency>
<groupId>org.weakref</groupId>
<artifactId>jmxutils</artifactId>
- <version>1.10</version>
+ <version>1.12</version>
+ </dependency>
+ <dependency>
+ <groupId>com.google.inject.extensions</groupId>
+ <artifactId>guice-servlet</artifactId>
+ <version>${guice.version}</version>
</dependency>
-
<dependency>
<groupId>com.yammer.metrics</groupId>
<artifactId>metrics-core</artifactId>
- <version>2.0.0-BETA17</version>
+ <version>${metrics.version}</version>
</dependency>
<dependency>
<groupId>com.yammer.metrics</groupId>
<artifactId>metrics-guice</artifactId>
- <version>2.0.0-BETA17</version>
- </dependency>
-
-
- <dependency>
- <groupId>com.google.inject.extensions</groupId>
- <artifactId>guice-servlet</artifactId>
- <version>3.0</version>
+ <version>${metrics.version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
- <version>1.10</version>
+ <version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-guice</artifactId>
- <version>1.10</version>
+ <version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
- <version>2.5</version>
- <scope>provided</scope>
+ <artifactId>javax.servlet-api</artifactId>
+ <version>3.0.1</version>
</dependency>
-
<!-- Do we want to depend on skeleton -->
<dependency>
<groupId>com.ning.jetty</groupId>
@@ -82,74 +77,37 @@
</dependency>
<dependency>
<groupId>com.ning.jetty</groupId>
- <artifactId>ning-service-skeleton-log4j</artifactId>
+ <artifactId>ning-service-skeleton-jdbi</artifactId>
<version>${skeleton.version}</version>
- <classifier>selfcontained</classifier>
- <scope>provided</scope>
- </dependency>
-
- <!-- JETTY -->
- <dependency>
- <groupId>org.eclipse.jetty</groupId>
- <artifactId>jetty-http</artifactId>
- <version>7.5.1.v20110908</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.eclipse.jetty</groupId>
- <artifactId>jetty-io</artifactId>
- <version>7.5.1.v20110908</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.eclipse.jetty</groupId>
- <artifactId>jetty-util</artifactId>
- <version>7.5.1.v20110908</version>
- <scope>provided</scope>
</dependency>
<dependency>
- <groupId>org.eclipse.jetty</groupId>
- <artifactId>jetty-server</artifactId>
- <version>7.5.1.v20110908</version>
+ <groupId>com.ning.jetty</groupId>
+ <artifactId>ning-service-skeleton-log4j</artifactId>
+ <version>${skeleton.version}</version>
+ <classifier>selfcontained</classifier>
<scope>provided</scope>
</dependency>
-
- <dependency>
- <groupId>org.eclipse.jetty</groupId>
- <artifactId>jetty-deploy</artifactId>
- <version>7.5.1.v20110908</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.eclipse.jetty</groupId>
- <artifactId>jetty-jmx</artifactId>
- <version>7.5.1.v20110908</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.eclipse.jetty</groupId>
- <artifactId>jetty-xml</artifactId>
- <version>7.5.1.v20110908</version>
- <scope>test</scope>
- </dependency>
-
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
- <version>1.6.3</version>
+ <version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
- <version>1.6.3</version>
+ <version>${slf4j.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <version>1.6.3</version>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-core</artifactId>
+ <version>${logback.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <version>${logback.version}</version>
</dependency>
-
<!-- FROM MASTER POM / LIBRARY -->
<dependency>
@@ -191,6 +149,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
+ <version>11.0.2</version>
<scope>compile</scope>
</dependency>
<dependency>
@@ -203,17 +162,16 @@
<artifactId>guice-multibindings</artifactId>
<scope>compile</scope>
</dependency>
-
- <!-- SCOPE RUNTIME FROM MAIN POM; DO WE NEED IT ? -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
+ <scope>runtime</scope>
</dependency>
- <dependency>
+ <dependency>
<groupId>org.antlr</groupId>
<artifactId>stringtemplate</artifactId>
+ <scope>runtime</scope>
</dependency>
-
<dependency>
<groupId>org.skife.config</groupId>
<artifactId>config-magic</artifactId>
@@ -222,7 +180,6 @@
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
</dependency>
-
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
@@ -232,13 +189,13 @@
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>commons-io</groupId>
- <artifactId>commons-io</artifactId>
- <scope>test</scope>
- </dependency>
</dependencies>
<build>
+ <resources>
+ <resource>
+ <directory>${basedir}/src/main/resources</directory>
+ </resource>
+ </resources>
<plugins>
<plugin>
<groupId>com.ning.maven.plugins</groupId>
@@ -358,7 +315,7 @@
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
- <version>7.5.1.v20110908</version>
+ <version>${jetty.version}</version>
<dependencies>
<dependency><!-- For LogLevelCounterAppender -->
<groupId>com.ning.jetty</groupId>
@@ -371,20 +328,25 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
- <version>1.6.3</version>
+ <version>${slf4j.version}</version>
</dependency>
<dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <version>1.6.3</version>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-core</artifactId>
+ <version>${logback.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <version>${logback.version}</version>
</dependency>
</dependencies>
<configuration>
<scanIntervalSeconds>60</scanIntervalSeconds>
<systemProperties>
<systemProperty>
- <name>log4j.configuration</name>
- <value>file:${basedir}/src/test/resources/log4j.xml</value>
+ <name>logback.configurationFile</name>
+ <value>file:${basedir}/src/main/resources/logback.xml</value>
</systemProperty>
</systemProperties>
</configuration>
diff --git a/server/src/main/java/com/ning/billing/server/config/KillbillServerConfig.java b/server/src/main/java/com/ning/billing/server/config/KillbillServerConfig.java
index fc29d5f..e3e1d96 100644
--- a/server/src/main/java/com/ning/billing/server/config/KillbillServerConfig.java
+++ b/server/src/main/java/com/ning/billing/server/config/KillbillServerConfig.java
@@ -16,9 +16,6 @@
package com.ning.billing.server.config;
-import org.skife.config.Config;
-import org.skife.config.Default;
-
-public interface KillbillServerConfig {
-
+public interface KillbillServerConfig
+{
}
diff --git a/server/src/main/java/com/ning/billing/server/healthchecks/KillbillHealthcheck.java b/server/src/main/java/com/ning/billing/server/healthchecks/KillbillHealthcheck.java
index 2cad006..62c79bf 100644
--- a/server/src/main/java/com/ning/billing/server/healthchecks/KillbillHealthcheck.java
+++ b/server/src/main/java/com/ning/billing/server/healthchecks/KillbillHealthcheck.java
@@ -15,30 +15,31 @@
*/
package com.ning.billing.server.healthchecks;
-import org.weakref.jmx.Managed;
-
import com.yammer.metrics.core.HealthCheck;
+import org.weakref.jmx.Managed;
-public class KillbillHealthcheck extends HealthCheck {
-
- @Override
- public String name() {
- return "KillbillHealthCheck";
+public class KillbillHealthcheck extends HealthCheck
+{
+ public KillbillHealthcheck()
+ {
+ super(KillbillHealthcheck.class.getSimpleName());
}
@Override
- public Result check() {
+ public Result check()
+ {
try {
// STEPH obviously needs more than that
return Result.healthy();
- } catch (Exception e) {
+ }
+ catch (Exception e) {
return Result.unhealthy(e);
}
}
-
- @Managed
- public boolean isHealthy() {
+ @Managed(description = "Basic killbill healthcheck")
+ public boolean isHealthy()
+ {
return check().isHealthy();
}
}
diff --git a/server/src/main/java/com/ning/billing/server/listeners/KillbillGuiceListener.java b/server/src/main/java/com/ning/billing/server/listeners/KillbillGuiceListener.java
index 880fc4f..451d5c3 100644
--- a/server/src/main/java/com/ning/billing/server/listeners/KillbillGuiceListener.java
+++ b/server/src/main/java/com/ning/billing/server/listeners/KillbillGuiceListener.java
@@ -13,59 +13,112 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
-
package com.ning.billing.server.listeners;
+import com.ning.billing.beatrix.lifecycle.DefaultLifecycle;
+import com.ning.billing.entitlement.api.user.SubscriptionTransition;
+import com.ning.billing.server.config.KillbillServerConfig;
+import com.ning.billing.server.healthchecks.KillbillHealthcheck;
+import com.ning.billing.server.modules.KillbillServerModule;
+import com.ning.billing.util.bus.Bus;
+import com.ning.billing.util.bus.BusService;
+import com.ning.jetty.base.modules.ServerModuleBuilder;
+import com.ning.jetty.core.listeners.SetupServer;
-import javax.servlet.ServletContextEvent;
-
-import org.apache.commons.lang.StringUtils;
+import com.google.common.eventbus.Subscribe;
+import com.google.inject.Injector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.inject.Injector;
-import com.ning.jetty.core.listeners.SetupServer;
-
-public class KillbillGuiceListener extends SetupServer {
-
-
- private static Injector injectorInstance;
+import javax.servlet.ServletContextEvent;
+public class KillbillGuiceListener extends SetupServer
+{
public static final Logger logger = LoggerFactory.getLogger(KillbillGuiceListener.class);
+ private DefaultLifecycle killbillLifecycle;
+ private BusService killbillBusService;
+
+ private KillbillEventHandler killbilleventHandler;
@Override
- public void contextInitialized(final ServletContextEvent event) {
+ public void contextInitialized(ServletContextEvent event)
+ {
+ final ServerModuleBuilder builder = new ServerModuleBuilder()
+ .addConfig(KillbillServerConfig.class)
+ .addHealthCheck(KillbillHealthcheck.class)
+ .addJMXExport(KillbillHealthcheck.class)
+ .addModule(new KillbillServerModule())
+ .addJerseyResource("com.ning.billing.jaxrs.resources");
- logger.info("GuiceListener : contextInitialized");
+ guiceModule = builder.build();
- final String moduleFactoryClassName = event.getServletContext().getInitParameter("guiceModuleFactoryClass");
+ super.contextInitialized(event);
- if (StringUtils.isEmpty(moduleFactoryClassName)) {
- throw new IllegalStateException("Missing parameter 'guiceModuleFactoryClass' for IrsGuiceListener!");
- }
- try {
- final Class<?> moduleFactoryClass = Class.forName(moduleFactoryClassName);
- if (!GuiceModuleFactory.class.isAssignableFrom(moduleFactoryClass)) {
- throw new IllegalStateException(String.format("%s exists but is not a guice module factory!", moduleFactoryClassName));
- }
+ logger.info("KillbillLifecycleListener : contextInitialized");
+ final Injector injector = injector(event);
+ killbillLifecycle = injector.getInstance(DefaultLifecycle.class);
+ killbillBusService = injector.getInstance(BusService.class);
- GuiceModuleFactory factory = GuiceModuleFactory.class.cast(moduleFactoryClass.newInstance());
- logger.info("Instantiated " + moduleFactoryClassName + " as the factory for the main guice module.");
+ killbilleventHandler = new KillbillEventHandler();
- guiceModule = factory.createModule();
+ //
+ // Fire all Startup levels up to service start
+ //
+ killbillLifecycle.fireStartupSequencePriorEventRegistration();
+ //
+ // Perform Bus registration
+ //
+ try {
+ killbillBusService.getBus().register(killbilleventHandler);
}
- catch (Exception ex) {
- throw new IllegalStateException(ex);
+ catch (Bus.EventBusException e) {
+ logger.error("Failed to register for event notifications, this is bad exiting!", e);
+ System.exit(1);
}
+ // Let's start!
+ killbillLifecycle.fireStartupSequencePostEventRegistration();
+ }
- super.contextInitialized(event);
+ @Override
+ public void contextDestroyed(ServletContextEvent sce)
+ {
+ super.contextDestroyed(sce);
+
+ logger.info("IrsKillbillListener : contextDestroyed");
+ // Stop services
+ // Guice error, no need to fill the screen with useless stack traces
+ if (killbillLifecycle == null) {
+ return;
+ }
- injectorInstance = this.injector(event);
+ killbillLifecycle.fireShutdownSequencePriorEventUnRegistration();
+ try {
+ killbillBusService.getBus().unregister(killbilleventHandler);
+ }
+ catch (Bus.EventBusException e) {
+ logger.warn("Failed to unregister for event notifications", e);
+ }
+
+ // Complete shutdown sequence
+ killbillLifecycle.fireShutdownSequencePostEventUnRegistration();
}
- public static Injector getInjectorInstance() {
- return injectorInstance;
+
+ //
+ // At this point we have one generic handler in IRS that could dispatch notifications to the various pieces
+ // interested but we could the various pieces register their own handler directly
+ //
+ public static class KillbillEventHandler
+ {
+ /*
+ * IRS event handler for killbill entitlement events
+ */
+ @Subscribe
+ public void handleEntitlementevents(SubscriptionTransition event)
+ {
+ logger.info("Killbill entitlement event {}", event.toString());
+ }
}
}
diff --git a/server/src/main/java/com/ning/billing/server/modules/KillbillServerModule.java b/server/src/main/java/com/ning/billing/server/modules/KillbillServerModule.java
index edf8f10..a7e243c 100644
--- a/server/src/main/java/com/ning/billing/server/modules/KillbillServerModule.java
+++ b/server/src/main/java/com/ning/billing/server/modules/KillbillServerModule.java
@@ -16,15 +16,6 @@
package com.ning.billing.server.modules;
-import java.lang.management.ManagementFactory;
-
-import javax.management.MBeanServer;
-
-import org.skife.config.ConfigurationObjectFactory;
-import org.skife.jdbi.v2.DBI;
-import org.skife.jdbi.v2.IDBI;
-
-import com.google.inject.AbstractModule;
import com.ning.billing.account.glue.AccountModule;
import com.ning.billing.analytics.setup.AnalyticsModule;
import com.ning.billing.beatrix.glue.BeatrixModule;
@@ -38,37 +29,34 @@ import com.ning.billing.jaxrs.resources.InvoiceResource;
import com.ning.billing.jaxrs.resources.PaymentResource;
import com.ning.billing.jaxrs.resources.SubscriptionResource;
import com.ning.billing.payment.setup.PaymentModule;
-import com.ning.billing.server.config.KillbillServerConfig;
import com.ning.billing.util.glue.BusModule;
import com.ning.billing.util.glue.ClockModule;
import com.ning.billing.util.glue.NotificationQueueModule;
import com.ning.billing.util.glue.TagStoreModule;
-import com.ning.jetty.utils.providers.DBIProvider;
+import com.ning.jetty.jdbi.guice.providers.DBIProvider;
-public class KillbillServerModule extends AbstractModule {
+import com.google.inject.AbstractModule;
+import org.skife.jdbi.v2.DBI;
+import org.skife.jdbi.v2.IDBI;
+public class KillbillServerModule extends AbstractModule
+{
@Override
- protected void configure() {
- configureConfig();
+ protected void configure()
+ {
configureDao();
configureResources();
installKillbillModules();
- // STEPH Do we need that?
- installMBeanExporter();
}
- protected void configureDao() {
+ protected void configureDao()
+ {
bind(IDBI.class).to(DBI.class).asEagerSingleton();
bind(DBI.class).toProvider(DBIProvider.class).asEagerSingleton();
}
-
- protected void configureConfig() {
- KillbillServerConfig config = new ConfigurationObjectFactory(System.getProperties()).build(KillbillServerConfig.class);
- bind(KillbillServerConfig.class).toInstance(config);
- }
-
- protected void configureResources() {
+ protected void configureResources()
+ {
bind(AccountResource.class).asEagerSingleton();
bind(BundleResource.class).asEagerSingleton();
bind(SubscriptionResource.class).asEagerSingleton();
@@ -77,7 +65,8 @@ public class KillbillServerModule extends AbstractModule {
bind(PaymentResource.class).asEagerSingleton();
}
- protected void installKillbillModules() {
+ protected void installKillbillModules()
+ {
install(new BusModule());
install(new NotificationQueueModule());
install(new AccountModule());
@@ -90,9 +79,4 @@ public class KillbillServerModule extends AbstractModule {
install(new BeatrixModule());
install(new ClockModule());
}
-
- protected void installMBeanExporter() {
- MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
- bind(MBeanServer.class).toInstance(mbeanServer);
- }
}
server/src/main/resources/logback.xml 13(+13 -0)
diff --git a/server/src/main/resources/logback.xml b/server/src/main/resources/logback.xml
new file mode 100644
index 0000000..3087885
--- /dev/null
+++ b/server/src/main/resources/logback.xml
@@ -0,0 +1,13 @@
+<configuration>
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <!-- encoders are assigned the type
+ ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
+ <encoder>
+ <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
+ </encoder>
+ </appender>
+
+ <root level="info">
+ <appender-ref ref="STDOUT" />
+ </root>
+</configuration>
diff --git a/server/src/main/webapp/WEB-INF/web.xml b/server/src/main/webapp/WEB-INF/web.xml
index e9c0ee0..9891d30 100644
--- a/server/src/main/webapp/WEB-INF/web.xml
+++ b/server/src/main/webapp/WEB-INF/web.xml
@@ -19,18 +19,10 @@
<!-- Jersey insists on using java.util.logging (JUL) -->
<listener-class>com.ning.jetty.core.listeners.SetupJULBridge</listener-class>
</listener>
- <!-- This param tells the IrsGuiceListener listener which factory to use for the root guice module -->
- <context-param>
- <param-name>guiceModuleFactoryClass</param-name>
- <param-value>com.ning.billing.server.listeners.KillbillGuiceModuleFactory</param-value>
- </context-param>
<listener>
<!-- Context listener: called at startup time and creates the injector -->
<listener-class>com.ning.billing.server.listeners.KillbillGuiceListener</listener-class>
</listener>
- <listener>
- <listener-class>com.ning.billing.server.listeners.KillbillLifecycleListener</listener-class>
- </listener>
<!-- ServletHandler#handle requires a backend servlet, it won't be used though (handled by Guice) -->
<servlet>
<servlet-name>log-invalid-resources</servlet-name>