peer2me.framework
Class Framework

java.lang.Object
  extended by peer2me.framework.Framework

public class Framework
extends java.lang.Object

Applications using the Peer2Me framework will interact mostly with this class. After this class is instanciated, it creates an instance of Session, initializes the Log, sets the Frame- workSubscriber and the FileHandler. This class will provide methods for most operations within the framework, beeing the link between the application and the Peer2Me framework.

Author:
Tommy Bjoernsgaard

Method Summary
 void clean()
          Cleans up resources used by the framework.
 Group createGroup(java.lang.String name)
          This method creates a new Group and adds it to the groupcollection 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 Calling on the corresponding method in Session.
 Node[] getAllNodes(Group group)
          Gets alle the nodes in the given group.
 FileHandler getFileHandler()
          Gets a reference of FileHandler
 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 Framework getInstance(java.lang.String groupName, java.lang.String serviceName, Network network, boolean activatePing, FrameworkSubscriber frameworkSubscriber)
          This method will create a new or get an existing instance of Framework.
 Node getLocalNode()
          Returns the local node
 Log getLog()
          Gets a reference to Log
 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 Calling on the corresponding method in Session.
 Session getSession()
          Gets a reference to Session
 void initialize()
          This method initializes the framework, calling on initialize() in Session
 void messagePartReceived(java.lang.String messageID, int part, int total)
          This method is called whenever new MessagePart is received.
 void messageReceived(Message message)
          This method is called whenever a new Message is received.
 void moveNode(Node node, Group from, Group to)
          Moves a Node from one Group to another.
 void nodeFound(Node node)
          This method is called whenever a new Node is discovered.
 void nodeLost(Node node)
          This method is called whenever a new 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()
          This methods starts a search for devices and services.
 void searchCompleted()
          This method is called whenever a search for devices and services is finished.
 void sendMessage(Message message)
          Passes on a Message to Session.
 void setFileHandler(FileHandler fileHandler)
          Sets a reference of FileHandler
 void setframeworkSubscriber(FrameworkSubscriber frameworkSubscriber)
          Sets the frameworksubscriber
 void setReceivedFilesFolder(java.lang.String path)
          Sets the path of the default folder in which received files are stored.
 java.lang.String whoAmI()
          A simple method which returns a friendly String with the name and address of the local node.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static Framework getInstance(java.lang.String groupName,
                                    java.lang.String serviceName,
                                    Network network,
                                    boolean activatePing,
                                    FrameworkSubscriber frameworkSubscriber)
This method will create a new or get an existing instance of Framework. Uses singelton. Will notify session of the groupname, servicename and network. Will also set the FrameworkSubscriber

Parameters:
groupName - the name of the default group
serviceName - the name of the service: serviceID
network - the network to be used
activatePing - sets if ping-functionality should be used
frameworkSubscriber - the frameworksubscriber
Returns:
a reference to Framework

clean

public void clean()
Cleans up resources used by the framework. Closes all active connections.


getSession

public Session getSession()
Gets a reference to Session

Returns:
the reference to session

getLog

public Log getLog()
Gets a reference to Log

Returns:
A reference to Log

initialize

public void initialize()
This method initializes the framework, calling on initialize() in Session


search

public void search()
            throws FrameworkNotInitializedException
This methods starts a search for devices and services. Initialize must be called before trying to perform a search. Calls on search() in Session

Throws:
FrameworkNotInitializedException

getGroups

public Group[] getGroups()
Gets all the groups. Calling on the corresponding method in Session

Returns:
an array of the groups

getGroupAt

public Group getGroupAt(int index)
                 throws GroupNotFoundException
Gets the Group at the given index in the collection of groups in session. Throws an exception if the group is not found. Calling on the corresponding method in Session.

Parameters:
index - the index of the group
Returns:
the group found at the index
Throws:
GroupNotFoundException

getGroup

public Group getGroup(java.lang.String name)
               throws GroupNotFoundException
Gets a Group with the corresponding name. Throws an exception if the group is not found. Calling on the corresponding method in Session.

Parameters:
name - the name of the group
Returns:
the group
Throws:
GroupNotFoundException

createGroup

public Group createGroup(java.lang.String name)
This method creates a new Group and adds it to the groupcollection session. Calling on the corresponding method in Session.

Parameters:
name - name of the group
Returns:
the group just created

createGroup

public Group createGroup(java.lang.String name,
                         Node[] nodes)
