Author: bdekruijff at gmail.com
Date: Tue Jan 11 12:32:02 2011
New Revision: 589
Log:
[sandbox] refactored for naming consistency and added exceptions
Added:
sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/FabricException.java
sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/cluster/service/ClusterChannelServiceBase.java
- copied, changed from r586,
/sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/cluster/service/ClusterMemberServiceBase.java
sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/cluster/service/tribes/TribesClusterChannelServiceImpl.java
- copied, changed from r586,
/sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/cluster/service/tribes/TribesClusterMemberServiceImpl.java
Removed:
sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/cluster/service/ClusterMemberServiceBase.java
sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/cluster/service/tribes/TribesClusterMemberServiceImpl.java
Modified:
sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/FabricManagerService.java
sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/cluster/ChannelMemberAddedEvent.java
sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/remote/internal/LocalServiceInvocationHandler.java
sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/remote/service/DiscoveryServiceImpl.java
sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/remote/service/DistributionServiceImpl.java
sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/service/FabricManagerServiceImpl.java
Added:
sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/FabricException.java
==============================================================================
--- (empty file)
+++
sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/FabricException.java
Tue Jan 11 12:32:02 2011
@@ -0,0 +1,18 @@
+package org.amdatu.core.fabric;
+
+public class FabricException extends Exception {
+
+ private static final long serialVersionUID = 1L;
+
+ public FabricException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public FabricException(String message) {
+ super(message);
+ }
+
+ public FabricException(Throwable cause) {
+ super(cause);
+ }
+}
Modified:
sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/FabricManagerService.java
==============================================================================
---
sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/FabricManagerService.java
(original)
+++
sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/FabricManagerService.java
Tue Jan 11 12:32:02 2011
@@ -6,16 +6,17 @@
String CONFIGURATION_PID = "org.amdatu.core.fabric";
- boolean createClusterChannel(String clusterChannelId, Dictionary<String,
Object> channelProperties);
+ boolean createClusterChannel(String clusterChannelId, Dictionary<String,
Object> channelProperties)
+ throws FabricException;
- boolean removeClusterChannel(String clusterChannelId);
+ boolean removeClusterChannel(String clusterChannelId) throws
FabricException;
- boolean createDiscovery(String clusterChannelId, String serviceGroupId);
+ boolean createDiscovery(String clusterChannelId, String serviceGroupId)
throws FabricException;
- boolean removeDiscovery(String clusterChannelId, String serviceGroupId);
+ boolean removeDiscovery(String clusterChannelId, String serviceGroupId)
throws FabricException;
- boolean createDistribution(String clusterChannelId, String serviceGroupId);
+ boolean createDistribution(String clusterChannelId, String serviceGroupId)
throws FabricException;
- boolean removeDistribution(String clusterChannelId, String serviceGroupId);
+ boolean removeDistribution(String clusterChannelId, String serviceGroupId)
throws FabricException;
}
Modified:
sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/cluster/ChannelMemberAddedEvent.java
==============================================================================
---
sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/cluster/ChannelMemberAddedEvent.java
(original)
+++
sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/cluster/ChannelMemberAddedEvent.java
Tue Jan 11 12:32:02 2011
@@ -2,20 +2,20 @@
public class ChannelMemberAddedEvent {
- private final String m_channelmemberId;
+ private final String m_channelMemberId;
public ChannelMemberAddedEvent(String channelMemberId) {
- m_channelmemberId = channelMemberId;
+ m_channelMemberId = channelMemberId;
}
public String getMemberName() {
- return m_channelmemberId;
+ return m_channelMemberId;
}
@Override
public String toString() {
StringBuilder sb = new
StringBuilder(ChannelMemberAddedEvent.class.getSimpleName() + "{");
- sb.append("\n\tchannelMemberId: " + m_channelmemberId);
+ sb.append("\n\tchannelMemberId: " + m_channelMemberId);
sb.append("\n}");
return sb.toString();
}
Copied:
sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/cluster/service/ClusterChannelServiceBase.java
(from r586,
/sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/cluster/service/ClusterMemberServiceBase.java)
==============================================================================
---
/sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/cluster/service/ClusterMemberServiceBase.java
(original)
+++
sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/cluster/service/ClusterChannelServiceBase.java
Tue Jan 11 12:32:02 2011
@@ -45,7 +45,7 @@
*
* TODO add a static(?) getConfigurationProperties method
*/
-public abstract class ClusterMemberServiceBase implements
ClusterChannelService {
+public abstract class ClusterChannelServiceBase implements
ClusterChannelService {
private final Map<String, ChannelMember> m_clusterMembers = new
HashMap<String, ChannelMember>();
private final ReentrantReadWriteLock m_clusterMembersLock = new
ReentrantReadWriteLock();
@@ -68,7 +68,7 @@
* Constructors
********************************************************/
- public ClusterMemberServiceBase(String clusterChannelId,
Dictionary<String, Object> channelProperties) {
+ public ClusterChannelServiceBase(String clusterChannelId,
Dictionary<String, Object> channelProperties) {
m_clusterChannelId = clusterChannelId;
m_channelMemberId = UUID.randomUUID().toString();
m_channelProperties = new Hashtable<String, Object>();
@@ -87,7 +87,7 @@
* Service lifecycle
********************************************************/
- public final synchronized void init() {
+ public final synchronized void init() throws Exception {
updateServiceProperties();
initLogServiceDependency();
initEventAdminDependency();
@@ -95,18 +95,18 @@
onInit();
}
- public final synchronized void destroy() {
+ public final synchronized void destroy() throws Exception {
onDestroy();
}
- public final synchronized void start() {
+ public final synchronized void start() throws Exception {
m_dependencyManager.add(m_broadcastEventHandlerComponent);
onStart();
m_logService.log(LogService.LOG_WARNING, "Started ClusterChannel: " +
m_clusterChannelId + "/"
+ m_channelMemberId);
}
- public final synchronized void stop() {
+ public final synchronized void stop() throws Exception {
m_dependencyManager.remove(m_broadcastEventHandlerComponent);
onStop();
m_logService.log(LogService.LOG_WARNING, "Stopped ClusterChannel: " +
m_clusterChannelId + "/"
@@ -203,17 +203,17 @@
* Abstract methods
********************************************************/
- protected abstract void onInit();
+ protected abstract void onInit() throws Exception;
- protected abstract void onDestroy();
+ protected abstract void onDestroy() throws Exception;
- protected abstract void onStart();
+ protected abstract void onStart() throws Exception;
- protected abstract void onStop();
+ protected abstract void onStop() throws Exception;
- protected abstract void doBroadcast(Object message);
+ protected abstract void doBroadcast(Object message) throws Exception;
- protected abstract void doSend(ChannelMember[] channelMember, Object
message);
+ protected abstract void doSend(ChannelMember[] channelMember, Object
message) throws Exception;
/********************************************************
* Private methods
@@ -263,7 +263,11 @@
public void handleEvent(Event event) {
Object message = event.getProperty(EVENT_MESSAGE_PROPERTY);
if (!(message instanceof RoutableMessage)) {
- doBroadcast(message);
+ try {
+ // TODO delegate to base and wrap
+ doBroadcast(message);
+ }
+ catch (Exception e) {}
return;
}
RoutableMessage routableMessage = (RoutableMessage) message;
@@ -277,10 +281,18 @@
+ routableMessage.toString());
return;
}
- doSend(new ChannelMember[] { clusterMember }, message);
+ try {
+ // TODO delegate to base and wrap
+ doSend(new ChannelMember[] { clusterMember }, message);
+ }
+ catch (Exception e) {}
}
else {
- doBroadcast(message);
+ try {
+ // TODO delegate to base and wrap
+ doBroadcast(message);
+ }
+ catch (Exception e) {}
}
}
}
Copied:
sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/cluster/service/tribes/TribesClusterChannelServiceImpl.java
(from r586,
/sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/cluster/service/tribes/TribesClusterMemberServiceImpl.java)
==============================================================================
---
/sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/cluster/service/tribes/TribesClusterMemberServiceImpl.java
(original)
+++
sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/cluster/service/tribes/TribesClusterChannelServiceImpl.java
Tue Jan 11 12:32:02 2011
@@ -30,7 +30,7 @@
import org.amdatu.core.fabric.cluster.ChannelMember;
import org.amdatu.core.fabric.cluster.internal.ChannelMemberImpl;
import org.amdatu.core.fabric.cluster.internal.tribes.ClusterChannelCreator;
-import org.amdatu.core.fabric.cluster.service.ClusterMemberServiceBase;
+import org.amdatu.core.fabric.cluster.service.ClusterChannelServiceBase;
import org.apache.catalina.tribes.Channel;
import org.apache.catalina.tribes.ChannelException;
import org.apache.catalina.tribes.ChannelListener;
@@ -40,7 +40,7 @@
import org.apache.catalina.tribes.util.Arrays;
import org.osgi.service.log.LogService;
-public final class TribesClusterMemberServiceImpl extends
ClusterMemberServiceBase {
+public final class TribesClusterChannelServiceImpl extends
ClusterChannelServiceBase {
public static final String CLUSTER_TRIBES_ARGS_PROP =
"org.amdatu.fabric.cluster.tribes.args";
@@ -54,7 +54,7 @@
* Constructors
********************************************************/
- public TribesClusterMemberServiceImpl(String clusterChannelId,
+ public TribesClusterChannelServiceImpl(String clusterChannelId,
Dictionary<String, Object> channelProperties) {
super(clusterChannelId, channelProperties);
}
@@ -215,11 +215,11 @@
class TribesMembershipListener implements MembershipListener {
public void memberAdded(Member member) {
- TribesClusterMemberServiceImpl.this.memberAdded(member);
+ TribesClusterChannelServiceImpl.this.memberAdded(member);
}
public void memberDisappeared(Member member) {
- TribesClusterMemberServiceImpl.this.memberDisappeared(member);
+ TribesClusterChannelServiceImpl.this.memberDisappeared(member);
}
}
Modified:
sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/remote/internal/LocalServiceInvocationHandler.java
==============================================================================
---
sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/remote/internal/LocalServiceInvocationHandler.java
(original)
+++
sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/remote/internal/LocalServiceInvocationHandler.java
Tue Jan 11 12:32:02 2011
@@ -47,7 +47,8 @@
*/
public final class LocalServiceInvocationHandler implements InvocationHandler {
- private final static long INVOCATION_TIMEOUT = 100;
+ // TODO make configurable
+ private final static long INVOCATION_TIMEOUT = 1000;
private final Set<String> m_invocationIdentifiers = new HashSet<String>();
private final Map<String, Object> m_invocationResponses = new
HashMap<String, Object>();
@@ -100,7 +101,7 @@
* Service lifecycle
********************************************************/
- public synchronized void init() {
+ public synchronized void init() throws Exception {
ServiceDependency eventAdminServiceDependency =
m_dependencyManager.createServiceDependency();
eventAdminServiceDependency.setService(EventAdmin.class);
eventAdminServiceDependency.setRequired(true);
@@ -120,15 +121,15 @@
m_serviceInvocationEventHandlerComponent.setImplementation(new
ServiceInvocationEventHandler());
}
- public synchronized void destroy() {
+ public synchronized void destroy() throws Exception {
}
- public synchronized void start() {
+ public synchronized void start() throws Exception {
m_logService.log(LogService.LOG_WARNING, "Starting
LocalServiceInvocationHandler");
m_dependencyManager.add(m_serviceInvocationEventHandlerComponent);
}
- public synchronized void stop() {
+ public synchronized void stop() throws Exception {
m_logService.log(LogService.LOG_WARNING, "Stopping
LocalServiceInvocationHandler");
m_dependencyManager.remove(m_serviceInvocationEventHandlerComponent);
}
@@ -151,6 +152,7 @@
Event event = new Event(m_clusterChannelInvokeTopic, eventPayload);
m_eventAdmin.postEvent(event);
+ //TODO exceptions
Object response = retrieveInvocationResponse(invocationIdentifier);
return response;
}
@@ -212,8 +214,8 @@
boolean isResponseRecieved = false;
boolean isResponseTimedOut = false;
Object response = null;
-
- //FIXME use blocking queue
+
+ // FIXME use blocking queue
while (!isResponseRecieved && !isResponseTimedOut) {
if (invocationResponseRecieved(invocationId)) {
response = retrieveInvocationResponseObject(invocationId);
Modified:
sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/remote/service/DiscoveryServiceImpl.java
==============================================================================
---
sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/remote/service/DiscoveryServiceImpl.java
(original)
+++
sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/remote/service/DiscoveryServiceImpl.java
Tue Jan 11 12:32:02 2011
@@ -86,7 +86,7 @@
* Life cycle
********************************************************/
- public synchronized void init() {
+ public synchronized void init() throws Exception {
@SuppressWarnings("unchecked")
Dictionary<String, Object> discoveryProps =
m_component.getServiceProperties();
@@ -137,17 +137,17 @@
m_discoveryEventHandlerComponent.setImplementation(new
DiscoveryEventHandler());
}
- public synchronized void destroy() {
+ public synchronized void destroy() throws Exception {
removeRemoteEndpointComponents();
}
- public synchronized void start() {
+ public synchronized void start() throws Exception {
m_logService.log(LogService.LOG_INFO, "Starting " + toString());
m_dependencyManager.add(m_discoveryEventHandlerComponent);
m_evenAdmin.postEvent(createDiscoveryEvent(null));
}
- public synchronized void stop() {
+ public synchronized void stop() throws Exception {
m_logService.log(LogService.LOG_INFO, "Stopping " + toString());
m_dependencyManager.remove(m_discoveryEventHandlerComponent);
}
Modified:
sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/remote/service/DistributionServiceImpl.java
==============================================================================
---
sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/remote/service/DistributionServiceImpl.java
(original)
+++
sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/remote/service/DistributionServiceImpl.java
Tue Jan 11 12:32:02 2011
@@ -91,7 +91,7 @@
* Lifecycle methods
********************************************************/
- public synchronized void init() {
+ public synchronized void init() throws Exception {
@SuppressWarnings("unchecked")
Dictionary<String, Object> distributionProps =
m_component.getServiceProperties();
@@ -155,18 +155,18 @@
m_distributionEventHandlerComponent.setImplementation(new
DistributionEventHandler());
}
- public synchronized void destroy() {
+ public synchronized void destroy() throws Exception {
removeLocalServiceEndPointComponents();
removeRemoteServiceEndPointComponents();
}
- public synchronized void start() {
+ public synchronized void start() throws Exception {
m_logService.log(LogService.LOG_INFO, "Starting " + toString());
m_dependencyManager.add(m_distributionEventHandlerComponent);
}
- public synchronized void stop() {
+ public synchronized void stop() throws Exception {
m_logService.log(LogService.LOG_INFO, "Stopping " + toString());
m_dependencyManager.remove(m_distributionEventHandlerComponent);
}
Modified:
sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/service/FabricManagerServiceImpl.java
==============================================================================
---
sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/service/FabricManagerServiceImpl.java
(original)
+++
sandbox/bdekruijff/fabric/src/main/java/org/amdatu/core/fabric/service/FabricManagerServiceImpl.java
Tue Jan 11 12:32:02 2011
@@ -22,10 +22,11 @@
import java.util.Map;
import java.util.concurrent.locks.ReentrantReadWriteLock;
+import org.amdatu.core.fabric.FabricException;
import org.amdatu.core.fabric.FabricManagerService;
import org.amdatu.core.fabric.cluster.ClusterChannelService;
import org.amdatu.core.fabric.cluster.internal.ClusterUtilities;
-import
org.amdatu.core.fabric.cluster.service.tribes.TribesClusterMemberServiceImpl;
+import
org.amdatu.core.fabric.cluster.service.tribes.TribesClusterChannelServiceImpl;
import org.amdatu.core.fabric.remote.DiscoveryService;
import org.amdatu.core.fabric.remote.DistributionService;
import org.amdatu.core.fabric.remote.service.DiscoveryServiceImpl;
@@ -62,7 +63,7 @@
* Lifecycle methods
********************************************************/
- public final synchronized void init() {
+ public final synchronized void init() throws Exception {
ServiceDependency logServiceDependency =
m_dependencyManager.createServiceDependency();
logServiceDependency.setService(LogService.class);
logServiceDependency.setRequired(true);
@@ -70,14 +71,14 @@
m_component.add(logServiceDependency);
}
- public final synchronized void destroy() {
+ public final synchronized void destroy() throws Exception {
}
- public synchronized void start() {
+ public synchronized void start() throws Exception {
m_logService.log(LogService.LOG_WARNING, "Amdatu Service Fabric
Manager started");
}
- public synchronized void stop() {
+ public synchronized void stop() throws Exception {
m_logService.log(LogService.LOG_WARNING, "Amdatu Service Fabric
Manager stopped");
}
@@ -85,7 +86,8 @@
* ManagedService methods
********************************************************/
- public synchronized void updated(Dictionary<String, Object> dictionary)
throws ConfigurationException {
+ public synchronized void updated(Dictionary<String, Object> dictionary)
throws FabricException,
+ ConfigurationException {
if (dictionary != null) {
String clusternamesValue = (String)
dictionary.get("org.amdatu.fabric.groupchannels");
if (clusternamesValue != null) {
@@ -97,7 +99,7 @@
String args = (String) dictionary.get("org.amdatu.fabric."
+ clusterName + ".tribes.args");
Dictionary<String, Object> properties = new
Hashtable<String, Object>();
properties
-
.put(TribesClusterMemberServiceImpl.CLUSTER_TRIBES_ARGS_PROP, args.split(" "));
+
.put(TribesClusterChannelServiceImpl.CLUSTER_TRIBES_ARGS_PROP, args.split(" "));
createClusterChannel(clusterGroupId, properties);
}
@@ -125,14 +127,11 @@
* FabricManagerService methods
********************************************************/
- public boolean createClusterChannel(String clusterChannelId,
Dictionary<String, Object> clusterChannelProperties) {
- if (!ClusterUtilities.isValidClusterChannelId(clusterChannelId)) {
- m_logService.log(LogService.LOG_ERROR, "Failed to create
clusterchannel. Invalid clusterChannelName: "
- + clusterChannelId);
- return false;
- }
+ public boolean createClusterChannel(String clusterChannelId,
Dictionary<String, Object> clusterChannelProperties)
+ throws FabricException {
+ checkIdParameter(clusterChannelId);
- Component clusterMemberComponent =
+ Component clusterChannelComponent =
m_dependencyManager
.createComponent()
.setInterface(ClusterChannelService.class.getName(),
clusterChannelProperties)
@@ -146,12 +145,13 @@
m_clusterMemberComponentsLock.writeLock().lock();
try {
if (m_clusterMemberComponents.containsKey(clusterChannelId)) {
+ m_logService.log(LogService.LOG_WARNING, "Overwriting existing
clusterchannel: " + clusterChannelId);
m_dependencyManager.remove(m_clusterMemberComponents
.remove(clusterChannelId));
}
- m_clusterMemberComponents.put(clusterChannelId,
clusterMemberComponent);
- m_dependencyManager.add(clusterMemberComponent);
+ m_clusterMemberComponents.put(clusterChannelId,
clusterChannelComponent);
+ m_dependencyManager.add(clusterChannelComponent);
return true;
}
finally {
@@ -159,12 +159,8 @@
}
}
- public boolean removeClusterChannel(String clusterChannelId) {
- if (!ClusterUtilities.isValidClusterChannelId(clusterChannelId)) {
- m_logService.log(LogService.LOG_ERROR, "Failed to remove
clusterchannel. Invalid clusterChannelName: "
- + clusterChannelId);
- return false;
- }
+ public boolean removeClusterChannel(String clusterChannelId) throws
FabricException {
+ checkIdParameter(clusterChannelId);
m_clusterMemberComponentsLock.writeLock().lock();
try {
@@ -179,18 +175,8 @@
}
}
- public boolean createDiscovery(String clusterChannelId, String
serviceGroupId) {
- if (!ClusterUtilities.isValidClusterChannelId(clusterChannelId)) {
- m_logService
- .log(LogService.LOG_ERROR, "Failed to create discovery.
Invalid clusterChannelName: "
- + clusterChannelId);
- return false;
- }
- if (!ClusterUtilities.isValidClusterChannelId(serviceGroupId)) {
- m_logService.log(LogService.LOG_ERROR, "Failed to create
discovery. Invalid serviceGroupName: "
- + serviceGroupId);
- return false;
- }
+ public boolean createDiscovery(String clusterChannelId, String
serviceGroupId) throws FabricException {
+ checkIdParameters(clusterChannelId, serviceGroupId);
Component discoveryComponent =
m_dependencyManager
@@ -206,6 +192,7 @@
m_discoveryComponentsLock.writeLock().lock();
try {
if (m_discoveryComponents.containsKey(getKey(clusterChannelId,
serviceGroupId))) {
+ m_logService.log(LogService.LOG_WARNING, "Overwriting existing
discovery: " + clusterChannelId);
m_dependencyManager.remove(m_discoveryComponents.remove(getKey(clusterChannelId,
serviceGroupId)));
}
@@ -218,18 +205,9 @@
}
}
- public boolean removeDiscovery(String clusterChannelId, String
serviceGroupId) {
- if (!ClusterUtilities.isValidClusterChannelId(clusterChannelId)) {
- m_logService
- .log(LogService.LOG_ERROR, "Failed to remove discovery.
Invalid clusterChannelName: "
- + clusterChannelId);
- return false;
- }
- if (!ClusterUtilities.isValidClusterChannelId(serviceGroupId)) {
- m_logService.log(LogService.LOG_ERROR, "Failed to remove
discovery. Invalid serviceGroupName: "
- + serviceGroupId);
- return false;
- }
+ public boolean removeDiscovery(String clusterChannelId, String
serviceGroupId) throws FabricException {
+ checkIdParameters(clusterChannelId, serviceGroupId);
+
m_discoveryComponentsLock.writeLock().lock();
try {
if (m_discoveryComponents.containsKey(getKey(clusterChannelId,
serviceGroupId))) {
@@ -244,17 +222,9 @@
}
}
- public boolean createDistribution(String clusterChannelId, String
serviceGroupId) {
- if (!ClusterUtilities.isValidClusterChannelId(clusterChannelId)) {
- m_logService
- .log(LogService.LOG_ERROR, "Failed to create distribution.
Invalid clustername: " + clusterChannelId);
- return false;
- }
- if (!ClusterUtilities.isValidClusterChannelId(serviceGroupId)) {
- m_logService.log(LogService.LOG_ERROR, "Failed to remove
distribution. Invalid servicegroupname: "
- + serviceGroupId);
- return false;
- }
+ public boolean createDistribution(String clusterChannelId, String
serviceGroupId) throws FabricException {
+ checkIdParameters(clusterChannelId, serviceGroupId);
+
Component distributionComponent =
m_dependencyManager
.createComponent()
@@ -268,6 +238,7 @@
m_distributionComponentsLock.writeLock().lock();
try {
if (m_distributionComponents.containsKey(getKey(clusterChannelId,
serviceGroupId))) {
+ m_logService.log(LogService.LOG_WARNING, "Overwriting existing
distribution: " + clusterChannelId);
m_dependencyManager.remove(m_distributionComponents.remove(getKey(clusterChannelId,
serviceGroupId)));
}
@@ -281,18 +252,9 @@
}
}
- public boolean removeDistribution(String clusterChannelId, String
serviceGroupId) {
- if (!ClusterUtilities.isValidClusterChannelId(clusterChannelId)) {
- m_logService
- .log(LogService.LOG_ERROR, "Failed to create distribution.
Invalid clusterChannelname: "
- + clusterChannelId);
- return false;
- }
- if (!ClusterUtilities.isValidClusterChannelId(serviceGroupId)) {
- m_logService.log(LogService.LOG_ERROR, "Failed to remove
distribution. Invalid serviceGroupName: "
- + serviceGroupId);
- return false;
- }
+ public boolean removeDistribution(String clusterChannelId, String
serviceGroupId) throws FabricException {
+ checkIdParameters(clusterChannelId, serviceGroupId);
+
m_distributionComponentsLock.writeLock().lock();
try {
if (m_distributionComponents.containsKey(getKey(clusterChannelId,
serviceGroupId))) {
@@ -311,6 +273,24 @@
* Private methods
********************************************************/
+ private void checkIdParameter(String clusterChannelId) throws
FabricException {
+ if (!ClusterUtilities.isValidClusterChannelId(clusterChannelId)) {
+ throw new FabricException("Invalid clusterChannelId: "
+ + clusterChannelId);
+ }
+ }
+
+ private void checkIdParameters(String clusterChannelId, String
serviceGroupId) throws FabricException {
+ if (!ClusterUtilities.isValidClusterChannelId(clusterChannelId)) {
+ throw new FabricException("Invalid clusterChannelId: "
+ + clusterChannelId);
+ }
+ if (!ClusterUtilities.isValidClusterChannelId(serviceGroupId)) {
+ throw new FabricException("Invalid serviceGroupId: "
+ + clusterChannelId);
+ }
+ }
+
private String getKey(String clusterChannelId, String serviceGroupId) {
return clusterChannelId + "#" + serviceGroupId;
}
@@ -331,7 +311,7 @@
}
public ClusterChannelService getInstance() {
- return new TribesClusterMemberServiceImpl(m_clusterChannelId,
m_clusterChannelProperties);
+ return new TribesClusterChannelServiceImpl(m_clusterChannelId,
m_clusterChannelProperties);
}
}