Skip to content

Commit

Permalink
- JGRP-2242 Narrow set of thrown exceptions in Streamable and Marshal…
Browse files Browse the repository at this point in the history
…ler method signatures.

- Refined Paul's PR
  • Loading branch information
pferraro authored and belaban committed Apr 10, 2019
1 parent 3af8901 commit b3bc5f1
Show file tree
Hide file tree
Showing 94 changed files with 693 additions and 567 deletions.
5 changes: 3 additions & 2 deletions src/org/jgroups/AnycastAddress.java
Expand Up @@ -71,6 +71,7 @@ private void initCollection(int estimatedSize) {
}
}

@Override
public int serializedSize() {
if (destinations == null) {
return Global.INT_SIZE;
Expand Down Expand Up @@ -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);
}

Expand Down
9 changes: 6 additions & 3 deletions src/org/jgroups/MergeView.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand Down
29 changes: 9 additions & 20 deletions src/org/jgroups/Message.java
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -835,15 +824,15 @@ 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);
}



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);
Expand Down
9 changes: 6 additions & 3 deletions src/org/jgroups/View.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
Expand Down
9 changes: 6 additions & 3 deletions src/org/jgroups/ViewId.java
Expand Up @@ -7,6 +7,7 @@

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.function.Supplier;


Expand Down Expand Up @@ -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);
}
Expand Down
7 changes: 5 additions & 2 deletions src/org/jgroups/auth/FixedMembershipToken.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
6 changes: 4 additions & 2 deletions src/org/jgroups/auth/Krb5Token.java
Expand Up @@ -105,15 +105,17 @@ public boolean authenticate(AuthToken token, Message msg) {

return false;
}


@Override
public void writeTo(DataOutput out) throws IOException {
if (isAuthenticated()) {
generateServiceTicket();
writeServiceTicketToSream(out);
}
}

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
Expand Down
7 changes: 5 additions & 2 deletions src/org/jgroups/auth/MD5Token.java
Expand Up @@ -7,6 +7,7 @@

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
* <p>
Expand Down Expand Up @@ -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);
}

Expand Down
15 changes: 4 additions & 11 deletions src/org/jgroups/auth/RegexMembership.java
Expand Up @@ -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() {
Expand Down
23 changes: 5 additions & 18 deletions src/org/jgroups/auth/SimpleToken.java
Expand Up @@ -7,6 +7,7 @@

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
* <p>
Expand Down Expand Up @@ -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()");
}
Expand Down
6 changes: 4 additions & 2 deletions src/org/jgroups/auth/X509Token.java
Expand Up @@ -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;
}
Expand Down
6 changes: 4 additions & 2 deletions src/org/jgroups/blocks/GridFile.java
Expand Up @@ -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();
Expand Down

0 comments on commit b3bc5f1

Please sign in to comment.