Author: timfox
Date: 2009-11-03 09:32:35 -0500 (Tue, 03 Nov 2009)
New Revision: 8192
Modified:
trunk/src/main/org/hornetq/core/server/group/GroupingHandler.java
trunk/src/main/org/hornetq/core/server/group/impl/GroupBinding.java
trunk/src/main/org/hornetq/core/server/group/impl/GroupingHandlerConfiguration.java
trunk/src/main/org/hornetq/core/server/group/impl/LocalGroupingHandler.java
trunk/src/main/org/hornetq/core/server/group/impl/Proposal.java
trunk/src/main/org/hornetq/core/server/group/impl/RemoteGroupingHandler.java
trunk/src/main/org/hornetq/core/server/group/impl/Response.java
Log:
reformatted code to fit code guidelines, also made responses map concurrent and declared
LHS as the interface not impl
Modified: trunk/src/main/org/hornetq/core/server/group/GroupingHandler.java
===================================================================
--- trunk/src/main/org/hornetq/core/server/group/GroupingHandler.java 2009-11-03 09:23:31
UTC (rev 8191)
+++ trunk/src/main/org/hornetq/core/server/group/GroupingHandler.java 2009-11-03 14:32:35
UTC (rev 8192)
@@ -12,12 +12,11 @@
*/
package org.hornetq.core.server.group;
-import org.hornetq.utils.SimpleString;
+import org.hornetq.core.management.NotificationListener;
+import org.hornetq.core.server.group.impl.GroupBinding;
import org.hornetq.core.server.group.impl.Proposal;
import org.hornetq.core.server.group.impl.Response;
-import org.hornetq.core.server.group.impl.GroupBinding;
-import org.hornetq.core.management.NotificationListener;
-import org.hornetq.core.management.Notification;
+import org.hornetq.utils.SimpleString;
/**
* @author <a href="mailto:andy.taylor@jboss.org">Andy Taylor</a>
Modified: trunk/src/main/org/hornetq/core/server/group/impl/GroupBinding.java
===================================================================
--- trunk/src/main/org/hornetq/core/server/group/impl/GroupBinding.java 2009-11-03
09:23:31 UTC (rev 8191)
+++ trunk/src/main/org/hornetq/core/server/group/impl/GroupBinding.java 2009-11-03
14:32:35 UTC (rev 8192)
@@ -28,13 +28,13 @@
private final SimpleString clusterName;
- public GroupBinding(SimpleString groupId, SimpleString clusterName)
+ public GroupBinding(final SimpleString groupId, final SimpleString clusterName)
{
this.groupId = groupId;
this.clusterName = clusterName;
}
- public GroupBinding(long id, SimpleString groupId, SimpleString clusterName)
+ public GroupBinding(final long id, final SimpleString groupId, final SimpleString
clusterName)
{
this.id = id;
this.groupId = groupId;
@@ -46,7 +46,7 @@
return id;
}
- public void setId(long id)
+ public void setId(final long id)
{
this.id = id;
}
Modified:
trunk/src/main/org/hornetq/core/server/group/impl/GroupingHandlerConfiguration.java
===================================================================
---
trunk/src/main/org/hornetq/core/server/group/impl/GroupingHandlerConfiguration.java 2009-11-03
09:23:31 UTC (rev 8191)
+++
trunk/src/main/org/hornetq/core/server/group/impl/GroupingHandlerConfiguration.java 2009-11-03
14:32:35 UTC (rev 8192)
@@ -31,12 +31,15 @@
public static final int DEFAULT_TIMEOUT = 5000;
- public GroupingHandlerConfiguration(final SimpleString name, final TYPE type,
SimpleString address)
+ public GroupingHandlerConfiguration(final SimpleString name, final TYPE type, final
SimpleString address)
{
this(name, type, address, DEFAULT_TIMEOUT);
}
- public GroupingHandlerConfiguration(final SimpleString name, final TYPE type,
SimpleString address, int timeout)
+ public GroupingHandlerConfiguration(final SimpleString name,
+ final TYPE type,
+ final SimpleString address,
+ final int timeout)
{
this.type = type;
this.name = name;
@@ -66,12 +69,11 @@
public enum TYPE
{
- LOCAL("LOCAL"),
- REMOTE("REMOTE");
+ LOCAL("LOCAL"), REMOTE("REMOTE");
private String type;
- TYPE(String type)
+ TYPE(final String type)
{
this.type = type;
}
Modified: trunk/src/main/org/hornetq/core/server/group/impl/LocalGroupingHandler.java
===================================================================
--- trunk/src/main/org/hornetq/core/server/group/impl/LocalGroupingHandler.java 2009-11-03
09:23:31 UTC (rev 8191)
+++ trunk/src/main/org/hornetq/core/server/group/impl/LocalGroupingHandler.java 2009-11-03
14:32:35 UTC (rev 8192)
@@ -36,19 +36,25 @@
{
private static Logger log = Logger.getLogger(LocalGroupingHandler.class);
- private ConcurrentHashMap<SimpleString, GroupBinding> map = new
ConcurrentHashMap<SimpleString, GroupBinding>();
+ private final ConcurrentHashMap<SimpleString, GroupBinding> map = new
ConcurrentHashMap<SimpleString, GroupBinding>();
- private ConcurrentHashMap<SimpleString, List<GroupBinding>> groupMap = new
ConcurrentHashMap<SimpleString, List<GroupBinding>>();
+ private final ConcurrentHashMap<SimpleString, List<GroupBinding>> groupMap
= new ConcurrentHashMap<SimpleString, List<GroupBinding>>();
private final SimpleString name;
private final ManagementService managementService;
- private SimpleString address;
- private StorageManager storageManager;
- private int timeout;
+ private final SimpleString address;
- public LocalGroupingHandler(final ManagementService managementService, final
SimpleString name, final SimpleString address, StorageManager storageManager, int
timeout)
+ private final StorageManager storageManager;
+
+ private final int timeout;
+
+ public LocalGroupingHandler(final ManagementService managementService,
+ final SimpleString name,
+ final SimpleString address,
+ final StorageManager storageManager,
+ final int timeout)
{
this.managementService = managementService;
this.name = name;
@@ -62,8 +68,7 @@
return name;
}
-
- public Response propose(Proposal proposal) throws Exception
+ public Response propose(final Proposal proposal) throws Exception
{
log.info("proposing proposal " + proposal);
if (proposal.getClusterName() == null)
@@ -77,7 +82,7 @@
groupBinding.setId(storageManager.generateUniqueID());
List<GroupBinding> newList = new ArrayList<GroupBinding>();
List<GroupBinding> oldList =
groupMap.putIfAbsent(groupBinding.getClusterName(), newList);
- if(oldList != null)
+ if (oldList != null)
{
newList = oldList;
}
@@ -96,11 +101,11 @@
}
}
- public void proposed(Response response) throws Exception
+ public void proposed(final Response response) throws Exception
{
}
- public void send(Response response, int distance) throws Exception
+ public void send(final Response response, final int distance) throws Exception
{
TypedProperties props = new TypedProperties();
props.putStringProperty(ManagementHelper.HDR_PROPOSAL_GROUP_ID,
response.getGroupId());
@@ -113,35 +118,36 @@
managementService.sendNotification(notification);
}
- public Response receive(Proposal proposal, int distance) throws Exception
+ public Response receive(final Proposal proposal, final int distance) throws Exception
{
log.trace("received proposal " + proposal);
return propose(proposal);
}
- public void addGroupBinding(GroupBinding groupBinding)
+ public void addGroupBinding(final GroupBinding groupBinding)
{
map.put(groupBinding.getGroupId(), groupBinding);
List<GroupBinding> newList = new ArrayList<GroupBinding>();
List<GroupBinding> oldList =
groupMap.putIfAbsent(groupBinding.getClusterName(), newList);
- if(oldList != null)
+ if (oldList != null)
{
newList = oldList;
}
newList.add(groupBinding);
}
- public Response getProposal(SimpleString fullID)
+ public Response getProposal(final SimpleString fullID)
{
GroupBinding original = map.get(fullID);
return original == null ? null : new Response(fullID, original.getClusterName());
}
- public void onNotification(Notification notification)
+ public void onNotification(final Notification notification)
{
if (notification.getType() == NotificationType.BINDING_REMOVED)
{
- SimpleString clusterName = (SimpleString)
notification.getProperties().getProperty(ManagementHelper.HDR_CLUSTER_NAME);
+ SimpleString clusterName = (SimpleString)notification.getProperties()
+
.getProperty(ManagementHelper.HDR_CLUSTER_NAME);
List<GroupBinding> list = groupMap.remove(clusterName);
if (list != null)
{
@@ -164,4 +170,3 @@
}
}
}
-
Modified: trunk/src/main/org/hornetq/core/server/group/impl/Proposal.java
===================================================================
--- trunk/src/main/org/hornetq/core/server/group/impl/Proposal.java 2009-11-03 09:23:31
UTC (rev 8191)
+++ trunk/src/main/org/hornetq/core/server/group/impl/Proposal.java 2009-11-03 14:32:35
UTC (rev 8192)
@@ -25,7 +25,7 @@
private final SimpleString clusterName;
- public Proposal(SimpleString groupId, SimpleString clusterName)
+ public Proposal(final SimpleString groupId, final SimpleString clusterName)
{
this.clusterName = clusterName;
this.groupId = groupId;
@@ -47,4 +47,3 @@
return getGroupId() + ":" + clusterName;
}
}
-
Modified: trunk/src/main/org/hornetq/core/server/group/impl/RemoteGroupingHandler.java
===================================================================
---
trunk/src/main/org/hornetq/core/server/group/impl/RemoteGroupingHandler.java 2009-11-03
09:23:31 UTC (rev 8191)
+++
trunk/src/main/org/hornetq/core/server/group/impl/RemoteGroupingHandler.java 2009-11-03
14:32:35 UTC (rev 8192)
@@ -12,26 +12,26 @@
*/
package org.hornetq.core.server.group.impl;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.Condition;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+import java.util.logging.Logger;
+
+import org.hornetq.core.client.management.impl.ManagementHelper;
+import org.hornetq.core.management.ManagementService;
+import org.hornetq.core.management.Notification;
import org.hornetq.core.management.NotificationType;
-import org.hornetq.core.management.Notification;
-import org.hornetq.core.management.ManagementService;
-import org.hornetq.core.client.management.impl.ManagementHelper;
import org.hornetq.core.postoffice.BindingType;
import org.hornetq.core.server.group.GroupingHandler;
import org.hornetq.utils.SimpleString;
import org.hornetq.utils.TypedProperties;
-import java.util.logging.Logger;
-import java.util.Map;
-import java.util.HashMap;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
-import java.util.concurrent.locks.Condition;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.ConcurrentHashMap;
-
/**
* A remote Grouping handler. This will use management notifications to communicate with
the node that has the Local
* Grouping handler to make proposals.
@@ -48,7 +48,7 @@
private final SimpleString address;
- private Map<SimpleString, Response> responses = new HashMap<SimpleString,
Response>();
+ private final Map<SimpleString, Response> responses = new
HashMap<SimpleString, Response>();
private final Lock lock = new ReentrantLock();
@@ -56,9 +56,12 @@
private final int timeout;
- private ConcurrentHashMap<SimpleString, List<SimpleString>> groupMap = new
ConcurrentHashMap<SimpleString, List<SimpleString>>();
+ private final ConcurrentHashMap<SimpleString, List<SimpleString>> groupMap
= new ConcurrentHashMap<SimpleString, List<SimpleString>>();
- public RemoteGroupingHandler(final ManagementService managementService, final
SimpleString name, final SimpleString address, int timeout)
+ public RemoteGroupingHandler(final ManagementService managementService,
+ final SimpleString name,
+ final SimpleString address,
+ final int timeout)
{
this.name = name;
this.address = address;
@@ -73,9 +76,9 @@
public Response propose(final Proposal proposal) throws Exception
{
- //sanity check in case it is already selected
+ // sanity check in case it is already selected
Response response = responses.get(proposal.getGroupId());
- if( response != null)
+ if (response != null)
{
return response;
}
@@ -111,19 +114,19 @@
{
lock.unlock();
}
- if(response == null)
+ if (response == null)
{
throw new IllegalStateException("no response received from group handler
for " + proposal.getGroupId());
}
return response;
}
- public Response getProposal(SimpleString fullID)
+ public Response getProposal(final SimpleString fullID)
{
return responses.get(fullID);
}
- public void proposed(Response response) throws Exception
+ public void proposed(final Response response) throws Exception
{
try
{
@@ -131,7 +134,7 @@
responses.put(response.getGroupId(), response);
List<SimpleString> newList = new ArrayList<SimpleString>();
List<SimpleString> oldList =
groupMap.putIfAbsent(response.getChosenClusterName(), newList);
- if(oldList != null)
+ if (oldList != null)
{
newList = oldList;
}
@@ -144,7 +147,7 @@
}
}
- public Response receive(Proposal proposal, int distance) throws Exception
+ public Response receive(final Proposal proposal, final int distance) throws Exception
{
TypedProperties props = new TypedProperties();
props.putStringProperty(ManagementHelper.HDR_PROPOSAL_GROUP_ID,
proposal.getGroupId());
@@ -157,29 +160,30 @@
return null;
}
- public void send(Response response, int distance) throws Exception
+ public void send(final Response response, final int distance) throws Exception
{
- //NO-OP
+ // NO-OP
}
- public void addGroupBinding(GroupBinding groupBinding)
+ public void addGroupBinding(final GroupBinding groupBinding)
{
- //NO-OP
+ // NO-OP
}
- public void onNotification(Notification notification)
+ public void onNotification(final Notification notification)
{
- //removing the groupid if the binding has been removed
- if(notification.getType() == NotificationType.BINDING_REMOVED)
+ // removing the groupid if the binding has been removed
+ if (notification.getType() == NotificationType.BINDING_REMOVED)
{
- SimpleString clusterName = (SimpleString)
notification.getProperties().getProperty(ManagementHelper.HDR_CLUSTER_NAME);
+ SimpleString clusterName = (SimpleString)notification.getProperties()
+
.getProperty(ManagementHelper.HDR_CLUSTER_NAME);
groupMap.remove(clusterName);
List<SimpleString> list = groupMap.remove(clusterName);
if (list != null)
{
for (SimpleString val : list)
{
- if(val != null)
+ if (val != null)
{
responses.remove(val);
}
@@ -189,4 +193,3 @@
}
}
}
-
Modified: trunk/src/main/org/hornetq/core/server/group/impl/Response.java
===================================================================
--- trunk/src/main/org/hornetq/core/server/group/impl/Response.java 2009-11-03 09:23:31
UTC (rev 8191)
+++ trunk/src/main/org/hornetq/core/server/group/impl/Response.java 2009-11-03 14:32:35
UTC (rev 8192)
@@ -27,17 +27,17 @@
private final SimpleString alternativeClusterName;
- private SimpleString groupId;
+ private final SimpleString groupId;
- public Response(SimpleString groupId, SimpleString clusterName)
+ public Response(final SimpleString groupId, final SimpleString clusterName)
{
this(groupId, clusterName, null);
}
- public Response(SimpleString groupId, SimpleString clusterName, SimpleString
alternativeClusterName)
+ public Response(final SimpleString groupId, final SimpleString clusterName, final
SimpleString alternativeClusterName)
{
this.groupId = groupId;
- this.accepted = alternativeClusterName == null;
+ accepted = alternativeClusterName == null;
this.clusterName = clusterName;
this.alternativeClusterName = alternativeClusterName;
}
@@ -59,13 +59,17 @@
public SimpleString getChosenClusterName()
{
- return alternativeClusterName != null? alternativeClusterName : clusterName;
+ return alternativeClusterName != null ? alternativeClusterName : clusterName;
}
@Override
public String toString()
{
- return "accepted = " + accepted + " clusterName = " +
clusterName + " alternativeClusterName = " + alternativeClusterName;
+ return "accepted = " + accepted +
+ " clusterName = " +
+ clusterName +
+ " alternativeClusterName = " +
+ alternativeClusterName;
}
public SimpleString getGroupId()