You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by im...@apache.org on 2015/03/03 09:21:47 UTC
stratos git commit: Removing tenant subscription events from
messaging component
Repository: stratos
Updated Branches:
refs/heads/master 2573d35cf -> 5e497cb07
Removing tenant subscription events from messaging component
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/5e497cb0
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/5e497cb0
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/5e497cb0
Branch: refs/heads/master
Commit: 5e497cb07e229ce0dabb677e26020ddcd3d933aa
Parents: 2573d35
Author: Imesh Gunaratne <im...@apache.org>
Authored: Tue Mar 3 13:51:35 2015 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Tue Mar 3 13:51:35 2015 +0530
----------------------------------------------------------------------
.../messaging/domain/tenant/Subscription.java | 77 -----------------
.../stratos/messaging/domain/tenant/Tenant.java | 29 -------
.../stratos/messaging/domain/topology/Port.java | 2 +
.../tenant/TenantMessageProcessorChain.java | 12 ---
.../TenantSubscribedMessageProcessor.java | 90 --------------------
.../TenantUnSubscribedMessageProcessor.java | 88 -------------------
.../messaging/test/TenantDomainTest.java | 45 ----------
7 files changed, 2 insertions(+), 341 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/5e497cb0/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/tenant/Subscription.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/tenant/Subscription.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/tenant/Subscription.java
deleted file mode 100644
index caab423..0000000
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/tenant/Subscription.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF 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.apache.stratos.messaging.domain.tenant;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.util.*;
-
-/**
- * Tenant's service subscription.
- */
-public class Subscription {
- private static final Log log = LogFactory.getLog(Subscription.class);
-
- private final String serviceName;
- private final Set<String> clusterIds;
- private final Map<String, SubscriptionDomain> subscriptionDomainMap;
-
- public Subscription(String serviceName, Set<String> clusterIds) {
- this.serviceName = serviceName;
- this.clusterIds = clusterIds;
- this.subscriptionDomainMap = new HashMap<String, SubscriptionDomain>();
- }
-
- public String getServiceName() {
- return serviceName;
- }
-
- public Set<String> getClusterIds() {
- return Collections.unmodifiableSet(clusterIds);
- }
-
- public void addSubscriptionDomain(SubscriptionDomain subscriptionDomain) {
- subscriptionDomainMap.put(subscriptionDomain.getDomainName(), subscriptionDomain);
- }
-
- public void addSubscriptionDomain(String domainName, String applicationContext) {
- addSubscriptionDomain(new SubscriptionDomain(domainName, applicationContext));
- }
-
- public void removeSubscriptionDomain(String domainName) {
- if(subscriptionDomainExists(domainName)) {
- subscriptionDomainMap.remove(domainName);
- }
- else {
- if(log.isWarnEnabled()) {
- log.warn("Subscription domain does not exist: " + domainName);
- }
- }
- }
-
- public boolean subscriptionDomainExists(String domainName) {
- return subscriptionDomainMap.containsKey(domainName);
- }
-
- public Collection<SubscriptionDomain> getSubscriptionDomains() {
- return Collections.unmodifiableCollection(subscriptionDomainMap.values());
- }
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/5e497cb0/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/tenant/Tenant.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/tenant/Tenant.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/tenant/Tenant.java
index ed20bd0..039ff8c 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/tenant/Tenant.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/tenant/Tenant.java
@@ -20,9 +20,6 @@
package org.apache.stratos.messaging.domain.tenant;
import java.io.Serializable;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
/**
* Tenant definition.
@@ -32,13 +29,10 @@ public class Tenant implements Serializable{
private int tenantId;
private String tenantDomain;
- // Map<ServiceName, Subscription>
- private Map<String, Subscription> serviceNameSubscriptionMap;
public Tenant(int tenantId, String tenantDomain) {
this.tenantId = tenantId;
this.tenantDomain = tenantDomain;
- this.serviceNameSubscriptionMap = new HashMap<String, Subscription>();
}
public int getTenantId() {
@@ -52,27 +46,4 @@ public class Tenant implements Serializable{
public void setTenantDomain(String tenantDomain) {
this.tenantDomain = tenantDomain;
}
-
- public Subscription getSubscription(String serviceName) {
- if(serviceNameSubscriptionMap.containsKey(serviceName)) {
- return serviceNameSubscriptionMap.get(serviceName);
- }
- return null;
- }
-
- public Collection<Subscription> getSubscriptions() {
- return serviceNameSubscriptionMap.values();
- }
-
- public boolean isSubscribed(String serviceName) {
- return serviceNameSubscriptionMap.containsKey(serviceName);
- }
-
- public void addSubscription(Subscription subscription) {
- serviceNameSubscriptionMap.put(subscription.getServiceName(), subscription);
- }
-
- public void removeSubscription(String serviceName) {
- serviceNameSubscriptionMap.remove(serviceName);
- }
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/5e497cb0/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Port.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Port.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Port.java
index 2bc3982..bc3acd6 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Port.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Port.java
@@ -25,7 +25,9 @@ import java.io.Serializable;
* Defines an application port.
*/
public class Port implements Serializable{
+
private static final long serialVersionUID = -2530288421360188256L;
+
private String protocol;
private int value;
private int proxy;
http://git-wip-us.apache.org/repos/asf/stratos/blob/5e497cb0/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/tenant/TenantMessageProcessorChain.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/tenant/TenantMessageProcessorChain.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/tenant/TenantMessageProcessorChain.java
index 5ab8af8..f1996f6 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/tenant/TenantMessageProcessorChain.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/tenant/TenantMessageProcessorChain.java
@@ -35,8 +35,6 @@ public class TenantMessageProcessorChain extends MessageProcessorChain {
private TenantCreatedMessageProcessor tenantCreatedMessageProcessor;
private TenantUpdatedMessageProcessor tenantUpdatedMessageProcessor;
private TenantRemovedMessageProcessor tenantRemovedMessageProcessor;
- private TenantSubscribedMessageProcessor tenantSubscribedMessageProcessor;
- private TenantUnSubscribedMessageProcessor tenantUnSubscribedMessageProcessor;
public void initialize() {
// Initialize tenant event processors
@@ -52,12 +50,6 @@ public class TenantMessageProcessorChain extends MessageProcessorChain {
tenantRemovedMessageProcessor = new TenantRemovedMessageProcessor();
add(tenantRemovedMessageProcessor);
- tenantSubscribedMessageProcessor = new TenantSubscribedMessageProcessor();
- add(tenantSubscribedMessageProcessor);
-
- tenantUnSubscribedMessageProcessor = new TenantUnSubscribedMessageProcessor();
- add(tenantUnSubscribedMessageProcessor);
-
if (log.isDebugEnabled()) {
log.debug("Tenant message processor chain initialized");
}
@@ -72,10 +64,6 @@ public class TenantMessageProcessorChain extends MessageProcessorChain {
tenantUpdatedMessageProcessor.addEventListener(eventListener);
} else if (eventListener instanceof TenantRemovedEventListener) {
tenantRemovedMessageProcessor.addEventListener(eventListener);
- } else if (eventListener instanceof TenantSubscribedEventListener) {
- tenantSubscribedMessageProcessor.addEventListener(eventListener);
- } else if (eventListener instanceof TenantUnSubscribedEventListener) {
- tenantUnSubscribedMessageProcessor.addEventListener(eventListener);
}
else {
throw new RuntimeException("Unknown event listener");
http://git-wip-us.apache.org/repos/asf/stratos/blob/5e497cb0/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/tenant/TenantSubscribedMessageProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/tenant/TenantSubscribedMessageProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/tenant/TenantSubscribedMessageProcessor.java
deleted file mode 100644
index 21bd137..0000000
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/tenant/TenantSubscribedMessageProcessor.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF 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.apache.stratos.messaging.message.processor.tenant;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.messaging.domain.tenant.Subscription;
-import org.apache.stratos.messaging.domain.tenant.Tenant;
-import org.apache.stratos.messaging.event.tenant.TenantSubscribedEvent;
-import org.apache.stratos.messaging.message.processor.MessageProcessor;
-import org.apache.stratos.messaging.message.receiver.tenant.TenantManager;
-import org.apache.stratos.messaging.util.MessagingUtil;
-
-/**
- * Tenant subscribed message processor for updating a tenant in tenant manager and
- * triggering tenant subscribed event listeners.
- */
-public class TenantSubscribedMessageProcessor extends MessageProcessor {
-
- private static final Log log = LogFactory.getLog(TenantSubscribedMessageProcessor.class);
-
- private MessageProcessor nextProcessor;
-
- @Override
- public void setNext(MessageProcessor nextProcessor) {
- this.nextProcessor = nextProcessor;
- }
-
- @Override
- public boolean process(String type, String message, Object object) {
- if (TenantSubscribedEvent.class.getName().equals(type)) {
- // Return if tenant manager has not initialized
- if(!TenantManager.getInstance().isInitialized()) {
- return false;
- }
-
- // Parse complete message and build event
- TenantSubscribedEvent event = (TenantSubscribedEvent) MessagingUtil.jsonToObject(message, TenantSubscribedEvent.class);
-
- try {
- TenantManager.acquireWriteLock();
- Tenant tenant = TenantManager.getInstance().getTenant(event.getTenantId());
- if(tenant == null) {
- if(log.isWarnEnabled()) {
- log.warn(String.format("Tenant not found: [tenant-id] %d", event.getTenantId()));
- }
- return false;
- }
- Subscription subscription = new Subscription(event.getServiceName(), event.getClusterIds());
- tenant.addSubscription(subscription);
- if(log.isInfoEnabled()) {
- log.info(String.format("Tenant subscribed to service: [tenant-id] %d [tenant-domain] %s [service] %s",
- tenant.getTenantId(), tenant.getTenantDomain(), event.getServiceName()));
- }
-
- // Notify event listeners
- notifyEventListeners(event);
- return true;
- }
- finally {
- TenantManager.releaseWriteLock();
- }
- }
- else {
- if(nextProcessor != null) {
- return nextProcessor.process(type, message, object);
- }
- else {
- throw new RuntimeException(String.format("Failed to process tenant message using available message processors: [type] %s [body] %s", type, message));
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/5e497cb0/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/tenant/TenantUnSubscribedMessageProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/tenant/TenantUnSubscribedMessageProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/tenant/TenantUnSubscribedMessageProcessor.java
deleted file mode 100644
index 1b17494..0000000
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/tenant/TenantUnSubscribedMessageProcessor.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF 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.apache.stratos.messaging.message.processor.tenant;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.messaging.domain.tenant.Tenant;
-import org.apache.stratos.messaging.event.tenant.TenantUnSubscribedEvent;
-import org.apache.stratos.messaging.message.processor.MessageProcessor;
-import org.apache.stratos.messaging.message.receiver.tenant.TenantManager;
-import org.apache.stratos.messaging.util.MessagingUtil;
-
-/**
- * Tenant un-subscribed message processor for updating a tenant in tenant manager and
- * triggering tenant subscribed event listeners.
- */
-public class TenantUnSubscribedMessageProcessor extends MessageProcessor {
-
- private static final Log log = LogFactory.getLog(TenantUnSubscribedMessageProcessor.class);
-
- private MessageProcessor nextProcessor;
-
- @Override
- public void setNext(MessageProcessor nextProcessor) {
- this.nextProcessor = nextProcessor;
- }
-
- @Override
- public boolean process(String type, String message, Object object) {
- if (TenantUnSubscribedEvent.class.getName().equals(type)) {
- // Return if tenant manager has not initialized
- if(!TenantManager.getInstance().isInitialized()) {
- return false;
- }
-
- // Parse complete message and build event
- TenantUnSubscribedEvent event = (TenantUnSubscribedEvent) MessagingUtil.jsonToObject(message, TenantUnSubscribedEvent.class);
-
- try {
- TenantManager.acquireWriteLock();
- Tenant tenant = TenantManager.getInstance().getTenant(event.getTenantId());
- if(tenant == null) {
- if(log.isWarnEnabled()) {
- log.warn(String.format("Tenant not found: [tenant-id] %d", event.getTenantId()));
- }
- return false;
- }
- tenant.removeSubscription(event.getServiceName());
- if(log.isInfoEnabled()) {
- log.info(String.format("Tenant un-subscribed from service: [tenant-id] %d [tenant-domain] %s [service] %s",
- tenant.getTenantId(), tenant.getTenantDomain(), event.getServiceName()));
- }
-
- // Notify event listeners
- notifyEventListeners(event);
- return true;
- }
- finally {
- TenantManager.releaseWriteLock();
- }
- }
- else {
- if(nextProcessor != null) {
- return nextProcessor.process(type, message, object);
- }
- else {
- throw new RuntimeException(String.format("Failed to process tenant message using available message processors: [type] %s [body] %s", type, message));
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/5e497cb0/components/org.apache.stratos.messaging/src/test/java/org/apache/stratos/messaging/test/TenantDomainTest.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/test/java/org/apache/stratos/messaging/test/TenantDomainTest.java b/components/org.apache.stratos.messaging/src/test/java/org/apache/stratos/messaging/test/TenantDomainTest.java
deleted file mode 100644
index fae8b79..0000000
--- a/components/org.apache.stratos.messaging/src/test/java/org/apache/stratos/messaging/test/TenantDomainTest.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF 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.apache.stratos.messaging.test;
-
-import junit.framework.Assert;
-import org.apache.stratos.messaging.domain.tenant.Subscription;
-import org.apache.stratos.messaging.domain.tenant.Tenant;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-import java.util.HashSet;
-
-/**
- * Tenant domain model test.
- */
-@RunWith(JUnit4.class)
-public class TenantDomainTest {
- @Test
- public void testSubscriptionModel() {
- Tenant tenant = new Tenant(1, "domain.org");
- Subscription subscription = new Subscription("subscription1", new HashSet<String>());
- tenant.addSubscription(subscription);
- Assert.assertTrue("Subscription not added", tenant.isSubscribed("subscription1"));
- tenant.removeSubscription("subscription1");
- Assert.assertTrue("Subscription not removed", !tenant.isSubscribed("subscription1"));
- }
-}