Skip to content

Commit

Permalink
cells: Refactor cloning of CellMessage and CellPath
Browse files Browse the repository at this point in the history
Target: trunk
Require-notes: no
Require-book: no
Acked-by: Tigran Mkrtchyan <tigran.mkrtchyan@desy.de>
Acked-by: Paul Millar <paul.millar@desy.de>
Patch: https://rb.dcache.org/r/8133/
  • Loading branch information
gbehrmann committed Apr 23, 2015
1 parent dc7c283 commit e4f6267
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 41 deletions.
Expand Up @@ -13,18 +13,8 @@ public CellExceptionMessage(CellPath addr, NoRouteToCellException msg)
super(addr, msg);
}

private CellExceptionMessage()
{
}

public NoRouteToCellException getException()
{
return (NoRouteToCellException) getMessageObject();
}

@Override
protected CellMessage cloneWithoutFields()
{
return new CellExceptionMessage();
}
}
44 changes: 24 additions & 20 deletions modules/cells/src/main/java/dmg/cells/nucleus/CellMessage.java
@@ -1,5 +1,7 @@
package dmg.cells.nucleus ;

import com.google.common.base.Throwables;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
Expand Down Expand Up @@ -47,7 +49,7 @@ public class CellMessage implements Cloneable , Serializable {

public CellMessage( CellPath addr , Serializable msg ){

_destination = (CellPath) addr.clone();
_destination = addr.clone();
_message = msg ;
_source = new CellPath() ;
_creationTime = System.currentTimeMillis() ;
Expand Down Expand Up @@ -136,40 +138,42 @@ public CellMessage()
_messageStream = null;
}

protected CellMessage cloneWithoutFields()
{
return new CellMessage();
}

protected CellMessage cloneWithoutPayload()
/**
* The method does not copy the message object - only the encoded message
* stream (if any).
*/
@Override
public CellMessage clone()
{
CellMessage copy = cloneWithoutFields();
copy._destination = (CellPath) _destination.clone();
copy._source = (CellPath) _source.clone();
copy._creationTime = _creationTime;
copy._receivedAt = _receivedAt;
copy._umid = _umid; // UOID is immutable
copy._lastUmid = _lastUmid;
copy._isPersistent = _isPersistent;
copy._session = _session;
copy._ttl = _ttl;
return copy;
try {
CellMessage copy = (CellMessage) super.clone();
copy._destination = _destination.clone();
if (_source != null) {
copy._source = _source.clone();
}
copy._messageStream = _messageStream;
return copy;
} catch (CloneNotSupportedException e) {
throw Throwables.propagate(e);
}
}

public CellMessage encode() throws SerializationException
{
checkState(_mode == ORIGINAL_MODE);
CellMessage encoded = cloneWithoutPayload();
CellMessage encoded = clone();
encoded._mode = STREAM_MODE;
encoded._message = null;
encoded._messageStream = encode(_message);
return encoded;
}

public CellMessage decode() throws SerializationException
{
checkState(_mode == STREAM_MODE);
CellMessage decoded = cloneWithoutPayload();
CellMessage decoded = clone();
decoded._mode = ORIGINAL_MODE;
decoded._messageStream = null;
decoded._message = decode(_messageStream);
return decoded;
}
Expand Down
Expand Up @@ -98,7 +98,7 @@ public synchronized void add(String path)
}

@Override
public synchronized Object clone()
public synchronized CellPath clone()
{
return new CellPath(_position, Lists.newArrayList(_list));
}
Expand Down
Expand Up @@ -458,7 +458,7 @@ private synchronized void forwardMessage( CellMessage message , String classEven
List<Entry> list = new ArrayList<>() ;
CellPath dest = message.getDestinationPath() ;
for (Map.Entry<CellAddressCore, Entry> mapentry: map.entrySet()) {
CellPath origin = (CellPath) dest.clone();
CellPath origin = dest.clone();
Entry entry = mapentry.getValue();
if (!entry.isValid()) {
list.add(entry);
Expand Down
Expand Up @@ -24,10 +24,10 @@ public BroadcastEventCommandMessage( String eventClass ){
}
public BroadcastEventCommandMessage(String eventClass , CellPath target ) {
_eventClass = eventClass ;
_target = target != null ? (CellPath)target.clone() : null ;
_target = target != null ? target.clone() : null ;
}
public CellPath getTarget(){
return _target == null ? null : (CellPath)_target.clone() ;
return _target == null ? null : _target.clone();
}
public String getEventClass(){ return _eventClass ; }
public String toString(){
Expand Down
Expand Up @@ -110,7 +110,7 @@ public MulticastCell( String name , String args )
@Override
public synchronized void messageArrived( CellMessage message ){
Object obj = message.getMessageObject() ;
CellPath path = (CellPath)(message.getSourcePath().clone()) ;
CellPath path = message.getSourcePath().clone();

if( obj instanceof NoRouteToCellException ){
synchronized( _ioLock ){
Expand Down
Expand Up @@ -464,8 +464,7 @@ public void messageArrived( CellMessage message ){
replicate.setProtocolInfo(info);

try {
sendMessage(new CellMessage((CellPath) path
.clone(), replicate));
sendMessage(new CellMessage(path.clone(), replicate));
} catch (RuntimeException ee) {
_log.warn("Problem : couldn't forward message to : " + entry._path + " : " + ee);
}
Expand Down
Expand Up @@ -123,8 +123,7 @@ public void setPoolMode(PoolV2Mode mode)
throw new LockedCacheException("Target file is busy");
}

Request request =
new Request((CellPath)envelope.getSourcePath().clone(), message);
Request request = new Request(envelope.getSourcePath().clone(), message);
_requests.put(request.getUUID(), request);
request.start();

Expand Down
3 changes: 1 addition & 2 deletions modules/dcache/src/main/java/org/dcache/util/Transfer.java
Expand Up @@ -892,8 +892,7 @@ public void startMover(String queue, long timeout)
/* As always, PoolIoFileMessage has to be sent via the
* PoolManager (which could be the SpaceManager).
*/
CellPath poolPath =
(CellPath) _poolManager.getDestinationPath().clone();
CellPath poolPath = _poolManager.getDestinationPath().clone();
poolPath.add(getPoolAddress());

setMoverId(_pool.sendAndWait(poolPath, message, timeout).getMoverId());
Expand Down

0 comments on commit e4f6267

Please sign in to comment.