|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectpeer2me.session.Session
public class Session
This class binds togethers most of the framework and acts as a
global access point. Initiates the Network
, creates a
Service
, and sets the default Group
.
Uses Singelton. getInstance(...)
will be used only one time.
After that getInstance()
should be used.
Method Summary | |
---|---|
Group |
createGroup(java.lang.String name)
This method creates a new Group and adds it to
the session. |
Group |
createGroup(java.lang.String name,
Node[] nodes)
This method creates a Group and adds it to
the session. |
Node[] |
getAllNodes()
Gets all the discovered nodes |
Node[] |
getAllNodes(Group group)
Gets alle the nodes in the given group. |
Group |
getGroup(Node node)
Gets a Group based on a Node . |
Group |
getGroup(java.lang.String name)
Gets a Group with the corresponding name. |
Group |
getGroupAt(int index)
Gets the Group at the given index in the collection of
groups in session. |
Group[] |
getGroups()
Gets all the groups |
static Session |
getInstance()
Must only be used after getInstance(...) |
static Session |
getInstance(Framework framework,
Group group,
Service service,
Network network,
boolean activatePing)
This should be used only one time, and sets a default Group ,
the Network and the Service . |
javax.bluetooth.LocalDevice |
getLocalDevice()
Gets the LocalDevice |
Node |
getLocalNode()
Gets the local Node |
Network |
getNetwork()
Gets a referecnce to Network |
Node |
getNode(int index,
Group group)
Gets the Node at the given index
in the given Group . |
Node |
getNode(java.lang.String address)
Gets a Node based on an address |
Service |
getService()
Gets a reference to Service |
void |
initialize()
Initializes the network. |
void |
messagePartReceived(java.lang.String messageID,
int part,
int total)
This method is called for every messagepart that is received, giving the messagepartnumber of the total number of messages. |
void |
messageReceived(Message message)
This method is called whenever a Message is received. |
void |
moveNode(Node node,
Group from,
Group to)
Moves a Node from one Group
to another. |
void |
nodeFound(NetworkNode networkNode)
This method is called whenever a new device running Peer2Me is found. |
void |
nodeLost(Node node)
This mehtod is called whenever a Node is lost or abscent. |
void |
removeGroup(int index)
Removes the Group at the given index. |
void |
removeGroup(java.lang.String name)
Removes the Group with the given name. |
void |
removeNode(int index,
Group group)
Removes a Node with the given index from a Group . |
void |
removeNode(Node node,
Group group)
Removes a Node from a Group . |
void |
search()
Performes a search for devices and services. |
void |
searchCompleted()
This method is called when a search has been completed |
void |
sendMessage(Message message)
Passes on a Message to Network . |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static Session getInstance(Framework framework, Group group, Service service, Network network, boolean activatePing)
Group
,
the Network
and the Service
. Will also set
local properties as localDevice
and localNode
.
framework
- a reference to framework.group
- a group which is set as defaultservice
- the service provided by frameworknetwork
- the network provided by frameworkactivatePing
- sets if ping-functionality should be used
public static Session getInstance()
getInstance(...)
has be called one time.
Acts as a global access point to Session
public void initialize()
public void search() throws FrameworkNotInitializedException
initialize
must be called before trying to search.
FrameworkNotInitializedException
public void nodeFound(NetworkNode networkNode)
NetworkNode
is a representative for this device.
It creates a new Node
and sends it up to Framework
.
The new node will also be added to the default group.
networkNode
- the networkNode that is foundpublic void nodeLost(Node node)
Node
is lost or abscent. It is then
removed from its Group
.
node
- the node which is lost or abscentpublic void searchCompleted()
public Network getNetwork()
Network
public Service getService()
Service
public javax.bluetooth.LocalDevice getLocalDevice()
LocalDevice
public Node getLocalNode()
Node
public void messageReceived(Message message)
Message
is received.
message
- the message which is receivedpublic void messagePartReceived(java.lang.String messageID, int part, int total)
part
- total
- public Group createGroup(java.lang.String name)
Group
and adds it to
the session.
name
- name of the group
public Group createGroup(java.lang.String name, Node[] nodes)
Group
and adds it to
the session. Adds also an array of nodes directly.
name
- the name of the groupnodes
- the nodes added upon creation of the group
public Group[] getGroups()
public Group getGroup(java.lang.String name) throws GroupNotFoundException
Group
with the corresponding name. Throws an exception if
the group is not found.
name
- the name of the group
GroupNotFoundException
public Group getGroup(Node node) throws GroupNotFoundException
Group
based on a Node
.
It will get the group the node is a member of.
node
- the node in the group
GroupNotFoundException
public Group getGroupAt(int index) throws GroupNotFoundException
Group
at the given index in the collection of
groups in session. Throws an exception if the group is not found.
index
- the index of the group
GroupNotFoundException
public void removeGroup(int index) throws GroupNotFoundException
Group
at the given index. Will also
remove the nodes in the group if not empty. Throws an exception if the group
is not found.
index
- the index of the group
GroupNotFoundException
public void removeGroup(java.lang.String name) throws GroupNotFoundException
Group
with the given name. Will also
remove the nodes in the group if not empty. Throws an exception if the group
is not found.
name
- the name of the group
GroupNotFoundException
public Node[] getAllNodes()
public Node[] getAllNodes(Group group)
group
- the group of the nodes
public Node getNode(java.lang.String address)
Node
based on an address
address
- the address of the node
public Node getNode(int index, Group group) throws NodeNotFoundException
Node
at the given index
in the given Group
. Throws an exception if
the node is not found.
index
- the index of the nodegroup
- the group of the node
NodeNotFoundException
public void moveNode(Node node, Group from, Group to)
Node
from one Group
to another. Will also send a notification to all other nodes about the
movement.
node
- the node to movefrom
- the group the node lies into
- the new group of the nodepublic void removeNode(int index, Group group) throws NodeNotFoundException
Node
with the given index
from a Group
.
Throws an exception if the node is not found.
index
- the index of the nodegroup
- the group of node
NodeNotFoundException
public void removeNode(Node node, Group group)
Node
from a Group
.
node
- the node to removegroup
- the group of the nodepublic void sendMessage(Message message)
Message
to Network
. Used when sending messages.
message
- the message to be sent.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |