Updated Branches: refs/heads/master 9cbad2329 -> 04add8436
Adding initial version of the tenant messaging model Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/40b3bf94 Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/40b3bf94 Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/40b3bf94 Branch: refs/heads/master Commit: 40b3bf94a0a650862665c47bd8c8d64acf50a2bc Parents: 419a460 Author: Imesh Gunaratne <[email protected]> Authored: Thu Dec 5 12:02:23 2013 +0530 Committer: Imesh Gunaratne <[email protected]> Committed: Thu Dec 5 12:02:23 2013 +0530 ---------------------------------------------------------------------- .../stratos/messaging/domain/tenant/Tenant.java | 45 ++++++++ .../event/tenant/TenantCreatedEvent.java | 45 ++++++++ .../messaging/event/tenant/TenantEvent.java | 31 +++++ .../event/tenant/TenantRemovedEvent.java | 39 +++++++ .../event/tenant/TenantUpdatedEvent.java | 45 ++++++++ .../tenant/TenantCreatedEventListener.java | 28 +++++ .../tenant/TenantRemovedEventListener.java | 28 +++++ .../tenant/TenantUpdatedEventListener.java | 28 +++++ .../tenant/TenantCreatedMessageProcessor.java | 39 +++++++ .../tenant/TenantRemovedMessageProcessor.java | 39 +++++++ .../tenant/TenantUpdatedMessageProcessor.java | 39 +++++++ .../message/receiver/tenant/TenantManager.java | 115 +++++++++++++++++++ 12 files changed, 521 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/40b3bf94/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 new file mode 100644 index 0000000..932cf72 --- /dev/null +++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/tenant/Tenant.java @@ -0,0 +1,45 @@ +/* + * 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 java.io.Serializable; + +/** + * Tenant definition. + */ +public class Tenant implements Serializable{ + private static final long serialVersionUID = 2154359124188618021L; + + private int tenantId; + private String tenantDomain; + + public Tenant(int tenantId, String tenantDomain) { + this.tenantId = tenantId; + this.tenantDomain = tenantDomain; + } + + public int getTenantId() { + return tenantId; + } + + public String getTenantDomain() { + return tenantDomain; + } +} http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/40b3bf94/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/tenant/TenantCreatedEvent.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/tenant/TenantCreatedEvent.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/tenant/TenantCreatedEvent.java new file mode 100644 index 0000000..34d3b69 --- /dev/null +++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/tenant/TenantCreatedEvent.java @@ -0,0 +1,45 @@ +/* + * 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.event.tenant; + +import java.io.Serializable; + +/** + * This event is fired when a tenant is created. + */ +public class TenantCreatedEvent extends TenantEvent implements Serializable { + private static final long serialVersionUID = -5954900215964894383L; + + private int tenantId; + private String tenantDomain; + + public TenantCreatedEvent(int tenantId, String tenantDomain) { + this.tenantId = tenantId; + this.tenantDomain = tenantDomain; + } + + public int getTenantId() { + return tenantId; + } + + public String getTenantDomain() { + return tenantDomain; + } +} http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/40b3bf94/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/tenant/TenantEvent.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/tenant/TenantEvent.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/tenant/TenantEvent.java new file mode 100644 index 0000000..3ebb005 --- /dev/null +++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/tenant/TenantEvent.java @@ -0,0 +1,31 @@ +/* + * 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.event.tenant; + +import org.apache.stratos.messaging.event.Event; + +import java.io.Serializable; + +/** + * Tenant event definition. + */ +public abstract class TenantEvent extends Event implements Serializable { + private static final long serialVersionUID = -214237911335280160L; +} http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/40b3bf94/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/tenant/TenantRemovedEvent.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/tenant/TenantRemovedEvent.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/tenant/TenantRemovedEvent.java new file mode 100644 index 0000000..c99dacd --- /dev/null +++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/tenant/TenantRemovedEvent.java @@ -0,0 +1,39 @@ +/* + * 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.event.tenant; + +import java.io.Serializable; + +/** + * This event is fired when a tenant is removed. + */ +public class TenantRemovedEvent extends TenantEvent implements Serializable { + private static final long serialVersionUID = -5759024961420183959L; + + private int tenantId; + + public TenantRemovedEvent(int tenantId) { + this.tenantId = tenantId; + } + + public int getTenantId() { + return tenantId; + } +} http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/40b3bf94/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/tenant/TenantUpdatedEvent.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/tenant/TenantUpdatedEvent.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/tenant/TenantUpdatedEvent.java new file mode 100644 index 0000000..faef774 --- /dev/null +++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/tenant/TenantUpdatedEvent.java @@ -0,0 +1,45 @@ +/* + * 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.event.tenant; + +import java.io.Serializable; + +/** + * This event is fired when a tenant updates its tenant domain. + */ +public class TenantUpdatedEvent extends TenantEvent implements Serializable { + private static final long serialVersionUID = -3507199180268215748L; + + private int tenantId; + private String tenantDomain; + + public TenantUpdatedEvent(int tenantId, String tenantDomain) { + this.tenantId = tenantId; + this.tenantDomain = tenantDomain; + } + + public int getTenantId() { + return tenantId; + } + + public String getTenantDomain() { + return tenantDomain; + } +} http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/40b3bf94/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/tenant/TenantCreatedEventListener.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/tenant/TenantCreatedEventListener.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/tenant/TenantCreatedEventListener.java new file mode 100644 index 0000000..0c5b3af --- /dev/null +++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/tenant/TenantCreatedEventListener.java @@ -0,0 +1,28 @@ +/* + * 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.listener.tenant; + +import org.apache.stratos.messaging.listener.EventListener; + +/** + * Tenant created event listener. + */ +public abstract class TenantCreatedEventListener extends EventListener { +} http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/40b3bf94/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/tenant/TenantRemovedEventListener.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/tenant/TenantRemovedEventListener.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/tenant/TenantRemovedEventListener.java new file mode 100644 index 0000000..f94305f --- /dev/null +++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/tenant/TenantRemovedEventListener.java @@ -0,0 +1,28 @@ +/* + * 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.listener.tenant; + +import org.apache.stratos.messaging.listener.EventListener; + +/** + * Tenant removed event listener. + */ +public abstract class TenantRemovedEventListener extends EventListener { +} http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/40b3bf94/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/tenant/TenantUpdatedEventListener.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/tenant/TenantUpdatedEventListener.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/tenant/TenantUpdatedEventListener.java new file mode 100644 index 0000000..44edbf1 --- /dev/null +++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/tenant/TenantUpdatedEventListener.java @@ -0,0 +1,28 @@ +/* + * 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.listener.tenant; + +import org.apache.stratos.messaging.listener.EventListener; + +/** + * Tenant updated event listener. + */ +public abstract class TenantUpdatedEventListener extends EventListener { +} http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/40b3bf94/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/tenant/TenantCreatedMessageProcessor.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/tenant/TenantCreatedMessageProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/tenant/TenantCreatedMessageProcessor.java new file mode 100644 index 0000000..e41982c --- /dev/null +++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/tenant/TenantCreatedMessageProcessor.java @@ -0,0 +1,39 @@ +/* + * 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.stratos.messaging.message.processor.MessageProcessor; + +/** + * Tenant created message processor for triggering tenant created event + * listener when a tenant created event message is received. + */ +public class TenantCreatedMessageProcessor extends MessageProcessor { + + @Override + public void setNext(MessageProcessor nextProcessor) { + + } + + @Override + public boolean process(String type, String message, Object object) { + return false; + } +} http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/40b3bf94/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/tenant/TenantRemovedMessageProcessor.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/tenant/TenantRemovedMessageProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/tenant/TenantRemovedMessageProcessor.java new file mode 100644 index 0000000..27bb681 --- /dev/null +++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/tenant/TenantRemovedMessageProcessor.java @@ -0,0 +1,39 @@ +/* + * 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.stratos.messaging.message.processor.MessageProcessor; + +/** + * Tenant removed message processor for triggering tenant removed event + * listener when a tenant removed event message is received. + */ +public class TenantRemovedMessageProcessor extends MessageProcessor { + + @Override + public void setNext(MessageProcessor nextProcessor) { + + } + + @Override + public boolean process(String type, String message, Object object) { + return false; + } +} http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/40b3bf94/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/tenant/TenantUpdatedMessageProcessor.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/tenant/TenantUpdatedMessageProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/tenant/TenantUpdatedMessageProcessor.java new file mode 100644 index 0000000..eae5cdd --- /dev/null +++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/tenant/TenantUpdatedMessageProcessor.java @@ -0,0 +1,39 @@ +/* + * 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.stratos.messaging.message.processor.MessageProcessor; + +/** + * Tenant updated message processor for triggering tenant updated event + * listener when a tenant updated event message is received. + */ +public class TenantUpdatedMessageProcessor extends MessageProcessor { + + @Override + public void setNext(MessageProcessor nextProcessor) { + + } + + @Override + public boolean process(String type, String message, Object object) { + return false; + } +} http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/40b3bf94/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/receiver/tenant/TenantManager.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/receiver/tenant/TenantManager.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/receiver/tenant/TenantManager.java new file mode 100644 index 0000000..a6b59ff --- /dev/null +++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/receiver/tenant/TenantManager.java @@ -0,0 +1,115 @@ +/* + * 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.receiver.tenant; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.stratos.messaging.domain.tenant.Tenant; + +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.locks.ReentrantReadWriteLock; + +/** + * A singleton class for managing the tenant information. + * + * Usage: + * Acquire a relevant lock and invoke a method inside a try block. + * Once processing is done release the lock using a finally block. + */ +public class TenantManager { + private static final Log log = LogFactory.getLog(TenantManager.class); + + private static volatile TenantManager instance; + private static volatile ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); + private static volatile ReentrantReadWriteLock.ReadLock readLock = lock.readLock(); + private static volatile ReentrantReadWriteLock.WriteLock writeLock = lock.writeLock(); + + private Map<Integer, Tenant> tenantIdTenantMap; + private Map<String, Tenant> tenantDomainTenantMap; + + public static void acquireReadLock() { + if(log.isDebugEnabled()) { + log.debug("Read lock acquired"); + } + readLock.lock(); + } + + public static void releaseReadLock() { + if(log.isDebugEnabled()) { + log.debug("Read lock released"); + } + readLock.unlock(); + } + + public static void acquireWriteLock() { + if(log.isDebugEnabled()) { + log.debug("Write lock acquired"); + } + writeLock.lock(); + } + + public static void releaseWriteLock() { + if(log.isDebugEnabled()) { + log.debug("Write lock released"); + } + writeLock.unlock(); + } + + private TenantManager() { + this.tenantIdTenantMap = new HashMap<Integer, Tenant>(); + this.tenantDomainTenantMap = new HashMap<String, Tenant>(); + } + + public static synchronized TenantManager getInstance() { + if (instance == null) { + synchronized (TenantManager.class){ + if (instance == null) { + instance = new TenantManager(); + if(log.isDebugEnabled()) { + log.debug("TenantManager object created"); + } + } + } + } + return instance; + } + + public void addTenant(Tenant tenant) { + this.tenantIdTenantMap.put(tenant.getTenantId(), tenant); + this.tenantDomainTenantMap.put(tenant.getTenantDomain(), tenant); + } + + public Tenant getTenant(int tenantId) { + return this.tenantIdTenantMap.get(tenantId); + } + + public Tenant getTenant(String tenantDomain) { + return this.tenantDomainTenantMap.get(tenantDomain); + } + + public void removeTenant(int tenantId) { + Tenant tenant = getTenant(tenantId); + if(tenant != null) { + tenantIdTenantMap.remove(tenant.getTenantId()); + tenantDomainTenantMap.remove(tenant.getTenantDomain()); + } + } +}
