Fixes for java implementation
Johannes Wienke <[email protected]> Tue, 27 Aug 2013 11:22:26 +0200
| Newsgroups | gmane.network.spread.user |
|---|---|
| Message-ID | <[email protected]> |
Hi, we have maintained some patches for the spread java implementation for some time in our system and I would like to contribute them back. After updating them to version 4.3 two issues have remained: 1. We have added a method to set the tcpnodelay option on the SpreadConnection to speed up sending of small messages. 2. Since java 1.5 is out for some time now a second patch adds generics to avoid compiler warnings. The first patch is an absolute necessity in our system and we would be glad if you could apply it. For the second patch you have to decide whether compatibility with java 1.4 is still required or not. Kind regards, Johannes _______________________________________________ Spread-users mailing list [email protected] http://lists.spread.org/mailman/listinfo/spread-users
0001-Allow-to-set-tcp-nodelay-flag.patch
(text/x-patch, 1.5 KB)
From b9388cb8a4c01c9c59e8cc87df917c64c51e1cde Mon Sep 17 00:00:00 2001 From: Johannes Wienke <[email protected]> Date: Tue, 27 Aug 2013 10:57:00 +0200 Subject: [PATCH 1/2] Allow to set tcp nodelay flag Add a method that allows to toggle the tcp nodelay flag on the socket used by SpreadConnection. If enabled, small messages are not accumulated to bigger chunks and hence sent immediately, which prevents unwanted delays. --- spread/SpreadConnection.java | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/spread/SpreadConnection.java b/spread/SpreadConnection.java index 0c1ebe0..d6d2b82 100644 --- a/spread/SpreadConnection.java +++ b/spread/SpreadConnection.java @@ -1027,6 +1027,29 @@ NOT SUPPORTED IN 1.1 */ } } + // Enable/disable TCP_NODELAY on the socket used for this connection. + ///////////////////////////////// + /** + * Enable/disable TCP_NODELAY (disable/enable Nagle's algorithm) on the + * socket used for this connection. + * + * @param noDelay If TCP_NODELAY should be enabled or not. + * @throws SpreadException if we could not set the TCP_NODELAY flag. + */ + public void setTcpNoDelay(boolean noDelay) throws SpreadException + { + try + { + socket.setTcpNoDelay(noDelay); + } + catch (SocketException e) + { + SpreadException se = new SpreadException("setTcpNoDelay(): " + e.getMessage()); + se.initCause(e); + throw se; + } + } + // Gets the user's private group. ///////////////////////////////// /** -- 1.7.9.5
0002-Use-generics.patch
(text/x-patch, 6.7 KB)
From 3a90b88babb92ca21e081545f092b349e32f31fb Mon Sep 17 00:00:00 2001 From: Johannes Wienke <[email protected]> Date: Tue, 27 Aug 2013 11:14:56 +0200 Subject: [PATCH 2/2] Use generics Avoid compiler warnings by using generics for containers and class instances. --- spread/MembershipInfo.java | 6 +++--- spread/SpreadConnection.java | 20 ++++++++++---------- spread/SpreadMessage.java | 15 ++++++++------- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/spread/MembershipInfo.java b/spread/MembershipInfo.java index 7afc607..7d78061 100644 --- a/spread/MembershipInfo.java +++ b/spread/MembershipInfo.java @@ -68,7 +68,7 @@ public class MembershipInfo // The group's members. /////////////////////// - private Vector members; + private Vector<SpreadGroup> members; // The private groups of members that joined/left/disconected/stayed. // For caused-by join/leave/disconnect, this has 1 element, with 1 member. @@ -85,7 +85,7 @@ public class MembershipInfo // Constructor. /////////////// protected MembershipInfo(SpreadConnection connection, int serviceType, - Vector groups, SpreadGroup sender, + Vector<SpreadGroup> groups, SpreadGroup sender, byte data[], boolean daemonEndianMismatch) { // Set local variables. @@ -157,7 +157,7 @@ public class MembershipInfo dataIndex += 4; for( int j = 0 ; j < numMembers ; ++j ) { virtualSynchronySets[i].addMember( connection.toGroup(data, dataIndex) ); - dataIndex += connection.MAX_GROUP_NAME; + dataIndex += SpreadConnection.MAX_GROUP_NAME; } } } diff --git a/spread/SpreadConnection.java b/spread/SpreadConnection.java index d6d2b82..fe17875 100644 --- a/spread/SpreadConnection.java +++ b/spread/SpreadConnection.java @@ -140,11 +140,11 @@ public class SpreadConnection // Basic listeners. /////////////////// - protected Vector basicListeners; + protected Vector<BasicMessageListener> basicListeners; // Advanced listeners. ////////////////////// - protected Vector advancedListeners; + protected Vector<AdvancedMessageListener> advancedListeners; // The daemon's address. //////////////////////// @@ -199,7 +199,7 @@ public class SpreadConnection // For commands with an argument (all except // for BUFFER_DISCONNECT), the argument follows in the Vector. ////////////////////////////////////////////////////////////// - private Vector listenerBuffer; + private Vector<Object> listenerBuffer; // Listener buffer commands. // These are Object's because they need to be added to a Vector. @@ -574,7 +574,7 @@ NOT SUPPORTED IN 1.1 */ ///////////////////////////////////// private void instantiateAuthMethod() throws SpreadException { - Class authclass; + Class<?> authclass; // System.out.println("Authname is " + authName); // System.out.println("class name is " + authClassName); @@ -746,12 +746,12 @@ NOT SUPPORTED IN 1.1 */ listenersynchro = new Boolean(false); // Init listeners. ////////////////// - basicListeners = new Vector(); - advancedListeners = new Vector(); + basicListeners = new Vector<BasicMessageListener>(); + advancedListeners = new Vector<AdvancedMessageListener>(); // Init listener command buffer. //////////////////////////////// - listenerBuffer = new Vector(); + listenerBuffer = new Vector<Object>(); // Init default authentication ////////////////////////////// @@ -1264,7 +1264,7 @@ NOT SUPPORTED IN 1.1 */ // Get the groups from the buffer. ////////////////////////////////// - Vector groups = new Vector(numGroups); + Vector<SpreadGroup> groups = new Vector<SpreadGroup>(numGroups); for(int bufferIndex = 0 ; bufferIndex < buffer.length ; bufferIndex += MAX_GROUP_NAME) { // Translate the name into a group and add it to the vector. @@ -1736,7 +1736,7 @@ NOT SUPPORTED IN 1.1 */ { // Get the listener. //////////////////// - basicListener = (BasicMessageListener)basicListeners.elementAt(i); + basicListener = basicListeners.elementAt(i); // Tell it. /////////// @@ -1749,7 +1749,7 @@ NOT SUPPORTED IN 1.1 */ { // Get the listener. //////////////////// - advancedListener = (AdvancedMessageListener)advancedListeners.elementAt(i); + advancedListener = advancedListeners.elementAt(i); // What type of message is it? ////////////////////////////// diff --git a/spread/SpreadMessage.java b/spread/SpreadMessage.java index 6e4bf21..bb89856 100644 --- a/spread/SpreadMessage.java +++ b/spread/SpreadMessage.java @@ -110,7 +110,7 @@ public class SpreadMessage // The groups this message is from/to. ////////////////////////////////////// - protected Vector groups; + protected Vector<SpreadGroup> groups; // The sender's group. ////////////////////// @@ -142,7 +142,7 @@ public class SpreadMessage // Creates a new incoming message. ////////////////////////////////// - protected SpreadMessage(int serviceType, Vector groups, SpreadGroup sender, byte[] data, short type, boolean endianMismatch, MembershipInfo membershipInfo) + protected SpreadMessage(int serviceType, Vector<SpreadGroup> groups, SpreadGroup sender, byte[] data, short type, boolean endianMismatch, MembershipInfo membershipInfo) { // Set member variables. //////////////////////// @@ -168,7 +168,7 @@ public class SpreadMessage outgoing = true; content = CONTENT_DATA; serviceType = RELIABLE_MESS; - groups = new Vector(); + groups = new Vector<SpreadGroup>(); data = new byte[0]; } @@ -599,11 +599,11 @@ public class SpreadMessage * @throws SpreadException if there is an error reading the objects * @see SpreadMessage#digest(Serializable) */ - public Vector getDigest() throws SpreadException + public Vector<Object> getDigest() throws SpreadException { // Make a vector to hold the objects. ///////////////////////////////////// - Vector objects = new Vector(); + Vector<Object> objects = new Vector<Object>(); // Setup the byte array stream. /////////////////////////////// @@ -789,7 +789,7 @@ public class SpreadMessage // Copy the data. ///////////////// - this.data = (byte[])data.clone(); + this.data = data.clone(); } // Sets the message to send the object. @@ -946,11 +946,12 @@ public class SpreadMessage * * @return a copy of this message */ + @SuppressWarnings("unchecked") public Object clone() { SpreadMessage message = new SpreadMessage(); message.setServiceType(serviceType); - message.groups = (Vector)groups.clone(); + message.groups = (Vector<SpreadGroup>) groups.clone(); message.setType(type); message.setData(data); message.content = content; -- 1.7.9.5
signature.asc
(application/pgp-signature, 263 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iEYEARECAAYFAlIcb9UACgkQBFcR5UV/ccJHBQCg6IpDovTGN81HcG2lIN/yxpNM zhQAn1LySf/yMy5PKnEIG7SdqQVQ5lsz =J2Hv -----END PGP SIGNATURE-----