You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ni...@apache.org on 2014/03/26 10:52:00 UTC
[7/8] git commit: asynchronously publishing tenant subscribed event
asynchronously publishing tenant subscribed event
Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/85d8ab9c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/85d8ab9c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/85d8ab9c
Branch: refs/heads/master
Commit: 85d8ab9c263f7475354082b07fcb82be066bfec9
Parents: be24be7
Author: Nirmal Fernando <ni...@apache.org>
Authored: Wed Mar 26 15:20:28 2014 +0530
Committer: Nirmal Fernando <ni...@apache.org>
Committed: Wed Mar 26 15:20:28 2014 +0530
----------------------------------------------------------------------
.../utils/CartridgeSubscriptionUtils.java | 50 +++++++++++++++-----
1 file changed, 38 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/85d8ab9c/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/utils/CartridgeSubscriptionUtils.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/utils/CartridgeSubscriptionUtils.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/utils/CartridgeSubscriptionUtils.java
index 130a727..cd50fd8 100644
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/utils/CartridgeSubscriptionUtils.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/utils/CartridgeSubscriptionUtils.java
@@ -43,6 +43,7 @@ import org.apache.stratos.messaging.event.tenant.TenantSubscribedEvent;
import org.apache.stratos.messaging.event.tenant.TenantUnSubscribedEvent;
import org.apache.stratos.messaging.util.Constants;
+import java.util.concurrent.Executor;
import java.util.regex.Pattern;
public class CartridgeSubscriptionUtils {
@@ -149,19 +150,44 @@ public class CartridgeSubscriptionUtils {
return key;
}
+ static class TenantSubscribedEventPublisher implements Runnable {
+
+ int tenantId;
+ String serviceName;
+
+ public TenantSubscribedEventPublisher(int tenantId, String service) {
+ this.tenantId = tenantId;
+ this.serviceName = service;
+ }
+ @Override
+ public void run() {
+ try {
+ if(log.isInfoEnabled()) {
+ log.info(String.format("Publishing tenant subscribed event: [tenant-id] %d [service] %s", tenantId, serviceName));
+ }
+ TenantSubscribedEvent subscribedEvent = new TenantSubscribedEvent(tenantId, serviceName);
+ EventPublisher eventPublisher = new EventPublisher(Constants.TENANT_TOPIC);
+ eventPublisher.publish(subscribedEvent);
+ } catch (Exception e) {
+ if (log.isErrorEnabled()) {
+ log.error(String.format("Could not publish tenant subscribed event: [tenant-id] %d [service] %s", tenantId, serviceName), e);
+ }
+ }
+
+ }
+
+ }
public static void publishTenantSubscribedEvent(int tenantId, String serviceName) {
- try {
- if(log.isInfoEnabled()) {
- log.info(String.format("Publishing tenant subscribed event: [tenant-id] %d [service] %s", tenantId, serviceName));
- }
- TenantSubscribedEvent subscribedEvent = new TenantSubscribedEvent(tenantId, serviceName);
- EventPublisher eventPublisher = new EventPublisher(Constants.TENANT_TOPIC);
- eventPublisher.publish(subscribedEvent);
- } catch (Exception e) {
- if (log.isErrorEnabled()) {
- log.error(String.format("Could not publish tenant subscribed event: [tenant-id] %d [service] %s", tenantId, serviceName), e);
- }
- }
+
+
+ Executor exec = new Executor() {
+ @Override
+ public void execute(Runnable command) {
+ command.run();
+ }
+ };
+
+ exec.execute(new TenantSubscribedEventPublisher(tenantId, serviceName));
}
public static void publishTenantUnSubscribedEvent(int tenantId, String serviceName) {