diff --git a/src/org/jgroups/AnycastAddress.java b/src/org/jgroups/AnycastAddress.java index b36af6ea3db..e78290cc407 100644 --- a/src/org/jgroups/AnycastAddress.java +++ b/src/org/jgroups/AnycastAddress.java @@ -71,6 +71,7 @@ private void initCollection(int estimatedSize) { } } + @Override public int serializedSize() { if (destinations == null) { return Global.INT_SIZE; @@ -124,12 +125,12 @@ public int compareTo(Address o) { } @Override - public void writeTo(DataOutput out) throws Exception { + public void writeTo(DataOutput out) throws IOException { Util.writeAddresses(destinations, out); } @Override - public void readFrom(DataInput in) throws Exception { + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { destinations=Util.readAddresses(in, ArrayList::new); } diff --git a/src/org/jgroups/MergeView.java b/src/org/jgroups/MergeView.java index fc886cd835e..60ed3697359 100644 --- a/src/org/jgroups/MergeView.java +++ b/src/org/jgroups/MergeView.java @@ -7,6 +7,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -101,8 +102,8 @@ public String toString() { return sb.toString(); } - - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { super.writeTo(out); // write subgroups @@ -130,7 +131,8 @@ public void writeTo(DataOutput out) throws Exception { } } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { super.readFrom(in); short len=in.readShort(); if(len > 0) { @@ -154,6 +156,7 @@ public void readFrom(DataInput in) throws Exception { } } + @Override public int serializedSize() { int retval=super.serializedSize(); retval+=Global.SHORT_SIZE; // for size of subgroups vector diff --git a/src/org/jgroups/Message.java b/src/org/jgroups/Message.java index 31a5313feed..dcca6ea10b0 100644 --- a/src/org/jgroups/Message.java +++ b/src/org/jgroups/Message.java @@ -7,6 +7,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.util.Map; import java.util.function.Supplier; @@ -528,7 +529,6 @@ public Message copy(boolean copy_buffer, boolean copy_headers) { if(copy_buffer && buf != null) retval.setBuffer(buf, offset, length); - //noinspection NonAtomicOperationOnVolatileField retval.headers=copy_headers && headers != null? Headers.copy(this.headers) : createHeaders(Util.DEFAULT_HEADERS); return retval; } @@ -590,14 +590,8 @@ public String printObjectHeaders() { /* ----------------------------------- Interface Streamable ------------------------------- */ - /** - * Streams all members (dest and src addresses, buffer and headers) to the output stream. - * - * - * @param out - * @throws Exception - */ - public void writeTo(DataOutput out) throws Exception { + /** Writes the message to the output stream */ + @Override public void writeTo(DataOutput out) throws IOException { byte leading=0; if(dest != null) @@ -646,13 +640,9 @@ public void writeTo(DataOutput out) throws Exception { /** * Writes the message to the output stream, but excludes the dest and src addresses unless the * src address given as argument is different from the message's src address - * - * @param src - * @param out * @param excluded_headers Don't marshal headers that are part of excluded_headers - * @throws Exception */ - public void writeToNoAddrs(Address src, DataOutput out, short ... excluded_headers) throws Exception { + public void writeToNoAddrs(Address src, DataOutput out, short ... excluded_headers) throws IOException { byte leading=0; boolean write_src_addr=src == null || sender != null && !sender.equals(src); @@ -696,9 +686,8 @@ public void writeToNoAddrs(Address src, DataOutput out, short ... excluded_heade } } - - public void readFrom(DataInput in) throws Exception { - + /** Reads the message's contents from an input stream */ + @Override public void readFrom(DataInput in) throws IOException, ClassNotFoundException { // 1. read the leading byte first byte leading=in.readByte(); @@ -734,7 +723,7 @@ public void readFrom(DataInput in) throws Exception { /** Reads the message's contents from an input stream, but skips the buffer and instead returns the * position (offset) at which the buffer starts */ - public int readFromSkipPayload(ByteArrayDataInputStream in) throws Exception { + public int readFromSkipPayload(ByteArrayDataInputStream in) throws IOException, ClassNotFoundException { // 1. read the leading byte first byte leading=in.readByte(); @@ -835,7 +824,7 @@ public static String transientFlagsToString(short flags) { return sb.toString(); } - protected static void writeHeader(Header hdr, DataOutput out) throws Exception { + protected static void writeHeader(Header hdr, DataOutput out) throws IOException { short magic_number=hdr.getMagicId(); out.writeShort(magic_number); hdr.writeTo(out); @@ -843,7 +832,7 @@ protected static void writeHeader(Header hdr, DataOutput out) throws Exception { - protected static Header readHeader(DataInput in) throws Exception { + protected static Header readHeader(DataInput in) throws IOException, ClassNotFoundException { short magic_number=in.readShort(); Header hdr=ClassConfigurator.create(magic_number); hdr.readFrom(in); diff --git a/src/org/jgroups/View.java b/src/org/jgroups/View.java index 740563c1353..207de6d7053 100644 --- a/src/org/jgroups/View.java +++ b/src/org/jgroups/View.java @@ -9,6 +9,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.util.*; import java.util.function.Supplier; import java.util.stream.Stream; @@ -196,18 +197,20 @@ public String toString() { return sb.toString(); } - - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { view_id.writeTo(out); Util.writeAddresses(members,out); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { view_id=new ViewId(); view_id.readFrom(in); members=Util.readAddresses(in); } + @Override public int serializedSize() { return (int)(view_id.serializedSize() + Util.size(members)); } diff --git a/src/org/jgroups/ViewId.java b/src/org/jgroups/ViewId.java index 53916c087ad..3cba2d5e27f 100644 --- a/src/org/jgroups/ViewId.java +++ b/src/org/jgroups/ViewId.java @@ -7,6 +7,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.util.function.Supplier; @@ -105,17 +106,19 @@ public int hashCode() { return (int)(creator.hashCode() + id); } - - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { Util.writeAddress(creator, out); Bits.writeLong(id,out); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { creator=Util.readAddress(in); id=Bits.readLong(in); } + @Override public int serializedSize() { return Bits.size(id) + Util.size(creator); } diff --git a/src/org/jgroups/auth/FixedMembershipToken.java b/src/org/jgroups/auth/FixedMembershipToken.java index 7cf9b1b11ea..427d6145993 100644 --- a/src/org/jgroups/auth/FixedMembershipToken.java +++ b/src/org/jgroups/auth/FixedMembershipToken.java @@ -10,6 +10,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.UnknownHostException; @@ -110,11 +111,13 @@ public void setMemberList(String list) throws UnknownHostException { } } - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { Bits.writeString(this.token,out); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException { this.token = Bits.readString(in); } diff --git a/src/org/jgroups/auth/Krb5Token.java b/src/org/jgroups/auth/Krb5Token.java index 0646e9b53d0..80df965d195 100644 --- a/src/org/jgroups/auth/Krb5Token.java +++ b/src/org/jgroups/auth/Krb5Token.java @@ -105,7 +105,8 @@ public boolean authenticate(AuthToken token, Message msg) { return false; } - + + @Override public void writeTo(DataOutput out) throws IOException { if (isAuthenticated()) { generateServiceTicket(); @@ -113,7 +114,8 @@ public void writeTo(DataOutput out) throws IOException { } } - public void readFrom(DataInput in) throws IOException, IllegalAccessException, InstantiationException { + @Override + public void readFrom(DataInput in) throws IOException { // This method is called from within a temporary token so it has not authenticated to a client principal // This token is passed to the authenticate diff --git a/src/org/jgroups/auth/MD5Token.java b/src/org/jgroups/auth/MD5Token.java index 57214026d9e..36271b2ae5c 100644 --- a/src/org/jgroups/auth/MD5Token.java +++ b/src/org/jgroups/auth/MD5Token.java @@ -7,6 +7,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; /** *

@@ -112,11 +113,13 @@ public boolean authenticate(AuthToken token, Message msg) { return false; } - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { Bits.writeString(this.auth_value,out); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException { this.auth_value = Bits.readString(in); } diff --git a/src/org/jgroups/auth/RegexMembership.java b/src/org/jgroups/auth/RegexMembership.java index 6a82648a761..7b4ff54812d 100644 --- a/src/org/jgroups/auth/RegexMembership.java +++ b/src/org/jgroups/auth/RegexMembership.java @@ -84,19 +84,12 @@ public boolean authenticate(AuthToken token, Message msg) { return false; } - - - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) { } - /** - * Required to deserialize the object when read in from the wire - * - * - * @param in - * @throws Exception - */ - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) { } public int size() { diff --git a/src/org/jgroups/auth/SimpleToken.java b/src/org/jgroups/auth/SimpleToken.java index 2669d1605f3..566214a0a10 100644 --- a/src/org/jgroups/auth/SimpleToken.java +++ b/src/org/jgroups/auth/SimpleToken.java @@ -7,6 +7,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; /** *

@@ -73,30 +74,16 @@ public boolean authenticate(AuthToken token, Message msg) { return false; } - /** - * Required to serialize the object to pass across the wire - * - * - * - * @param out - * @throws Exception - */ - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { if (log.isDebugEnabled()) { log.debug("SimpleToken writeTo()"); } Bits.writeString(this.auth_value,out); } - /** - * Required to deserialize the object when read in from the wire - * - * - * - * @param in - * @throws Exception - */ - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException { if (log.isDebugEnabled()) { log.debug("SimpleToken readFrom()"); } diff --git a/src/org/jgroups/auth/X509Token.java b/src/org/jgroups/auth/X509Token.java index e573b96fb9a..bfa21e1abce 100644 --- a/src/org/jgroups/auth/X509Token.java +++ b/src/org/jgroups/auth/X509Token.java @@ -123,11 +123,13 @@ public boolean authenticate(AuthToken token, Message msg) { return false; } - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { Util.writeByteBuffer(this.encryptedToken, out); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException { this.encryptedToken = Util.readByteBuffer(in); this.valueSet = true; } diff --git a/src/org/jgroups/blocks/GridFile.java b/src/org/jgroups/blocks/GridFile.java index 8362beee942..8520ee4fe19 100644 --- a/src/org/jgroups/blocks/GridFile.java +++ b/src/org/jgroups/blocks/GridFile.java @@ -365,14 +365,16 @@ public String toString() { return sb.toString(); } - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { out.writeInt(length); out.writeLong(modification_time); out.writeInt(chunk_size); out.writeByte(flags); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException { length=in.readInt(); modification_time=in.readLong(); chunk_size=in.readInt(); diff --git a/src/org/jgroups/blocks/Marshaller.java b/src/org/jgroups/blocks/Marshaller.java index c364e7120cf..d81ca8fa669 100644 --- a/src/org/jgroups/blocks/Marshaller.java +++ b/src/org/jgroups/blocks/Marshaller.java @@ -2,6 +2,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; /** * Performs serialization and de-serialization of RPC call arguments and return values (including exceptions) @@ -26,15 +27,16 @@ default int estimatedSize(Object arg) { * Serializes an object to an output stream * @param obj the object to be serialized * @param out the output stream, created taking {@link #estimatedSize(Object)} into account - * @throws Exception thrown if serialization failed + * @throws IOException thrown if serialization failed */ - void objectToStream(Object obj, DataOutput out) throws Exception; + void objectToStream(Object obj, DataOutput out) throws IOException; /** * Creates an object from a stream * @param in the input stream * @return an object read from the input stream - * @throws Exception thrown if deserialization failed + * @throws IOException thrown if deserialization failed + * @throws ClassNotFoundException if a requisite class was not found */ - Object objectFromStream(DataInput in) throws Exception; + Object objectFromStream(DataInput in) throws IOException, ClassNotFoundException; } diff --git a/src/org/jgroups/blocks/MethodCall.java b/src/org/jgroups/blocks/MethodCall.java index 68081c2d3cc..8ea9e8d9dd4 100644 --- a/src/org/jgroups/blocks/MethodCall.java +++ b/src/org/jgroups/blocks/MethodCall.java @@ -212,13 +212,12 @@ public String toStringDetails() { return ret.toString(); } - - - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { writeTo(out, null); } - public void writeTo(DataOutput out, Marshaller marshaller) throws Exception { + public void writeTo(DataOutput out, Marshaller marshaller) throws IOException { out.write(mode); switch(mode) { @@ -239,14 +238,12 @@ public void writeTo(DataOutput out, Marshaller marshaller) throws Exception { writeArgs(out, marshaller); } - - - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { readFrom(in, null); } - - public void readFrom(DataInput in, Marshaller marshaller) throws Exception { + public void readFrom(DataInput in, Marshaller marshaller) throws IOException, ClassNotFoundException { switch(mode=in.readByte()) { case METHOD: method_name=Bits.readString(in); @@ -302,7 +299,7 @@ protected static Method getMethod(Class target, String methodName, Class[] types return null; } - protected void writeArgs(DataOutput out, Marshaller marshaller) throws Exception { + protected void writeArgs(DataOutput out, Marshaller marshaller) throws IOException { int args_len=args != null? args.length : 0; out.write(args_len); if(args_len == 0) @@ -315,7 +312,7 @@ protected void writeArgs(DataOutput out, Marshaller marshaller) throws Exception } } - protected void readArgs(DataInput in, Marshaller marshaller) throws Exception { + protected void readArgs(DataInput in, Marshaller marshaller) throws IOException, ClassNotFoundException { int args_len=in.readByte(); if(args_len == 0) return; @@ -325,7 +322,7 @@ protected void readArgs(DataInput in, Marshaller marshaller) throws Exception { } - protected void writeTypes(DataOutput out) throws Exception { + protected void writeTypes(DataOutput out) throws IOException { int types_len=types != null? types.length : 0; out.write(types_len); if(types_len > 0) @@ -333,7 +330,7 @@ protected void writeTypes(DataOutput out) throws Exception { Util.objectToStream(type, out); } - protected void readTypes(DataInput in) throws Exception { + protected void readTypes(DataInput in) throws IOException, ClassNotFoundException { int types_len=in.readByte(); if(types_len > 0) { types=new Class[types_len]; @@ -342,7 +339,7 @@ protected void readTypes(DataInput in) throws Exception { } } - protected void writeMethod(DataOutput out) throws Exception { + protected void writeMethod(DataOutput out) throws IOException { if(method != null) { out.write(1); Util.objectToStream(method.getParameterTypes(),out); @@ -352,7 +349,7 @@ protected void writeMethod(DataOutput out) throws Exception { out.write(0); } - protected void readMethod(DataInput in) throws Exception { + protected void readMethod(DataInput in) throws IOException, ClassNotFoundException { if(in.readByte() == 1) { Class[] parametertypes=Util.objectFromStream(in); Class declaringclass=Util.objectFromStream(in); diff --git a/src/org/jgroups/blocks/PartitionedHashMap.java b/src/org/jgroups/blocks/PartitionedHashMap.java index 0ec84b5d01c..de6c3e6c8c9 100644 --- a/src/org/jgroups/blocks/PartitionedHashMap.java +++ b/src/org/jgroups/blocks/PartitionedHashMap.java @@ -14,6 +14,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.lang.reflect.Method; import java.util.*; @@ -488,8 +489,8 @@ private static class CustomMarshaller implements Marshaller { static final byte OBJ = 2; static final byte VALUE = 3; - - public void objectToStream(Object obj, DataOutput out) throws Exception { + @Override + public void objectToStream(Object obj, DataOutput out) throws IOException { if(obj == null) { out.write(NULL); return; @@ -506,7 +507,8 @@ public void objectToStream(Object obj, DataOutput out) throws Exception { } } - public Object objectFromStream(DataInput in) throws Exception { + @Override + public Object objectFromStream(DataInput in) throws IOException, ClassNotFoundException { byte type=in.readByte(); if(type == NULL) return null; diff --git a/src/org/jgroups/blocks/ReplCache.java b/src/org/jgroups/blocks/ReplCache.java index d565a6a8adb..a8fe8e3a55d 100644 --- a/src/org/jgroups/blocks/ReplCache.java +++ b/src/org/jgroups/blocks/ReplCache.java @@ -849,8 +849,8 @@ private static class CustomMarshaller implements Marshaller { static final byte OBJ = 2; static final byte VALUE = 3; - - public void objectToStream(Object obj, DataOutput out) throws Exception { + @Override + public void objectToStream(Object obj, DataOutput out) throws IOException { if(obj == null) { out.write(NULL); return; @@ -867,7 +867,8 @@ public void objectToStream(Object obj, DataOutput out) throws Exception { } } - public Object objectFromStream(DataInput in) throws Exception { + @Override + public Object objectFromStream(DataInput in) throws IOException, ClassNotFoundException { byte type=in.readByte(); if(type == NULL) return null; diff --git a/src/org/jgroups/blocks/RequestCorrelator.java b/src/org/jgroups/blocks/RequestCorrelator.java index cdb6c143206..3ba00a05f3c 100644 --- a/src/org/jgroups/blocks/RequestCorrelator.java +++ b/src/org/jgroups/blocks/RequestCorrelator.java @@ -13,6 +13,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.io.NotSerializableException; import java.lang.reflect.InvocationTargetException; import java.util.*; @@ -547,19 +548,21 @@ public String toString() { return ret.toString(); } - - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { out.writeByte(type); Bits.writeLong(req_id, out); out.writeShort(corrId); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { type=in.readByte(); req_id=Bits.readLong(in); corrId=in.readShort(); } + @Override public int serializedSize() { return Global.BYTE_SIZE // type + Bits.size(req_id) // req_id @@ -585,16 +588,19 @@ public Supplier create() { return MultiDestinationHeader::new; } - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { super.writeTo(out); Util.writeAddresses(exclusion_list, out); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { super.readFrom(in); exclusion_list=Util.readAddresses(in); } + @Override public int serializedSize() { return (int)(super.serializedSize() + Util.size(exclusion_list)); } diff --git a/src/org/jgroups/blocks/executor/ExecutionService.java b/src/org/jgroups/blocks/executor/ExecutionService.java index da2f50c5f65..b88fb76aac8 100644 --- a/src/org/jgroups/blocks/executor/ExecutionService.java +++ b/src/org/jgroups/blocks/executor/ExecutionService.java @@ -715,51 +715,17 @@ public T call() { return result; } @Override - public void writeTo(DataOutput out) throws Exception { - try { - Util.writeObject(task, out); - } - catch (IOException e) { - throw e; - } - catch (Exception e) { - throw new IOException("Exception encountered while writing execution runnable", e); - } - - try { - Util.writeObject(result, out); - } - catch (IOException e) { - throw e; - } - catch (Exception e) { - throw new IOException("Exception encountered while writing execution result", e); - } + public void writeTo(DataOutput out) throws IOException { + Util.writeObject(task, out); + Util.writeObject(result, out); } @SuppressWarnings("unchecked") @Override - public void readFrom(DataInput in) throws Exception { + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { // We can't use Util.readObject since it's size is limited to 2^15-1 // The runner could be larger than that possibly - try { - task = (Runnable)Util.readObject(in); - } - catch (IOException e) { - throw e; - } - catch (Exception e) { - throw new IOException("Exception encountered while reading execution runnable", e); - } - - try { - result = (T)Util.readObject(in); - } - catch (IOException e) { - throw e; - } - catch (Exception e) { - throw new IOException("Exception encountered while reading execution result", e); - } + task = (Runnable)Util.readObject(in); + result = (T)Util.readObject(in); } } diff --git a/src/org/jgroups/blocks/executor/Executions.java b/src/org/jgroups/blocks/executor/Executions.java index f993bc4d2df..fe2c3f3b777 100644 --- a/src/org/jgroups/blocks/executor/Executions.java +++ b/src/org/jgroups/blocks/executor/Executions.java @@ -135,7 +135,7 @@ public Object call() throws Exception { } @Override - public void writeTo(DataOutput out) throws Exception { + public void writeTo(DataOutput out) throws IOException { out.writeUTF(_classCallable.getName()); out.writeByte(_constructorNumber); out.writeByte(_args.length); @@ -149,16 +149,10 @@ public void writeTo(DataOutput out) throws Exception { } } - @SuppressWarnings("unchecked") @Override - public void readFrom(DataInput in) throws Exception { - try { - String classname=in.readUTF(); - _classCallable=ClassConfigurator.get(classname); - } - catch (ClassNotFoundException e) { - throw new IOException("failed to read class from classname", e); - } + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { + String classname=in.readUTF(); + _classCallable=ClassConfigurator.get(classname); _constructorNumber = in.readByte(); short numberOfArgs = in.readByte(); _args = new Object[numberOfArgs]; diff --git a/src/org/jgroups/conf/ClassConfigurator.java b/src/org/jgroups/conf/ClassConfigurator.java index 93a6cb39a80..527baeeb4a9 100644 --- a/src/org/jgroups/conf/ClassConfigurator.java +++ b/src/org/jgroups/conf/ClassConfigurator.java @@ -111,12 +111,19 @@ public static void addProtocol(short id, Class protocol) { } - public static T create(short id) throws Exception { + public static T create(short id) throws ClassNotFoundException { if(id >= MIN_CUSTOM_MAGIC_NUMBER) { Object val=magicMapUser.get(id); if(val == null) throw new ClassNotFoundException("Class for magic number " + id + " cannot be found"); - return (T) ((val instanceof Supplier)? ((Supplier)val).get() : ((Class)val).newInstance()); + if (val instanceof Supplier) { + return ((Supplier) val).get(); + } + try { + return ((Class) val).newInstance(); + } catch (IllegalAccessException | InstantiationException e) { + throw new IllegalStateException(e); + } } Supplier supplier=magicMap[id]; if(supplier == null) diff --git a/src/org/jgroups/demos/DrawCommand.java b/src/org/jgroups/demos/DrawCommand.java index 4a9c271f2be..f65d17e21fc 100644 --- a/src/org/jgroups/demos/DrawCommand.java +++ b/src/org/jgroups/demos/DrawCommand.java @@ -5,6 +5,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; /** * Encapsulates information about a draw command. @@ -33,15 +34,16 @@ public DrawCommand() { // needed for streamable this.rgb=rgb; } - - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { out.writeByte(mode); out.writeInt(x); out.writeInt(y); out.writeInt(rgb); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException { mode=in.readByte(); x=in.readInt(); y=in.readInt(); diff --git a/src/org/jgroups/demos/ExecutionServiceDemo.java b/src/org/jgroups/demos/ExecutionServiceDemo.java index 6c9bc008ab5..f9be0a5eb4f 100644 --- a/src/org/jgroups/demos/ExecutionServiceDemo.java +++ b/src/org/jgroups/demos/ExecutionServiceDemo.java @@ -10,6 +10,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.nio.ByteBuffer; import java.util.ArrayDeque; import java.util.Arrays; @@ -88,14 +89,14 @@ protected ByteBufferStreamable(ByteBuffer buffer) { } @Override - public void writeTo(DataOutput out) throws Exception { + public void writeTo(DataOutput out) throws IOException { int sizeLocal = buffer.limit() - buffer.position(); out.writeInt(sizeLocal); out.write(buffer.array(), buffer.position(), sizeLocal); } @Override - public void readFrom(DataInput in) throws Exception { + public void readFrom(DataInput in) throws IOException { buffer = ByteBuffer.allocate(in.readInt()); in.readFully(buffer.array()); } @@ -145,12 +146,12 @@ public ByteBufferStreamable call() throws Exception { // We copy over as a single array with no offset @Override - public void writeTo(DataOutput out) throws Exception { + public void writeTo(DataOutput out) throws IOException { Util.writeStreamable(new ByteBufferStreamable(buffer), out); } @Override - public void readFrom(DataInput in) throws Exception { + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { buffer = Util.readStreamable(ByteBufferStreamable::new, in).buffer; } } @@ -201,13 +202,13 @@ else if (j < byte2Max) { } @Override - public void writeTo(DataOutput out) throws Exception { + public void writeTo(DataOutput out) throws IOException { Util.writeStreamable(new ByteBufferStreamable(bytes1), out); Util.writeStreamable(new ByteBufferStreamable(bytes2), out); } @Override - public void readFrom(DataInput in) throws Exception { + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { bytes1 = Util.readStreamable(ByteBufferStreamable::new, in).buffer; bytes2 = Util.readStreamable(ByteBufferStreamable::new, in).buffer; } diff --git a/src/org/jgroups/protocols/ABP.java b/src/org/jgroups/protocols/ABP.java index 15cc37fad55..97391447667 100644 --- a/src/org/jgroups/protocols/ABP.java +++ b/src/org/jgroups/protocols/ABP.java @@ -12,6 +12,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.util.concurrent.BlockingQueue; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; @@ -188,13 +189,13 @@ public int serializedSize() { } @Override - public void writeTo(DataOutput out) throws Exception { + public void writeTo(DataOutput out) throws IOException { out.writeByte(type.ordinal()); out.writeByte(bit); } @Override - public void readFrom(DataInput in) throws Exception { + public void readFrom(DataInput in) throws IOException { type=Type.values()[in.readByte()]; bit=in.readByte(); } diff --git a/src/org/jgroups/protocols/AuthHeader.java b/src/org/jgroups/protocols/AuthHeader.java index 1cb22959919..81d6374bbb2 100644 --- a/src/org/jgroups/protocols/AuthHeader.java +++ b/src/org/jgroups/protocols/AuthHeader.java @@ -7,6 +7,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.util.function.Supplier; /** @@ -33,14 +34,17 @@ public AuthHeader(AuthToken token) { public AuthToken token() {return this.token;} public short getMagicId() {return 66;} - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { writeAuthToken(out, token); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { this.token=readAuthToken(in); } + @Override public int serializedSize() { return sizeOf(token); } @@ -50,7 +54,7 @@ public String toString() { } - protected static void writeAuthToken(DataOutput out, AuthToken tok) throws Exception { + protected static void writeAuthToken(DataOutput out, AuthToken tok) throws IOException { out.writeByte(tok == null? 0 : 1); if(tok == null) return; short id=ClassConfigurator.getMagicNumber(tok.getClass()); @@ -62,7 +66,7 @@ protected static void writeAuthToken(DataOutput out, AuthToken tok) throws Excep tok.writeTo(out); } - protected static AuthToken readAuthToken(DataInput in) throws Exception { + protected static AuthToken readAuthToken(DataInput in) throws IOException, ClassNotFoundException { if(in.readByte() == 0) return null; short id=in.readShort(); AuthToken retval=null; @@ -71,7 +75,11 @@ protected static AuthToken readAuthToken(DataInput in) throws Exception { else { String classname=in.readUTF(); Class clazz=Class.forName(classname); - retval=(AuthToken)clazz.newInstance(); + try { + retval=(AuthToken)clazz.newInstance(); + } catch (IllegalAccessException | InstantiationException e) { + throw new IllegalStateException(e); + } } retval.readFrom(in); return retval; diff --git a/src/org/jgroups/protocols/COMPRESS.java b/src/org/jgroups/protocols/COMPRESS.java index 55481e98781..6d8e0194934 100644 --- a/src/org/jgroups/protocols/COMPRESS.java +++ b/src/org/jgroups/protocols/COMPRESS.java @@ -11,6 +11,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; import java.util.function.Supplier; @@ -195,15 +196,18 @@ public Supplier create() { return CompressHeader::new; } + @Override public int serializedSize() { return Global.INT_SIZE; } - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { out.writeInt(original_size); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException { original_size=in.readInt(); } } diff --git a/src/org/jgroups/protocols/COUNTER.java b/src/org/jgroups/protocols/COUNTER.java index 8136a6d0c00..60b47880b18 100644 --- a/src/org/jgroups/protocols/COUNTER.java +++ b/src/org/jgroups/protocols/COUNTER.java @@ -587,7 +587,7 @@ protected synchronized void stopReconciliationTask() { } - protected static void writeReconciliation(DataOutput out, String[] names, long[] values, long[] versions) throws Exception { + protected static void writeReconciliation(DataOutput out, String[] names, long[] values, long[] versions) throws IOException { if(names == null) { out.writeInt(0); return; @@ -601,14 +601,14 @@ protected static void writeReconciliation(DataOutput out, String[] names, long[] Bits.writeLong(version, out); } - protected static String[] readReconciliationNames(DataInput in, int len) throws Exception { + protected static String[] readReconciliationNames(DataInput in, int len) throws IOException { String[] retval=new String[len]; for(int i=0; i < len; i++) retval[i]=Bits.readString(in); return retval; } - protected static long[] readReconciliationLongs(DataInput in, int len) throws Exception { + protected static long[] readReconciliationLongs(DataInput in, int len) throws IOException { long[] retval=new long[len]; for(int i=0; i < len; i++) retval[i]=Bits.readLong(in); @@ -771,12 +771,14 @@ protected SimpleRequest(Owner owner, String name) { this.name=name; } - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { owner.writeTo(out); Bits.writeString(name,out); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { owner=new Owner(); owner.readFrom(in); name=Bits.readString(in); @@ -788,8 +790,10 @@ public String toString() { } protected static class ResendPendingRequests implements Request { - public void writeTo(DataOutput out) throws Exception {} - public void readFrom(DataInput in) throws Exception {} + @Override + public void writeTo(DataOutput out) throws IOException {} + @Override + public void readFrom(DataInput in) throws IOException {} public String toString() {return "ResendPendingRequests";} } @@ -803,12 +807,14 @@ protected GetOrCreateRequest() {} this.initial_value=initial_value; } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { super.readFrom(in); initial_value=Bits.readLong(in); } - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { super.writeTo(out); Bits.writeLong(initial_value, out); } @@ -849,12 +855,14 @@ protected SetRequest(Owner owner, String name, long value) { this.value=value; } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { super.readFrom(in); value=Bits.readLong(in); } - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { super.writeTo(out); Bits.writeLong(value, out); } @@ -874,13 +882,15 @@ protected CompareAndSetRequest(Owner owner, String name, long expected, long upd this.update=update; } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { super.readFrom(in); expected=Bits.readLong(in); update=Bits.readLong(in); } - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { super.writeTo(out); Bits.writeLong(expected, out); Bits.writeLong(update, out); @@ -903,11 +913,13 @@ protected ReconcileRequest(String[] names, long[] values, long[] versions) { this.versions=versions; } - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { writeReconciliation(out, names, values, versions); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException { int len=in.readInt(); names=readReconciliationNames(in, len); values=readReconciliationLongs(in, len); @@ -931,13 +943,15 @@ protected UpdateRequest(String name, long value, long version) { this.version=version; } - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { Bits.writeString(name,out); Bits.writeLong(value, out); Bits.writeLong(version, out); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException { name=Bits.readString(in); value=Bits.readLong(in); version=Bits.readLong(in); @@ -963,13 +977,15 @@ protected SimpleResponse(Owner owner, long version) { this.version=version; } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { owner=new Owner(); owner.readFrom(in); version=Bits.readLong(in); } - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { owner.writeTo(out); Bits.writeLong(version, out); } @@ -988,12 +1004,14 @@ protected BooleanResponse(Owner owner, long version, boolean result) { this.result=result; } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { super.readFrom(in); result=in.readBoolean(); } - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { super.writeTo(out); out.writeBoolean(result); } @@ -1011,12 +1029,14 @@ protected ValueResponse(Owner owner, long result, long version) { this.result=result; } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { super.readFrom(in); result=Bits.readLong(in); } - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { super.writeTo(out); Bits.writeLong(result, out); } @@ -1046,12 +1066,14 @@ protected ExceptionResponse(Owner owner, String error_message) { this.error_message=error_message; } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { super.readFrom(in); error_message=Bits.readString(in); } - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { super.writeTo(out); Bits.writeString(error_message,out); } @@ -1074,11 +1096,13 @@ protected ReconcileResponse(String[] names, long[] values, long[] versions) { this.versions=versions; } - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { writeReconciliation(out,names,values,versions); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException { int len=in.readInt(); names=readReconciliationNames(in, len); values=readReconciliationLongs(in, len); @@ -1096,9 +1120,12 @@ public String toString() { public static class CounterHeader extends Header { public Supplier create() {return CounterHeader::new;} public short getMagicId() {return 74;} + @Override public int serializedSize() {return 0;} - public void writeTo(DataOutput out) throws Exception {} - public void readFrom(DataInput in) throws Exception {} + @Override + public void writeTo(DataOutput out) {} + @Override + public void readFrom(DataInput in) {} } diff --git a/src/org/jgroups/protocols/DAISYCHAIN.java b/src/org/jgroups/protocols/DAISYCHAIN.java index 91768f20ff0..bbfd51b515d 100644 --- a/src/org/jgroups/protocols/DAISYCHAIN.java +++ b/src/org/jgroups/protocols/DAISYCHAIN.java @@ -11,6 +11,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.util.concurrent.Executor; import java.util.function.Supplier; @@ -194,15 +195,18 @@ public void setTTL(short ttl) { public Supplier create() {return DaisyHeader::new;} + @Override public int serializedSize() { return Global.SHORT_SIZE; } - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { out.writeShort(ttl); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException { ttl=in.readShort(); } diff --git a/src/org/jgroups/protocols/DH_KEY_EXCHANGE.java b/src/org/jgroups/protocols/DH_KEY_EXCHANGE.java index 0b365543efc..ac29f21f3b4 100644 --- a/src/org/jgroups/protocols/DH_KEY_EXCHANGE.java +++ b/src/org/jgroups/protocols/DH_KEY_EXCHANGE.java @@ -13,6 +13,7 @@ import javax.crypto.spec.SecretKeySpec; import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.security.*; import java.security.spec.X509EncodedKeySpec; import java.util.function.Supplier; @@ -285,6 +286,7 @@ public static DhHeader createSecretKeyResponse(byte[] dh_pub_key, byte[] encrypt public byte[] encryptedSecret() {return encrypted_secret_key;} public byte[] version() {return secret_key_version;} + @Override public int serializedSize() { switch(type) { case SECRET_KEY_REQ: @@ -299,7 +301,8 @@ public int serializedSize() { } } - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { out.writeByte(type.ordinal()); switch(type) { case SECRET_KEY_REQ: @@ -325,7 +328,8 @@ public void writeTo(DataOutput out) throws Exception { } } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException { byte ordinal=in.readByte(); type=Type.values()[ordinal]; diff --git a/src/org/jgroups/protocols/EXAMPLE.java b/src/org/jgroups/protocols/EXAMPLE.java index 8acbdb11cd0..5297c1c3e50 100644 --- a/src/org/jgroups/protocols/EXAMPLE.java +++ b/src/org/jgroups/protocols/EXAMPLE.java @@ -9,6 +9,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.function.Supplier; @@ -81,11 +82,13 @@ public String toString() { return "[EXAMPLE: ]"; } - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { // write variables to stream } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { // initialize variables from stream } } diff --git a/src/org/jgroups/protocols/EncryptHeader.java b/src/org/jgroups/protocols/EncryptHeader.java index 3b1f23bac3f..01f379254a4 100644 --- a/src/org/jgroups/protocols/EncryptHeader.java +++ b/src/org/jgroups/protocols/EncryptHeader.java @@ -7,6 +7,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.util.function.Supplier; /** @@ -41,18 +42,21 @@ public EncryptHeader(byte[] version) { public short getMagicId() {return 88;} public Supplier create() {return EncryptHeader::new;} - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { out.writeByte(type); Util.writeByteBuffer(version, 0, version != null? version.length : 0, out); Util.writeAddress(server, out); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { type=in.readByte(); version=Util.readByteBuffer(in); server=Util.readAddress(in); } + @Override public String toString() { return String.format("%s [version=%s]", typeToString(type), (version != null? Util.byteArrayToHexString(version) : "null")) diff --git a/src/org/jgroups/protocols/Executing.java b/src/org/jgroups/protocols/Executing.java index 4a02d661442..72692d6cdb6 100644 --- a/src/org/jgroups/protocols/Executing.java +++ b/src/org/jgroups/protocols/Executing.java @@ -951,7 +951,8 @@ public Supplier create() { return Request::new; } - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { out.writeByte(type.ordinal()); // We can't use Util.writeObject since it's size is limited to 2^15-1 try { @@ -974,7 +975,8 @@ public void writeTo(DataOutput out) throws Exception { out.writeLong(request); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { type=Type.values()[in.readByte()]; // We can't use Util.readObject since it's size is limited to 2^15-1 try { @@ -1024,13 +1026,13 @@ public Supplier create() { } @Override - public void readFrom(DataInput in) throws Exception { + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { super.readFrom(in); threadId = in.readLong(); } @Override - public void writeTo(DataOutput out) throws Exception { + public void writeTo(DataOutput out) throws IOException { super.writeTo(out); out.writeLong(threadId); } @@ -1053,10 +1055,12 @@ public int serializedSize() { public Supplier create() {return ExecutorHeader::new;} - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { } } diff --git a/src/org/jgroups/protocols/FD.java b/src/org/jgroups/protocols/FD.java index 3950bedab8a..6c6d249ebf6 100644 --- a/src/org/jgroups/protocols/FD.java +++ b/src/org/jgroups/protocols/FD.java @@ -12,6 +12,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.util.*; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; @@ -418,7 +419,7 @@ public String toString() { } } - + @Override public int serializedSize() { int retval=Global.BYTE_SIZE; // type retval+=Util.size(mbrs); @@ -426,15 +427,15 @@ public int serializedSize() { return retval; } - - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { out.writeByte(type); Util.writeAddresses(mbrs, out); Util.writeAddress(from, out); } - - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { type=in.readByte(); mbrs=Util.readAddresses(in, ArrayList::new); from=Util.readAddress(in); diff --git a/src/org/jgroups/protocols/FD_ALL.java b/src/org/jgroups/protocols/FD_ALL.java index 4ebfd232879..d4e9e5d2cc1 100644 --- a/src/org/jgroups/protocols/FD_ALL.java +++ b/src/org/jgroups/protocols/FD_ALL.java @@ -400,9 +400,12 @@ public HeartbeatHeader() {} public String toString() {return "heartbeat";} public short getMagicId() {return 62;} public Supplier create() {return HeartbeatHeader::new;} + @Override public int serializedSize() {return 0;} - public void writeTo(DataOutput out) throws Exception {} - public void readFrom(DataInput in) throws Exception {} + @Override + public void writeTo(DataOutput out) {} + @Override + public void readFrom(DataInput in) {} } diff --git a/src/org/jgroups/protocols/FD_ALL2.java b/src/org/jgroups/protocols/FD_ALL2.java index 5724e236a7e..cc1a56dc241 100644 --- a/src/org/jgroups/protocols/FD_ALL2.java +++ b/src/org/jgroups/protocols/FD_ALL2.java @@ -374,9 +374,12 @@ public HeartbeatHeader() {} public short getMagicId() {return 63;} public Supplier create() {return HeartbeatHeader::new;} public String toString() {return "heartbeat";} + @Override public int serializedSize() {return 0;} - public void writeTo(DataOutput out) throws Exception {} - public void readFrom(DataInput in) throws Exception {} + @Override + public void writeTo(DataOutput out) {} + @Override + public void readFrom(DataInput in) {} } diff --git a/src/org/jgroups/protocols/FD_SOCK.java b/src/org/jgroups/protocols/FD_SOCK.java index 0496e273c6e..9e694a9e5a5 100644 --- a/src/org/jgroups/protocols/FD_SOCK.java +++ b/src/org/jgroups/protocols/FD_SOCK.java @@ -897,7 +897,7 @@ public static String type2String(byte type) { } } - + @Override public int serializedSize() { int retval=Global.BYTE_SIZE; // type retval+=Util.size(mbr); @@ -916,7 +916,8 @@ public int serializedSize() { return retval; } - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { out.writeByte(type); Util.writeAddress(mbr, out); Util.writeStreamable(sock_addr, out); @@ -927,7 +928,8 @@ public void writeTo(DataOutput out) throws Exception { Util.writeAddress(address, out); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { type=in.readByte(); mbr=Util.readAddress(in); sock_addr=Util.readStreamable(IpAddress::new, in); diff --git a/src/org/jgroups/protocols/FORK.java b/src/org/jgroups/protocols/FORK.java index b7cec7a3559..afa0913dfff 100644 --- a/src/org/jgroups/protocols/FORK.java +++ b/src/org/jgroups/protocols/FORK.java @@ -376,14 +376,17 @@ public void setForkChannelId(String fork_channel_id) { this.fork_channel_id=fork_channel_id; } + @Override public int serializedSize() {return Util.size(fork_stack_id) + Util.size(fork_channel_id);} - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { Bits.writeString(fork_stack_id,out); Bits.writeString(fork_channel_id,out); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException { fork_stack_id=Bits.readString(in); fork_channel_id=Bits.readString(in); } diff --git a/src/org/jgroups/protocols/FORWARD_TO_COORD.java b/src/org/jgroups/protocols/FORWARD_TO_COORD.java index d1dba2746ea..ffe9fe47280 100644 --- a/src/org/jgroups/protocols/FORWARD_TO_COORD.java +++ b/src/org/jgroups/protocols/FORWARD_TO_COORD.java @@ -9,6 +9,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.util.Collections; import java.util.List; import java.util.Objects; @@ -204,14 +205,17 @@ public ForwardHeader(byte type, long id) { public short getMagicId() {return 81;} public long getId() {return id;} public byte getType() {return type;} + @Override public int serializedSize() {return Global.BYTE_SIZE + Bits.size(id);} - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { out.writeByte(type); Bits.writeLong(id,out); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException { type=in.readByte(); id=Bits.readLong(in); } diff --git a/src/org/jgroups/protocols/FcHeader.java b/src/org/jgroups/protocols/FcHeader.java index c4343f1f50e..e55f0eb5a66 100644 --- a/src/org/jgroups/protocols/FcHeader.java +++ b/src/org/jgroups/protocols/FcHeader.java @@ -5,6 +5,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.util.function.Supplier; /** @@ -31,15 +32,18 @@ public Supplier create() { public short getMagicId() {return 59;} + @Override public int serializedSize() { return Global.BYTE_SIZE; } - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { out.writeByte(type); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException { type=in.readByte(); } diff --git a/src/org/jgroups/protocols/Frag3Header.java b/src/org/jgroups/protocols/Frag3Header.java index 0e45c1ed103..22060831d23 100644 --- a/src/org/jgroups/protocols/Frag3Header.java +++ b/src/org/jgroups/protocols/Frag3Header.java @@ -5,6 +5,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.util.function.Supplier; @@ -48,8 +49,8 @@ public String toString() { id, frag_id, num_frags, original_length, offset); } - - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { Bits.writeInt(id,out); Bits.writeInt(frag_id, out); Bits.writeInt(num_frags, out); @@ -57,11 +58,13 @@ public void writeTo(DataOutput out) throws Exception { Bits.writeInt(offset, out); } + @Override public int serializedSize() { return Bits.size(id) + Bits.size(frag_id) + Bits.size(num_frags) + Bits.size(original_length) + Bits.size(offset); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException { id=Bits.readInt(in); frag_id=Bits.readInt(in); num_frags=Bits.readInt(in); diff --git a/src/org/jgroups/protocols/FragHeader.java b/src/org/jgroups/protocols/FragHeader.java index 02fcd81da13..5d58e3a7acd 100644 --- a/src/org/jgroups/protocols/FragHeader.java +++ b/src/org/jgroups/protocols/FragHeader.java @@ -5,6 +5,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.util.function.Supplier; @@ -36,18 +37,20 @@ public String toString() { return "[id=" + id + ", frag_id=" + frag_id + ", num_frags=" + num_frags + ']'; } - - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { Bits.writeLong(id,out); Bits.writeInt(frag_id, out); Bits.writeInt(num_frags, out); } + @Override public int serializedSize() { return Bits.size(id) + Bits.size(frag_id) + Bits.size(num_frags); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException { id=Bits.readLong(in); frag_id=Bits.readInt(in); num_frags=Bits.readInt(in); diff --git a/src/org/jgroups/protocols/Locking.java b/src/org/jgroups/protocols/Locking.java index 4b97a89c26a..a614a58ac82 100644 --- a/src/org/jgroups/protocols/Locking.java +++ b/src/org/jgroups/protocols/Locking.java @@ -13,6 +13,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.util.*; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentSkipListSet; @@ -1537,7 +1538,8 @@ public Request(Type type, String lock_name, Owner owner, long timeout, boolean i public Address sender() {return this.sender;} public Request sender(Address sender) {this.sender=sender; return this;} - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { out.writeByte(type.ordinal()); Bits.writeString(lock_name,out); out.writeInt(lock_id); @@ -1548,7 +1550,8 @@ public void writeTo(DataOutput out) throws Exception { Util.writeAddress(sender, out); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { type=Type.values()[in.readByte()]; lock_name=Bits.readString(in); lock_id=in.readInt(); @@ -1625,14 +1628,17 @@ public Supplier create() { return LockingHeader::new; } + @Override public int serializedSize() { return 0; } - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { } } @@ -1648,7 +1654,7 @@ protected LockInfoResponse add(Tuple el) { return this; } - public void writeTo(DataOutput out) throws Exception { + public void writeTo(DataOutput out) throws IOException { if(existing_locks == null) out.writeInt(0); else { @@ -1667,7 +1673,7 @@ public void writeTo(DataOutput out) throws Exception { } } - public void readFrom(DataInput in) throws Exception { + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { int size=in.readInt(); if(size > 0) { existing_locks=new ArrayList<>(size); diff --git a/src/org/jgroups/protocols/MERGE3.java b/src/org/jgroups/protocols/MERGE3.java index 7ba1a871b6d..9f0e32c0f5e 100644 --- a/src/org/jgroups/protocols/MERGE3.java +++ b/src/org/jgroups/protocols/MERGE3.java @@ -12,6 +12,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.util.*; import java.util.concurrent.ConcurrentSkipListSet; import java.util.concurrent.Future; @@ -533,6 +534,7 @@ protected MergeHeader(Type type, ViewId view_id, String logical_name, PhysicalAd public short getMagicId() {return 75;} public Supplier create() {return MergeHeader::new;} + @Override public int serializedSize() { int retval=Global.BYTE_SIZE; // for the type retval+=Util.size(view_id); @@ -543,15 +545,16 @@ public int serializedSize() { return retval; } - public void writeTo(DataOutput outstream) throws Exception { + @Override + public void writeTo(DataOutput outstream) throws IOException { outstream.writeByte(type.ordinal()); // a byte if ok as we only have 3 types anyway Util.writeViewId(view_id,outstream); Bits.writeString(logical_name,outstream); Util.writeAddress(physical_addr, outstream); } - @SuppressWarnings("unchecked") - public void readFrom(DataInput instream) throws Exception { + @Override + public void readFrom(DataInput instream) throws IOException, ClassNotFoundException { type=Type.values()[instream.readByte()]; view_id=Util.readViewId(instream); logical_name=Bits.readString(instream); diff --git a/src/org/jgroups/protocols/NAMING.java b/src/org/jgroups/protocols/NAMING.java index 26ed492a97e..5f80ffad4ba 100644 --- a/src/org/jgroups/protocols/NAMING.java +++ b/src/org/jgroups/protocols/NAMING.java @@ -11,6 +11,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.util.Objects; import java.util.function.Supplier; @@ -174,22 +175,26 @@ public Header(Type t, Address addr, String name) { public short getMagicId() {return 89;} - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { out.writeShort(type.ordinal()); Util.writeAddress(addr, out); Bits.writeString(name, out); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { type=Type.values()[in.readShort()]; addr=Util.readAddress(in); name=Bits.readString(in); } + @Override public String toString() { return String.format("%s addr=%s name=%s", type, addr, name); } + @Override public int serializedSize() { return Global.SHORT_SIZE + Util.size(addr) + Util.size(name); } diff --git a/src/org/jgroups/protocols/PDC.java b/src/org/jgroups/protocols/PDC.java index fd349f19be5..3bb7929fe10 100644 --- a/src/org/jgroups/protocols/PDC.java +++ b/src/org/jgroups/protocols/PDC.java @@ -300,13 +300,15 @@ public Mapping(Address logical_addr, PhysicalAddress physical_addr, String logic public Address getPhysicalAddr() {return physical_addr;} public String getLogicalName() {return logical_name;} - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { Util.writeAddress(logical_addr, out); Util.writeAddress(physical_addr, out); Bits.writeString(logical_name,out); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { logical_addr=Util.readAddress(in); physical_addr=Util.readAddress(in); logical_name=Bits.readString(in); diff --git a/src/org/jgroups/protocols/PERF.java b/src/org/jgroups/protocols/PERF.java index 55a64150fc7..fb182bf3861 100644 --- a/src/org/jgroups/protocols/PERF.java +++ b/src/org/jgroups/protocols/PERF.java @@ -10,6 +10,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.util.function.Supplier; /** @@ -105,15 +106,18 @@ public Supplier create() { return PerfHeader::new; } + @Override public int serializedSize() { return Global.LONG_SIZE; } - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { out.writeLong(start_time); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException { start_time=in.readLong(); } } diff --git a/src/org/jgroups/protocols/PingData.java b/src/org/jgroups/protocols/PingData.java index 96eb73589b5..fde999ed4f3 100644 --- a/src/org/jgroups/protocols/PingData.java +++ b/src/org/jgroups/protocols/PingData.java @@ -11,6 +11,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.Objects; @@ -121,6 +122,7 @@ else if(isServer()) return sb.toString(); } + @Override public int serializedSize() { int retval=Global.BYTE_SIZE; // for is_server retval+=Util.size(sender); @@ -132,7 +134,8 @@ public int serializedSize() { return retval; } - public void writeTo(DataOutput outstream) throws Exception { + @Override + public void writeTo(DataOutput outstream) throws IOException { Util.writeAddress(sender, outstream); outstream.writeByte(flags); Bits.writeString(logical_name,outstream); @@ -140,7 +143,8 @@ public void writeTo(DataOutput outstream) throws Exception { Util.writeAddresses(mbrs, outstream); } - public void readFrom(DataInput instream) throws Exception { + @Override + public void readFrom(DataInput instream) throws IOException, ClassNotFoundException { sender=Util.readAddress(instream); flags=instream.readByte(); logical_name=Bits.readString(instream); diff --git a/src/org/jgroups/protocols/PingHeader.java b/src/org/jgroups/protocols/PingHeader.java index 2d3e991c0b5..8b105377663 100644 --- a/src/org/jgroups/protocols/PingHeader.java +++ b/src/org/jgroups/protocols/PingHeader.java @@ -7,6 +7,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.util.function.Supplier; @@ -35,6 +36,7 @@ public PingHeader() { public Supplier create() {return PingHeader::new;} + @Override public int serializedSize() { int retval=Global.BYTE_SIZE *3; // type, cluster_name presence and initial_discovery if(cluster_name != null) @@ -54,14 +56,15 @@ static String type2Str(byte t) { } } - - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { out.writeByte(type); Bits.writeString(cluster_name,out); out.writeBoolean(initial_discovery); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException { type=in.readByte(); cluster_name=Bits.readString(in); initial_discovery=in.readBoolean(); diff --git a/src/org/jgroups/protocols/RELAY.java b/src/org/jgroups/protocols/RELAY.java index 53da069b243..8bc58e59909 100644 --- a/src/org/jgroups/protocols/RELAY.java +++ b/src/org/jgroups/protocols/RELAY.java @@ -11,6 +11,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.util.*; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; @@ -630,6 +631,7 @@ public Supplier create() { return RelayHeader::new; } + @Override public int serializedSize() { int retval=Global.BYTE_SIZE; // type switch(type) { @@ -644,7 +646,8 @@ public int serializedSize() { return retval; } - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { out.writeByte(type.ordinal()); switch(type) { case DISSEMINATE: @@ -657,7 +660,8 @@ public void writeTo(DataOutput out) throws Exception { } } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { type=Type.values()[in.readByte()]; switch(type) { case DISSEMINATE: @@ -705,8 +709,8 @@ public static ViewData create(View remote_view, View global_view) { return new ViewData(remote_view, global_view, tmp); } - - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { Util.writeView(remote_view, out); Util.writeView(global_view, out); out.writeInt(uuids.size()); @@ -716,7 +720,8 @@ public void writeTo(DataOutput out) throws Exception { } } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { remote_view=Util.readView(in); global_view=Util.readView(in); int size=in.readInt(); diff --git a/src/org/jgroups/protocols/RSVP.java b/src/org/jgroups/protocols/RSVP.java index 753784efc61..e70b1d27300 100644 --- a/src/org/jgroups/protocols/RSVP.java +++ b/src/org/jgroups/protocols/RSVP.java @@ -12,6 +12,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.util.*; import java.util.concurrent.*; import java.util.function.Supplier; @@ -384,16 +385,19 @@ public RsvpHeader(byte type, short id) { public short getMagicId() {return 76;} public Supplier create() {return RsvpHeader::new;} + @Override public int serializedSize() { return Global.BYTE_SIZE + Global.SHORT_SIZE; } - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { out.writeByte(type); out.writeShort(id); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException { type=in.readByte(); id=in.readShort(); } diff --git a/src/org/jgroups/protocols/SEQUENCER.java b/src/org/jgroups/protocols/SEQUENCER.java index a98880d5a82..3d4ea99c2f2 100644 --- a/src/org/jgroups/protocols/SEQUENCER.java +++ b/src/org/jgroups/protocols/SEQUENCER.java @@ -11,6 +11,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.util.List; import java.util.Map; import java.util.NavigableMap; @@ -640,19 +641,21 @@ protected final String printType() { } } - - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { out.writeByte(type); Bits.writeLong(seqno,out); out.writeBoolean(flush_ack); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException { type=in.readByte(); seqno=Bits.readLong(in); flush_ack=in.readBoolean(); } + @Override public int serializedSize() { return Global.BYTE_SIZE + Bits.size(seqno) + Global.BYTE_SIZE; // type + seqno + flush_ack } diff --git a/src/org/jgroups/protocols/SEQUENCER2.java b/src/org/jgroups/protocols/SEQUENCER2.java index 57caabd65a8..c92f88a94a3 100644 --- a/src/org/jgroups/protocols/SEQUENCER2.java +++ b/src/org/jgroups/protocols/SEQUENCER2.java @@ -14,6 +14,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.util.List; import java.util.Objects; import java.util.concurrent.BlockingQueue; @@ -459,19 +460,22 @@ protected final String printType() { } } - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { out.writeByte(type); Bits.writeLong(seqno,out); out.writeShort(num_seqnos); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException { type=in.readByte(); seqno=Bits.readLong(in); num_seqnos=in.readUnsignedShort(); } // type + seqno + localSeqno + flush_ack + @Override public int serializedSize() { return Global.BYTE_SIZE + Bits.size(seqno) + Global.SHORT_SIZE; } diff --git a/src/org/jgroups/protocols/STOMP.java b/src/org/jgroups/protocols/STOMP.java index 2eb31fc634c..232616a1f42 100644 --- a/src/org/jgroups/protocols/STOMP.java +++ b/src/org/jgroups/protocols/STOMP.java @@ -646,8 +646,7 @@ public static StompHeader createHeader(Type type, Map headers) { return retval; } - - + @Override public int serializedSize() { int retval=Global.INT_SIZE *2; // type + size of hashmap for(Map.Entry entry: headers.entrySet()) { @@ -657,7 +656,8 @@ public int serializedSize() { return retval; } - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { out.writeInt(type.ordinal()); out.writeInt(headers.size()); for(Map.Entry entry: headers.entrySet()) { @@ -666,7 +666,8 @@ public void writeTo(DataOutput out) throws Exception { } } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException { type=Type.values()[in.readInt()]; int size=in.readInt(); for(int i=0; i < size; i++) { diff --git a/src/org/jgroups/protocols/SaslHeader.java b/src/org/jgroups/protocols/SaslHeader.java index 3ec9cba5489..118c1b2b9d1 100644 --- a/src/org/jgroups/protocols/SaslHeader.java +++ b/src/org/jgroups/protocols/SaslHeader.java @@ -5,6 +5,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.util.function.Supplier; public class SaslHeader extends Header { @@ -58,13 +59,13 @@ public Supplier create() { } @Override - public void writeTo(DataOutput out) throws Exception { + public void writeTo(DataOutput out) throws IOException { out.writeByte(type.ordinal()); Util.writeByteBuffer(payload, out); } @Override - public void readFrom(DataInput in) throws Exception { + public void readFrom(DataInput in) throws IOException { type = Type.values()[in.readByte()]; payload = Util.readByteBuffer(in); } diff --git a/src/org/jgroups/protocols/TpHeader.java b/src/org/jgroups/protocols/TpHeader.java index be202b8972a..4e052dff4ae 100644 --- a/src/org/jgroups/protocols/TpHeader.java +++ b/src/org/jgroups/protocols/TpHeader.java @@ -7,6 +7,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.util.function.Supplier; @@ -45,18 +46,21 @@ public String toString() { public byte[] getClusterName() {return cluster_name;} + @Override public int serializedSize() { return cluster_name != null? Global.SHORT_SIZE + cluster_name.length : Global.SHORT_SIZE; } - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { int length=cluster_name != null? cluster_name.length : -1; out.writeShort(length); if(cluster_name != null) out.write(cluster_name, 0, cluster_name.length); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException { int len=in.readShort(); if(len >= 0) { cluster_name=new byte[len]; diff --git a/src/org/jgroups/protocols/UnicastHeader3.java b/src/org/jgroups/protocols/UnicastHeader3.java index 94c4677f211..1ba93d71980 100644 --- a/src/org/jgroups/protocols/UnicastHeader3.java +++ b/src/org/jgroups/protocols/UnicastHeader3.java @@ -6,6 +6,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.util.function.Supplier; /** @@ -133,7 +134,8 @@ public UnicastHeader3 copy() { * | CLOSE | conn_id | * */ - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { out.writeByte(type); switch(type) { case DATA: @@ -157,7 +159,8 @@ public void writeTo(DataOutput out) throws Exception { } } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException { type=in.readByte(); switch(type) { case DATA: diff --git a/src/org/jgroups/protocols/VERIFY_SUSPECT.java b/src/org/jgroups/protocols/VERIFY_SUSPECT.java index 8cf9492ee78..216a0d784bd 100644 --- a/src/org/jgroups/protocols/VERIFY_SUSPECT.java +++ b/src/org/jgroups/protocols/VERIFY_SUSPECT.java @@ -9,6 +9,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.net.InetAddress; import java.net.NetworkInterface; import java.util.*; @@ -381,17 +382,19 @@ public String toString() { } } - - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { out.writeShort(type); Util.writeAddress(from, out); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { type=in.readShort(); from=Util.readAddress(in); } + @Override public int serializedSize() { return Global.SHORT_SIZE + Util.size(from); } diff --git a/src/org/jgroups/protocols/pbcast/DeltaView.java b/src/org/jgroups/protocols/pbcast/DeltaView.java index 3b03aeec173..826289a2344 100644 --- a/src/org/jgroups/protocols/pbcast/DeltaView.java +++ b/src/org/jgroups/protocols/pbcast/DeltaView.java @@ -8,6 +8,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.util.Arrays; import java.util.Iterator; @@ -53,7 +54,7 @@ public DeltaView(ViewId view_id, ViewId ref_view_id, Address[] left_members, Add public Address[] getLeftMembers() {return left_members;} public Address[] getNewMembers() {return new_members;} - + @Override public int serializedSize() { int retval=view_id.serializedSize() + ref_view_id.serializedSize(); retval+=Util.size(left_members); @@ -61,15 +62,16 @@ public int serializedSize() { return retval; } - - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { view_id.writeTo(out); ref_view_id.writeTo(out); Util.writeAddresses(left_members, out); Util.writeAddresses(new_members, out); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { view_id=new ViewId(); view_id.readFrom(in); ref_view_id=new ViewId(); diff --git a/src/org/jgroups/protocols/pbcast/FLUSH.java b/src/org/jgroups/protocols/pbcast/FLUSH.java index 932a03fb8ea..fb2f7ba4689 100644 --- a/src/org/jgroups/protocols/pbcast/FLUSH.java +++ b/src/org/jgroups/protocols/pbcast/FLUSH.java @@ -7,6 +7,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.util.*; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -1039,14 +1040,14 @@ public String toString() { } } - - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { out.writeByte(type); out.writeLong(viewID); } - @SuppressWarnings("unchecked") - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException { type = in.readByte(); viewID = in.readLong(); } diff --git a/src/org/jgroups/protocols/pbcast/GMS.java b/src/org/jgroups/protocols/pbcast/GMS.java index 4ed40ca147f..7d7492fa5d8 100644 --- a/src/org/jgroups/protocols/pbcast/GMS.java +++ b/src/org/jgroups/protocols/pbcast/GMS.java @@ -16,6 +16,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.util.*; import java.util.concurrent.Callable; import java.util.concurrent.TimeoutException; @@ -1416,7 +1417,8 @@ public GmsHeader(byte type, Address mbr) { public Supplier create() {return GmsHeader::new;} - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { out.writeByte(type); short flags=determineFlags(); out.writeShort(flags); @@ -1425,7 +1427,8 @@ public void writeTo(DataOutput out) throws Exception { merge_id.writeTo(out); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { type=in.readByte(); short flags=in.readShort(); mbr=Util.readAddress(in); @@ -1437,6 +1440,7 @@ public void readFrom(DataInput in) throws Exception { useFlushIfPresent=(flags & USE_FLUSH) == USE_FLUSH; } + @Override public int serializedSize() { int retval=Global.BYTE_SIZE // type + Global.SHORT_SIZE // flags diff --git a/src/org/jgroups/protocols/pbcast/JoinRsp.java b/src/org/jgroups/protocols/pbcast/JoinRsp.java index 9ddb268a654..26307adf26d 100644 --- a/src/org/jgroups/protocols/pbcast/JoinRsp.java +++ b/src/org/jgroups/protocols/pbcast/JoinRsp.java @@ -10,6 +10,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.util.function.Supplier; @@ -45,8 +46,8 @@ public Supplier create() { public String getFailReason() {return fail_reason;} public JoinRsp setFailReason(String r) {fail_reason=r; return this;} - - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { byte flags=0; if(view != null) flags|=VIEW_PRESENT; @@ -69,7 +70,8 @@ public void writeTo(DataOutput out) throws Exception { out.writeUTF(fail_reason); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { byte flags=in.readByte(); // 1. view @@ -89,6 +91,7 @@ public void readFrom(DataInput in) throws Exception { fail_reason=in.readUTF(); } + @Override public int serializedSize() { int retval=Global.BYTE_SIZE; // flags diff --git a/src/org/jgroups/protocols/pbcast/NakAckHeader2.java b/src/org/jgroups/protocols/pbcast/NakAckHeader2.java index 86b11e82cce..6fb6f82857b 100644 --- a/src/org/jgroups/protocols/pbcast/NakAckHeader2.java +++ b/src/org/jgroups/protocols/pbcast/NakAckHeader2.java @@ -9,6 +9,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.util.function.Supplier; @@ -70,8 +71,8 @@ private NakAckHeader2(byte type, Address sender) { public long getSeqno() {return seqno;} public Address getSender() {return sender;} - - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { out.writeByte(type); switch(type) { case MSG: @@ -85,7 +86,8 @@ public void writeTo(DataOutput out) throws Exception { } } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { type=in.readByte(); switch(type) { case MSG: @@ -98,8 +100,8 @@ public void readFrom(DataInput in) throws Exception { break; } } - + @Override public int serializedSize() { int retval=Global.BYTE_SIZE; // type switch(type) { diff --git a/src/org/jgroups/protocols/pbcast/STABLE.java b/src/org/jgroups/protocols/pbcast/STABLE.java index 10af1e70d8b..649c1034823 100644 --- a/src/org/jgroups/protocols/pbcast/STABLE.java +++ b/src/org/jgroups/protocols/pbcast/STABLE.java @@ -9,6 +9,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.util.Collections; import java.util.List; import java.util.Objects; @@ -789,17 +790,20 @@ public String toString() { return String.format("[%s] view-id= %s", type2String(type), view_id); } + @Override public int serializedSize() { return Global.BYTE_SIZE // type + Util.size(view_id); } - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { out.writeByte(type); Util.writeViewId(view_id, out); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { type=in.readByte(); view_id=Util.readViewId(in); } diff --git a/src/org/jgroups/protocols/pbcast/STATE_TRANSFER.java b/src/org/jgroups/protocols/pbcast/STATE_TRANSFER.java index 5abc037c12b..66f5cbca2da 100644 --- a/src/org/jgroups/protocols/pbcast/STATE_TRANSFER.java +++ b/src/org/jgroups/protocols/pbcast/STATE_TRANSFER.java @@ -14,6 +14,7 @@ import java.io.DataInput; import java.io.DataOutput; import java.io.EOFException; +import java.io.IOException; import java.util.*; import java.util.concurrent.atomic.LongAdder; import java.util.function.Supplier; @@ -440,17 +441,19 @@ static String type2Str(int t) { } } - - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { out.writeByte(type); Util.writeStreamable(my_digest, out); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { type=in.readByte(); my_digest=Util.readStreamable(Digest::new, in); } + @Override public int serializedSize() { int retval=Global.BYTE_SIZE; // type retval+=Global.BYTE_SIZE; // presence byte for my_digest diff --git a/src/org/jgroups/protocols/pbcast/StreamingStateTransfer.java b/src/org/jgroups/protocols/pbcast/StreamingStateTransfer.java index d0e56b4315c..b5c92d6e3eb 100644 --- a/src/org/jgroups/protocols/pbcast/StreamingStateTransfer.java +++ b/src/org/jgroups/protocols/pbcast/StreamingStateTransfer.java @@ -9,6 +9,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.*; @@ -569,19 +570,21 @@ static String type2Str(int t) { } } - - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { out.writeByte(type); Util.writeStreamable(digest, out); Util.writeStreamable(bind_addr, out); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { type=in.readByte(); digest=Util.readStreamable(Digest::new, in); bind_addr=Util.readStreamable(IpAddress::new, in); } + @Override public int serializedSize() { int retval=Global.BYTE_SIZE; // type retval+=Global.BYTE_SIZE; // presence byte for my_digest diff --git a/src/org/jgroups/protocols/relay/RELAY2.java b/src/org/jgroups/protocols/relay/RELAY2.java index 1f0a5791ba7..e11352faf1c 100644 --- a/src/org/jgroups/protocols/relay/RELAY2.java +++ b/src/org/jgroups/protocols/relay/RELAY2.java @@ -13,6 +13,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.io.InputStream; import java.util.*; import java.util.concurrent.TimeUnit; @@ -781,17 +782,20 @@ public Relay2Header(byte type, Address final_dest, Address original_sender) { public short getMagicId() {return 80;} public Supplier create() {return Relay2Header::new;} + @Override public int serializedSize() { return Global.BYTE_SIZE + Util.size(final_dest) + Util.size(original_sender); } - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { out.writeByte(type); Util.writeAddress(final_dest, out); Util.writeAddress(original_sender, out); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { type=in.readByte(); final_dest=Util.readAddress(in); original_sender=Util.readAddress(in); diff --git a/src/org/jgroups/protocols/tom/MessageID.java b/src/org/jgroups/protocols/tom/MessageID.java index 04fd0e1312f..253e0000890 100644 --- a/src/org/jgroups/protocols/tom/MessageID.java +++ b/src/org/jgroups/protocols/tom/MessageID.java @@ -7,6 +7,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; /** @@ -77,18 +78,19 @@ public int hashCode() { return result; } + @Override public int serializedSize() { return Bits.size(id) + Util.size(address); } @Override - public void writeTo(DataOutput out) throws Exception { + public void writeTo(DataOutput out) throws IOException { Util.writeAddress(address, out); Bits.writeLong(id, out); } @Override - public void readFrom(DataInput in) throws Exception { + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { address = Util.readAddress(in); id = Bits.readLong(in); } diff --git a/src/org/jgroups/protocols/tom/ToaHeader.java b/src/org/jgroups/protocols/tom/ToaHeader.java index ed67db21850..c459e4a1824 100644 --- a/src/org/jgroups/protocols/tom/ToaHeader.java +++ b/src/org/jgroups/protocols/tom/ToaHeader.java @@ -1,14 +1,15 @@ package org.jgroups.protocols.tom; +import org.jgroups.Global; +import org.jgroups.Header; +import org.jgroups.util.Bits; + import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.util.Objects; import java.util.function.Supplier; -import org.jgroups.Global; -import org.jgroups.Header; -import org.jgroups.util.Bits; - /** * The header for the Total Order Anycast (TOA) protocol * @@ -61,7 +62,7 @@ public int serializedSize() { } @Override - public void writeTo(DataOutput out) throws Exception { + public void writeTo(DataOutput out) throws IOException { out.writeByte(type); messageID.writeTo(out); Bits.writeLong(sequencerNumber, out); @@ -69,7 +70,7 @@ public void writeTo(DataOutput out) throws Exception { } @Override - public void readFrom(DataInput in) throws Exception { + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { type = in.readByte(); messageID = new MessageID(); messageID.readFrom(in); diff --git a/src/org/jgroups/stack/GossipData.java b/src/org/jgroups/stack/GossipData.java index f390ef0295e..2e54966d458 100644 --- a/src/org/jgroups/stack/GossipData.java +++ b/src/org/jgroups/stack/GossipData.java @@ -12,6 +12,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -138,8 +139,8 @@ public int serializedSize() { return retval; } - - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { out.writeByte(type.ordinal()); Bits.writeString(group, out); Util.writeAddress(addr, out); @@ -160,12 +161,13 @@ public void writeTo(DataOutput out) throws Exception { out.write(buffer, offset, length); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { readFrom(in, true); } - protected void readFrom(DataInput in, boolean read_type) throws Exception { + protected void readFrom(DataInput in, boolean read_type) throws IOException, ClassNotFoundException { if(read_type) type=GossipType.values()[in.readByte()]; group=Bits.readString(in); diff --git a/src/org/jgroups/stack/IpAddress.java b/src/org/jgroups/stack/IpAddress.java index 53f2ef0fe95..654c0fc861c 100644 --- a/src/org/jgroups/stack/IpAddress.java +++ b/src/org/jgroups/stack/IpAddress.java @@ -151,7 +151,8 @@ public String printIpAddress() { } - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { if(ip_addr != null) { byte[] address=ip_addr.getAddress(); // 4 bytes (IPv4) or 16 bytes (IPv6) out.writeByte(address.length); // 1 byte @@ -165,7 +166,8 @@ public void writeTo(DataOutput out) throws Exception { out.writeShort(port); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException { int len=in.readByte(); if(len > 0 && (len != Global.IPV4_SIZE && len != Global.IPV6_SIZE)) throw new IOException("length has to be " + Global.IPV4_SIZE + " or " + Global.IPV6_SIZE + " bytes (was " + @@ -184,6 +186,7 @@ public void readFrom(DataInput in) throws Exception { port=in.readUnsignedShort(); } + @Override public int serializedSize() { // length (1 bytes) + 4 bytes for port int tmp_size=Global.BYTE_SIZE+ Global.SHORT_SIZE; diff --git a/src/org/jgroups/stack/IpAddressUUID.java b/src/org/jgroups/stack/IpAddressUUID.java index c2b3e4bbe09..cc391b39587 100644 --- a/src/org/jgroups/stack/IpAddressUUID.java +++ b/src/org/jgroups/stack/IpAddressUUID.java @@ -7,6 +7,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.UnknownHostException; @@ -110,18 +111,21 @@ public boolean equals(Object obj) { (high >> 16) ^ high); }*/ - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { super.writeTo(out); out.writeLong(low); out.writeInt(high); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException { super.readFrom(in); low=in.readLong(); high=in.readInt(); } + @Override public int serializedSize() { return super.serializedSize() + Global.LONG_SIZE + Global.INT_SIZE; } diff --git a/src/org/jgroups/util/Average.java b/src/org/jgroups/util/Average.java index 3d69f111e11..eb28e8b491e 100644 --- a/src/org/jgroups/util/Average.java +++ b/src/org/jgroups/util/Average.java @@ -2,6 +2,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; /** * Maintains an approximation of an average of values. Done by keeping track of the number of samples, and computing @@ -62,12 +63,14 @@ public String toString() { return String.valueOf(getAverage()); } - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { out.writeDouble(avg); Bits.writeLong(count, out); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException { avg=in.readDouble(); count=Bits.readLong(in); } diff --git a/src/org/jgroups/util/AverageMinMax.java b/src/org/jgroups/util/AverageMinMax.java index 5a510a4a76e..76af88bb48f 100644 --- a/src/org/jgroups/util/AverageMinMax.java +++ b/src/org/jgroups/util/AverageMinMax.java @@ -2,6 +2,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -78,13 +79,13 @@ public String toString() { return count == 0? "n/a" : String.format("min/avg/max=%,d/%,.2f/%,d", min, getAverage(), max); } - public void writeTo(DataOutput out) throws Exception { + public void writeTo(DataOutput out) throws IOException { super.writeTo(out); Bits.writeLong(min, out); Bits.writeLong(max, out); } - public void readFrom(DataInput in) throws Exception { + public void readFrom(DataInput in) throws IOException { super.readFrom(in); min=Bits.readLong(in); max=Bits.readLong(in); diff --git a/src/org/jgroups/util/Digest.java b/src/org/jgroups/util/Digest.java index 63954644a9a..fbd6b02a4b9 100644 --- a/src/org/jgroups/util/Digest.java +++ b/src/org/jgroups/util/Digest.java @@ -7,6 +7,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.util.*; import java.util.function.Supplier; @@ -143,11 +144,12 @@ public Digest copy() { return new Digest(members, Arrays.copyOf(seqnos, seqnos.length)); } - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { writeTo(out, true); } - public void writeTo(DataOutput out, boolean write_addrs) throws Exception { + public void writeTo(DataOutput out, boolean write_addrs) throws IOException { if(write_addrs) Util.writeAddresses(members, out); else @@ -156,11 +158,12 @@ public void writeTo(DataOutput out, boolean write_addrs) throws Exception { Bits.writeLongSequence(seqnos[i * 2], seqnos[i * 2 +1], out); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { readFrom(in, true); } - public void readFrom(DataInput in, boolean read_addrs) throws Exception { + public void readFrom(DataInput in, boolean read_addrs) throws IOException, ClassNotFoundException { if(read_addrs) { members=Util.readAddresses(in); seqnos=new long[capacity() * 2]; @@ -172,6 +175,7 @@ public void readFrom(DataInput in, boolean read_addrs) throws Exception { Bits.readLongSequence(in, seqnos, i*2); } + @Override public int serializedSize() { return (int)serializedSize(true); } diff --git a/src/org/jgroups/util/ExtendedUUID.java b/src/org/jgroups/util/ExtendedUUID.java index b7eb67f1bda..9afcf8aefed 100644 --- a/src/org/jgroups/util/ExtendedUUID.java +++ b/src/org/jgroups/util/ExtendedUUID.java @@ -149,20 +149,20 @@ public T addContents(T o) { return (T)this; } - - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { super.writeTo(out); write(out); } - - - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException { super.readFrom(in); read(in); } /** The number of bytes required to serialize this instance */ + @Override public int serializedSize() { return super.serializedSize() + Global.BYTE_SIZE + sizeofHashMap(); } diff --git a/src/org/jgroups/util/FlagsUUID.java b/src/org/jgroups/util/FlagsUUID.java index bcd926929af..8c2aa0ad885 100644 --- a/src/org/jgroups/util/FlagsUUID.java +++ b/src/org/jgroups/util/FlagsUUID.java @@ -61,19 +61,20 @@ public T addContents(T other) { return (T)this; } - - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { super.writeTo(out); Bits.writeInt(flags, out); } - - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException { super.readFrom(in); flags=Bits.readInt(in); } /** The number of bytes required to serialize this instance */ + @Override public int serializedSize() {return super.serializedSize() + Bits.size(flags);} public String toString() { return flags == 0? super.toString() : String.format("%s (flags=%d)", super.toString(), flags); diff --git a/src/org/jgroups/util/MergeId.java b/src/org/jgroups/util/MergeId.java index 5408eb63433..587ec0468b6 100644 --- a/src/org/jgroups/util/MergeId.java +++ b/src/org/jgroups/util/MergeId.java @@ -5,6 +5,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; /** ID to uniquely identify a merge * @author Bela Ban @@ -41,12 +42,14 @@ public int size() { return Util.size(initiator) + Global.INT_SIZE; } - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { Util.writeAddress(initiator, out); out.writeInt(id); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { initiator=Util.readAddress(in); id=in.readInt(); } diff --git a/src/org/jgroups/util/Owner.java b/src/org/jgroups/util/Owner.java index 09c8d7c868e..f26da3e61b7 100644 --- a/src/org/jgroups/util/Owner.java +++ b/src/org/jgroups/util/Owner.java @@ -5,6 +5,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; /** @@ -31,12 +32,14 @@ public long getThreadId() { return thread_id; } - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { Util.writeAddress(address, out); Bits.writeLong(thread_id, out); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { address=Util.readAddress(in); thread_id=Bits.readLong(in); } diff --git a/src/org/jgroups/util/Range.java b/src/org/jgroups/util/Range.java index 9d881cff9a5..b6c81002109 100644 --- a/src/org/jgroups/util/Range.java +++ b/src/org/jgroups/util/Range.java @@ -4,6 +4,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; public class Range implements SizeStreamable, Comparable { @@ -42,18 +43,20 @@ public boolean equals(Object obj) { } - - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { Bits.writeLongSequence(low, high, out); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException { long[] seqnos={0,0}; Bits.readLongSequence(in, seqnos, 0); low=seqnos[0]; high=seqnos[1]; } + @Override public int serializedSize() { return Bits.size(low, high); } diff --git a/src/org/jgroups/util/SeqnoList.java b/src/org/jgroups/util/SeqnoList.java index 9b2506ecc94..1e2f2027ab9 100644 --- a/src/org/jgroups/util/SeqnoList.java +++ b/src/org/jgroups/util/SeqnoList.java @@ -5,6 +5,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.util.Iterator; import java.util.NoSuchElementException; import java.util.function.Supplier; @@ -77,19 +78,22 @@ public long getLast() { return index == -1? -1 : seqno(index); } + @Override public int serializedSize() { return Global.INT_SIZE // number of words + (words.length+1) * Global.LONG_SIZE; // words + offset } - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { out.writeInt(size); out.writeLong(offset); for(long word: words) out.writeLong(word); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException { size=in.readInt(); offset=in.readLong(); words=new long[wordIndex(size - 1) + 1]; diff --git a/src/org/jgroups/util/Streamable.java b/src/org/jgroups/util/Streamable.java index 76d2f4ed783..58b58b1a39e 100644 --- a/src/org/jgroups/util/Streamable.java +++ b/src/org/jgroups/util/Streamable.java @@ -2,6 +2,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; /** * Implementations of Streamable can add their state directly to the output stream, enabling them to bypass costly @@ -12,9 +13,9 @@ public interface Streamable { /** Write the entire state of the current object (including superclasses) to outstream. * Note that the output stream must not be closed */ - void writeTo(DataOutput out) throws Exception; + void writeTo(DataOutput out) throws IOException; /** Read the state of the current object (including superclasses) from instream * Note that the input stream must not be closed */ - void readFrom(DataInput in) throws Exception; + void readFrom(DataInput in) throws IOException, ClassNotFoundException; } diff --git a/src/org/jgroups/util/UUID.java b/src/org/jgroups/util/UUID.java index 80cf837cf00..db9311737a7 100644 --- a/src/org/jgroups/util/UUID.java +++ b/src/org/jgroups/util/UUID.java @@ -6,6 +6,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.security.SecureRandom; import java.util.function.Supplier; @@ -204,18 +205,19 @@ public int compareTo(Address other) { } - - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { out.writeLong(leastSigBits); out.writeLong(mostSigBits); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException { leastSigBits=in.readLong(); mostSigBits=in.readLong(); } - + @Override public int serializedSize() { return SIZE; } diff --git a/src/org/jgroups/util/Util.java b/src/org/jgroups/util/Util.java index 64349609735..54d4769c3f5 100644 --- a/src/org/jgroups/util/Util.java +++ b/src/org/jgroups/util/Util.java @@ -498,17 +498,17 @@ public static byte clearFlags(byte bits,byte flag) { /** * Creates an object from a byte buffer */ - public static T objectFromByteBuffer(byte[] buffer) throws Exception { + public static T objectFromByteBuffer(byte[] buffer) throws IOException, ClassNotFoundException { if(buffer == null) return null; return objectFromByteBuffer(buffer,0,buffer.length); } - public static T objectFromByteBuffer(byte[] buffer,int offset,int length) throws Exception { + public static T objectFromByteBuffer(byte[] buffer,int offset,int length) throws IOException, ClassNotFoundException { return objectFromByteBuffer(buffer, offset, length, null); } - public static T objectFromByteBuffer(byte[] buffer,int offset,int length, ClassLoader loader) throws Exception { + public static T objectFromByteBuffer(byte[] buffer,int offset,int length, ClassLoader loader) throws IOException, ClassNotFoundException { if(buffer == null) return null; byte type=buffer[offset++]; length--; @@ -548,7 +548,7 @@ public static T objectFromByteBuffer(byte[] buffer,int offset * Serializes/Streams an object into a byte buffer. * The object has to implement interface Serializable or Externalizable or Streamable. */ - public static byte[] objectToByteBuffer(Object obj) throws Exception { + public static byte[] objectToByteBuffer(Object obj) throws IOException { if(obj == null) return TYPE_NULL_ARRAY; @@ -575,7 +575,7 @@ public static byte[] objectToByteBuffer(Object obj) throws Exception { } - public static Buffer objectToBuffer(Object obj) throws Exception { + public static Buffer objectToBuffer(Object obj) throws IOException { if(obj == null) return new Buffer(TYPE_NULL_ARRAY); @@ -667,7 +667,7 @@ protected static byte[] marshalPrimitiveType(byte type, Object obj) { - public static void objectToStream(Object obj, DataOutput out) throws Exception { + public static void objectToStream(Object obj, DataOutput out) throws IOException { if(obj == null) { out.write(TYPE_NULL); return; @@ -743,11 +743,11 @@ else if((type=PRIMITIVE_TYPES.get(obj.getClass())) != null) { } } - public static T objectFromStream(DataInput in) throws Exception { + public static T objectFromStream(DataInput in) throws IOException, ClassNotFoundException { return objectFromStream(in, null); } - public static T objectFromStream(DataInput in, ClassLoader loader) throws Exception { + public static T objectFromStream(DataInput in, ClassLoader loader) throws IOException, ClassNotFoundException { if(in == null) return null; byte b=in.readByte(); @@ -788,7 +788,8 @@ public static T objectFromStream(DataInput in, ClassLoader lo } } - public static T streamableFromByteBuffer(Class cl,byte[] buffer) throws Exception { + public static T streamableFromByteBuffer(Class cl,byte[] buffer) + throws Exception { return streamableFromByteBuffer(cl,buffer,0,buffer.length); } @@ -799,12 +800,12 @@ public static T streamableFromByteBuffer(Supplier fact /** * Poor man's serialization of an exception. Serializes only the message, stack trace and cause (not suppressed exceptions) */ - public static void exceptionToStream(Throwable t, DataOutput out) throws Exception { + public static void exceptionToStream(Throwable t, DataOutput out) throws IOException { Set causes=new HashSet<>(); exceptionToStream(causes, t, out); } - protected static void exceptionToStream(Set causes, Throwable t, DataOutput out) throws Exception { + protected static void exceptionToStream(Set causes, Throwable t, DataOutput out) throws IOException { // 1. null check if( t == null) { out.writeBoolean(true); @@ -823,19 +824,19 @@ protected static void exceptionToStream(Set causes, Throwable t, Data writeException(causes, t, out); } - public static Buffer exceptionToBuffer(Throwable t) throws Exception { + public static Buffer exceptionToBuffer(Throwable t) throws IOException { ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(512, true); exceptionToStream(t, out); return out.getBuffer(); } - public static Throwable exceptionFromStream(DataInput in) throws Exception { + public static Throwable exceptionFromStream(DataInput in) throws IOException, ClassNotFoundException { return exceptionFromStream(in, 0); } - protected static Throwable exceptionFromStream(DataInput in, int recursion_count) throws Exception { + protected static Throwable exceptionFromStream(DataInput in, int recursion_count) throws IOException, ClassNotFoundException { // 1. null check if(in.readBoolean()) return null; @@ -846,7 +847,7 @@ protected static Throwable exceptionFromStream(DataInput in, int recursion_count return readException(in, recursion_count); } - protected static void writeException(Set causes, Throwable t, DataOutput out) throws Exception { + protected static void writeException(Set causes, Throwable t, DataOutput out) throws IOException { // 3. classname Bits.writeString(t.getClass().getName(), out); @@ -876,7 +877,7 @@ protected static void writeException(Set causes, Throwable t, DataOut } - protected static Throwable readException(DataInput in, int recursion_count) throws Exception { + protected static Throwable readException(DataInput in, int recursion_count) throws IOException, ClassNotFoundException { // 3. classname String classname=Bits.readString(in); Class clazz=(Class)Util.loadClass(classname, (ClassLoader)null); @@ -898,10 +899,15 @@ protected static Throwable readException(DataInput in, int recursion_count) thro catch(Throwable ignored) { } - if(retval == null) - retval=clazz.newInstance(); + if(retval == null) { + try { + retval=clazz.getDeclaredConstructor().newInstance(); + } catch (IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e) { + throw new IllegalStateException(e); + } + } - // 5. stack trace + // 5. stack trace int depth=in.readShort(); if(depth > 0) { StackTraceElement[] stack_trace=new StackTraceElement[depth]; @@ -935,7 +941,7 @@ protected static Throwable readException(DataInput in, int recursion_count) thro } - public static Throwable exceptionFromBuffer(byte[] buf, int offset, int length) throws Exception { + public static Throwable exceptionFromBuffer(byte[] buf, int offset, int length) throws IOException, ClassNotFoundException { ByteArrayDataInputStream in=new ByteArrayDataInputStream(buf, offset,length); return exceptionFromStream(in); } @@ -958,7 +964,7 @@ public static void bufferToArray(final Address sender, final ByteBuffer buf, org public static T streamableFromByteBuffer(Class cl,byte[] buffer,int offset,int length) throws Exception { if(buffer == null) return null; DataInput in=new ByteArrayDataInputStream(buffer,offset,length); - T retval=(T)cl.newInstance(); + T retval=(T)cl.getDeclaredConstructor().newInstance(); retval.readFrom(in); return retval; } @@ -971,18 +977,13 @@ public static T streamableFromByteBuffer(Supplier fact return retval; } - @Deprecated - public static T streamableFromBuffer(Class clazz,byte[] buffer,int offset,int length) throws Exception { - DataInput in=new ByteArrayDataInputStream(buffer,offset,length); - return Util.readStreamable(clazz, in); - } - - public static T streamableFromBuffer(Supplier factory, byte[] buffer, int offset, int length) throws Exception { - DataInput in=new ByteArrayDataInputStream(buffer,offset,length); + public static T streamableFromBuffer(Supplier factory, byte[] buf, int off, int len) + throws IOException, ClassNotFoundException { + DataInput in=new ByteArrayDataInputStream(buf,off,len); return Util.readStreamable(factory, in); } - public static byte[] streamableToByteBuffer(Streamable obj) throws Exception { + public static byte[] streamableToByteBuffer(Streamable obj) throws IOException { int expected_size=obj instanceof SizeStreamable? ((SizeStreamable)obj).serializedSize() : 512; final ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(expected_size); obj.writeTo(out); @@ -1002,7 +1003,7 @@ public static Buffer streamableToBuffer(Streamable obj) { } - public static byte[] collectionToByteBuffer(Collection

c) throws Exception { + public static byte[] collectionToByteBuffer(Collection
c) throws IOException { final ByteArrayDataOutputStream out=new ByteArrayDataOutputStream((int)Util.size(c)); Util.writeAddresses(c,out); return Arrays.copyOf(out.buffer(), out.position()); @@ -1074,12 +1075,7 @@ public static Object convert(String arg, Class type) { - /** - * This method needs to be synchronized on out_stream when it is called - * @param msg - * @throws java.io.IOException - */ - public static void writeMessage(Message msg, DataOutput dos, boolean multicast) throws Exception { + public static void writeMessage(Message msg, DataOutput dos, boolean multicast) throws IOException { byte flags=0; dos.writeShort(Version.version); // write the version if(multicast) @@ -1088,7 +1084,7 @@ public static void writeMessage(Message msg, DataOutput dos, boolean multicast) msg.writeTo(dos); } - public static Message readMessage(DataInput instream) throws Exception { + public static Message readMessage(DataInput instream) throws IOException, ClassNotFoundException { Message msg=new Message(false); // don't create headers, readFrom() will do this msg.readFrom(instream); return msg; @@ -1113,7 +1109,7 @@ public static Message readMessage(DataInput instream) throws Exception { * @throws Exception */ public static void writeMessageList(Address dest, Address src, byte[] cluster_name, - List msgs, DataOutput dos, boolean multicast, short transport_id) throws Exception { + List msgs, DataOutput dos, boolean multicast, short transport_id) throws IOException { writeMessageListHeader(dest, src, cluster_name, msgs != null ? msgs.size() : 0, dos, multicast); if(msgs != null) @@ -1121,7 +1117,7 @@ public static void writeMessageList(Address dest, Address src, byte[] cluster_na msg.writeToNoAddrs(src, dos, transport_id); // exclude the transport header } - public static void writeMessageListHeader(Address dest, Address src, byte[] cluster_name, int numMsgs, DataOutput dos, boolean multicast) throws Exception { + public static void writeMessageListHeader(Address dest, Address src, byte[] cluster_name, int numMsgs, DataOutput dos, boolean multicast) throws IOException { dos.writeShort(Version.version); byte flags=LIST; @@ -1142,7 +1138,7 @@ public static void writeMessageListHeader(Address dest, Address src, byte[] clus } - public static List readMessageList(DataInput in, short transport_id) throws Exception { + public static List readMessageList(DataInput in, short transport_id) throws IOException, ClassNotFoundException { List list=new LinkedList<>(); Address dest=Util.readAddress(in); Address src=Util.readAddress(in); @@ -1181,7 +1177,7 @@ public static List readMessageList(DataInput in, short transport_id) th * @return an array of 4 MessageBatches in the order above, the first batch is at index 0 * @throws Exception */ - public static MessageBatch[] readMessageBatch(DataInput in, boolean multicast) throws Exception { + public static MessageBatch[] readMessageBatch(DataInput in, boolean multicast) throws IOException, ClassNotFoundException { MessageBatch[] batches=new MessageBatch[4]; // [0]: reg, [1]: OOB, [2]: internal-oob, [3]: internal Address dest=Util.readAddress(in); Address src=Util.readAddress(in); @@ -1283,7 +1279,7 @@ public static String dump(byte[] buf, int offset, int length) { } - public static void writeView(View view,DataOutput out) throws Exception { + public static void writeView(View view,DataOutput out) throws IOException { if(view == null) { out.writeBoolean(false); return; @@ -1294,7 +1290,7 @@ public static void writeView(View view,DataOutput out) throws Exception { } - public static View readView(DataInput in) throws Exception { + public static View readView(DataInput in) throws IOException, ClassNotFoundException { if(!in.readBoolean()) return null; boolean isMergeView=in.readBoolean(); @@ -1307,7 +1303,7 @@ public static View readView(DataInput in) throws Exception { return view; } - public static void writeViewId(ViewId vid,DataOutput out) throws Exception { + public static void writeViewId(ViewId vid,DataOutput out) throws IOException { if(vid == null) { out.writeBoolean(false); return; @@ -1316,7 +1312,7 @@ public static void writeViewId(ViewId vid,DataOutput out) throws Exception { vid.writeTo(out); } - public static ViewId readViewId(DataInput in) throws Exception { + public static ViewId readViewId(DataInput in) throws IOException, ClassNotFoundException { if(!in.readBoolean()) return null; ViewId retval=new ViewId(); @@ -1325,7 +1321,7 @@ public static ViewId readViewId(DataInput in) throws Exception { } - public static void writeAddress(Address addr,DataOutput out) throws Exception { + public static void writeAddress(Address addr,DataOutput out) throws IOException { byte flags=0; boolean streamable_addr=true; @@ -1359,7 +1355,7 @@ else if(addr.getClass().equals(IpAddressUUID.class)) writeOtherAddress(addr,out); } - public static Address readAddress(DataInput in) throws Exception { + public static Address readAddress(DataInput in) throws IOException, ClassNotFoundException { byte flags=in.readByte(); if(Util.isFlagSet(flags,Address.NULL)) return null; @@ -1435,14 +1431,14 @@ public static int size(byte[] buf) { return buf == null? Global.BYTE_SIZE : Global.BYTE_SIZE + Global.INT_SIZE + buf.length; } - private static Address readOtherAddress(DataInput in) throws Exception { + private static Address readOtherAddress(DataInput in) throws IOException, ClassNotFoundException { short magic_number=in.readShort(); Address addr=ClassConfigurator.create(magic_number); addr.readFrom(in); return addr; } - private static void writeOtherAddress(Address addr,DataOutput out) throws Exception { + private static void writeOtherAddress(Address addr,DataOutput out) throws IOException { short magic_number=ClassConfigurator.getMagicNumber(addr.getClass()); // write the class info @@ -1459,7 +1455,7 @@ private static void writeOtherAddress(Address addr,DataOutput out) throws Except * @param out * @throws Exception */ - public static void writeAddresses(Collection v,DataOutput out) throws Exception { + public static void writeAddresses(Collection v,DataOutput out) throws IOException { if(v == null) { out.writeShort(-1); return; @@ -1470,7 +1466,7 @@ public static void writeAddresses(Collection v,DataOutput out } } - public static void writeAddresses(final Address[] addrs,DataOutput out) throws Exception { + public static void writeAddresses(final Address[] addrs,DataOutput out) throws IOException { if(addrs == null) { out.writeShort(-1); return; @@ -1480,32 +1476,9 @@ public static void writeAddresses(final Address[] addrs,DataOutput out) throws E Util.writeAddress(addr,out); } - /** - * @param in - * @param cl The type of Collection, e.g. ArrayList.class - * @return Collection of Address objects - * @throws Exception - */ - @Deprecated - public static Collection readAddresses(DataInput in,Class cl) throws Exception { - short length=in.readShort(); - if(length < 0) return null; - Collection
retval=(Collection
)cl.newInstance(); - Address addr; - for(int i=0; i < length; i++) { - addr=Util.readAddress(in); - retval.add(addr); - } - return retval; - } - /** - * @param in - * @param factory a factory for creating the returned collection, parameterized by size - * @return Collection of Address objects - * @throws Exception - */ - public static > T readAddresses(DataInput in, IntFunction factory) throws Exception { + public static > T readAddresses(DataInput in, IntFunction factory) + throws IOException, ClassNotFoundException { short length=in.readShort(); if(length < 0) return null; T retval = factory.apply(length); @@ -1518,7 +1491,7 @@ public static > T readAddresses(DataInput in, IntF } - public static Address[] readAddresses(DataInput in) throws Exception { + public static Address[] readAddresses(DataInput in) throws IOException, ClassNotFoundException { short length=in.readShort(); if(length < 0) return null; Address[] retval=new Address[length]; @@ -1554,7 +1527,7 @@ public static long size(Address[] addrs) { } - public static void writeStreamable(Streamable obj,DataOutput out) throws Exception { + public static void writeStreamable(Streamable obj,DataOutput out) throws IOException { if(obj == null) { out.writeBoolean(false); return; @@ -1563,17 +1536,8 @@ public static void writeStreamable(Streamable obj,DataOutput out) throws Excepti obj.writeTo(out); } - @Deprecated - public static T readStreamable(Class clazz,DataInput in) throws Exception { - T retval=null; - if(!in.readBoolean()) - return null; - retval=clazz.newInstance(); - retval.readFrom(in); - return retval; - } - public static T readStreamable(Supplier factory, DataInput in) throws Exception { + public static T readStreamable(Supplier factory, DataInput in) throws IOException, ClassNotFoundException { T retval=null; if(!in.readBoolean()) return null; @@ -1582,7 +1546,7 @@ public static T readStreamable(Supplier factory, DataI return retval; } - public static void writeGenericStreamable(Streamable obj, DataOutput out) throws Exception { + public static void writeGenericStreamable(Streamable obj, DataOutput out) throws IOException { short magic_number; String classname; @@ -1601,11 +1565,11 @@ public static void writeGenericStreamable(Streamable obj, DataOutput out) throws obj.writeTo(out); // write the contents } - public static T readGenericStreamable(DataInput in) throws Exception { + public static T readGenericStreamable(DataInput in) throws IOException, ClassNotFoundException { return readGenericStreamable(in, null); } - public static T readGenericStreamable(DataInput in, ClassLoader loader) throws Exception { + public static T readGenericStreamable(DataInput in, ClassLoader loader) throws IOException, ClassNotFoundException { T retval=null; int b=in.readByte(); if(b == 0) @@ -1620,7 +1584,11 @@ public static T readGenericStreamable(DataInput in, Class else { String classname=in.readUTF(); clazz=ClassConfigurator.get(classname, loader); - retval=(T)clazz.newInstance(); + try { + retval=(T)clazz.getDeclaredConstructor().newInstance(); + } catch (IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e) { + throw new IllegalStateException(e); + } } retval.readFrom(in); @@ -1628,7 +1596,7 @@ public static T readGenericStreamable(DataInput in, Class } - public static void write(T[] array, DataOutput out) throws Exception { + public static void write(T[] array, DataOutput out) throws IOException { Bits.writeInt(array != null? array.length : 0, out); if(array == null) return; @@ -1643,7 +1611,7 @@ public static T[] read(Class clazz, DataInput in) thro T[] retval=(T[])Array.newInstance(clazz, size); for(int i=0; i < retval.length; i++) { - retval[i]=clazz.newInstance(); + retval[i]=clazz.getDeclaredConstructor().newInstance(); retval[i].readFrom(in); } return retval; @@ -1651,7 +1619,7 @@ public static T[] read(Class clazz, DataInput in) thro - public static void writeObject(Object obj,DataOutput out) throws Exception { + public static void writeObject(Object obj,DataOutput out) throws IOException { if(obj instanceof Streamable) { out.writeInt(-1); writeGenericStreamable((Streamable)obj,out); @@ -1663,7 +1631,7 @@ public static void writeObject(Object obj,DataOutput out) throws Exception { } } - public static Object readObject(DataInput in) throws Exception { + public static Object readObject(DataInput in) throws IOException, ClassNotFoundException { int len=in.readInt(); if(len == -1) return readGenericStreamable(in); @@ -1704,7 +1672,8 @@ public static String readContents(InputStream input) { } public static byte[] readFileContents(InputStream input) throws IOException { - byte contents[]=new byte[10000], buf[]=new byte[1024]; + byte[] contents=new byte[10000]; + byte[] buf=new byte[1024]; InputStream in=new BufferedInputStream(input); int bytes_read=0; @@ -1772,11 +1741,11 @@ public static int readIntFromStdin(String message) throws Exception { } - public static void writeByteBuffer(byte[] buf,DataOutput out) throws Exception { + public static void writeByteBuffer(byte[] buf,DataOutput out) throws IOException { writeByteBuffer(buf,0,buf.length,out); } - public static void writeByteBuffer(byte[] buf, int offset, int length, DataOutput out) throws Exception { + public static void writeByteBuffer(byte[] buf, int offset, int length, DataOutput out) throws IOException { if(buf != null) { out.write(1); out.writeInt(length); @@ -1786,7 +1755,7 @@ public static void writeByteBuffer(byte[] buf, int offset, int length, DataOutpu out.write(0); } - public static byte[] readByteBuffer(DataInput in) throws Exception { + public static byte[] readByteBuffer(DataInput in) throws IOException { int b=in.readByte(); if(b == 1) { b=in.readInt(); @@ -1798,16 +1767,15 @@ public static byte[] readByteBuffer(DataInput in) throws Exception { } - public static Buffer messageToByteBuffer(Message msg) throws Exception { + public static Buffer messageToByteBuffer(Message msg) throws IOException { ByteArrayDataOutputStream out=new ByteArrayDataOutputStream((int)msg.size()+1); - out.writeBoolean(msg != null); if(msg != null) msg.writeTo(out); return out.getBuffer(); } - public static Message byteBufferToMessage(byte[] buffer,int offset,int length) throws Exception { + public static Message byteBufferToMessage(byte[] buffer,int offset,int length) throws IOException, ClassNotFoundException { DataInput in=new ByteArrayDataInputStream(buffer,offset,length); if(!in.readBoolean()) return null; @@ -2302,12 +2270,9 @@ public static String[] components(String path,String separator) { * @return An array of byte buffers ({@code byte[]}). */ public static byte[][] fragmentBuffer(byte[] buf,int frag_size,final int length) { - byte[] retval[]; - int accumulated_size=0; + byte[][] retval; byte[] fragment; - int tmp_size=0; - int num_frags; - int index=0; + int accumulated_size=0, tmp_size=0, num_frags, index=0; num_frags=length % frag_size == 0? length / frag_size : length / frag_size + 1; retval=new byte[num_frags][]; @@ -2364,7 +2329,7 @@ public static List computeFragOffsets(byte[] buf,int frag_size) { * @param fragments An array of byte buffers ({@code byte[]}) * @return A byte buffer */ - public static byte[] defragmentBuffer(byte[] fragments[]) { + public static byte[] defragmentBuffer(byte[][] fragments) { int total_length=0; byte[] ret; int index=0; @@ -2461,16 +2426,6 @@ public static String printMapWithDelimiter(Map map,String delimiter) { } - /** Returns true if all elements of c match obj */ - public static boolean all(Collection c,Object obj) { - for(Iterator iterator=c.iterator(); iterator.hasNext(); ) { - Object o=iterator.next(); - if(!o.equals(obj)) - return false; - } - return true; - } - public static List
leftMembers(Collection
old_list,Collection
new_list) { if(old_list == null || new_list == null) @@ -3768,22 +3723,18 @@ public static InetAddress validateBindAddressFromInterface(InetAddress bind_addr } // 4. if only interface is specified, get first non-loopback address on that interface, - else { + else bind_addr=getAddress(bind_intf,AddressScope.NON_LOOPBACK); - } - //http://jira.jboss.org/jira/browse/JGRP-739 //check all bind_address against NetworkInterface.getByInetAddress() to see if it exists on the machine //in some Linux setups NetworkInterface.getByInetAddress(InetAddress.getLocalHost()) returns null, so skip //the check in that case - if(bind_addr != null && NetworkInterface.getByInetAddress(bind_addr) == null) { + if(bind_addr != null && NetworkInterface.getByInetAddress(bind_addr) == null) throw new UnknownHostException("Invalid bind address " + bind_addr); - } // if bind_addr == null, we have tried to obtain a bind_addr but were not successful // in such a case, return the original value of null so the default will be applied - return bind_addr; } @@ -4563,11 +4514,7 @@ public static String sha(String source) { } } - /** - * Converts a method name to an attribute name, e.g. getFooBar() --> foo_bar, isFlag --> flag. - * @param methodName - * @return - */ + /** Converts a method name to an attribute name, e.g. getFooBar() --> foo_bar, isFlag --> flag */ public static String methodNameToAttributeName(final String methodName) { String name=methodName; if((methodName.startsWith("get") || methodName.startsWith("set")) && methodName.length() > 3) diff --git a/tests/junit-functional/org/jgroups/tests/HeadersTest.java b/tests/junit-functional/org/jgroups/tests/HeadersTest.java index 199a56db645..4a8e157a482 100644 --- a/tests/junit-functional/org/jgroups/tests/HeadersTest.java +++ b/tests/junit-functional/org/jgroups/tests/HeadersTest.java @@ -158,12 +158,15 @@ public Supplier create() { return MyHeader::new; } - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) { } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) { } + @Override public int serializedSize() { return 0; } diff --git a/tests/junit-functional/org/jgroups/tests/MessageTest.java b/tests/junit-functional/org/jgroups/tests/MessageTest.java index 225eb93381c..cb5359b656d 100644 --- a/tests/junit-functional/org/jgroups/tests/MessageTest.java +++ b/tests/junit-functional/org/jgroups/tests/MessageTest.java @@ -492,14 +492,17 @@ public short getNum() { return num; } + @Override public int serializedSize() { return 0; } - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) { } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) { } public String toString() { diff --git a/tests/junit-functional/org/jgroups/tests/UtilTest.java b/tests/junit-functional/org/jgroups/tests/UtilTest.java index 0db9126bd13..6a52809a628 100644 --- a/tests/junit-functional/org/jgroups/tests/UtilTest.java +++ b/tests/junit-functional/org/jgroups/tests/UtilTest.java @@ -406,7 +406,6 @@ public static void testReadBytes() { } - @SuppressWarnings("unchecked") public void testSerialization() throws Exception { byte[] buf; Address addr=Util.createRandomAddress(), addr2; @@ -646,14 +645,17 @@ public void testBufferToArray() { // test heap based ByteBuffer: String hello="hello"; byte[] buffer=hello.getBytes(); - ByteBuffer buf=(ByteBuffer)ByteBuffer.allocate(50).putInt(322649).put(buffer).flip(); + ByteBuffer buf=ByteBuffer.allocate(50).putInt(322649).put(buffer); + buf.flip(); // for java 8 compatibility + buf.getInt(); MyNioReceiver receiver=new MyNioReceiver(); receiver.receive(null, buf); assert receiver.name.equals(hello); // test direct ByteBuffer: - buf=(ByteBuffer)ByteBuffer.allocateDirect(50).putInt(322649).put(buffer).flip(); + buf=ByteBuffer.allocateDirect(50).putInt(322649).put(buffer); + buf.flip(); buf.getInt(); receiver.receive(null, buf); assert receiver.name.equals(hello); @@ -1034,16 +1036,6 @@ public static void testPickNextN() { } - public static void testAll() { - List l=new ArrayList<>(); - l.add("one"); l.add("two"); l.add("one"); - System.out.println("-- list is " + l); - assert !(Util.all(l, "one")); - l.remove("two"); - System.out.println("-- list is " + l); - assert Util.all(l, "one"); - } - public static void testParseCommaDelimitedString() { String input="1,2,3,4,5,6,7,8,9,10 , 11, 12 ,13"; diff --git a/tests/junit/org/jgroups/blocks/RpcDispatcherSerializationTest.java b/tests/junit/org/jgroups/blocks/RpcDispatcherSerializationTest.java index cddbf95f04f..e2fb52fc0a3 100644 --- a/tests/junit/org/jgroups/blocks/RpcDispatcherSerializationTest.java +++ b/tests/junit/org/jgroups/blocks/RpcDispatcherSerializationTest.java @@ -110,7 +110,8 @@ static class MyMarshaller implements Marshaller { static final byte LONG = 2; static final byte OBJ = 3; - public void objectToStream(Object obj, DataOutput out) throws Exception { + @Override + public void objectToStream(Object obj, DataOutput out) throws IOException { if(obj == null) out.writeByte(NULL); else if(obj instanceof Boolean) { @@ -128,7 +129,8 @@ else if(obj instanceof Long) { } } - public Object objectFromStream(DataInput in) throws Exception { + @Override + public Object objectFromStream(DataInput in) throws IOException, ClassNotFoundException { int type=in.readByte(); switch(type) { case NULL: diff --git a/tests/junit/org/jgroups/blocks/executor/ExecutingServiceTest.java b/tests/junit/org/jgroups/blocks/executor/ExecutingServiceTest.java index 8db35ea5153..a2351f17c35 100644 --- a/tests/junit/org/jgroups/blocks/executor/ExecutingServiceTest.java +++ b/tests/junit/org/jgroups/blocks/executor/ExecutingServiceTest.java @@ -201,12 +201,12 @@ public SleepingStreamableCallable(long millis) { } @Override - public void writeTo(DataOutput out) throws Exception { + public void writeTo(DataOutput out) throws IOException { out.writeLong(millis); } @Override - public void readFrom(DataInput in) throws Exception { + public void readFrom(DataInput in) throws IOException { millis = in.readLong(); } @@ -255,30 +255,14 @@ public String toString() { } @Override - public void writeTo(DataOutput out) throws Exception { - try { - Util.writeObject(_object, out); - } - catch (IOException e) { - throw e; - } - catch (Exception e) { - throw new IOException(e); - } + public void writeTo(DataOutput out) throws IOException { + Util.writeObject(_object, out); } @SuppressWarnings("unchecked") @Override - public void readFrom(DataInput in) throws Exception { - try { - _object = (V)Util.readObject(in); - } - catch (IOException e) { - throw e; - } - catch (Exception e) { - throw new IOException(e); - } + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { + _object = (V)Util.readObject(in); } } diff --git a/tests/other/org/jgroups/tests/UnicastTestRpc.java b/tests/other/org/jgroups/tests/UnicastTestRpc.java index fad1e640aa8..3db2462a5e5 100644 --- a/tests/other/org/jgroups/tests/UnicastTestRpc.java +++ b/tests/other/org/jgroups/tests/UnicastTestRpc.java @@ -12,6 +12,7 @@ import java.io.BufferedReader; import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.io.InputStreamReader; import java.lang.reflect.Method; import java.util.ArrayList; @@ -366,11 +367,13 @@ public int estimatedSize(Object arg) { return 50; } - public void objectToStream(Object obj, DataOutput out) throws Exception { + @Override + public void objectToStream(Object obj, DataOutput out) throws IOException { Util.objectToStream(obj, out); } - public Object objectFromStream(DataInput in) throws Exception { + @Override + public Object objectFromStream(DataInput in) throws IOException, ClassNotFoundException { return Util.objectFromStream(in); } } diff --git a/tests/perf/org/jgroups/tests/perf/MPerf.java b/tests/perf/org/jgroups/tests/perf/MPerf.java index cf89b2f072d..242a3151430 100644 --- a/tests/perf/org/jgroups/tests/perf/MPerf.java +++ b/tests/perf/org/jgroups/tests/perf/MPerf.java @@ -608,12 +608,14 @@ public int size() { return Util.size(attr_name) + Util.size(attr_value); } - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { Bits.writeString(attr_name,out); Util.writeByteBuffer(attr_value, out); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException { attr_name=Bits.readString(in); attr_value=Util.readByteBuffer(in); } @@ -640,13 +642,13 @@ public int size() { return retval; } - public void writeTo(DataOutput out) throws Exception { + public void writeTo(DataOutput out) throws IOException { out.writeInt(changes.size()); for(ConfigChange change: changes) change.writeTo(out); } - public void readFrom(DataInput in) throws Exception { + public void readFrom(DataInput in) throws IOException { int len=in.readInt(); for(int i=0; i < len; i++) { ConfigChange change=new ConfigChange(); @@ -706,12 +708,12 @@ public int size() { return Bits.size(time) + Bits.size(msgs); } - public void writeTo(DataOutput out) throws Exception { + public void writeTo(DataOutput out) throws IOException { Bits.writeLong(time,out); Bits.writeLong(msgs,out); } - public void readFrom(DataInput in) throws Exception { + public void readFrom(DataInput in) throws IOException { time=Bits.readLong(in); msgs=Bits.readLong(in); } @@ -746,6 +748,7 @@ public Supplier create() { return MPerfHeader::new; } + @Override public int serializedSize() { int retval=Global.BYTE_SIZE; if(type == DATA) @@ -753,13 +756,13 @@ public int serializedSize() { return retval; } - public void writeTo(DataOutput out) throws Exception { + public void writeTo(DataOutput out) throws IOException { out.writeByte(type); if(type == DATA) Bits.writeLong(seqno, out); } - public void readFrom(DataInput in) throws Exception { + public void readFrom(DataInput in) throws IOException { type=in.readByte(); if(type == DATA) seqno=Bits.readLong(in); diff --git a/tests/perf/org/jgroups/tests/perf/MPerfRpc.java b/tests/perf/org/jgroups/tests/perf/MPerfRpc.java index 5f477cb3b49..22ca87da983 100644 --- a/tests/perf/org/jgroups/tests/perf/MPerfRpc.java +++ b/tests/perf/org/jgroups/tests/perf/MPerfRpc.java @@ -532,12 +532,14 @@ public int size() { return Util.size(attr_name) + Util.size(attr_value); } - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { Bits.writeString(attr_name,out); Util.writeByteBuffer(attr_value, out); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException { attr_name=Bits.readString(in); attr_value=Util.readByteBuffer(in); } @@ -564,13 +566,15 @@ public int size() { return retval; } - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { out.writeInt(changes.size()); for(ConfigChange change: changes) change.writeTo(out); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException { int len=in.readInt(); for(int i=0; i < len; i++) { ConfigChange change=new ConfigChange(); @@ -630,12 +634,14 @@ public int size() { return Bits.size(time) + Bits.size(msgs); } - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { Bits.writeLong(time, out); Bits.writeLong(msgs, out); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException { time=Bits.readLong(in); msgs=Bits.readLong(in); } @@ -654,11 +660,13 @@ public int estimatedSize(Object arg) { return 50; } - public void objectToStream(Object obj, DataOutput out) throws Exception { + @Override + public void objectToStream(Object obj, DataOutput out) throws IOException { Util.objectToStream(obj, out); } - public Object objectFromStream(DataInput in) throws Exception { + @Override + public Object objectFromStream(DataInput in) throws IOException, ClassNotFoundException { return Util.objectFromStream(in); } diff --git a/tests/perf/org/jgroups/tests/perf/ProgrammaticUPerf.java b/tests/perf/org/jgroups/tests/perf/ProgrammaticUPerf.java index b628a623e9e..2a2d7cfd5b6 100644 --- a/tests/perf/org/jgroups/tests/perf/ProgrammaticUPerf.java +++ b/tests/perf/org/jgroups/tests/perf/ProgrammaticUPerf.java @@ -18,6 +18,7 @@ import javax.management.MBeanServer; import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.net.InetAddress; @@ -492,7 +493,7 @@ public int estimatedSize(Object arg) { // Unless and until serialization is supported on GraalVM, we're sending only the exception message across the // wire, but not the entire exception - public void objectToStream(Object obj, DataOutput out) throws Exception { + public void objectToStream(Object obj, DataOutput out) throws IOException { if(obj instanceof Throwable) { Throwable t=(Throwable)obj; out.writeByte(1); @@ -504,7 +505,7 @@ public void objectToStream(Object obj, DataOutput out) throws Exception { } } - public Object objectFromStream(DataInput in) throws Exception { + public Object objectFromStream(DataInput in) throws IOException, ClassNotFoundException { byte type=in.readByte(); if(type == 0) return Util.objectFromStream(in); @@ -622,7 +623,7 @@ public Results(int num_gets, int num_puts, long time, AverageMinMax avg_gets, Av this.avg_puts=avg_puts; } - public void writeTo(DataOutput out) throws Exception { + public void writeTo(DataOutput out) throws IOException { Bits.writeLong(num_gets, out); Bits.writeLong(num_puts, out); Bits.writeLong(time, out); @@ -630,7 +631,7 @@ public void writeTo(DataOutput out) throws Exception { Util.writeStreamable(avg_puts, out); } - public void readFrom(DataInput in) throws Exception { + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { num_gets=Bits.readLong(in); num_puts=Bits.readLong(in); time=Bits.readLong(in); @@ -659,7 +660,7 @@ public Config add(String key, Object value) { return this; } - public void writeTo(DataOutput out) throws Exception { + public void writeTo(DataOutput out) throws IOException { out.writeInt(values.size()); for(Map.Entry entry: values.entrySet()) { Bits.writeString(entry.getKey(),out); @@ -667,7 +668,7 @@ public void writeTo(DataOutput out) throws Exception { } } - public void readFrom(DataInput in) throws Exception { + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { int size=in.readInt(); for(int i=0; i < size; i++) { String key=Bits.readString(in); diff --git a/tests/perf/org/jgroups/tests/perf/ProgrammaticUPerf2.java b/tests/perf/org/jgroups/tests/perf/ProgrammaticUPerf2.java index 9eaed3e5f1e..e0ae6943fbc 100644 --- a/tests/perf/org/jgroups/tests/perf/ProgrammaticUPerf2.java +++ b/tests/perf/org/jgroups/tests/perf/ProgrammaticUPerf2.java @@ -14,6 +14,7 @@ import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.net.InetAddress; @@ -476,7 +477,7 @@ public int estimatedSize(Object arg) { // Unless and until serialization is supported on GraalVM, we're sending only the exception message across the // wire, but not the entire exception - public void objectToStream(Object obj, DataOutput out) throws Exception { + public void objectToStream(Object obj, DataOutput out) throws IOException { if(obj instanceof Throwable) { Throwable t=(Throwable)obj; out.writeByte(1); @@ -488,7 +489,7 @@ public void objectToStream(Object obj, DataOutput out) throws Exception { } } - public Object objectFromStream(DataInput in) throws Exception { + public Object objectFromStream(DataInput in) throws IOException, ClassNotFoundException { byte type=in.readByte(); if(type == 0) return Util.objectFromStream(in); @@ -606,7 +607,7 @@ public Results(int num_gets, int num_puts, long execution_time, AverageMinMax av this.avg_puts=avg_puts; } - public void writeTo(DataOutput out) throws Exception { + public void writeTo(DataOutput out) throws IOException { Bits.writeLong(num_gets, out); Bits.writeLong(num_puts, out); Bits.writeLong(execution_time, out); @@ -614,7 +615,7 @@ public void writeTo(DataOutput out) throws Exception { Util.writeStreamable(avg_puts, out); } - public void readFrom(DataInput in) throws Exception { + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { num_gets=Bits.readLong(in); num_puts=Bits.readLong(in); execution_time=Bits.readLong(in); @@ -643,7 +644,7 @@ public Config add(String key, Object value) { return this; } - public void writeTo(DataOutput out) throws Exception { + public void writeTo(DataOutput out) throws IOException { out.writeInt(values.size()); for(Map.Entry entry: values.entrySet()) { Bits.writeString(entry.getKey(),out); @@ -651,7 +652,7 @@ public void writeTo(DataOutput out) throws Exception { } } - public void readFrom(DataInput in) throws Exception { + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { int size=in.readInt(); for(int i=0; i < size; i++) { String key=Bits.readString(in); diff --git a/tests/perf/org/jgroups/tests/perf/UPerf.java b/tests/perf/org/jgroups/tests/perf/UPerf.java index f553f066463..cfdb240a343 100644 --- a/tests/perf/org/jgroups/tests/perf/UPerf.java +++ b/tests/perf/org/jgroups/tests/perf/UPerf.java @@ -13,6 +13,7 @@ import javax.management.MBeanServer; import java.io.DataInput; import java.io.DataOutput; +import java.io.IOException; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.*; @@ -462,11 +463,13 @@ public int estimatedSize(Object arg) { return 50; } - public void objectToStream(Object obj, DataOutput out) throws Exception { + @Override + public void objectToStream(Object obj, DataOutput out) throws IOException { Util.objectToStream(obj, out); } - public Object objectFromStream(DataInput in) throws Exception { + @Override + public Object objectFromStream(DataInput in) throws IOException, ClassNotFoundException { return Util.objectFromStream(in); } } @@ -577,7 +580,8 @@ public Results(int num_gets, int num_puts, long time, AverageMinMax avg_gets, Av this.avg_puts=avg_puts; } - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { Bits.writeLong(num_gets, out); Bits.writeLong(num_puts, out); Bits.writeLong(time, out); @@ -585,7 +589,8 @@ public void writeTo(DataOutput out) throws Exception { Util.writeStreamable(avg_puts, out); } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { num_gets=Bits.readLong(in); num_puts=Bits.readLong(in); time=Bits.readLong(in); @@ -614,7 +619,8 @@ public Config add(String key, Object value) { return this; } - public void writeTo(DataOutput out) throws Exception { + @Override + public void writeTo(DataOutput out) throws IOException { out.writeInt(values.size()); for(Map.Entry entry: values.entrySet()) { Bits.writeString(entry.getKey(),out); @@ -622,7 +628,8 @@ public void writeTo(DataOutput out) throws Exception { } } - public void readFrom(DataInput in) throws Exception { + @Override + public void readFrom(DataInput in) throws IOException, ClassNotFoundException { int size=in.readInt(); for(int i=0; i < size; i++) { String key=Bits.readString(in); diff --git a/tests/util/org/jgroups/util/JUnitXMLReporter.java b/tests/util/org/jgroups/util/JUnitXMLReporter.java index 6ac731691ba..7c31feea596 100644 --- a/tests/util/org/jgroups/util/JUnitXMLReporter.java +++ b/tests/util/org/jgroups/util/JUnitXMLReporter.java @@ -618,7 +618,7 @@ protected static String statusToString(int status) { } } - public void writeTo(DataOutput out) throws Exception { + public void writeTo(DataOutput out) throws IOException { out.writeInt(status); Bits.writeString(classname,out); Bits.writeString(name,out); @@ -629,7 +629,7 @@ public void writeTo(DataOutput out) throws Exception { Bits.writeString(stack_trace,out); } - public void readFrom(DataInput in) throws Exception { + public void readFrom(DataInput in) throws IOException { status=in.readInt(); classname=Bits.readString(in); name=Bits.readString(in);