diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fc368f3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,16 @@ +# Eclipse +.classpath +.project +.settings/ + +# Intellij +.idea/ +*.iml +*.iws + +# Mac +.DS_Store + +# Maven +log/ +target/ diff --git a/README.md b/README.md index 690e08d..bf1d73d 100644 --- a/README.md +++ b/README.md @@ -1,66 +1,79 @@ - -Gossip protocol is a method for a group of nodes to discover and check the livelyness of a cluster. More information can be found at http://en.wikipedia.org/wiki/Gossip_protocol. - -The original implementation was forked from https://code.google.com/p/java-gossip/. Several bug fixes and changes have already been added. - -Usage ------ - -To gossip you need one or more seed nodes. Seed is just a list of places to initially connect to. - - GossipSettings settings = new GossipSettings(); - int seedNodes = 3; - ArrayList startupMembers = new ArrayList(); - for (int i = 1; i < seedNodes+1; ++i) { - startupMembers.add(new RemoteGossipMember("127.0.0." + i, 2000, i + "")); - } - -Here we start five gossip processes and check that they discover each other. (Normally these are on different hosts but here we give each process a distinct local ip. - - ArrayList clients = new ArrayList(); - int clusterMembers = 5; - for (int i = 1; i < clusterMembers+1; ++i) { - GossipService gossipService = new GossipService("127.0.0." + i, 2000, i + "", - LogLevel.DEBUG, startupMembers, settings, null); - clients.add(gossipService); - gossipService.start(); - } - -Later we can check that the nodes discover each other - - Thread.sleep(10000); - for (int i = 0; i < clusterMembers; ++i) { - Assert.assertEquals(4, clients.get(i).get_gossipManager().getMemberList().size()); - } - -Event Listener ------- - -The status can be polled using the getters that return immutable lists. - - List getMemberList() - public List getDeadList() - -Users can also attach an event listener: - - GossipService gossipService = new GossipService("127.0.0." + i, 2000, i + "", LogLevel.DEBUG, - startupMembers, settings, - new GossipListener(){ - @Override - public void gossipEvent(GossipMember member, GossipState state) { - System.out.println(member+" "+ state); - } - }); - - -Maven ------- - - -You can get this software from maven central. - - - io.teknek - gossip - ${pick_the_latest_version} - +# Gossip + +Gossip protocol is a method for a group of nodes to discover and check the liveliness of a cluster. More information can be found at http://en.wikipedia.org/wiki/Gossip_protocol. + +The original implementation was forked from https://code.google.com/p/java-gossip/. Several bug fixes and changes have already been added. + +Usage +----- + +To gossip you need one or more seed nodes. Seed is just a list of places to initially connect to. + +```java + GossipSettings settings = new GossipSettings(); + int seedNodes = 3; + List startupMembers = new ArrayList<>(); + for (int i = 1; i < seedNodes+1; ++i) { + startupMembers.add(new RemoteGossipMember("127.0.0." + i, 2000, i + "")); + } +``` + +Here we start five gossip processes and check that they discover each other. (Normally these are on different hosts but here we give each process a distinct local ip. + +```java + List clients = new ArrayList<>(); + int clusterMembers = 5; + for (int i = 1; i < clusterMembers+1; ++i) { + GossipService gossipService = new GossipService("127.0.0." + i, 2000, i + "", + LogLevel.DEBUG, startupMembers, settings, null); + clients.add(gossipService); + gossipService.start(); + } +``` + +Later we can check that the nodes discover each other + +```java + Thread.sleep(10000); + for (int i = 0; i < clusterMembers; ++i) { + Assert.assertEquals(4, clients.get(i).get_gossipManager().getMemberList().size()); + } +``` + +Event Listener +------ + +The status can be polled using the getters that return immutable lists. + +```java + List getMemberList() + public List getDeadList() +``` + +Users can also attach an event listener: + +```java + GossipService gossipService = new GossipService("127.0.0." + i, 2000, i + "", LogLevel.DEBUG, + startupMembers, settings, + new GossipListener(){ + @Override + public void gossipEvent(GossipMember member, GossipState state) { + System.out.println(member+" "+ state); + } + }); +``` + + +Maven +------ + + +You can get this software from maven central. + +```xml + + io.teknek + gossip + ${pick_the_latest_version} + +``` diff --git a/src/main/java/com/google/code/gossip/GossipMember.java b/src/main/java/com/google/code/gossip/GossipMember.java index 50e9af3..bf60820 100644 --- a/src/main/java/com/google/code/gossip/GossipMember.java +++ b/src/main/java/com/google/code/gossip/GossipMember.java @@ -7,20 +7,20 @@ import org.json.JSONObject; /** * A abstract class representing a gossip member. - * + * * @author joshclemm, harmenw */ public abstract class GossipMember implements Comparable{ - + public static final String JSON_HOST = "host"; public static final String JSON_PORT = "port"; public static final String JSON_HEARTBEAT = "heartbeat"; public static final String JSON_ID = "id"; - protected String _host; - protected int _port; + protected final String _host; + protected final int _port; protected int _heartbeat; protected String _id; - + /** * Constructor. * @param host The hostname or IP address. @@ -33,7 +33,7 @@ public abstract class GossipMember implements Comparable{ _id = id; _heartbeat = heartbeat; } - + /** * Get the hostname or IP address of the remote gossip member. * @return The hostname or IP address. @@ -41,7 +41,7 @@ public abstract class GossipMember implements Comparable{ public String getHost() { return _host; } - + /** * Get the port number of the remote gossip member. * @return The port number. @@ -65,7 +65,7 @@ public abstract class GossipMember implements Comparable{ public int getHeartbeat() { return _heartbeat; } - + /** * Set the heartbeat of this gossip member. * @param heartbeat The new heartbeat. @@ -73,8 +73,8 @@ public abstract class GossipMember implements Comparable{ public void setHeartbeat(int heartbeat) { this._heartbeat = heartbeat; } - - + + public String getId() { return _id; } @@ -86,7 +86,7 @@ public abstract class GossipMember implements Comparable{ public String toString() { return "Member [address=" + getAddress() + ", id=" + _id + ", heartbeat=" + _heartbeat + "]"; } - + /** * @see java.lang.Object#hashCode() */ @@ -136,7 +136,7 @@ public abstract class GossipMember implements Comparable{ throw new RuntimeException(e); } } - + public int compareTo(GossipMember other){ return this.getAddress().compareTo(other.getAddress()); } diff --git a/src/main/java/com/google/code/gossip/GossipRunner.java b/src/main/java/com/google/code/gossip/GossipRunner.java index e452f93..8d856cd 100644 --- a/src/main/java/com/google/code/gossip/GossipRunner.java +++ b/src/main/java/com/google/code/gossip/GossipRunner.java @@ -7,7 +7,6 @@ import java.io.IOException; import org.json.JSONException; public class GossipRunner { - private StartupSettings _settings; public static void main(String[] args) { File configFile; @@ -26,9 +25,9 @@ public class GossipRunner { if (configFile != null && configFile.exists()) { try { System.out.println("Parsing the configuration file..."); - _settings = StartupSettings.fromJSONFile(configFile); + StartupSettings _settings = StartupSettings.fromJSONFile(configFile); GossipService gossipService = new GossipService(_settings); - System.out.println("Gossip service successfully inialized, let's start it..."); + System.out.println("Gossip service successfully initialized, let's start it..."); gossipService.start(); } catch (FileNotFoundException e) { System.err.println("The given file is not found!"); diff --git a/src/main/java/com/google/code/gossip/GossipService.java b/src/main/java/com/google/code/gossip/GossipService.java index 1f05c25..707937f 100644 --- a/src/main/java/com/google/code/gossip/GossipService.java +++ b/src/main/java/com/google/code/gossip/GossipService.java @@ -1,9 +1,9 @@ package com.google.code.gossip; import java.net.InetAddress; -import java.net.SocketException; import java.net.UnknownHostException; -import java.util.ArrayList; +import java.util.List; + import org.apache.log4j.Logger; import com.google.code.gossip.event.GossipListener; @@ -12,7 +12,7 @@ import com.google.code.gossip.manager.random.RandomGossipManager; /** * This object represents the service which is responsible for gossiping with other gossip members. - * + * * @author joshclemm, harmenw */ public class GossipService { @@ -23,7 +23,7 @@ public class GossipService { /** * Constructor with the default settings. - * + * * @throws InterruptedException * @throws UnknownHostException */ @@ -36,13 +36,12 @@ public class GossipService { /** * Setup the client's lists, gossiping parameters, and parse the startup config file. - * - * @throws SocketException + * * @throws InterruptedException * @throws UnknownHostException */ public GossipService(String ipAddress, int port, String id, int logLevel, - ArrayList gossipMembers, GossipSettings settings, GossipListener listener) + List gossipMembers, GossipSettings settings, GossipListener listener) throws InterruptedException, UnknownHostException { _gossipManager = new RandomGossipManager(ipAddress, port, id, settings, gossipMembers, listener); } diff --git a/src/main/java/com/google/code/gossip/GossipTimeoutTimer.java b/src/main/java/com/google/code/gossip/GossipTimeoutTimer.java index c3613fb..3df8041 100644 --- a/src/main/java/com/google/code/gossip/GossipTimeoutTimer.java +++ b/src/main/java/com/google/code/gossip/GossipTimeoutTimer.java @@ -9,20 +9,20 @@ import javax.management.timer.Timer; * This object represents a timer for a gossip member. When the timer has elapsed without being * reset in the meantime, it will inform the GossipService about this who in turn will put the * gossip member on the dead list, because it is apparantly not alive anymore. - * + * * @author joshclemm, harmenw */ public class GossipTimeoutTimer extends Timer { - private long _sleepTime; - private LocalGossipMember _source; + private final long _sleepTime; + private final LocalGossipMember _source; /** * Constructor. Creates a reset-able timer that wakes up after millisecondsSleepTime. - * + * * @param millisecondsSleepTime * The time for this timer to wait before an event. - * @param service + * @param notificationListener * @param member */ public GossipTimeoutTimer(long millisecondsSleepTime, NotificationListener notificationListener, @@ -51,7 +51,7 @@ public class GossipTimeoutTimer extends Timer { /** * Adds a new wake-up time for this timer. - * + * * @param milliseconds */ private void setWakeupTime(long milliseconds) { diff --git a/src/main/java/com/google/code/gossip/LocalGossipMember.java b/src/main/java/com/google/code/gossip/LocalGossipMember.java index 6d040ae..1c651a9 100644 --- a/src/main/java/com/google/code/gossip/LocalGossipMember.java +++ b/src/main/java/com/google/code/gossip/LocalGossipMember.java @@ -5,24 +5,24 @@ import javax.management.NotificationListener; /** * This object represent a gossip member with the properties known locally. These objects are stored * in the local list of gossip member.s - * + * * @author harmenw */ public class LocalGossipMember extends GossipMember { /** The timeout timer for this gossip member. */ - private transient GossipTimeoutTimer timeoutTimer; + private final transient GossipTimeoutTimer timeoutTimer; /** * Constructor. - * - * @param host + * + * @param hostname * The hostname or IP address. * @param port * The port number. + * @param id * @param heartbeat * The current heartbeat. - * @param gossipService - * The GossipService object. + * @param notificationListener * @param cleanupTimeout * The cleanup timeout for this gossip member. */ diff --git a/src/main/java/com/google/code/gossip/RemoteGossipMember.java b/src/main/java/com/google/code/gossip/RemoteGossipMember.java index f42f699..5a95004 100644 --- a/src/main/java/com/google/code/gossip/RemoteGossipMember.java +++ b/src/main/java/com/google/code/gossip/RemoteGossipMember.java @@ -3,15 +3,15 @@ package com.google.code.gossip; /** * The object represents a gossip member with the properties as received from a remote gossip * member. - * + * * @author harmenw */ public class RemoteGossipMember extends GossipMember { /** * Constructor. - * - * @param host + * + * @param hostname * The hostname or IP address. * @param port * The port number. @@ -24,8 +24,8 @@ public class RemoteGossipMember extends GossipMember { /** * Construct a RemoteGossipMember with a heartbeat of 0. - * - * @param host + * + * @param hostname * The hostname or IP address. * @param port * The port number. diff --git a/src/main/java/com/google/code/gossip/StartupSettings.java b/src/main/java/com/google/code/gossip/StartupSettings.java index 2e558ef..a377f29 100644 --- a/src/main/java/com/google/code/gossip/StartupSettings.java +++ b/src/main/java/com/google/code/gossip/StartupSettings.java @@ -6,6 +6,7 @@ import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; +import java.util.List; import org.json.JSONArray; import org.json.JSONException; @@ -13,7 +14,7 @@ import org.json.JSONObject; /** * This object represents the settings used when starting the gossip service. - * + * * @author harmenw */ public class StartupSettings { @@ -25,14 +26,14 @@ public class StartupSettings { private int _logLevel; /** The gossip settings used at startup. */ - private GossipSettings _gossipSettings; + private final GossipSettings _gossipSettings; /** The list with gossip members to start with. */ - private ArrayList _gossipMembers; + private final List _gossipMembers; /** * Constructor. - * + * * @param port * The port to start the service on. */ @@ -42,7 +43,7 @@ public class StartupSettings { /** * Constructor. - * + * * @param port * The port to start the service on. */ @@ -50,12 +51,12 @@ public class StartupSettings { _port = port; _logLevel = logLevel; _gossipSettings = gossipSettings; - _gossipMembers = new ArrayList(); + _gossipMembers = new ArrayList<>(); } /** * Set the port of the gossip service. - * + * * @param port * The port for the gossip service. */ @@ -65,7 +66,7 @@ public class StartupSettings { /** * Get the port for the gossip service. - * + * * @return The port of the gossip service. */ public int getPort() { @@ -74,7 +75,7 @@ public class StartupSettings { /** * Set the log level of the gossip service. - * + * * @param logLevel * The log level({LogLevel}). */ @@ -84,7 +85,7 @@ public class StartupSettings { /** * Get the log level of the gossip service. - * + * * @return The log level. */ public int getLogLevel() { @@ -93,7 +94,7 @@ public class StartupSettings { /** * Get the GossipSettings. - * + * * @return The GossipSettings object. */ public GossipSettings getGossipSettings() { @@ -102,7 +103,7 @@ public class StartupSettings { /** * Add a gossip member to the list of members to start with. - * + * * @param member * The member to add. */ @@ -112,16 +113,16 @@ public class StartupSettings { /** * Get the list with gossip members. - * + * * @return The gossip members. */ - public ArrayList getGossipMembers() { + public List getGossipMembers() { return _gossipMembers; } /** * Parse the settings for the gossip service from a JSON file. - * + * * @param jsonFile * The file object which refers to the JSON config file. * @return The StartupSettings object with the settings from the config file. diff --git a/src/main/java/com/google/code/gossip/event/GossipState.java b/src/main/java/com/google/code/gossip/event/GossipState.java index 9e5db5f..bea5924 100644 --- a/src/main/java/com/google/code/gossip/event/GossipState.java +++ b/src/main/java/com/google/code/gossip/event/GossipState.java @@ -2,8 +2,8 @@ package com.google.code.gossip.event; public enum GossipState { UP("up"), DOWN("down"); - private String state; - + private final String state; + private GossipState(String state){ this.state = state; } diff --git a/src/main/java/com/google/code/gossip/examples/GossipExample.java b/src/main/java/com/google/code/gossip/examples/GossipExample.java index ffcf7ca..f5ddfea 100644 --- a/src/main/java/com/google/code/gossip/examples/GossipExample.java +++ b/src/main/java/com/google/code/gossip/examples/GossipExample.java @@ -3,6 +3,7 @@ package com.google.code.gossip.examples; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.ArrayList; +import java.util.List; import com.google.code.gossip.GossipMember; import com.google.code.gossip.GossipService; @@ -13,7 +14,7 @@ import com.google.code.gossip.RemoteGossipMember; /** * This class is an example of how one could use the gossip service. Here we start multiple gossip * clients on this host as specified in the config file. - * + * * @author harmenw */ public class GossipExample extends Thread { @@ -41,14 +42,14 @@ public class GossipExample extends Thread { try { GossipSettings settings = new GossipSettings(); - ArrayList clients = new ArrayList(); + List clients = new ArrayList<>(); // Get my ip address. String myIpAddress = InetAddress.getLocalHost().getHostAddress(); // Create the gossip members and put them in a list and give them a port number starting with // 2000. - ArrayList startupMembers = new ArrayList(); + List startupMembers = new ArrayList<>(); for (int i = 0; i < NUMBER_OF_CLIENTS; ++i) { startupMembers.add(new RemoteGossipMember(myIpAddress, 2000 + i, "")); } diff --git a/src/main/java/com/google/code/gossip/manager/ActiveGossipThread.java b/src/main/java/com/google/code/gossip/manager/ActiveGossipThread.java index 5823c74..1dd8837 100644 --- a/src/main/java/com/google/code/gossip/manager/ActiveGossipThread.java +++ b/src/main/java/com/google/code/gossip/manager/ActiveGossipThread.java @@ -14,7 +14,7 @@ import com.google.code.gossip.LocalGossipMember; */ abstract public class ActiveGossipThread implements Runnable { - private GossipManager _gossipManager; + private final GossipManager _gossipManager; private final AtomicBoolean _keepRunning; @@ -50,7 +50,7 @@ abstract public class ActiveGossipThread implements Runnable { /** * Abstract method which should be implemented by a subclass. This method should return a member * of the list to gossip with. - * + * * @param memberList * The list of members which are stored in the local list of members. * @return The chosen LocalGossipMember to gossip with. diff --git a/src/main/java/com/google/code/gossip/manager/GossipManager.java b/src/main/java/com/google/code/gossip/manager/GossipManager.java index 197d624..4edc426 100644 --- a/src/main/java/com/google/code/gossip/manager/GossipManager.java +++ b/src/main/java/com/google/code/gossip/manager/GossipManager.java @@ -24,24 +24,24 @@ import com.google.code.gossip.event.GossipListener; import com.google.code.gossip.event.GossipState; public abstract class GossipManager extends Thread implements NotificationListener { - + public static final Logger LOGGER = Logger.getLogger(GossipManager.class); public static final int MAX_PACKET_SIZE = 102400; - private ConcurrentSkipListMap members; - private LocalGossipMember _me; - private GossipSettings _settings; - private AtomicBoolean _gossipServiceRunning; - private ExecutorService _gossipThreadExecutor; - private Class _passiveGossipThreadClass; - private PassiveGossipThread passiveGossipThread; - private Class _activeGossipThreadClass; + private final ConcurrentSkipListMap members; + private final LocalGossipMember _me; + private final GossipSettings _settings; + private final AtomicBoolean _gossipServiceRunning; + private final Class _passiveGossipThreadClass; + private final Class _activeGossipThreadClass; + private final GossipListener listener; private ActiveGossipThread activeGossipThread; - private GossipListener listener; + private PassiveGossipThread passiveGossipThread; + private ExecutorService _gossipThreadExecutor; public GossipManager(Class passiveGossipThreadClass, Class activeGossipThreadClass, String address, int port, - String id, GossipSettings settings, ArrayList gossipMembers, + String id, GossipSettings settings, List gossipMembers, GossipListener listener) { _passiveGossipThreadClass = passiveGossipThreadClass; _activeGossipThreadClass = activeGossipThreadClass; @@ -87,7 +87,7 @@ public abstract class GossipManager extends Thread implements NotificationListen listener.gossipEvent(m, GossipState.UP); } } - + public GossipSettings getSettings() { return _settings; } @@ -105,7 +105,7 @@ public abstract class GossipManager extends Thread implements NotificationListen public LocalGossipMember getMyself() { return _me; } - + public List getDeadList() { List up = new ArrayList<>(); for (Entry entry : members.entrySet()){ @@ -119,8 +119,6 @@ public abstract class GossipManager extends Thread implements NotificationListen /** * Starts the client. Specifically, start the various cycles for this protocol. Start the gossip * thread and start the receiver thread. - * - * @throws InterruptedException */ public void run() { for (LocalGossipMember member : members.keySet()) { @@ -160,7 +158,7 @@ public abstract class GossipManager extends Thread implements NotificationListen activeGossipThread.shutdown(); try { boolean result = _gossipThreadExecutor.awaitTermination(1000, TimeUnit.MILLISECONDS); - if (result == false){ + if (!result){ LOGGER.error("executor shutdown timed out"); } } catch (InterruptedException e) { diff --git a/src/main/java/com/google/code/gossip/manager/PassiveGossipThread.java b/src/main/java/com/google/code/gossip/manager/PassiveGossipThread.java index 314432a..02a6be8 100644 --- a/src/main/java/com/google/code/gossip/manager/PassiveGossipThread.java +++ b/src/main/java/com/google/code/gossip/manager/PassiveGossipThread.java @@ -26,13 +26,13 @@ import com.google.code.gossip.RemoteGossipMember; * determine the incoming message. */ abstract public class PassiveGossipThread implements Runnable { - + public static final Logger LOGGER = Logger.getLogger(PassiveGossipThread.class); /** The socket used for the passive thread of the gossip service. */ private DatagramSocket _server; - private GossipManager _gossipManager; + private final GossipManager _gossipManager; private AtomicBoolean _keepRunning; @@ -73,7 +73,7 @@ abstract public class PassiveGossipThread implements Runnable { // A package larger than this would not be possible to be send from a GossipService, // since this is check before sending the message. // This could normally only occur when the list of members is very big, - // or when the packet is misformed, and the first 4 bytes is not the right in anymore. + // or when the packet is malformed, and the first 4 bytes is not the right in anymore. // For this reason we regards the message. if (packet_length <= GossipManager.MAX_PACKET_SIZE) { byte[] json_bytes = new byte[packet_length]; @@ -84,7 +84,7 @@ abstract public class PassiveGossipThread implements Runnable { GossipService.LOGGER.debug("Received message (" + packet_length + " bytes): " + receivedMessage); try { - ArrayList remoteGossipMembers = new ArrayList(); + List remoteGossipMembers = new ArrayList<>(); RemoteGossipMember senderMember = null; GossipService.LOGGER.debug("Received member list:"); JSONArray jsonArray = new JSONArray(receivedMessage); @@ -136,7 +136,7 @@ abstract public class PassiveGossipThread implements Runnable { /** * Abstract method for merging the local and remote list. - * + * * @param gossipManager * The GossipManager for retrieving the local members and dead members list. * @param senderMember @@ -147,4 +147,4 @@ abstract public class PassiveGossipThread implements Runnable { */ abstract protected void mergeLists(GossipManager gossipManager, RemoteGossipMember senderMember, List remoteList); -} \ No newline at end of file +} diff --git a/src/main/java/com/google/code/gossip/manager/impl/OnlyProcessReceivedPassiveGossipThread.java b/src/main/java/com/google/code/gossip/manager/impl/OnlyProcessReceivedPassiveGossipThread.java index f0afaf9..2441204 100644 --- a/src/main/java/com/google/code/gossip/manager/impl/OnlyProcessReceivedPassiveGossipThread.java +++ b/src/main/java/com/google/code/gossip/manager/impl/OnlyProcessReceivedPassiveGossipThread.java @@ -19,7 +19,9 @@ public class OnlyProcessReceivedPassiveGossipThread extends PassiveGossipThread * Merge remote list (received from peer), and our local member list. Simply, we must update the * heartbeats that the remote list has with our list. Also, some additional logic is needed to * make sure we have not timed out a member and then immediately received a list with that member. - * + * + * @param gossipManager + * @param senderMember * @param remoteList */ protected void mergeLists(GossipManager gossipManager, RemoteGossipMember senderMember, @@ -92,6 +94,6 @@ public class OnlyProcessReceivedPassiveGossipThread extends PassiveGossipThread } } - + } diff --git a/src/main/java/com/google/code/gossip/manager/impl/SendMembersActiveGossipThread.java b/src/main/java/com/google/code/gossip/manager/impl/SendMembersActiveGossipThread.java index 85e4b8a..d788f79 100644 --- a/src/main/java/com/google/code/gossip/manager/impl/SendMembersActiveGossipThread.java +++ b/src/main/java/com/google/code/gossip/manager/impl/SendMembersActiveGossipThread.java @@ -35,8 +35,7 @@ abstract public class SendMembersActiveGossipThread extends ActiveGossipThread { GossipService.LOGGER.debug("Sending memberlist to " + dest + ":" + member.getPort()); jsonArray.put(me.toJSONObject()); GossipService.LOGGER.debug(me); - for (int i = 0; i < memberList.size(); i++) { - LocalGossipMember other = memberList.get(i); + for (LocalGossipMember other : memberList) { jsonArray.put(other.toJSONObject()); GossipService.LOGGER.debug(other); } diff --git a/src/main/java/com/google/code/gossip/manager/random/RandomActiveGossipThread.java b/src/main/java/com/google/code/gossip/manager/random/RandomActiveGossipThread.java index d232f38..7849f8d 100644 --- a/src/main/java/com/google/code/gossip/manager/random/RandomActiveGossipThread.java +++ b/src/main/java/com/google/code/gossip/manager/random/RandomActiveGossipThread.java @@ -11,7 +11,7 @@ import com.google.code.gossip.manager.impl.SendMembersActiveGossipThread; public class RandomActiveGossipThread extends SendMembersActiveGossipThread { /** The Random used for choosing a member to gossip with. */ - private Random _random; + private final Random _random; public RandomActiveGossipThread(GossipManager gossipManager) { super(gossipManager); @@ -21,7 +21,7 @@ public class RandomActiveGossipThread extends SendMembersActiveGossipThread { /** * [The selectToSend() function.] Find a random peer from the local membership list. In the case * where this client is the only member in the list, this method will return null. - * + * * @return Member random member if list is greater than 1, null otherwise */ protected LocalGossipMember selectPartner(List memberList) { diff --git a/src/main/java/com/google/code/gossip/manager/random/RandomGossipManager.java b/src/main/java/com/google/code/gossip/manager/random/RandomGossipManager.java index 3d028eb..dc82170 100644 --- a/src/main/java/com/google/code/gossip/manager/random/RandomGossipManager.java +++ b/src/main/java/com/google/code/gossip/manager/random/RandomGossipManager.java @@ -1,16 +1,16 @@ package com.google.code.gossip.manager.random; -import java.util.ArrayList; - import com.google.code.gossip.GossipMember; import com.google.code.gossip.GossipSettings; import com.google.code.gossip.event.GossipListener; import com.google.code.gossip.manager.GossipManager; import com.google.code.gossip.manager.impl.OnlyProcessReceivedPassiveGossipThread; +import java.util.List; + public class RandomGossipManager extends GossipManager { public RandomGossipManager(String address, int port, String id, GossipSettings settings, - ArrayList gossipMembers, GossipListener listener) { + List gossipMembers, GossipListener listener) { super(OnlyProcessReceivedPassiveGossipThread.class, RandomActiveGossipThread.class, address, port, id, settings, gossipMembers, listener); } diff --git a/src/test/java/io/teknek/gossip/TenNodeThreeSeedTest.java b/src/test/java/io/teknek/gossip/TenNodeThreeSeedTest.java index 93f93c5..76c5b5b 100644 --- a/src/test/java/io/teknek/gossip/TenNodeThreeSeedTest.java +++ b/src/test/java/io/teknek/gossip/TenNodeThreeSeedTest.java @@ -2,6 +2,7 @@ package io.teknek.gossip; import java.net.UnknownHostException; import java.util.ArrayList; +import java.util.List; import junit.framework.Assert; @@ -17,25 +18,25 @@ import com.google.code.gossip.event.GossipState; public class TenNodeThreeSeedTest { - + @Test public void test() throws UnknownHostException, InterruptedException{ abc(); } - + @Test public void testAgain() throws UnknownHostException, InterruptedException{ abc(); } - + public void abc() throws InterruptedException, UnknownHostException{ GossipSettings settings = new GossipSettings(); int seedNodes = 3; - ArrayList startupMembers = new ArrayList(); + List startupMembers = new ArrayList<>(); for (int i = 1; i < seedNodes+1; ++i) { startupMembers.add(new RemoteGossipMember("127.0.0." + i, 2000, i + "")); } - ArrayList clients = new ArrayList(); + List clients = new ArrayList<>(); int clusterMembers = 5; for (int i = 1; i < clusterMembers+1; ++i) { GossipService gossipService = new GossipService("127.0.0." + i, 2000, i + "", LogLevel.DEBUG, @@ -56,6 +57,6 @@ public class TenNodeThreeSeedTest { } for (int i = 0; i < clusterMembers; ++i) { clients.get(i).shutdown(); - } + } } }