Skip to content

Commit

Permalink
- Replaced Java serialization with streamable in NAKACK2, UNICAST3,
Browse files Browse the repository at this point in the history
  FlowControl, Locking, ExtendedUUID/SiteUUID
 (https://issues.jboss.org/browse/JGRP-2033)
- Moved RpcDispatcher$Marshaller into its own interface
- Marshaller now (de-)serializes only RPC args and return values (incl exceptions)
  • Loading branch information
belaban committed Mar 24, 2016
1 parent 2bdd1a4 commit 692143c
Show file tree
Hide file tree
Showing 37 changed files with 604 additions and 819 deletions.
10 changes: 5 additions & 5 deletions src/org/jgroups/Address.java
Expand Up @@ -20,11 +20,11 @@
*/
public interface Address extends Streamable, Comparable<Address>, Externalizable {
// flags used for marshalling
public static final byte NULL = 1 << 0;
public static final byte UUID_ADDR = 1 << 1;
public static final byte SITE_UUID = 1 << 2;
public static final byte SITE_MASTER = 1 << 3;
public static final byte IP_ADDR = 1 << 4;
byte NULL = 1 << 0;
byte UUID_ADDR = 1 << 1;
byte SITE_UUID = 1 << 2;
byte SITE_MASTER = 1 << 3;
byte IP_ADDR = 1 << 4;


/** Returns serialized size of this address */
Expand Down
2 changes: 1 addition & 1 deletion src/org/jgroups/JChannel.java
Expand Up @@ -699,7 +699,7 @@ public Object up(Event evt) {
if(up_handler != null) {
try {
Object retval=up_handler.up(evt);
state_promise.setResult(new StateTransferResult());
state_promise.setResult(result);
return retval;
}
catch(Throwable t) {
Expand Down
6 changes: 3 additions & 3 deletions src/org/jgroups/JChannelProbeHandler.java
Expand Up @@ -87,7 +87,7 @@ protected void handleJmx(Map<String, String> map, String input) {
Protocol prot=ch.getProtocolStack().findProtocol(protocol_name);
Field field=prot != null? Util.getField(prot.getClass(), attrname) : null;
if(field != null) {
Object value=MethodCall.convert(attrvalue,field.getType());
Object value=Util.convert(attrvalue,field.getType());
if(value != null)
prot.setValue(attrname, value);
}
Expand All @@ -100,7 +100,7 @@ protected void handleJmx(Map<String, String> map, String input) {
((ResourceDMBean.FieldAccessor)setter).getField().getType() :
setter instanceof ResourceDMBean.MethodAccessor?
((ResourceDMBean.MethodAccessor)setter).getMethod().getParameterTypes()[0].getClass() : null;
Object converted_value=MethodCall.convert(attrvalue, type);
Object converted_value=Util.convert(attrvalue, type);
setter.invoke(converted_value);
}
catch(Exception e) {
Expand Down Expand Up @@ -181,7 +181,7 @@ protected void handleOperation(Map<String, String> map, String operation) throws
converted_args=new Object[args.length];
Class<?>[] types=method.getParameterTypes();
for(int i=0; i < args.length; i++)
converted_args[i]=MethodCall.convert(args[i], types[i]);
converted_args[i]=Util.convert(args[i], types[i]);
}
Object retval=call.invoke(prot, converted_args);
if(retval != null)
Expand Down
27 changes: 9 additions & 18 deletions src/org/jgroups/Message.java
Expand Up @@ -222,7 +222,7 @@ public byte[] getRawBuffer() {
*
* @return byte array with a copy of the buffer.
*/
final public byte[] getBuffer() {
public byte[] getBuffer() {
if(buf == null)
return null;
if(offset == 0 && length == buf.length)
Expand All @@ -234,6 +234,12 @@ final public byte[] getBuffer() {
}
}

public Buffer getBuffer2() {
if(buf == null)
return null;
return new Buffer(buf, offset, length);
}

/**
* <em>
* Note that the byte[] buffer passed as argument must not be modified. Reason: if we retransmit the
Expand Down Expand Up @@ -349,7 +355,7 @@ final public Message setObject(Object obj) {
}


final public Object getObject() {
final public <T extends Object> T getObject() {
return getObject(null);
}

Expand All @@ -365,7 +371,7 @@ final public Object getObject() {
*
* @return the object
*/
final public Object getObject(ClassLoader loader) {
final public <T extends Object> T getObject(ClassLoader loader) {
try {
return Util.objectFromByteBuffer(buf, offset, length, loader);
}
Expand Down Expand Up @@ -657,21 +663,6 @@ public String toString() {




/** Tries to read an object from the message's buffer and prints it */
public String toStringAsObject() {
if(buf == null) return null;
try {
Object obj=getObject();
return obj != null ? obj.toString() : "";
}
catch(Exception e) { // it is not an object
return "";
}
}



public String printObjectHeaders() {
return Headers.printObjectHeaders(this.headers);
}
Expand Down
40 changes: 40 additions & 0 deletions src/org/jgroups/blocks/Marshaller.java
@@ -0,0 +1,40 @@
package org.jgroups.blocks;

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

/**
* Performs serialization and de-serialization of RPC call arguments and return values (including exceptions)
* @author Bela Ban
* @since 2.x, 4.0
*/
public interface Marshaller {

/**
* Estimates the number of bytes needed to serialize an object to an output stream. This is used to create an output
* stream with an initial capacity, so it does not need to be exact. However, if the estimated size is much smaller than
* the actual size needed by the arguments, the output stream's buffer will have to be copied, possibly multiple times.
* @param arg the object; argument to an RPC, or return value (could also be an exception). May be null (e.g. an
* RPC returning void)
* @return the estimated size
*/
default int estimatedSize(Object arg) {
return arg == null? 2: 50;
}

/**
* 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
*/
void objectToStream(Object obj, DataOutput out) throws Exception;

/**
* 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
*/
Object objectFromStream(DataInput in) throws Exception;
}

0 comments on commit 692143c

Please sign in to comment.