peer2me.network.bluetooth
Class BluetoothSearcher

java.lang.Object
  extended by java.lang.Thread
      extended by peer2me.network.bluetooth.BluetoothSearcher
All Implemented Interfaces:
java.lang.Runnable, javax.bluetooth.DiscoveryListener

public class BluetoothSearcher
extends java.lang.Thread
implements javax.bluetooth.DiscoveryListener

The purpose of this class is to search for nearby Bluetooth devices that runs the same application as the local node.

Author:
Kim Saxlund

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Fields inherited from interface javax.bluetooth.DiscoveryListener
INQUIRY_COMPLETED, INQUIRY_ERROR, INQUIRY_TERMINATED, SERVICE_SEARCH_COMPLETED, SERVICE_SEARCH_DEVICE_NOT_REACHABLE, SERVICE_SEARCH_ERROR, SERVICE_SEARCH_NO_RECORDS, SERVICE_SEARCH_TERMINATED
 
Method Summary
 void deviceDiscovered(javax.bluetooth.RemoteDevice remoteDevice, javax.bluetooth.DeviceClass deviceClass)
          Required method from DiscoveryListener.
 void distributeNodeInformation()
          Distributes information about all the found nodes.
 void inquiryCompleted(int returnValue)
          Required method from DiscoveryListener.
 void search()
          Starts a search for other Bluetooth devices.
 void servicesDiscovered(int transID, javax.bluetooth.ServiceRecord[] serviceRecords)
          Required method from DiscoveryListener.
 void serviceSearchCompleted(int transID, int respCode)
          Required method from DiscoveryListener.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, run, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

search

public void search()
Starts a search for other Bluetooth devices.


deviceDiscovered

public void deviceDiscovered(javax.bluetooth.RemoteDevice remoteDevice,
                             javax.bluetooth.DeviceClass deviceClass)
Required method from DiscoveryListener. Is invoked when a device is discovered

Specified by:
deviceDiscovered in interface javax.bluetooth.DiscoveryListener
Parameters:
deviceClass - The type of Bluetooth device that was discovered
remoteDevice - A representation of the device

inquiryCompleted

public void inquiryCompleted(int returnValue)
Required method from DiscoveryListener. Is invoked when a device discovery has completed. A search for services on the discovered devices is initiated.

Specified by:
inquiryCompleted in interface javax.bluetooth.DiscoveryListener

servicesDiscovered

public void servicesDiscovered(int transID,
                               javax.bluetooth.ServiceRecord[] serviceRecords)
Required method from DiscoveryListener. Is invoked when a service is found on a remote Bluetooth device. If the device has the service we are looking for, a BluetoothNode will be created to represent the device and the node is added to the local group. The FrameworkSubscriber.nodeDiscovered(Node) is also invoked, informing the application about the discovered device.

Specified by:
servicesDiscovered in interface javax.bluetooth.DiscoveryListener
Parameters:
serviceRecords - The services that were found on the device
transID - The transaction ID of the service search that is posting the result

serviceSearchCompleted

public void serviceSearchCompleted(int transID,
                                   int respCode)
Required method from DiscoveryListener. Called when a service search is completed or was terminated because of an error. Continues to perform a service search on the remaining devices. If there are no more devices the search is entirely completed and FrameworkSubscriber.searchCompleted() is invoked. The ping is also activated

Specified by:
serviceSearchCompleted in interface javax.bluetooth.DiscoveryListener
Parameters:
transID - The transaction ID identifying the request which initiated the service search
respCode - The response code that indicates the status of the transaction

distributeNodeInformation

public void distributeNodeInformation()
Distributes information about all the found nodes. This way, all the other nodes are informed about each other and they do not have to perform a search to connect to each other.