This method creates a Group and adds it to the session. Adds also an array of nodes directly. Calling on the corresponding method in Session.

Parameters:
name - the name of the group
nodes - the nodes added upon creation of the group
Returns:
the group just created

removeGroup

public void removeGroup(int index)
                 throws GroupNotFoundException
Removes the 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. Calling on the corresponding method in Session.

Parameters:
index - the index of the group
Throws:
GroupNotFoundException

removeGroup

public void removeGroup(java.lang.String name)
                 throws GroupNotFoundException
Removes the 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. Calling on the corresponding method in Session.

Parameters:
name - the name of the group
Throws:
GroupNotFoundException

getAllNodes

public Node[] getAllNodes()
Gets all the discovered nodes Calling on the corresponding method in Session.

Returns:
an array of the nodes

getAllNodes

public Node[] getAllNodes(Group group)
Gets alle the nodes in the given group. Calling on the corresponding method in Session.

Parameters:
group - the group of the nodes
Returns:
an array of nodes

getNode

public Node getNode(java.lang.String address)
             throws NodeNotFoundException
Gets a Node based on an address Calling on the corresponding method in Session.

Parameters:
address - the address of the node
Returns:
the node with the given address
Throws:
NodeNotFoundException

getNode

public Node getNode(int index,
                    Group group)
             throws NodeNotFoundException
Gets the Node at the given index in the given Group. Throws an exception if the node is not found. Calling on the corresponding method in Session.

Parameters:
index - the index of the node
group - the group of the node
Returns:
the node
Throws:
NodeNotFoundException

moveNode

public void moveNode(Node node,
                     Group from,
                     Group to)
              throws NodeNotFoundException
Moves a Node from one Group to another. Will also send a notification to all other nodes about the movement. Calling on the corresponding method in Session.

Parameters:
node - the node to move
from - the group the node lies in
to - the new group of the node
Throws:
NodeNotFoundException

removeNode

public void removeNode(int index,
                       Group group)
                throws NodeNotFoundException
Removes a Node with the given index from a Group. Throws an exception if the node is not found. Calling on the corresponding method in Session.

Parameters:
index - the index of the node
group - the group of node
Throws:
NodeNotFoundException

removeNode

public void removeNode(Node node,
                       Group group)
Removes a Node from a Group. Calling on the corresponding method in Session.

Parameters:
node - the node to remove
group - the group of the node

setframeworkSubscriber

public void setframeworkSubscriber(FrameworkSubscriber frameworkSubscriber)
Sets the frameworksubscriber

Parameters:
frameworkSubscriber - a reference to the frameworksubscriber

nodeFound

public void nodeFound(Node node)
This method is called whenever a new Node is discovered. Uses FrameworkSubscriber to communicate with the MIDlet.

Parameters:
node - the node that is found

nodeLost

public void nodeLost(Node node)
This method is called whenever a new Node is lost or abscent. Uses FrameworkSubscriber to communicate with the MIDlet.

Parameters:
node - the node that is lost or abscent

searchCompleted

public void searchCompleted()
This method is called whenever a search for devices and services is finished. Uses FrameworkSubscriber to communicate with the MIDlet.


messageReceived

public void messageReceived(Message message)
This method is called whenever a new Message is received. Uses FrameworkSubscriber to communicate with the MIDlet.


messagePartReceived

public void messagePartReceived(java.lang.String messageID,
                                int part,
                                int total)
This method is called whenever new MessagePart is received. This method is useful when creating progressbars etc. Uses FrameworkSubscriber to communicate with the MIDlet.

Parameters:
part - the part received of a total
total - the total number of parts to receive

sendMessage

public void sendMessage(Message message)
Passes on a Message to Session. Used when sending messages. Calling on the corresponding method in Session.

Parameters:
message - the message to be sent.

getFileHandler

public FileHandler getFileHandler()
Gets a reference of FileHandler

Returns:
a object of the type filehandler

setFileHandler

public void setFileHandler(FileHandler fileHandler)
Sets a reference of FileHandler

Parameters:
fileHandler - the reference of filehandler

setReceivedFilesFolder

public void setReceivedFilesFolder(java.lang.String path)
Sets the path of the default folder in which received files are stored. Calls on the corresponding method in FileHandler

Parameters:
path - the absolute path of the folder

whoAmI

public java.lang.String whoAmI()
A simple method which returns a friendly String with the name and address of the local node.

Returns:
a String with the name and address

getLocalNode

public Node getLocalNode()
Returns the local node

Returns:
The local node