Skip to content

Commit

Permalink
cells: Restore CellExceptionMessage encoding
Browse files Browse the repository at this point in the history
Some years ago we modified the cell message encoding/decoding to copy the
message rather than convert in place. Since then the CellExceptionMessage type
has been lost as it would be encoded and decoded as regular CellMessage. The
CellExceptionMessage type is important as it is used to distinguish message
delivery problems from service problems - thus we can avoid that a
no-route-to-cell exception bounces back and forth.

This patch restores the original encoding of CellExceptionMessage encoding.

Target: trunk
Require-notes: yes
Require-book: no
Request: 2.12
Request: 2.11
Request: 2.10
Acked-by: Paul Millar <paul.millar@desy.de>
Acked-by: Tigran Mkrtchyan <tigran.mkrtchyan@desy.de>
Patch: https://rb.dcache.org/r/8034/
(cherry picked from commit 829aa73)
  • Loading branch information
gbehrmann committed Mar 30, 2015
1 parent 39f8ed0 commit 8ee0741
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 32 deletions.
@@ -1,19 +1,23 @@
package dmg.cells.nucleus ;
package dmg.cells.nucleus;

import java.io.Serializable;

/**
*
*
* @author Patrick Fuhrmann
* @version 0.1, 15 Feb 1998
*/
public class CellExceptionMessage extends CellMessage {
public class CellExceptionMessage extends CellMessage
{
private static final long serialVersionUID = -5819709105553527283L;

private static final long serialVersionUID = -5819709105553527283L;
public CellExceptionMessage( CellPath addr , Serializable msg ){
super( addr , msg ) ;
}


public CellExceptionMessage(CellPath addr, Serializable msg)
{
super(addr, msg);
}

private CellExceptionMessage()
{
}

@Override
protected CellMessage cloneWithoutFields()
{
return new CellExceptionMessage();
}
}
45 changes: 27 additions & 18 deletions modules/cells/src/main/java/dmg/cells/nucleus/CellMessage.java
Expand Up @@ -136,9 +136,14 @@ public CellMessage()
_messageStream = null;
}

private CellMessage cloneWithoutPayload()
protected CellMessage cloneWithoutFields()
{
CellMessage copy = new CellMessage();
return new CellMessage();
}

protected CellMessage cloneWithoutPayload()
{
CellMessage copy = cloneWithoutFields();
copy._destination = (CellPath) _destination.clone();
copy._source = (CellPath) _source.clone();
copy._creationTime = _creationTime;
Expand All @@ -156,9 +161,24 @@ public CellMessage encode() throws SerializationException
checkState(_mode == ORIGINAL_MODE);
CellMessage encoded = cloneWithoutPayload();
encoded._mode = STREAM_MODE;
encoded._messageStream = encode(_message);
return encoded;
}

public CellMessage decode() throws SerializationException
{
checkState(_mode == STREAM_MODE);
CellMessage decoded = cloneWithoutPayload();
decoded._mode = ORIGINAL_MODE;
decoded._message = decode(_messageStream);
return decoded;
}

protected static byte[] encode(Object message)
{
ByteArrayOutputStream array = new ByteArrayOutputStream();
try (ObjectOutputStream out = new ObjectOutputStream(array)) {
out.writeObject(_message);
out.writeObject(message);
} catch (InvalidClassException e) {
throw new SerializationException("Failed to serialize object: "
+ e + "(this is usually a bug)", e);
Expand All @@ -167,29 +187,18 @@ public CellMessage encode() throws SerializationException
} catch (IOException e) {
throw new SerializationException("Failed to serialize object: " + e, e);
}

encoded._messageStream = array.toByteArray();
return encoded;
return array.toByteArray();
}

public CellMessage decode() throws SerializationException
protected static Object decode(byte[] messageStream)
{
checkState(_mode == STREAM_MODE);
CellMessage decoded = cloneWithoutPayload();
decoded._mode = ORIGINAL_MODE;
ByteArrayInputStream in;
ObjectInputStream stream;
try {
in = new ByteArrayInputStream(_messageStream);
stream = new ObjectInputStream(in);
decoded._message = stream.readObject();
try (ObjectInputStream stream = new ObjectInputStream(new ByteArrayInputStream(messageStream))) {
return stream.readObject();
} catch (ClassNotFoundException e) {
throw new SerializationException("Failed to deserialize object: The class could not be found. Is there a software version mismatch in your installation?", e);
} catch (IOException e) {
throw new SerializationException("Failed to deserialize object: " + e, e);
}

return decoded;
}

public void addSourceAddress( CellAddressCore source ){
Expand Down

0 comments on commit 8ee0741

Please sign in to comment.