tenant) throws JsonProcessingException {
50 | return check(healthcheck, tenant.orElse(null), null);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/org/killbill/billing/plugin/helloworld/HelloWorldInvoicePluginApi.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020-2022 Equinix, Inc
3 | * Copyright 2014-2022 The Billing Project, LLC
4 | *
5 | * The Billing Project licenses this file to you under the Apache License, version 2.0
6 | * (the "License"); you may not use this file except in compliance with the
7 | * License. You may obtain a copy of the License at:
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 | * License for the specific language governing permissions and limitations
15 | * under the License.
16 | */
17 |
18 | package org.killbill.billing.plugin.helloworld;
19 |
20 | import java.math.BigDecimal;
21 | import java.util.HashSet;
22 | import java.util.LinkedList;
23 | import java.util.List;
24 | import java.util.Set;
25 | import java.util.UUID;
26 |
27 | import org.killbill.billing.account.api.Account;
28 | import org.killbill.billing.invoice.api.Invoice;
29 | import org.killbill.billing.invoice.api.InvoiceItem;
30 | import org.killbill.billing.invoice.api.InvoiceItemType;
31 | import org.killbill.billing.invoice.plugin.api.AdditionalItemsResult;
32 | import org.killbill.billing.invoice.plugin.api.InvoiceContext;
33 | import org.killbill.billing.notification.plugin.api.ExtBusEvent;
34 | import org.killbill.billing.osgi.libs.killbill.OSGIConfigPropertiesService;
35 | import org.killbill.billing.osgi.libs.killbill.OSGIKillbillAPI;
36 | import org.killbill.billing.osgi.libs.killbill.OSGIKillbillEventDispatcher.OSGIKillbillEventHandler;
37 | import org.killbill.billing.payment.api.PluginProperty;
38 | import org.killbill.billing.plugin.api.invoice.PluginInvoiceItem;
39 | import org.killbill.billing.plugin.api.invoice.PluginInvoicePluginApi;
40 | import org.killbill.billing.util.callcontext.TenantContext;
41 | import org.killbill.clock.Clock;
42 |
43 | class HelloWorldInvoicePluginApi extends PluginInvoicePluginApi implements OSGIKillbillEventHandler {
44 |
45 | public HelloWorldInvoicePluginApi(final OSGIKillbillAPI killbillAPI, final OSGIConfigPropertiesService configProperties,
46 | final Clock clock) {
47 | super(killbillAPI, configProperties, clock);
48 | }
49 |
50 | /**
51 | * Returns additional invoice items to be added to invoice
52 | *
53 | * This method produces two types of invoice items a. Tax Item on Invoice Item
54 | * b. Adjustment Item on only the very first Historical Invoice Tax Item
55 | * automatically ( just for Demo purpose )
56 | *
57 | * @param newInvoice The invoice that is being created.
58 | * @param dryRun Whether it is dryRun or not
59 | * @param properties Any user-specified plugin properties, coming straight out
60 | * of the API request that has triggered this code to run.
61 | * @param callCtx The context in which this code is running.
62 | * @return A new immutable list of new tax items, or adjustments on existing tax
63 | * items.
64 | */
65 | @Override
66 | public AdditionalItemsResult getAdditionalInvoiceItems(final Invoice newInvoice, final boolean dryRun,
67 | final Iterable properties, final InvoiceContext invoiceContext) {
68 |
69 | final UUID accountId = newInvoice.getAccountId();
70 | final Account account = getAccount(accountId, invoiceContext);
71 | final Set allInvoices = getAllInvoicesOfAccount(account, newInvoice, invoiceContext);
72 | final List additionalItems = new LinkedList();
73 |
74 | // Creating tax item for first Item of new Invoice
75 | final List newInvoiceItems = newInvoice.getInvoiceItems();
76 | final InvoiceItem newInvoiceItem = newInvoiceItems.get(0);
77 | BigDecimal charge = new BigDecimal("80");
78 | final InvoiceItem taxItem = PluginInvoiceItem.createTaxItem(newInvoiceItem, newInvoiceItem.getInvoiceId(),
79 | newInvoice.getInvoiceDate(), null, charge, "Tax Item");
80 | additionalItems.add(taxItem);
81 |
82 | // Creating External Charge for first Item of new Invoice
83 | final InvoiceItem externalItem = PluginInvoiceItem.create(newInvoiceItem, newInvoiceItem.getInvoiceId(),
84 | newInvoice.getInvoiceDate(), null, charge, "External Item", InvoiceItemType.EXTERNAL_CHARGE);
85 | additionalItems.add(externalItem);
86 |
87 | // Adding adjustment invoice item to the first historical invoice, if it does not have the adjustment item
88 | for (final Invoice invoice : allInvoices) {
89 | if (!invoice.getId().equals(newInvoice.getId())) {
90 | final List invoiceItems = invoice.getInvoiceItems();
91 | // Check for if any adjustment item exists for Historical Invoice
92 | if (checkforAdjustmentItem(invoiceItems)) {
93 | break;
94 | }
95 | for (final InvoiceItem item : invoiceItems) {
96 | charge = new BigDecimal("-30");
97 | final InvoiceItem adjItem = PluginInvoiceItem.createAdjustmentItem(item, item.getInvoiceId(),
98 | newInvoice.getInvoiceDate(), newInvoice.getInvoiceDate(), charge, "Adjustment Item");
99 | additionalItems.add(adjItem);
100 | break;
101 | }
102 | break;
103 | }
104 | }
105 |
106 | return new AdditionalItemsResult() {
107 | @Override
108 | public List getAdditionalItems() {
109 | return additionalItems;
110 | }
111 |
112 | @Override
113 | public Iterable getAdjustedPluginProperties() {
114 | return null;
115 | }
116 | };
117 | }
118 |
119 | /**
120 | * This method returns all invoices of account
121 | *
122 | * @param account The account to consider.
123 | * @param newInvoice New Invoice Item to be added to existing invoices of the
124 | * account
125 | * @param tenantCtx
126 | * @return All invoices of account
127 | */
128 | private Set getAllInvoicesOfAccount(final Account account, final Invoice newInvoice, final TenantContext tenantCtx) {
129 | final Set invoices = new HashSet();
130 | invoices.addAll(getInvoicesByAccountId(account.getId(), tenantCtx));
131 | invoices.add(newInvoice);
132 | return invoices;
133 | }
134 |
135 | /**
136 | * Check whether adjustment item is already present in invoice Item of Invoice
137 | *
138 | * @param invoiceItems
139 | * @return
140 | */
141 | private boolean checkforAdjustmentItem(final List invoiceItems) {
142 | boolean adjustmentItemPresent = false;
143 | for (final InvoiceItem invoiceItem : invoiceItems) {
144 | if (invoiceItem.getInvoiceItemType().equals(InvoiceItemType.ITEM_ADJ)) {
145 | adjustmentItemPresent = true;
146 | break;
147 | }
148 | }
149 | return adjustmentItemPresent;
150 | }
151 |
152 | protected boolean isTaxItem(final InvoiceItem invoiceItem) {
153 | return InvoiceItemType.TAX.equals(invoiceItem.getInvoiceItemType());
154 | }
155 |
156 | @Override
157 | public void handleKillbillEvent(final ExtBusEvent killbillEvent) {
158 | }
159 |
160 | }
161 |
--------------------------------------------------------------------------------
/src/main/java/org/killbill/billing/plugin/helloworld/HelloWorldListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010-2014 Ning, Inc.
3 | * Copyright 2014-2020 Groupon, Inc
4 | * Copyright 2020-2020 Equinix, Inc
5 | * Copyright 2014-2020 The Billing Project, LLC
6 | *
7 | * The Billing Project licenses this file to you under the Apache License, version 2.0
8 | * (the "License"); you may not use this file except in compliance with the
9 | * License. You may obtain a copy of the License at:
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16 | * License for the specific language governing permissions and limitations
17 | * under the License.
18 | */
19 |
20 | package org.killbill.billing.plugin.helloworld;
21 |
22 | import java.util.List;
23 | import java.util.Locale;
24 | import java.util.Properties;
25 |
26 | import org.joda.time.LocalDate;
27 | import org.killbill.billing.account.api.Account;
28 | import org.killbill.billing.account.api.AccountApiException;
29 | import org.killbill.billing.invoice.api.Invoice;
30 | import org.killbill.billing.invoice.api.InvoiceItem;
31 | import org.killbill.billing.invoice.api.formatters.InvoiceFormatter;
32 | import org.killbill.billing.invoice.api.formatters.InvoiceItemFormatter;
33 | import org.killbill.billing.invoice.plugin.api.InvoiceFormatterFactory;
34 | import org.killbill.billing.notification.plugin.api.ExtBusEvent;
35 | import org.killbill.billing.osgi.libs.killbill.OSGIKillbillAPI;
36 | import org.killbill.billing.osgi.libs.killbill.OSGIKillbillEventDispatcher;
37 | import org.killbill.billing.plugin.api.PluginTenantContext;
38 | import org.killbill.billing.util.callcontext.TenantContext;
39 | import org.osgi.util.tracker.ServiceTracker;
40 | import org.slf4j.Logger;
41 | import org.slf4j.LoggerFactory;
42 |
43 | public class HelloWorldListener implements OSGIKillbillEventDispatcher.OSGIKillbillEventHandler {
44 |
45 | private static final Logger logger = LoggerFactory.getLogger(HelloWorldListener.class);
46 |
47 | private final OSGIKillbillAPI osgiKillbillAPI;
48 |
49 | private final ServiceTracker invoiceFormatterTracker;
50 |
51 | private final Properties configProperties;
52 |
53 | public HelloWorldListener(final OSGIKillbillAPI killbillAPI, final ServiceTracker invoiceFormatterTracker, Properties configProperties) {
54 | this.osgiKillbillAPI = killbillAPI;
55 | this.invoiceFormatterTracker = invoiceFormatterTracker;
56 | this.configProperties = configProperties;
57 | }
58 |
59 | private static final String defaultLocale = "en_US";
60 |
61 | @Override
62 | public void handleKillbillEvent(final ExtBusEvent killbillEvent) {
63 | logger.info("Received event {} for object id {} of type {}",
64 | killbillEvent.getEventType(),
65 | killbillEvent.getObjectId(),
66 | killbillEvent.getObjectType());
67 |
68 | final TenantContext context = new PluginTenantContext(killbillEvent.getAccountId(), killbillEvent.getTenantId());
69 | switch (killbillEvent.getEventType()) {
70 | //
71 | // Handle ACCOUNT_CREATION and ACCOUNT_CHANGE only for demo purpose and just print the account
72 | //
73 | case ACCOUNT_CREATION:
74 | case ACCOUNT_CHANGE:
75 | try {
76 | final Account account = osgiKillbillAPI.getAccountUserApi().getAccountById(killbillEvent.getAccountId(), context);
77 | logger.info("Account information: " + account);
78 | } catch (final AccountApiException e) {
79 | logger.warn("Unable to find account", e);
80 | }
81 | break;
82 | case INVOICE_CREATION:
83 |
84 | final Account account;
85 | try {
86 | account = osgiKillbillAPI.getAccountUserApi().getAccountById(killbillEvent.getAccountId(), context);
87 | } catch (AccountApiException e) {
88 | throw new RuntimeException(e);
89 | }
90 | final List invoices = osgiKillbillAPI.getInvoiceUserApi().getInvoicesByAccount(killbillEvent.getAccountId(), false, false, true, context);
91 | logger.info("Invoices in hello-world-plugin {}: ",invoices.size());
92 |
93 | final String invoiceFormatterPluginName = configProperties.getProperty("org.killbill.template.invoiceFormatterFactoryPluginName");
94 | if(invoiceFormatterPluginName == null || invoiceFormatterPluginName.isEmpty()){
95 | logger.info("Invoice formatter plugin not configured. set the org.killbill.template.invoiceFormatterFactoryPluginName property to configure it");
96 | return;
97 | }
98 |
99 | final InvoiceFormatterFactory formatterFactory = (invoiceFormatterTracker != null ? invoiceFormatterTracker.getService() : null);
100 | Invoice invoice = invoices.get(0); //For demo purpose, we are only retrieving the formattedEndDate for the first invoice
101 | //TODO Using null for parameters like catalogBundlePath,bundle, defaultBundle, etc. Update this to use correct values if possible or verify that using null values has no adverse effect
102 |
103 | InvoiceFormatter invoiceFormatter = formatterFactory.createInvoiceFormatter(defaultLocale, null, invoice, Locale.forLanguageTag(account.getLocale()), osgiKillbillAPI.getCurrencyConversionApi(), null, null);
104 |
105 | List items = invoiceFormatter.getInvoiceItems();
106 | logger.info("hello-world-plugin got items:{}",items.size());
107 | for(InvoiceItem item:items) {
108 | final InvoiceItemFormatter invoiceItemFormatter = (InvoiceItemFormatter)item;
109 | final String formattedEndDate = invoiceItemFormatter.getFormattedEndDate();
110 | logger.info("hello-world-plugin formattedEndDate:{}",formattedEndDate);
111 | }
112 | // Nothing
113 | default:
114 | break;
115 |
116 | }
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/src/main/java/org/killbill/billing/plugin/helloworld/HelloWorldPaymentPluginApi.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010-2014 Ning, Inc.
3 | * Copyright 2014-2020 Groupon, Inc
4 | * Copyright 2020-2020 Equinix, Inc
5 | * Copyright 2014-2020 The Billing Project, LLC
6 | *
7 | * The Billing Project licenses this file to you under the Apache License, version 2.0
8 | * (the "License"); you may not use this file except in compliance with the
9 | * License. You may obtain a copy of the License at:
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16 | * License for the specific language governing permissions and limitations
17 | * under the License.
18 | */
19 |
20 | package org.killbill.billing.plugin.helloworld;
21 |
22 | import java.math.BigDecimal;
23 | import java.util.List;
24 | import java.util.UUID;
25 |
26 | import org.killbill.billing.catalog.api.Currency;
27 | import org.killbill.billing.payment.api.PaymentMethodPlugin;
28 | import org.killbill.billing.payment.api.PluginProperty;
29 | import org.killbill.billing.payment.plugin.api.GatewayNotification;
30 | import org.killbill.billing.payment.plugin.api.HostedPaymentPageFormDescriptor;
31 | import org.killbill.billing.payment.plugin.api.PaymentMethodInfoPlugin;
32 | import org.killbill.billing.payment.plugin.api.PaymentPluginApi;
33 | import org.killbill.billing.payment.plugin.api.PaymentPluginApiException;
34 | import org.killbill.billing.payment.plugin.api.PaymentTransactionInfoPlugin;
35 | import org.killbill.billing.util.callcontext.CallContext;
36 | import org.killbill.billing.util.callcontext.TenantContext;
37 | import org.killbill.billing.util.entity.Pagination;
38 |
39 | //
40 | // A 'real' payment plugin would of course implement this interface.
41 | //
42 | public class HelloWorldPaymentPluginApi implements PaymentPluginApi {
43 |
44 | @Override
45 | public PaymentTransactionInfoPlugin authorizePayment(final UUID kbAccountId, final UUID kbPaymentId, final UUID kbTransactionId, final UUID kbPaymentMethodId, final BigDecimal amount, final Currency currency, final Iterable properties, final CallContext context) throws PaymentPluginApiException {
46 | return null;
47 | }
48 |
49 | @Override
50 | public PaymentTransactionInfoPlugin capturePayment(final UUID kbAccountId, final UUID kbPaymentId, final UUID kbTransactionId, final UUID kbPaymentMethodId, final BigDecimal amount, final Currency currency, final Iterable properties, final CallContext context) throws PaymentPluginApiException {
51 | return null;
52 | }
53 |
54 | @Override
55 | public PaymentTransactionInfoPlugin purchasePayment(final UUID kbAccountId, final UUID kbPaymentId, final UUID kbTransactionId, final UUID kbPaymentMethodId, final BigDecimal amount, final Currency currency, final Iterable properties, final CallContext context) throws PaymentPluginApiException {
56 | return null;
57 | }
58 |
59 | @Override
60 | public PaymentTransactionInfoPlugin voidPayment(final UUID kbAccountId, final UUID kbPaymentId, final UUID kbTransactionId, final UUID kbPaymentMethodId, final Iterable properties, final CallContext context) throws PaymentPluginApiException {
61 | return null;
62 | }
63 |
64 | @Override
65 | public PaymentTransactionInfoPlugin creditPayment(final UUID kbAccountId, final UUID kbPaymentId, final UUID kbTransactionId, final UUID kbPaymentMethodId, final BigDecimal amount, final Currency currency, final Iterable properties, final CallContext context) throws PaymentPluginApiException {
66 | return null;
67 | }
68 |
69 | @Override
70 | public PaymentTransactionInfoPlugin refundPayment(final UUID kbAccountId, final UUID kbPaymentId, final UUID kbTransactionId, final UUID kbPaymentMethodId, final BigDecimal amount, final Currency currency, final Iterable properties, final CallContext context) throws PaymentPluginApiException {
71 | return null;
72 | }
73 |
74 | @Override
75 | public List getPaymentInfo(final UUID kbAccountId, final UUID kbPaymentId, final Iterable properties, final TenantContext context) throws PaymentPluginApiException {
76 | return null;
77 | }
78 |
79 | @Override
80 | public Pagination searchPayments(final String searchKey, final Long offset, final Long limit, final Iterable properties, final TenantContext context) throws PaymentPluginApiException {
81 | return null;
82 | }
83 |
84 | @Override
85 | public void addPaymentMethod(final UUID kbAccountId, final UUID kbPaymentMethodId, final PaymentMethodPlugin paymentMethodProps, final boolean setDefault, final Iterable properties, final CallContext context) throws PaymentPluginApiException {
86 |
87 | }
88 |
89 | @Override
90 | public void deletePaymentMethod(final UUID kbAccountId, final UUID kbPaymentMethodId, final Iterable properties, final CallContext context) throws PaymentPluginApiException {
91 |
92 | }
93 |
94 | @Override
95 | public PaymentMethodPlugin getPaymentMethodDetail(final UUID kbAccountId, final UUID kbPaymentMethodId, final Iterable properties, final TenantContext context) throws PaymentPluginApiException {
96 | return null;
97 | }
98 |
99 | @Override
100 | public void setDefaultPaymentMethod(final UUID kbAccountId, final UUID kbPaymentMethodId, final Iterable properties, final CallContext context) throws PaymentPluginApiException {
101 |
102 | }
103 |
104 | @Override
105 | public List getPaymentMethods(final UUID kbAccountId, final boolean refreshFromGateway, final Iterable properties, final CallContext context) throws PaymentPluginApiException {
106 | return null;
107 | }
108 |
109 | @Override
110 | public Pagination searchPaymentMethods(final String searchKey, final Long offset, final Long limit, final Iterable properties, final TenantContext context) throws PaymentPluginApiException {
111 | return null;
112 | }
113 |
114 | @Override
115 | public void resetPaymentMethods(final UUID kbAccountId, final List paymentMethods, final Iterable properties, final CallContext context) throws PaymentPluginApiException {
116 |
117 | }
118 |
119 | @Override
120 | public HostedPaymentPageFormDescriptor buildFormDescriptor(final UUID kbAccountId, final Iterable customFields, final Iterable properties, final CallContext context) throws PaymentPluginApiException {
121 | return null;
122 | }
123 |
124 | @Override
125 | public GatewayNotification processNotification(final String notification, final Iterable properties, final CallContext context) throws PaymentPluginApiException {
126 | return null;
127 | }
128 | }
129 |
--------------------------------------------------------------------------------
/src/main/java/org/killbill/billing/plugin/helloworld/HelloWorldServlet.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010-2014 Ning, Inc.
3 | * Copyright 2014-2020 Groupon, Inc
4 | * Copyright 2020-2020 Equinix, Inc
5 | * Copyright 2014-2020 The Billing Project, LLC
6 | *
7 | * The Billing Project licenses this file to you under the Apache License, version 2.0
8 | * (the "License"); you may not use this file except in compliance with the
9 | * License. You may obtain a copy of the License at:
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16 | * License for the specific language governing permissions and limitations
17 | * under the License.
18 | */
19 |
20 | package org.killbill.billing.plugin.helloworld;
21 |
22 | import java.util.Optional;
23 | import javax.inject.Named;
24 | import javax.inject.Singleton;
25 |
26 | import org.jooby.mvc.GET;
27 | import org.jooby.mvc.Local;
28 | import org.jooby.mvc.Path;
29 | import org.killbill.billing.tenant.api.Tenant;
30 | import org.slf4j.Logger;
31 | import org.slf4j.LoggerFactory;
32 |
33 |
34 | @Singleton
35 | @Path("/")
36 | public class HelloWorldServlet {
37 |
38 | private static final Logger logger = LoggerFactory.getLogger(HelloWorldServlet.class);
39 |
40 | public HelloWorldServlet() {
41 | }
42 |
43 | /**
44 | * Kill Bill automatically injects Tenant object in this method when this end point is accessed with the X-Killbill-ApiKey and X-Killbill-ApiSecret headers
45 | * @param tenant
46 | */
47 | @GET
48 | public void hello(@Local @Named("killbill_tenant") final Optional tenant) {
49 | // Find me on http://127.0.0.1:8080/plugins/hello-world-plugin
50 | logger.info("Hello world");
51 | if(tenant != null && tenant.isPresent() ) {
52 | logger.info("tenant is available");
53 | Tenant t1 = tenant.get();
54 | logger.info("tenant id:"+t1.getId());
55 | }
56 | else {
57 | logger.info("tenant is not available");
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/org/killbill/billing/plugin/helloworld/MetricsGeneratorExample.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020-2022 Equinix, Inc
3 | * Copyright 2014-2022 The Billing Project, LLC
4 | *
5 | * The Billing Project licenses this file to you under the Apache License, version 2.0
6 | * (the "License"); you may not use this file except in compliance with the
7 | * License. You may obtain a copy of the License at:
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 | * License for the specific language governing permissions and limitations
15 | * under the License.
16 | */
17 |
18 | package org.killbill.billing.plugin.helloworld;
19 |
20 | import org.killbill.billing.osgi.libs.killbill.OSGIMetricRegistry;
21 | import org.killbill.billing.osgi.libs.killbill.OSGIServiceNotAvailable;
22 | import org.slf4j.Logger;
23 | import org.slf4j.LoggerFactory;
24 |
25 | public class MetricsGeneratorExample {
26 |
27 | private static final Logger logger = LoggerFactory.getLogger(MetricsGeneratorExample.class);
28 |
29 | private final Thread thread;
30 |
31 | private volatile boolean stopMetrics;
32 |
33 | public MetricsGeneratorExample(final OSGIMetricRegistry metricRegistry) {
34 | this.thread = new Thread(new Runnable() {
35 | public void run() {
36 | while (!stopMetrics) {
37 | try {
38 | Thread.sleep(1000L);
39 | } catch (final InterruptedException ignored) {
40 | Thread.currentThread().interrupt();
41 | logger.info("MetricsGenerator shutting down");
42 | break;
43 | }
44 |
45 | try {
46 | metricRegistry.getMetricRegistry().counter("hello_counter").inc(1);
47 | } catch (final OSGIServiceNotAvailable ignored) {
48 | // No MetricRegistry available
49 | logger.warn("No MetricRegistry available");
50 | }
51 | }
52 | }
53 | });
54 | }
55 |
56 | public void start() {
57 | thread.start();
58 | }
59 |
60 | public void stop() {
61 | stopMetrics = true;
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/test/resources/log4jdbc.log4j2.properties:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright 2020-2020 Equinix, Inc
3 | # Copyright 2020-2020 The Billing Project, LLC
4 | #
5 | # The Billing Project licenses this file to you under the Apache License, version 2.0
6 | # (the "License"); you may not use this file except in compliance with the
7 | # License. You may obtain a copy of the License at:
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 | # License for the specific language governing permissions and limitations
15 | # under the License.
16 | #
17 | # Configure the SpyLogDelegator to use SLF4J. By default, the library expects Log4j2 (see SpyLogFactory#loadSpyLogDelegator),
18 | # which isn't in our classpath. Creating a new instance of DriverSpy would then fail in ServiceLoader.LazyIterator#nextService,
19 | # which would cause the loop in DriverManager#loadInitialDrivers to bail early (in which case some drivers might not be registered).
20 | log4jdbc.spylogdelegator.name=net.sf.log4jdbc.log.slf4j.Slf4jSpyLogDelegator
--------------------------------------------------------------------------------