peer2me.network.bluetooth
Class BluetoothNetwork

java.lang.Object
  extended bypeer2me.network.Network
      extended bypeer2me.network.bluetooth.BluetoothNetwork
All Implemented Interfaces:
BluetoothServiceDiscoveryListener

public class BluetoothNetwork
extends Network
implements BluetoothServiceDiscoveryListener

This class is a bluetooth specific sub class of the Network class and implements all the abstract methods of it's parent class in a bluetooth context. It uses the bluetooth Java API, JSR-82, to perform operations on the bluetooth hardware of the mobile device.

Author:
Torbjørn Vatn & Steinar A. Hestnes

Constructor Summary
BluetoothNetwork()
          Constructor.
 
Method Summary
 void connectionEstablished()
          This method is called from the ConnectionListener.run() when the acceptAndOpen() method in ConnectionListener.run() is done.
 void connectToNode(java.lang.String nodeAddress)
          This method establishes a connection to the chosen node.
 java.lang.String getNodeAddress(java.lang.Object input)
          This method returns the node address.
 java.lang.String getRemoteNodeName(java.lang.Object input)
          This method fetches the name of the remote node.
 java.lang.String getUUIDString()
          This method returns the UUID string used as an identifier in the discovery process.
 void init()
          Initiates the network instance.
 void nodeFound(java.lang.Object input)
          Called when the same MIDlet is found on a remote device.
 void searchForNodes()
          Starts a search for devices running the same MIDlet
 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 serviceDiscoveryError()
          What to do when something went wrong during servicediscovery.
 void serviceSearchCompleted()
          Sets the boolean serviceSearchCompleted = true.
 
Methods inherited from class peer2me.network.Network
getApplicationId, getConnectionListener, getFrameworkFrontEnd, getInstance, getInstance, setApplicationId, setConnectionListener, setFrameworkFrontEnd
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BluetoothNetwork

public BluetoothNetwork()
Constructor. Protected to ensure singleton pattern.

Method Detail

init

public void init()
          throws javax.bluetooth.BluetoothStateException
Initiates the network instance. It is called from the FrameworkFrontEnd.initFramework()

Specified by:
init in class Network
Throws:
javax.bluetooth.BluetoothStateException - Failed to initiate the network

connectionEstablished

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

Specified by:
connectionEstablished in class Network

searchForNodes

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

Specified by:
searchForNodes in class Network
Throws:
java.io.IOException - Error during the search

nodeFound

public void nodeFound(java.lang.Object input)
Called when the same MIDlet is found on a remote device. It is called from BluetoothServiceDiscovery.serviceSearchCompleted().

Specified by:
nodeFound in class Network
Parameters:
input - Either a ServiceRecord or a StreamConnection that describes the characteristics of the Bluetooth service found

getRemoteNodeName

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

Specified by:
getRemoteNodeName in class Network
Parameters:
input - An object representing the connection to the found node.
Returns:
The name of the remote node.

connectToNode

public void connectToNode(java.lang.String nodeAddress)
This method establishes a connection to the chosen node. It is run from the BluetoothNetwork.sendDataPackage().

Specified by:
connectToNode in class Network
Parameters:
nodeAddress - The address to the node to connect to

serviceSearchCompleted

public void serviceSearchCompleted()
Sets the boolean serviceSearchCompleted = true. This value will interrupt the while-loop in sendDataPackage. This because the serviceSearch must be completed before we try to send a package. The method is called from BluetoothServiceDiscovery.serviceSearchCompleted().

Specified by:
serviceSearchCompleted in interface BluetoothServiceDiscoveryListener

serviceDiscoveryError

public void serviceDiscoveryError()
What to do when something went wrong during servicediscovery. The method is called from BluetoothServiceDiscovery.serviceSearchCompleted().

Specified by:
serviceDiscoveryError in interface BluetoothServiceDiscoveryListener

getNodeAddress

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

Specified by:
getNodeAddress in class Network
Parameters:
input - String "localNode" to retreive the address of the local device. A ServiceRecord or StreamConnection object to retreive the address of a remote device.
Returns:
The node network address.
Throws:
java.io.IOException

sendDataPackage

public 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.

Specified by:
sendDataPackage in class Network
Parameters:
dataPackage - The data package to be sent
recipients - A list containing addresses to the recipient nodes

getUUIDString

public java.lang.String getUUIDString()
This method returns the UUID string used as an identifier in the discovery process. The UUID string is generated based on the application ID given by the application running the framework. The UUID must be used to ensure that all nodes joining the network are running the same application.

Returns:
uuidString