dk.netarkivet.common.distribute
Class NetarkivetMessage

java.lang.Object
  extended by dk.netarkivet.common.distribute.NetarkivetMessage
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
ArchiveMessage, BatchTerminationMessage, HarvesterMessage, MonitorMessage

public abstract class NetarkivetMessage
extends java.lang.Object
implements java.io.Serializable

Common base class for all messages exchanged in the NetarchiveSuite.

See Also:
Serialized Form

Field Summary
(package private) static java.lang.String ERROR_DELIMITTER
           
protected  java.lang.String replyOfId
           
 
Constructor Summary
protected NetarkivetMessage(ChannelID to, ChannelID replyTo)
          Creates a new NetarkivetMessage.
 
Method Summary
 java.lang.String getErrMsg()
          Retrieve error message.
 java.lang.String getID()
          Retrieve message id.
 java.lang.String getReplyOfId()
          Retrieve replyOfId.
 ChannelID getReplyTo()
          Retrieve specified reply channel.
 ChannelID getTo()
          Retrieve initial destination.
 boolean hasBeenSent()
          Check, if a given message has been sent yet.
 boolean isOk()
          Did an error occur when processing the message.
 void setNotOk(java.lang.String err)
          Set or append error message.
 void setNotOk(java.lang.Throwable e)
          Set error message based on an exception.
 java.lang.String toString()
          Returns a string containing: : To ReplyTo [:error message].
(package private)  void updateId(java.lang.String newId)
          Sets the ID of this message if it has not already been set.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ERROR_DELIMITTER

static final java.lang.String ERROR_DELIMITTER
See Also:
Constant Field Values

replyOfId

protected java.lang.String replyOfId
Constructor Detail

NetarkivetMessage

protected NetarkivetMessage(ChannelID to,
                            ChannelID replyTo)
Creates a new NetarkivetMessage.

Parameters:
to - the initial receiver of the message
replyTo - the initial sender of the message
Throws:
ArgumentNotValid - if to==replyTo, the replyTo parameter is a topic instead of a queue, or there is a null parameter.
Method Detail

isOk

public boolean isOk()
Did an error occur when processing the message.

Returns:
true if no error occurred, otherwise false

setNotOk

public void setNotOk(java.lang.String err)
Set or append error message. Sets isOk field to false.

Parameters:
err - error message

setNotOk

public void setNotOk(java.lang.Throwable e)
Set error message based on an exception.

Parameters:
e - An exception thrown during processing.

getErrMsg

public java.lang.String getErrMsg()
                           throws PermissionDenied
Retrieve error message.

Returns:
error message
Throws:
PermissionDenied - if the message is not an error message

getID

public java.lang.String getID()
Retrieve message id. Note that message ID is not set until message is sent, and this method must not be called before then.

Returns:
message id
Throws:
PermissionDenied - If the message has not yet been sent.

updateId

void updateId(java.lang.String newId)
Sets the ID of this message if it has not already been set.

Parameters:
newId - The new ID

getReplyOfId

public java.lang.String getReplyOfId()
Retrieve replyOfId. This is set by subclasses of NetarkivetMessage, to indicate that this is a reply of some other message. If the subclass doesn't set replyOfId, this method behaves like getId.

Returns:
replyOfId

getTo

public ChannelID getTo()
Retrieve initial destination.

Returns:
initial destination

getReplyTo

public ChannelID getReplyTo()
Retrieve specified reply channel.

Returns:
initial origin

toString

public java.lang.String toString()
Returns a string containing: : To ReplyTo [:error message].

Overrides:
toString in class java.lang.Object
Returns:
String representation of Message.

hasBeenSent

public boolean hasBeenSent()
Check, if a given message has been sent yet. If the message has a null id, it hasn't been sent yet.

Returns:
true, if message has been sent yet, false otherwise.