peer2me.network
Class Network

java.lang.Object
  extended bypeer2me.network.Network
Direct Known Subclasses:
BluetoothNetwork

public abstract class Network
extends java.lang.Object

This is the super class of the technology specific network classes. Methods that are equal for all the sub classes are located in this super class, and there are abstact methods that the sub classes have to implement. The getInstance() method in this class returns a reference to the preferred network sub class.

Author:
Torbjørn Vatn & Steinar A. Hestnes

Constructor Summary
Network()
           
 
Method Summary
abstract  void connectionEstablished()
          This method is called from the ConnectionListener.run() when the acceptAndOpen() method in ConnectionListener.run() is done.
abstract  void connectToNode(java.lang.String nodeAddress)
          This method establishes a connection to the chosen node.
 java.lang.String getApplicationId()
          This method returns the applicationId
 ConnectionListener getConnectionListener()
          This method returns the ConnectionListener reference
 FrameworkFrontEnd getFrameworkFrontEnd()
          This method returns the FrameworkFrontEnd reference
static Network getInstance()
          This method returns a reference to the instance of the preferred network.
static Network getInstance(java.lang.String preferredNetwork)
          This method returns an instance of the preferred network.
abstract  java.lang.String getNodeAddress(java.lang.Object input)
          This method returns the node address.
abstract  java.lang.String getRemoteNodeName(java.lang.Object input)
          This method fetches the name of the remote node.
abstract  void init()
          Initiates the network instance.
abstract  void nodeFound(java.lang.Object input)
          Called when the same MIDlet is found on a remote device
abstract  void searchForNodes()
          Starts a search for devices running the same MIDlet
abstract  void sendDataPackage(DataPackage dataPackage, java.lang.String[] recipients)
          This method is used by the FrameworkFrontEnd to send a data package of any sort to a remote node.
 void setApplicationId(java.lang.String applicationID)
          This method sets the applicationID.
 void setConnectionListener(ConnectionListener connectionListener)
          This method sets a reference to the ConnectionListener
 void setFrameworkFrontEnd(FrameworkFrontEnd frameworkFrontEnd)
          This method sets a reference to the FrameworkFrontEnd
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Network

public Network()
Method Detail

getInstance

public static Network getInstance(java.lang.String preferredNetwork)
                           throws java.lang.ClassNotFoundException,
                                  java.lang.IllegalAccessException,
                                  java.lang.InstantiationException
This method returns an instance of the preferred network. It is called from FrameworkFrontEnd.initFramework().

Parameters:
preferredNetwork - Indicating which network implementation to use.
Returns:
The Network instance
Throws:
java.lang.ClassNotFoundException - The input preferredNetwork is invalid
java.lang.IllegalAccessException - The input preferredNetwork is invalid
java.lang.InstantiationException - The input preferredNetwork is invalid

getInstance

public static Network getInstance()
This method returns a reference to the instance of the preferred network. It is used when an instance already is created and a reference to this instance is needed.

Returns:
The Network instance
Throws:
java.lang.ClassNotFoundException - The input preferredNetwork is invalid
java.lang.IllegalAccessException - The input preferredNetwork is invalid
java.lang.InstantiationException - The input preferredNetwork is invalid

setConnectionListener

public void setConnectionListener(ConnectionListener connectionListener)
This method sets a reference to the ConnectionListener

Parameters:
connectionListener - A reference to the ConnectionListener

getConnectionListener

public ConnectionListener getConnectionListener()
This method returns the ConnectionListener reference

Returns:
connectionListener A reference to the ConnectionListener

setFrameworkFrontEnd

public void setFrameworkFrontEnd(FrameworkFrontEnd frameworkFrontEnd)
This method sets a reference to the FrameworkFrontEnd

Parameters:
frameworkFrontEnd - A reference to the FrameworkFrontEnd

getFrameworkFrontEnd

public FrameworkFrontEnd getFrameworkFrontEnd()
This method returns the FrameworkFrontEnd reference

Returns:
frameworkFrontEnd A reference to the FrameworkFrontEnd

setApplicationId

public void setApplicationId(java.lang.String applicationID)
This method sets the applicationID. The application ID must be used to ensure that all nodes joining the network are running the same MIDlet.

Parameters:
applicationID - The ID of the MIDlet (e.g. the MIDlet name)

getApplicationId

public java.lang.String getApplicationId()
This method returns the applicationId

Returns:
applicationID The ID of the MIDlet

init

public abstract void init()
                   throws java.lang.Exception
Initiates the network instance. It is called from the FrameworkFrontEnd.initFramework()

Throws:
java.lang.Exception - Failed to initiate the network

searchForNodes

public abstract void searchForNodes()
                             throws java.io.IOException
Starts a search for devices running the same MIDlet

Throws:
java.io.IOException - Error during the search

nodeFound

public abstract void nodeFound(java.lang.Object input)
                        throws java.io.IOException
Called when the same MIDlet is found on a remote device

Parameters:
input - An object representing the connection to the found node.
Throws:
java.io.IOException

getRemoteNodeName

public abstract java.lang.String getRemoteNodeName(java.lang.Object input)
This method fetches the name of the remote node.

Parameters:
input - An object representing the connection to the found node.
Returns:
The name of the remote node.

connectToNode

public abstract void connectToNode(java.lang.String nodeAddress)
This method establishes a connection to the chosen node. It could e.g. be run from the Network.sendDataPackage() to connect before sending a package.

Parameters:
nodeAddress - The address to the node to connect to

connectionEstablished

public abstract void connectionEstablished()
This method is called from the ConnectionListener.run() when the acceptAndOpen() method in ConnectionListener.run() is done.


getNodeAddress

public abstract java.lang.String getNodeAddress(java.lang.Object input)
                                         throws java.io.IOException
This method returns the node address.

Parameters:
input - String "localNode" to retreive the address of the local device. A object representing the connection to the remote node to retreive the address of a remote device.
Returns:
The node network address.
Throws:
java.io.IOException

sendDataPackage

public abstract void sendDataPackage(DataPackage dataPackage,
                                     java.lang.String[] recipients)
This method is used by the FrameworkFrontEnd to send a data package of any sort to a remote node.

Parameters:
dataPackage - The data package to be sent
recipients - A list containing addresses to the recipient nodes