peer2me.domain
Class DataPackage

java.lang.Object
  extended bypeer2me.domain.DataPackage
Direct Known Subclasses:
FilePackage, GroupSyncPackage, TextPackage

public abstract class DataPackage
extends java.lang.Object

This class is the super class of the different type of packages that can be sent between nodes in the network. It contains the attributes that are common for all types of data packages. These are the address of the sender and the address(es) to the recipiant(s) of the DataPackage. Currently, there exists three types of data packages.

Author:
Torbjørn Vatn & Steinar A. Hestnes

Field Summary
static int FILE_PACKAGE
           
static int GROUP_SYNC_PACKAGE
           
 Log log
           
static int TEXT_PACKAGE
           
 
Constructor Summary
DataPackage(int type)
          Constructor used to create an empty DataPackage object to fill with the parseBytes() method
DataPackage(int type, Node sender, java.lang.String[] recipients)
          Constructor
 
Method Summary
 java.lang.String[] getRecipients()
          This method returns all the recipients of this data package
 Node getSender()
          This method returns the sender of this data package
 int getType()
          This method returns an int indicating the type of data package
abstract  void parseBytes(byte[] data)
          This method parses the content of the byte array (byte[]) back into a DataPackage object
 void setRecipients(java.lang.String[] recipients)
          This method sets the nodes to receive this package
 void setSender(Node sender)
          This method sets the sender of this data package
abstract  byte[] toSendableFormat()
          This method transforms this data package into a byte array (byte[]) that is possible to send over a network stream
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

public Log log

GROUP_SYNC_PACKAGE

public static final int GROUP_SYNC_PACKAGE
See Also:
Constant Field Values

TEXT_PACKAGE

public static final int TEXT_PACKAGE
See Also:
Constant Field Values

FILE_PACKAGE

public static final int FILE_PACKAGE
See Also:
Constant Field Values
Constructor Detail

DataPackage

public DataPackage(int type,
                   Node sender,
                   java.lang.String[] recipients)
Constructor

Parameters:
type - The type specifying the type of data package
sender - A node object representing the sender node
recipients - The addresses to the recipients of the data package

DataPackage

public DataPackage(int type)
Constructor used to create an empty DataPackage object to fill with the parseBytes() method

Parameters:
type - The type of the DataPackage
Method Detail

getType

public int getType()
This method returns an int indicating the type of data package

Returns:
type An int indicating the type of data package

getSender

public Node getSender()
This method returns the sender of this data package

Returns:
sender The node that sends this package

setSender

public void setSender(Node sender)
This method sets the sender of this data package

Parameters:
sender - The node that sends this package

getRecipients

public java.lang.String[] getRecipients()
This method returns all the recipients of this data package

Returns:
recipients The addresses to the recipients of this package

setRecipients

public void setRecipients(java.lang.String[] recipients)
This method sets the nodes to receive this package

Parameters:
recipients - The addresses to the nodes that shall receive this package

toSendableFormat

public abstract byte[] toSendableFormat()
This method transforms this data package into a byte array (byte[]) that is possible to send over a network stream

Returns:
The byte[] representation of the data package

parseBytes

public abstract void parseBytes(byte[] data)
This method parses the content of the byte array (byte[]) back into a DataPackage object

Parameters:
data - The byte[] containing the data representing the DataPackage object