peer2me.network.bluetooth
Class Bluetooth

java.lang.Object
  extended by peer2me.network.Network
      extended by peer2me.network.bluetooth.Bluetooth

public class Bluetooth
extends Network

This class extends the Network and every Bluetooth network operation is controlled indirectly from this class. This class starts two listeners that are able to establish incomming connections. It also have two queues that are used for outgoing messages and pings.

Author:
Kim Saxlund

Constructor Summary
Bluetooth()
          Constructor that creates two empty queues for outgoing messages and pings
 
Method Summary
 void activatePing()
          Activates the ping functionality.
 void checkPingResponse(Node node)
          Checks to see if nodes has responded to pings.
 void clean()
          Stops the listeners from reveiving connections.
 void echo(Node node)
          This method should run Node.incrementEcho() on the given Node
 java.lang.String getLocalConnectionURL()
          Returns the connectionURL of the local node
 java.lang.String getLocalPingConnectionURL()
          Returns the connectionURL that must be used to ping the local node
 LinkedMessageList getMessageQue()
          Returns the list that contains all messages that are to be sent
 LinkedPingRecipientsList getPingQue()
          Returns the list that contains all pings that are to be sent
 void initialize()
          Starts accepting incoming connections and starts the queue processors
 void messagePartReceived(java.lang.String messageID, int part, int total)
          Every time when the BluetoothConnectionHandler receives a part of a message, it invokes this method.
 void messageReceived(Message message)
          When the BluetoothConnectionHandler receives a message, it reconstructs it and invokes this method when the message is reconstructed.
 void nodeFound(NetworkNode networkNode)
          When the BluetoothSearcher has found other nodes, it invokes this method.
 void nodeLost(Node node)
          If a node leaves the network or does not respond to pings, this method is invoked.
 void ping()
          This method puts all nodes in the pingQueue so that the PingQueueProcessor can process the pings.
 boolean search()
          Starts a search for other devices if there are no more messages in the queue.
 void searchCompleted()
          Is invoked by BluetoothSearcher when a search has completed.
 void sendMessage(Message message)
          Puts a message in the queue.
 void setActivatePing(boolean activatePing)
          Sets a local variable determining if ping shall be used
 void setGoodbyeSent(boolean canILeaveNow)
          To allow the node to exit, this method must be used
 void setLocalConnectionURL(java.lang.String localConnectionURL)
          Sets the connectionURL of the local node
 void setLocalPingConnectionURL(java.lang.String localPingConnectionURL)
          Sets the connectionURL that must be used to ping the local node
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Bluetooth

public Bluetooth()
Constructor that creates two empty queues for outgoing messages and pings

Method Detail

initialize

public void initialize()
Starts accepting incoming connections and starts the queue processors

Specified by:
initialize in class Network

search

public boolean search()
Starts a search for other devices if there are no more messages in the queue. This is because Bluetooth cannot perform a search and send messages at the same time

Specified by:
search in class Network
Returns:
True if a search was started, false otherwise

echo

public void echo(Node node)
Description copied from class: Network
This method should run Node.incrementEcho() on the given Node

Specified by:
echo in class Network
Parameters:
node - the node that has responded

sendMessage

public void sendMessage(Message message)
Puts a message in the queue. The MessageQueueProcessor takes care of processing the message.

Specified by:
sendMessage in class Network
Parameters:
message - The message that is put in the queue

messageReceived

public void messageReceived(Message message)
When the BluetoothConnectionHandler receives a message, it reconstructs it and invokes this method when the message is reconstructed. This method forwards the message to Session.

Specified by:
messageReceived in class Network
Parameters:
message -

messagePartReceived

public void messagePartReceived(java.lang.String messageID,
                                int part,
                                int total)
Every time when the BluetoothConnectionHandler receives a part of a message, it invokes this method. This method forwards the part number and total parts to Session.

Parameters:
part - The part number that was received
total - Total number of parts in the message

nodeFound

public void nodeFound(NetworkNode networkNode)
When the BluetoothSearcher has found other nodes, it invokes this method. The method is also invoked if the BluetoothConnectionHandler receives a message that contains information about other nodes.

Specified by:
nodeFound in class Network
Parameters:
networkNode - the networkNode that is found

searchCompleted

public void searchCompleted()
Is invoked by BluetoothSearcher when a search has completed. No mather what the result of the search was, this method will be called either way. This is so that the application knows when a search is completed. A usual scenario might just be that no nodes where found.

Specified by:
searchCompleted in class Network

nodeLost

public void nodeLost(Node node)
If a node leaves the network or does not respond to pings, this method is invoked.

Specified by:
nodeLost in class Network
Parameters:
node - The node that is lost

ping

public void ping()
This method puts all nodes in the pingQueue so that the PingQueueProcessor can process the pings. This method is invoked at regular intervals by the NetworkTimer.

Specified by:
ping in class Network

checkPingResponse

public void checkPingResponse(Node node)
Checks to see if nodes has responded to pings. If they have not, they are reported as lost.


setActivatePing

public void setActivatePing(boolean activatePing)
Sets a local variable determining if ping shall be used

Specified by:
setActivatePing in class Network
Parameters:
activatePing - True if ping, false otherwise

activatePing

public void activatePing()
Activates the ping functionality. This method is invoked when a node is found


clean

public void clean()
Stops the listeners from reveiving connections. Must be called by the application through Framework.clean() upon exit.

Specified by:
clean in class Network

getLocalConnectionURL

public java.lang.String getLocalConnectionURL()
Returns the connectionURL of the local node

Returns:
The connectionURL of the local node

setLocalConnectionURL

public void setLocalConnectionURL(java.lang.String localConnectionURL)
Sets the connectionURL of the local node

Parameters:
localConnectionURL - The connectionURL of the local node

getMessageQue

public LinkedMessageList getMessageQue()
Returns the list that contains all messages that are to be sent

Returns:
The queue, represented as a LinkedMessageList

getPingQue

public LinkedPingRecipientsList getPingQue()
Returns the list that contains all pings that are to be sent

Returns:
The queue, represented as a LinkedPingRecipientsList

getLocalPingConnectionURL

public java.lang.String getLocalPingConnectionURL()
Returns the connectionURL that must be used to ping the local node

Returns:
The pingConnectionURL

setLocalPingConnectionURL

public void setLocalPingConnectionURL(java.lang.String localPingConnectionURL)
Sets the connectionURL that must be used to ping the local node

Parameters:
localPingConnectionURL - The URL that is set as the localPingConnectionURL

setGoodbyeSent

public void setGoodbyeSent(boolean canILeaveNow)
To allow the node to exit, this method must be used

Parameters:
canILeaveNow - True if the node can exit, false otherwise