killbill-aplcache
Changes
profiles/killbill/src/main/java/org/killbill/billing/server/modules/KillbillServerModule.java 2(+2 -0)
Details
diff --git a/profiles/killbill/src/main/java/org/killbill/billing/server/modules/KillbillServerModule.java b/profiles/killbill/src/main/java/org/killbill/billing/server/modules/KillbillServerModule.java
index bb85d35..a89a560 100644
--- a/profiles/killbill/src/main/java/org/killbill/billing/server/modules/KillbillServerModule.java
+++ b/profiles/killbill/src/main/java/org/killbill/billing/server/modules/KillbillServerModule.java
@@ -68,6 +68,7 @@ import org.killbill.billing.util.dao.RecordIdIdMappingsMapper;
import org.killbill.billing.util.email.EmailModule;
import org.killbill.billing.util.email.templates.TemplateModule;
import org.killbill.billing.util.glue.AuditModule;
+import org.killbill.billing.util.glue.BroadcastModule;
import org.killbill.billing.util.glue.CacheModule;
import org.killbill.billing.util.glue.CallContextModule;
import org.killbill.billing.util.glue.ClockModule;
@@ -140,6 +141,7 @@ public class KillbillServerModule extends KillbillPlatformModule {
protected void installKillbillModules() {
install(new AuditModule(configSource));
install(new InfoModule(configSource));
+ install(new BroadcastModule(configSource));
install(new BeatrixModule(configSource));
install(new CacheModule(configSource));
install(new CallContextModule(configSource));
diff --git a/profiles/killpay/src/main/java/org/killbill/billing/server/modules/KillpayServerModule.java b/profiles/killpay/src/main/java/org/killbill/billing/server/modules/KillpayServerModule.java
index 7360228..d2a464b 100644
--- a/profiles/killpay/src/main/java/org/killbill/billing/server/modules/KillpayServerModule.java
+++ b/profiles/killpay/src/main/java/org/killbill/billing/server/modules/KillpayServerModule.java
@@ -51,6 +51,7 @@ import org.killbill.billing.usage.glue.UsageModule;
import org.killbill.billing.util.email.EmailModule;
import org.killbill.billing.util.email.templates.TemplateModule;
import org.killbill.billing.util.glue.AuditModule;
+import org.killbill.billing.util.glue.BroadcastModule;
import org.killbill.billing.util.glue.CacheModule;
import org.killbill.billing.util.glue.CallContextModule;
import org.killbill.billing.util.glue.CustomFieldModule;
@@ -74,6 +75,7 @@ public class KillpayServerModule extends KillbillServerModule {
protected void installKillbillModules() {
install(new AuditModule(configSource));
install(new InfoModule(configSource));
+ install(new BroadcastModule(configSource));
install(new BeatrixModule(configSource));
install(new CacheModule(configSource));
install(new CallContextModule(configSource));
diff --git a/util/src/main/java/org/killbill/billing/util/broadcast/BroadcastService.java b/util/src/main/java/org/killbill/billing/util/broadcast/BroadcastService.java
new file mode 100644
index 0000000..9508483
--- /dev/null
+++ b/util/src/main/java/org/killbill/billing/util/broadcast/BroadcastService.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2014-2015 Groupon, Inc
+ * Copyright 2014-2015 The Billing Project, LLC
+ *
+ * The Billing Project 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 org.killbill.billing.util.broadcast;
+
+import org.killbill.billing.platform.api.KillbillService;
+
+public interface BroadcastService extends KillbillService {
+
+}
diff --git a/util/src/main/java/org/killbill/billing/util/broadcast/dao/BroadcastDao.java b/util/src/main/java/org/killbill/billing/util/broadcast/dao/BroadcastDao.java
new file mode 100644
index 0000000..fd8130d
--- /dev/null
+++ b/util/src/main/java/org/killbill/billing/util/broadcast/dao/BroadcastDao.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2014-2015 Groupon, Inc
+ * Copyright 2014-2015 The Billing Project, LLC
+ *
+ * The Billing Project 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 org.killbill.billing.util.broadcast.dao;
+
+import java.util.List;
+
+public interface BroadcastDao {
+
+ public void create(final BroadcastModelDao broadcastModelDao);
+
+ public List<BroadcastModelDao> getLatestEntriesFrom(final Long recordId);
+
+ public BroadcastModelDao getLatestEntry();
+}
diff --git a/util/src/main/java/org/killbill/billing/util/broadcast/dao/BroadcastModelDao.java b/util/src/main/java/org/killbill/billing/util/broadcast/dao/BroadcastModelDao.java
new file mode 100644
index 0000000..14938ea
--- /dev/null
+++ b/util/src/main/java/org/killbill/billing/util/broadcast/dao/BroadcastModelDao.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2014-2015 Groupon, Inc
+ * Copyright 2014-2015 The Billing Project, LLC
+ *
+ * The Billing Project 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 org.killbill.billing.util.broadcast.dao;
+
+import org.joda.time.DateTime;
+
+public class BroadcastModelDao {
+
+ private Long recordId;
+ private String serviceName;
+ private String type;
+ private String event;
+ private DateTime createdDate;
+ private String createdBy;
+
+ public BroadcastModelDao() {
+ }
+
+ public BroadcastModelDao(final String serviceName, final String type, final String event, final DateTime createdDate, final String createdBy) {
+ this.recordId = -1L;
+ this.serviceName = serviceName;
+ this.type = type;
+ this.event = event;
+ this.createdDate = createdDate;
+ this.createdBy = createdBy;
+ }
+
+ public Long getRecordId() {
+ return recordId;
+ }
+
+ public String getServiceName() {
+ return serviceName;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public String getEvent() {
+ return event;
+ }
+
+ public DateTime getCreatedDate() {
+ return createdDate;
+ }
+
+ public String getCreatedBy() {
+ return createdBy;
+ }
+}
diff --git a/util/src/main/java/org/killbill/billing/util/broadcast/dao/BroadcastSqlDao.java b/util/src/main/java/org/killbill/billing/util/broadcast/dao/BroadcastSqlDao.java
new file mode 100644
index 0000000..9efa110
--- /dev/null
+++ b/util/src/main/java/org/killbill/billing/util/broadcast/dao/BroadcastSqlDao.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2014-2015 Groupon, Inc
+ * Copyright 2014-2015 The Billing Project, LLC
+ *
+ * The Billing Project 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 org.killbill.billing.util.broadcast.dao;
+
+import java.util.List;
+
+import org.killbill.billing.util.entity.dao.EntitySqlDaoStringTemplate;
+import org.skife.jdbi.v2.sqlobject.Bind;
+import org.skife.jdbi.v2.sqlobject.BindBean;
+import org.skife.jdbi.v2.sqlobject.SqlQuery;
+import org.skife.jdbi.v2.sqlobject.SqlUpdate;
+
+@EntitySqlDaoStringTemplate
+public interface BroadcastSqlDao {
+
+ @SqlUpdate
+ public void create(@BindBean final BroadcastModelDao broadcastModelDao);
+
+ @SqlQuery
+ public List<BroadcastModelDao> getLatestEntries(@Bind("recordId") final Long recordId);
+
+ @SqlQuery
+ public BroadcastModelDao getLatestEntry();
+
+}
diff --git a/util/src/main/java/org/killbill/billing/util/broadcast/dao/DefaultBroadcastDao.java b/util/src/main/java/org/killbill/billing/util/broadcast/dao/DefaultBroadcastDao.java
new file mode 100644
index 0000000..6d7f32a
--- /dev/null
+++ b/util/src/main/java/org/killbill/billing/util/broadcast/dao/DefaultBroadcastDao.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2014-2015 Groupon, Inc
+ * Copyright 2014-2015 The Billing Project, LLC
+ *
+ * The Billing Project 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 org.killbill.billing.util.broadcast.dao;
+
+import java.util.List;
+
+import javax.inject.Inject;
+
+import org.killbill.clock.Clock;
+import org.killbill.commons.jdbi.mapper.LowerToCamelBeanMapperFactory;
+import org.skife.jdbi.v2.DBI;
+import org.skife.jdbi.v2.Handle;
+import org.skife.jdbi.v2.IDBI;
+import org.skife.jdbi.v2.TransactionCallback;
+import org.skife.jdbi.v2.TransactionStatus;
+
+
+public class DefaultBroadcastDao implements BroadcastDao {
+
+ private final IDBI dbi;
+ private final Clock clock;
+
+ @Inject
+ public DefaultBroadcastDao(final IDBI dbi, final Clock clock) {
+ this.dbi = dbi;
+ this.clock = clock;
+ ((DBI) dbi).registerMapper(new LowerToCamelBeanMapperFactory(BroadcastModelDao.class));
+
+ }
+
+ @Override
+ public void create(final BroadcastModelDao broadcastModelDao) {
+ dbi.inTransaction(new TransactionCallback<Void>() {
+ @Override
+ public Void inTransaction(final Handle handle, final TransactionStatus status) throws Exception {
+ final BroadcastSqlDao sqlDao = handle.attach(BroadcastSqlDao.class);
+ sqlDao.create(broadcastModelDao);
+ return null;
+ }
+ });
+ }
+
+
+ @Override
+ public List<BroadcastModelDao> getLatestEntriesFrom(final Long recordId) {
+ return dbi.inTransaction(new TransactionCallback<List<BroadcastModelDao>>() {
+ @Override
+ public List<BroadcastModelDao> inTransaction(final Handle handle, final TransactionStatus status) throws Exception {
+ final BroadcastSqlDao sqlDao = handle.attach(BroadcastSqlDao.class);
+ return sqlDao.getLatestEntries(recordId);
+ }
+ });
+ }
+
+ @Override
+ public BroadcastModelDao getLatestEntry() {
+ return dbi.inTransaction(new TransactionCallback<BroadcastModelDao>() {
+ @Override
+ public BroadcastModelDao inTransaction(final Handle handle, final TransactionStatus status) throws Exception {
+ final BroadcastSqlDao sqlDao = handle.attach(BroadcastSqlDao.class);
+ return sqlDao.getLatestEntry();
+ }
+ });
+ }
+}
diff --git a/util/src/main/java/org/killbill/billing/util/broadcast/DefaultBroadcastService.java b/util/src/main/java/org/killbill/billing/util/broadcast/DefaultBroadcastService.java
new file mode 100644
index 0000000..3609e6a
--- /dev/null
+++ b/util/src/main/java/org/killbill/billing/util/broadcast/DefaultBroadcastService.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2014-2015 Groupon, Inc
+ * Copyright 2014-2015 The Billing Project, LLC
+ *
+ * The Billing Project 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 org.killbill.billing.util.broadcast;
+
+import org.killbill.billing.platform.api.LifecycleHandlerType;
+import org.killbill.billing.platform.api.LifecycleHandlerType.LifecycleLevel;
+
+public class DefaultBroadcastService implements BroadcastService {
+
+ public static final String BROADCAST_SERVICE_NAME = "broadcast-service";
+
+ @Override
+ public String getName() {
+ return BROADCAST_SERVICE_NAME;
+ }
+
+ @LifecycleHandlerType(LifecycleHandlerType.LifecycleLevel.START_SERVICE)
+ public void start() {
+ }
+
+ @LifecycleHandlerType(LifecycleLevel.STOP_SERVICE)
+ public void stop() {
+ }
+}
diff --git a/util/src/main/java/org/killbill/billing/util/glue/BroadcastModule.java b/util/src/main/java/org/killbill/billing/util/glue/BroadcastModule.java
new file mode 100644
index 0000000..1fe9dee
--- /dev/null
+++ b/util/src/main/java/org/killbill/billing/util/glue/BroadcastModule.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2014-2015 Groupon, Inc
+ * Copyright 2014-2015 The Billing Project, LLC
+ *
+ * The Billing Project 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 org.killbill.billing.util.glue;
+
+import org.killbill.billing.platform.api.KillbillConfigSource;
+import org.killbill.billing.util.broadcast.dao.BroadcastDao;
+import org.killbill.billing.util.broadcast.dao.DefaultBroadcastDao;
+import org.killbill.billing.util.info.DefaultKillbillInfoApi;
+import org.killbill.billing.util.info.DefaultKillbillInfoService;
+import org.killbill.billing.util.info.KillbillInfoApi;
+import org.killbill.billing.util.info.KillbillInfoService;
+import org.killbill.billing.util.info.NodeInfoMapper;
+import org.killbill.billing.util.info.dao.DefaultNodeInfoDao;
+import org.killbill.billing.util.info.dao.NodeInfoDao;
+
+public class BroadcastModule extends KillBillModule {
+
+ public BroadcastModule(final KillbillConfigSource configSource) {
+ super(configSource);
+ }
+
+ protected void installDaos() {
+ bind(BroadcastDao.class).to(DefaultBroadcastDao.class).asEagerSingleton();
+ }
+
+ protected void installUserApi() {
+ //bind(KillbillInfoApi.class).to(DefaultKillbillInfoApi.class).asEagerSingleton();
+ }
+
+
+ @Override
+ protected void configure() {
+ installDaos();
+ installUserApi();
+ }
+}
diff --git a/util/src/main/resources/org/killbill/billing/util/broadcast/dao/BroadcastSqlDao.sql.stg b/util/src/main/resources/org/killbill/billing/util/broadcast/dao/BroadcastSqlDao.sql.stg
new file mode 100644
index 0000000..49fa45a
--- /dev/null
+++ b/util/src/main/resources/org/killbill/billing/util/broadcast/dao/BroadcastSqlDao.sql.stg
@@ -0,0 +1,59 @@
+group BroadcastSqlDao;
+
+tableName() ::= "service_broadcasts"
+
+
+tableFields(prefix) ::= <<
+ <prefix>service_name
+, <prefix>type
+, <prefix>event
+, <prefix>created_date
+, <prefix>created_by
+>>
+
+allTableFields(prefix) ::= <<
+ <prefix>record_id
+, <tableFields(prefix)>
+>>
+
+tableValues() ::= <<
+ :serviceName
+, :type
+, :event
+, :createdDate
+, :createdBy
+>>
+
+allTableValues() ::= <<
+ :recordId
+, <tableValues()>
+>>
+
+create() ::= <<
+insert into <tableName()> (
+<tableFields()>
+)
+values (
+<tableValues()>
+)
+;
+>>
+
+
+getLatestEntries() ::= <<
+select
+ <allTableFields("t.")>
+from <tableName()> t
+where record_id > :recordId
+<defaultOrderBy("t.")>
+;
+>>
+
+
+getLatestEntry() ::= <<
+select
+ <allTableFields("t.")>
+from <tableName()> t
+where record_id = (select max(record_id) from <tableName()>)
+;
+>>
diff --git a/util/src/main/resources/org/killbill/billing/util/ddl.sql b/util/src/main/resources/org/killbill/billing/util/ddl.sql
index afcc4a1..3b67044 100644
--- a/util/src/main/resources/org/killbill/billing/util/ddl.sql
+++ b/util/src/main/resources/org/killbill/billing/util/ddl.sql
@@ -301,3 +301,15 @@ CREATE TABLE node_infos (
PRIMARY KEY(record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE UNIQUE INDEX node_name_idx ON node_infos(node_name);
+
+
+DROP TABLE IF EXISTS service_broadcasts;
+CREATE TABLE service_broadcasts (
+ record_id serial unique,
+ service_name varchar(50) NOT NULL,
+ type varchar(64) NOT NULL,
+ event text NOT NULL,
+ created_date datetime NOT NULL,
+ created_by varchar(50) NOT NULL,
+ PRIMARY KEY(record_id)
+) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
diff --git a/util/src/test/java/org/killbill/billing/util/broadcast/dao/TestBroadcastDao.java b/util/src/test/java/org/killbill/billing/util/broadcast/dao/TestBroadcastDao.java
new file mode 100644
index 0000000..777cea8
--- /dev/null
+++ b/util/src/test/java/org/killbill/billing/util/broadcast/dao/TestBroadcastDao.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2014-2015 Groupon, Inc
+ * Copyright 2014-2015 The Billing Project, LLC
+ *
+ * The Billing Project 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 org.killbill.billing.util.broadcast.dao;
+
+import java.util.List;
+
+import org.joda.time.DateTime;
+import org.killbill.billing.util.UtilTestSuiteWithEmbeddedDB;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.assertEquals;
+
+public class TestBroadcastDao extends UtilTestSuiteWithEmbeddedDB {
+
+ @Test(groups = "slow")
+ public void testBasic() throws Exception {
+
+ DateTime now = clock.getUTCNow();
+
+ final BroadcastModelDao b1 = new BroadcastModelDao("svc1", "type1", "{attribute: kewl}", now, "tester");
+ broadcastDao.create(b1);
+
+ final BroadcastModelDao res = broadcastDao.getLatestEntry();
+ assertEquals(res.getEvent(), b1.getEvent());
+ assertEquals(res.getServiceName(), b1.getServiceName());
+ assertEquals(res.getType(), b1.getType());
+
+ final List<BroadcastModelDao> all = broadcastDao.getLatestEntriesFrom(0L);
+ assertEquals(all.size(), 1);
+
+ final List<BroadcastModelDao> none = broadcastDao.getLatestEntriesFrom(1L);
+ assertEquals(none.size(), 0);
+
+ }
+}
diff --git a/util/src/test/java/org/killbill/billing/util/glue/TestUtilModuleWithEmbeddedDB.java b/util/src/test/java/org/killbill/billing/util/glue/TestUtilModuleWithEmbeddedDB.java
index ca72831..a5d908a 100644
--- a/util/src/test/java/org/killbill/billing/util/glue/TestUtilModuleWithEmbeddedDB.java
+++ b/util/src/test/java/org/killbill/billing/util/glue/TestUtilModuleWithEmbeddedDB.java
@@ -43,6 +43,7 @@ public class TestUtilModuleWithEmbeddedDB extends TestUtilModule {
install(new AuditModule(configSource));
install(new InfoModuleWithPluginInfoApi(configSource));
+ install(new BroadcastModule(configSource));
install(new TagStoreModule(configSource));
install(new CustomFieldModule(configSource));
install(new NonEntityDaoModule(configSource));
diff --git a/util/src/test/java/org/killbill/billing/util/UtilTestSuiteWithEmbeddedDB.java b/util/src/test/java/org/killbill/billing/util/UtilTestSuiteWithEmbeddedDB.java
index 971042a..082644a 100644
--- a/util/src/test/java/org/killbill/billing/util/UtilTestSuiteWithEmbeddedDB.java
+++ b/util/src/test/java/org/killbill/billing/util/UtilTestSuiteWithEmbeddedDB.java
@@ -24,7 +24,7 @@ import org.killbill.billing.GuicyKillbillTestSuiteWithEmbeddedDB;
import org.killbill.billing.api.TestApiListener;
import org.killbill.billing.security.api.SecurityApi;
import org.killbill.billing.util.audit.dao.AuditDao;
-import org.killbill.billing.util.cache.CacheControllerDispatcher;
+import org.killbill.billing.util.broadcast.dao.BroadcastDao;
import org.killbill.billing.util.callcontext.InternalCallContextFactory;
import org.killbill.billing.util.config.SecurityConfig;
import org.killbill.billing.util.customfield.api.DefaultCustomFieldUserApi;
@@ -90,6 +90,8 @@ public abstract class UtilTestSuiteWithEmbeddedDB extends GuicyKillbillTestSuite
protected SecurityConfig securityConfig;
@Inject
protected NodeInfoDao nodeInfoDao;
+ @Inject
+ protected BroadcastDao broadcastDao;
@BeforeClass(groups = "slow")
public void beforeClass() throws Exception {