killbill-aplcache
Changes
osgi-bundles/bundles/pom.xml 2(+1 -1)
osgi-bundles/libs/killbill/pom.xml 65(+65 -0)
osgi-bundles/libs/killbill/src/main/java/com/ning/killbill/osgi/libs/killbill/OSGIKillbillRegistrar.java 54(+54 -0)
osgi-bundles/libs/killbill/src/main/java/com/ning/killbill/osgi/libs/killbill/OSGIKillbillTracker.java 369(+369 -0)
osgi-bundles/libs/killbill/src/main/java/com/ning/killbill/osgi/libs/killbill/OSGIServiceNotAvailable.java 38(+38 -0)
osgi-bundles/libs/pom.xml 3(+2 -1)
osgi-bundles/tests/beatrix/pom.xml 16(+14 -2)
osgi-bundles/tests/beatrix/src/test/java/com/ning/billing/osgi/bundles/test/TestActivator.java 76(+22 -54)
osgi-bundles/tests/pom.xml 2(+1 -1)
pom.xml 4(+2 -2)
Details
osgi-bundles/bundles/pom.xml 2(+1 -1)
diff --git a/osgi-bundles/bundles/pom.xml b/osgi-bundles/bundles/pom.xml
index c8f46ff..eaeeee5 100644
--- a/osgi-bundles/bundles/pom.xml
+++ b/osgi-bundles/bundles/pom.xml
@@ -19,7 +19,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.ning.billing</groupId>
- <artifactId>killbill</artifactId>
+ <artifactId>killbill-osgi-all-bundles</artifactId>
<version>0.1.56-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
osgi-bundles/libs/killbill/pom.xml 65(+65 -0)
diff --git a/osgi-bundles/libs/killbill/pom.xml b/osgi-bundles/libs/killbill/pom.xml
new file mode 100644
index 0000000..47ef9c0
--- /dev/null
+++ b/osgi-bundles/libs/killbill/pom.xml
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2010-2013 Ning, Inc.
+ ~
+ ~ Ning licenses this file to you under the Apache License, version 2.0
+ ~ (the "License"); you may not use this file except in compliance with the
+ ~ License. You may obtain a copy of the License at:
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ ~ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ ~ License for 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">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>com.ning.billing</groupId>
+ <artifactId>killbill-osgi-lib-bundles</artifactId>
+ <version>0.1.56-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>killbill-osgi-bundles-lib-killbill</artifactId>
+ <name>Killbill billing platform: OSGI Killbill Library</name>
+ <packaging>jar</packaging>
+ <dependencies>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.ning.billing</groupId>
+ <artifactId>killbill-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>osgi-over-slf4j</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/osgi-bundles/libs/killbill/src/main/java/com/ning/killbill/osgi/libs/killbill/OSGIKillbillRegistrar.java b/osgi-bundles/libs/killbill/src/main/java/com/ning/killbill/osgi/libs/killbill/OSGIKillbillRegistrar.java
new file mode 100644
index 0000000..c2c79e0
--- /dev/null
+++ b/osgi-bundles/libs/killbill/src/main/java/com/ning/killbill/osgi/libs/killbill/OSGIKillbillRegistrar.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2010-2013 Ning, Inc.
+ *
+ * Ning licenses this file to you under the Apache License, version 2.0
+ * (the "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ning.killbill.osgi.libs.killbill;
+
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+import com.ning.billing.payment.plugin.api.PaymentPluginApi;
+
+public class OSGIKillbillRegistrar {
+
+ private final Map<String, ServiceRegistration> serviceRegistrations;
+
+ public OSGIKillbillRegistrar() {
+ this.serviceRegistrations = new HashMap<String, ServiceRegistration>();
+ }
+
+ public <S, T extends S> void registerService(final BundleContext context, final Class<S> svcClass, final S service, final Dictionary props) {
+ ServiceRegistration svcRegistration = context.registerService(svcClass.getName(), service, props);
+ serviceRegistrations.put(svcClass.getName(), svcRegistration);
+ }
+
+ public <S> void unregisterService(final Class<S> svcClass) {
+ ServiceRegistration svc = serviceRegistrations.remove(svcClass.getName());
+ if (svc != null) {
+ svc.unregister();
+ }
+ }
+
+ public void unregisterAll() {
+ for (ServiceRegistration cur : serviceRegistrations.values()) {
+ cur.unregister();
+ }
+ serviceRegistrations.clear();
+ }
+}
diff --git a/osgi-bundles/libs/killbill/src/main/java/com/ning/killbill/osgi/libs/killbill/OSGIKillbillTracker.java b/osgi-bundles/libs/killbill/src/main/java/com/ning/killbill/osgi/libs/killbill/OSGIKillbillTracker.java
new file mode 100644
index 0000000..8bd1f97
--- /dev/null
+++ b/osgi-bundles/libs/killbill/src/main/java/com/ning/killbill/osgi/libs/killbill/OSGIKillbillTracker.java
@@ -0,0 +1,369 @@
+/*
+ * Copyright 2010-2013 Ning, Inc.
+ *
+ * Ning licenses this file to you under the Apache License, version 2.0
+ * (the "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ning.killbill.osgi.libs.killbill;
+
+import javax.annotation.Nullable;
+import javax.sql.DataSource;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogService;
+import org.osgi.util.tracker.ServiceTracker;
+
+import com.ning.billing.account.api.AccountUserApi;
+import com.ning.billing.analytics.api.sanity.AnalyticsSanityApi;
+import com.ning.billing.analytics.api.user.AnalyticsUserApi;
+import com.ning.billing.beatrix.bus.api.ExternalBus;
+import com.ning.billing.catalog.api.CatalogUserApi;
+import com.ning.billing.entitlement.api.migration.EntitlementMigrationApi;
+import com.ning.billing.entitlement.api.timeline.EntitlementTimelineApi;
+import com.ning.billing.entitlement.api.transfer.EntitlementTransferApi;
+import com.ning.billing.entitlement.api.user.EntitlementUserApi;
+import com.ning.billing.invoice.api.InvoiceMigrationApi;
+import com.ning.billing.invoice.api.InvoicePaymentApi;
+import com.ning.billing.invoice.api.InvoiceUserApi;
+import com.ning.billing.osgi.api.OSGIKillbill;
+import com.ning.billing.osgi.api.config.PluginConfigServiceApi;
+import com.ning.billing.overdue.OverdueUserApi;
+import com.ning.billing.payment.api.PaymentApi;
+import com.ning.billing.tenant.api.TenantUserApi;
+import com.ning.billing.usage.api.UsageUserApi;
+import com.ning.billing.util.api.AuditUserApi;
+import com.ning.billing.util.api.CustomFieldUserApi;
+import com.ning.billing.util.api.ExportUserApi;
+import com.ning.billing.util.api.TagUserApi;
+
+public class OSGIKillbillTracker implements OSGIKillbill, LogService {
+
+
+ private static final String LOG_SERVICE_NAME = "org.osgi.service.log.LogService";
+ private static final String KILLBILL_SERVICE_NAME = "com.ning.billing.osgi.api.OSGIKillbill";
+
+ private final ServiceTracker<LogService, LogService> logTracker;
+ private final ServiceTracker<OSGIKillbill, OSGIKillbill> killbillTracker;
+
+ public OSGIKillbillTracker(BundleContext context) {
+ logTracker = new ServiceTracker(context, LOG_SERVICE_NAME, null);
+ logTracker.open();
+
+ killbillTracker = new ServiceTracker(context, KILLBILL_SERVICE_NAME, null);
+ killbillTracker.open();
+ }
+
+ public void close() {
+ if (logTracker != null) {
+ logTracker.close();
+ }
+ if (killbillTracker != null) {
+ killbillTracker.close();
+ }
+ }
+
+
+ @Override
+ public AccountUserApi getAccountUserApi() {
+ return withServiceTracker(killbillTracker, new APICallback<AccountUserApi, OSGIKillbill>(KILLBILL_SERVICE_NAME) {
+ @Override
+ public AccountUserApi executeWithService(final OSGIKillbill service) {
+ return service.getAccountUserApi();
+ }
+ });
+ }
+
+ @Override
+ public AnalyticsSanityApi getAnalyticsSanityApi() {
+ return withServiceTracker(killbillTracker, new APICallback<AnalyticsSanityApi, OSGIKillbill>(KILLBILL_SERVICE_NAME) {
+ @Override
+ public AnalyticsSanityApi executeWithService(final OSGIKillbill service) {
+ return service.getAnalyticsSanityApi();
+ }
+ });
+ }
+
+ @Override
+ public AnalyticsUserApi getAnalyticsUserApi() {
+ return withServiceTracker(killbillTracker, new APICallback<AnalyticsUserApi, OSGIKillbill>(KILLBILL_SERVICE_NAME) {
+ @Override
+ public AnalyticsUserApi executeWithService(final OSGIKillbill service) {
+ return service.getAnalyticsUserApi();
+ }
+ });
+
+ }
+
+ @Override
+ public CatalogUserApi getCatalogUserApi() {
+ return withServiceTracker(killbillTracker, new APICallback<CatalogUserApi, OSGIKillbill>(KILLBILL_SERVICE_NAME) {
+ @Override
+ public CatalogUserApi executeWithService(final OSGIKillbill service) {
+ return service.getCatalogUserApi();
+ }
+ });
+ }
+
+ @Override
+ public EntitlementMigrationApi getEntitlementMigrationApi() {
+ return withServiceTracker(killbillTracker, new APICallback<EntitlementMigrationApi, OSGIKillbill>(KILLBILL_SERVICE_NAME) {
+ @Override
+ public EntitlementMigrationApi executeWithService(final OSGIKillbill service) {
+ return service.getEntitlementMigrationApi();
+ }
+ });
+ }
+
+ @Override
+ public EntitlementTimelineApi getEntitlementTimelineApi() {
+ return withServiceTracker(killbillTracker, new APICallback<EntitlementTimelineApi, OSGIKillbill>(KILLBILL_SERVICE_NAME) {
+ @Override
+ public EntitlementTimelineApi executeWithService(final OSGIKillbill service) {
+ return service.getEntitlementTimelineApi();
+ }
+ });
+ }
+
+ @Override
+ public EntitlementTransferApi getEntitlementTransferApi() {
+ return withServiceTracker(killbillTracker, new APICallback<EntitlementTransferApi, OSGIKillbill>(KILLBILL_SERVICE_NAME) {
+ @Override
+ public EntitlementTransferApi executeWithService(final OSGIKillbill service) {
+ return service.getEntitlementTransferApi();
+ }
+ });
+ }
+
+ @Override
+ public EntitlementUserApi getEntitlementUserApi() {
+ return withServiceTracker(killbillTracker, new APICallback<EntitlementUserApi, OSGIKillbill>(KILLBILL_SERVICE_NAME) {
+ @Override
+ public EntitlementUserApi executeWithService(final OSGIKillbill service) {
+ return service.getEntitlementUserApi();
+ }
+ });
+ }
+
+ @Override
+ public InvoiceMigrationApi getInvoiceMigrationApi() {
+ return withServiceTracker(killbillTracker, new APICallback<InvoiceMigrationApi, OSGIKillbill>(KILLBILL_SERVICE_NAME) {
+ @Override
+ public InvoiceMigrationApi executeWithService(final OSGIKillbill service) {
+ return service.getInvoiceMigrationApi();
+ }
+ });
+ }
+
+ @Override
+ public InvoicePaymentApi getInvoicePaymentApi() {
+ return withServiceTracker(killbillTracker, new APICallback<InvoicePaymentApi, OSGIKillbill>(KILLBILL_SERVICE_NAME) {
+ @Override
+ public InvoicePaymentApi executeWithService(final OSGIKillbill service) {
+ return service.getInvoicePaymentApi();
+ }
+ });
+ }
+
+ @Override
+ public InvoiceUserApi getInvoiceUserApi() {
+ return withServiceTracker(killbillTracker, new APICallback<InvoiceUserApi, OSGIKillbill>(KILLBILL_SERVICE_NAME) {
+ @Override
+ public InvoiceUserApi executeWithService(final OSGIKillbill service) {
+ return service.getInvoiceUserApi();
+ }
+ });
+ }
+
+ @Override
+ public OverdueUserApi getOverdueUserApi() {
+ return withServiceTracker(killbillTracker, new APICallback<OverdueUserApi, OSGIKillbill>(KILLBILL_SERVICE_NAME) {
+ @Override
+ public OverdueUserApi executeWithService(final OSGIKillbill service) {
+ return service.getOverdueUserApi();
+ }
+ });
+ }
+
+ @Override
+ public PaymentApi getPaymentApi() {
+ return withServiceTracker(killbillTracker, new APICallback<PaymentApi, OSGIKillbill>(KILLBILL_SERVICE_NAME) {
+ @Override
+ public PaymentApi executeWithService(final OSGIKillbill service) {
+ return service.getPaymentApi();
+ }
+ });
+ }
+
+ @Override
+ public TenantUserApi getTenantUserApi() {
+ return withServiceTracker(killbillTracker, new APICallback<TenantUserApi, OSGIKillbill>(KILLBILL_SERVICE_NAME) {
+ @Override
+ public TenantUserApi executeWithService(final OSGIKillbill service) {
+ return service.getTenantUserApi();
+ }
+ });
+ }
+
+ @Override
+ public UsageUserApi getUsageUserApi() {
+ return withServiceTracker(killbillTracker, new APICallback<UsageUserApi, OSGIKillbill>(KILLBILL_SERVICE_NAME) {
+ @Override
+ public UsageUserApi executeWithService(final OSGIKillbill service) {
+ return service.getUsageUserApi();
+ }
+ });
+ }
+
+ @Override
+ public AuditUserApi getAuditUserApi() {
+ return withServiceTracker(killbillTracker, new APICallback<AuditUserApi, OSGIKillbill>(KILLBILL_SERVICE_NAME) {
+ @Override
+ public AuditUserApi executeWithService(final OSGIKillbill service) {
+ return service.getAuditUserApi();
+ }
+ });
+ }
+
+ @Override
+ public CustomFieldUserApi getCustomFieldUserApi() {
+ return withServiceTracker(killbillTracker, new APICallback<CustomFieldUserApi, OSGIKillbill>(KILLBILL_SERVICE_NAME) {
+ @Override
+ public CustomFieldUserApi executeWithService(final OSGIKillbill service) {
+ return service.getCustomFieldUserApi();
+ }
+ });
+ }
+
+ @Override
+ public ExportUserApi getExportUserApi() {
+ return withServiceTracker(killbillTracker, new APICallback<ExportUserApi, OSGIKillbill>(KILLBILL_SERVICE_NAME) {
+ @Override
+ public ExportUserApi executeWithService(final OSGIKillbill service) {
+ return service.getExportUserApi();
+ }
+ });
+ }
+
+ @Override
+ public TagUserApi getTagUserApi() {
+ return withServiceTracker(killbillTracker, new APICallback<TagUserApi, OSGIKillbill>(KILLBILL_SERVICE_NAME) {
+ @Override
+ public TagUserApi executeWithService(final OSGIKillbill service) {
+ return service.getTagUserApi();
+ }
+ });
+ }
+
+ @Override
+ public ExternalBus getExternalBus() {
+ return withServiceTracker(killbillTracker, new APICallback<ExternalBus, OSGIKillbill>(KILLBILL_SERVICE_NAME) {
+ @Override
+ public ExternalBus executeWithService(final OSGIKillbill service) {
+ return service.getExternalBus();
+ }
+ });
+ }
+
+ @Override
+ public PluginConfigServiceApi getPluginConfigServiceApi() {
+ return withServiceTracker(killbillTracker, new APICallback<PluginConfigServiceApi, OSGIKillbill>(KILLBILL_SERVICE_NAME) {
+ @Override
+ public PluginConfigServiceApi executeWithService(final OSGIKillbill service) {
+ return service.getPluginConfigServiceApi();
+ }
+ });
+ }
+
+ @Override
+ public DataSource getDataSource() {
+ return withServiceTracker(killbillTracker, new APICallback<DataSource, OSGIKillbill>(KILLBILL_SERVICE_NAME) {
+ @Override
+ public DataSource executeWithService(final OSGIKillbill service) {
+ return service.getDataSource();
+ }
+ });
+ }
+
+ @Override
+ public void log(final int level, final String message) {
+ logInternal(level, message, null);
+ }
+
+ @Override
+ public void log(final int level, final String message, final Throwable exception) {
+ logInternal(level, message, exception);
+ }
+
+ @Override
+ public void log(final ServiceReference sr, final int level, final String message) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void log(final ServiceReference sr, final int level, final String message, final Throwable exception) {
+ throw new UnsupportedOperationException();
+ }
+
+
+ private void logInternal(final int level, final String message, @Nullable final Throwable t) {
+
+ withServiceTracker(logTracker, new APICallback<Void, LogService>(LOG_SERVICE_NAME) {
+ @Override
+ public Void executeWithService(final LogService service) {
+ if (t == null) {
+ service.log(level, message);
+ } else {
+ service.log(level, message, t);
+ }
+ return null;
+ }
+
+ protected Void executeWithNoService() {
+
+ if (level >= 2) {
+ System.out.println(message);
+ } else {
+ System.err.println(message);
+ }
+ if (t != null) {
+ t.printStackTrace(System.err);
+ }
+ return null;
+ }
+ });
+ }
+
+ private abstract class APICallback<API, T> {
+
+ private final String serviceName;
+
+ protected APICallback(final String serviceName) {
+ this.serviceName = serviceName;
+ }
+
+ public abstract API executeWithService(T service);
+
+ protected API executeWithNoService() {
+ throw new OSGIServiceNotAvailable(serviceName);
+ }
+ }
+
+ private <API, S, T> API withServiceTracker(ServiceTracker<S, T> t, APICallback<API, T> foo) {
+ T service = t.getService();
+ if (service == null) {
+ return foo.executeWithNoService();
+ }
+ return foo.executeWithService(service);
+ }
+}
diff --git a/osgi-bundles/libs/killbill/src/main/java/com/ning/killbill/osgi/libs/killbill/OSGIServiceNotAvailable.java b/osgi-bundles/libs/killbill/src/main/java/com/ning/killbill/osgi/libs/killbill/OSGIServiceNotAvailable.java
new file mode 100644
index 0000000..4a86243
--- /dev/null
+++ b/osgi-bundles/libs/killbill/src/main/java/com/ning/killbill/osgi/libs/killbill/OSGIServiceNotAvailable.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2010-2013 Ning, Inc.
+ *
+ * Ning licenses this file to you under the Apache License, version 2.0
+ * (the "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ning.killbill.osgi.libs.killbill;
+
+public class OSGIServiceNotAvailable extends RuntimeException {
+
+ private static final String FORMAT_SERVICE_NOT_AVAILABLE = "OSGI service %s is not available";
+
+ public OSGIServiceNotAvailable(String serviceName) {
+ super(toFormat(serviceName));
+ }
+
+ public OSGIServiceNotAvailable(String serviceName, Throwable cause) {
+ super(toFormat(serviceName), cause);
+ }
+
+ public OSGIServiceNotAvailable(Throwable cause) {
+ super(cause);
+ }
+
+ private static String toFormat(String serviceName) {
+ return String.format(FORMAT_SERVICE_NOT_AVAILABLE, serviceName);
+ }
+}
osgi-bundles/libs/pom.xml 3(+2 -1)
diff --git a/osgi-bundles/libs/pom.xml b/osgi-bundles/libs/pom.xml
index 7614509..219e436 100644
--- a/osgi-bundles/libs/pom.xml
+++ b/osgi-bundles/libs/pom.xml
@@ -19,7 +19,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.ning.billing</groupId>
- <artifactId>killbill</artifactId>
+ <artifactId>killbill-osgi-all-bundles</artifactId>
<version>0.1.56-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
@@ -27,5 +27,6 @@
<name>Killbill billing platform: OSGI library bundles</name>
<packaging>pom</packaging>
<modules>
+ <module>killbill</module>
</modules>
</project>
osgi-bundles/tests/beatrix/pom.xml 16(+14 -2)
diff --git a/osgi-bundles/tests/beatrix/pom.xml b/osgi-bundles/tests/beatrix/pom.xml
index 332a621..81f2fc0 100644
--- a/osgi-bundles/tests/beatrix/pom.xml
+++ b/osgi-bundles/tests/beatrix/pom.xml
@@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.ning.billing</groupId>
- <artifactId>killbill-osgi-bundles</artifactId>
+ <artifactId>killbill-osgi-test-bundles</artifactId>
<version>0.1.56-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
@@ -37,6 +37,18 @@
<artifactId>killbill-api</artifactId>
</dependency>
<dependency>
+ <groupId>com.ning.billing</groupId>
+ <artifactId>killbill-osgi-bundles-lib-killbill</artifactId>
+ </dependency>
+
+
+ <!--
+ <dependency>
+ <groupId>com.ning.billing</groupId>
+ <artifactId>killbill-osgi-all-bundles</artifactId>
+ </dependency>
+-->
+ <dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
</dependency>
@@ -92,7 +104,7 @@
<instructions>
<Bundle-Activator>com.ning.billing.osgi.bundles.test.TestActivator</Bundle-Activator>
<Import-Package>
- *;resolution:=optional
+ *;resolution:=optional,com.ning.billing.osgi.api
</Import-Package>
</instructions>
</configuration>
diff --git a/osgi-bundles/tests/beatrix/src/test/java/com/ning/billing/osgi/bundles/test/TestActivator.java b/osgi-bundles/tests/beatrix/src/test/java/com/ning/billing/osgi/bundles/test/TestActivator.java
index 06f1308..f7baff3 100644
--- a/osgi-bundles/tests/beatrix/src/test/java/com/ning/billing/osgi/bundles/test/TestActivator.java
+++ b/osgi-bundles/tests/beatrix/src/test/java/com/ning/billing/osgi/bundles/test/TestActivator.java
@@ -22,8 +22,6 @@ import java.util.UUID;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-import org.osgi.framework.ServiceRegistration;
import org.osgi.service.log.LogService;
import org.skife.jdbi.v2.DBI;
import org.skife.jdbi.v2.IDBI;
@@ -33,31 +31,26 @@ import com.ning.billing.account.api.AccountApiException;
import com.ning.billing.beatrix.bus.api.ExtBusEvent;
import com.ning.billing.beatrix.bus.api.ExtBusEventType;
import com.ning.billing.beatrix.bus.api.ExternalBus;
-import com.ning.billing.osgi.api.OSGIKillbill;
import com.ning.billing.osgi.api.OSGIPluginProperties;
import com.ning.billing.osgi.bundles.test.dao.TestDao;
import com.ning.billing.payment.plugin.api.PaymentPluginApi;
import com.ning.billing.util.callcontext.TenantContext;
+import com.ning.killbill.osgi.libs.killbill.OSGIKillbillRegistrar;
+import com.ning.killbill.osgi.libs.killbill.OSGIKillbillTracker;
import com.google.common.eventbus.Subscribe;
/**
* Test class used by Beatrix OSGI test to verify that:
- * - "test" bundle is started
- * - test bundle is able to make API call
- * - test bundle is able to register a fake PaymentApi service
- * - test bundle can use the DataSource from Killbill and write on disk
+ * - "test" bundle is started
+ * - test bundle is able to make API call
+ * - test bundle is able to register a fake PaymentApi service
+ * - test bundle can use the DataSource from Killbill and write on disk
*/
public class TestActivator implements BundleActivator {
- private OSGIKillbill osgiKillbill;
- private volatile ServiceReference<OSGIKillbill> osgiKillbillReference;
-
- private final Logger logger = new Logger();
-
- private volatile boolean isRunning;
- private volatile ServiceRegistration paymentInfoPluginRegistration;
-
+ private OSGIKillbillTracker kb;
+ private OSGIKillbillRegistrar registrar;
private TestDao testDao;
@Override
@@ -66,10 +59,11 @@ public class TestActivator implements BundleActivator {
final String bundleName = context.getBundle().getSymbolicName();
System.out.println("TestActivator starting bundle = " + bundleName);
- fetchOSGIKIllbill(context);
- logger.start(context);
+ kb = new OSGIKillbillTracker(context);
- final IDBI dbi = new DBI(osgiKillbill.getDataSource());
+ registrar = new OSGIKillbillRegistrar();
+
+ final IDBI dbi = new DBI(kb.getDataSource());
testDao = new TestDao(dbi);
registerPaymentApi(context, testDao);
@@ -78,24 +72,22 @@ public class TestActivator implements BundleActivator {
testDao.createTable();
testDao.insertStarted();
-
- this.isRunning = true;
}
@Override
public void stop(final BundleContext context) {
- this.isRunning = false;
- releaseOSGIKIllbill(context);
- this.osgiKillbill = null;
- unregisterPlaymentPluginApi(context);
- logger.close();
+ if (kb != null) {
+ kb.close();
+ this.kb = null;
+ }
+ registrar.unregisterAll();
System.out.println("Good bye world from TestActivator!");
}
@Subscribe
public void handleKillbillEvent(final ExtBusEvent killbillEvent) {
- logger.log(LogService.LOG_INFO, "Received external event " + killbillEvent.toString());
+ kb.log(LogService.LOG_INFO, "Received external event " + killbillEvent.toString());
// Only looking at account creation
if (killbillEvent.getEventType() != ExtBusEventType.ACCOUNT_CREATION) {
@@ -111,18 +103,18 @@ public class TestActivator implements BundleActivator {
try {
- Account account = osgiKillbill.getAccountUserApi().getAccountById(killbillEvent.getAccountId(), tenantContext);
+ Account account = kb.getAccountUserApi().getAccountById(killbillEvent.getAccountId(), tenantContext);
testDao.insertAccountExternalKey(account.getExternalKey());
} catch (AccountApiException e) {
- logger.log(LogService.LOG_ERROR, e.getMessage());
+ kb.log(LogService.LOG_ERROR, e.getMessage());
}
}
private void registerForKillbillEvents(final BundleContext context) {
try {
- final ExternalBus externalBus = osgiKillbill.getExternalBus();
+ final ExternalBus externalBus = kb.getExternalBus();
externalBus.register(this);
} catch (Exception e) {
System.err.println("Error in TestActivator: " + e.getLocalizedMessage());
@@ -130,34 +122,10 @@ public class TestActivator implements BundleActivator {
}
}
- private void fetchOSGIKIllbill(final BundleContext context) {
- this.osgiKillbillReference = (ServiceReference<OSGIKillbill>) context.getServiceReference(OSGIKillbill.class.getName());
- try {
- this.osgiKillbill = context.getService(osgiKillbillReference);
- } catch (Exception e) {
- System.err.println("Error in TestActivator: " + e.getLocalizedMessage());
- }
- }
-
- private void releaseOSGIKIllbill(final BundleContext context) {
- if (osgiKillbillReference != null) {
- context.ungetService(osgiKillbillReference);
- }
- }
-
private void registerPaymentApi(final BundleContext context, final TestDao dao) {
final Dictionary props = new Hashtable();
props.put(OSGIPluginProperties.PLUGIN_NAME_PROP, "test");
-
- this.paymentInfoPluginRegistration = context.registerService(PaymentPluginApi.class.getName(),
- new TestPaymentPluginApi("test", dao), props);
- }
-
- private void unregisterPlaymentPluginApi(final BundleContext context) {
- if (paymentInfoPluginRegistration != null) {
- paymentInfoPluginRegistration.unregister();
- paymentInfoPluginRegistration = null;
- }
+ registrar.registerService(context, PaymentPluginApi.class, new TestPaymentPluginApi("test", dao), props);
}
}
osgi-bundles/tests/pom.xml 2(+1 -1)
diff --git a/osgi-bundles/tests/pom.xml b/osgi-bundles/tests/pom.xml
index 3fd6aa4..a9fb702 100644
--- a/osgi-bundles/tests/pom.xml
+++ b/osgi-bundles/tests/pom.xml
@@ -19,7 +19,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.ning.billing</groupId>
- <artifactId>killbill</artifactId>
+ <artifactId>killbill-osgi-all-bundles</artifactId>
<version>0.1.56-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
pom.xml 4(+2 -2)
diff --git a/pom.xml b/pom.xml
index c9d75f8..5eb26b9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -261,12 +261,12 @@
</dependency>
<dependency>
<groupId>com.ning.billing</groupId>
- <artifactId>killbill-osgi-bundles</artifactId>
+ <artifactId>killbill-osgi-all-bundles</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.ning.billing</groupId>
- <artifactId>killbill-osgi-bundles-hello</artifactId>
+ <artifactId>killbill-osgi-bundles-lib-killbill</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>