sg.edu.nus.peer
Class ServerPeer

java.lang.Object
  extended by sg.edu.nus.peer.AbstractPeer
      extended by sg.edu.nus.peer.ServerPeer

public class ServerPeer
extends AbstractPeer

Implement a super peer.

Version:
1.0 2006-2-1
Author:
Xu Linhao

Field Summary
static java.lang.String BESTPEERDB
           
static java.lang.String BESTPEERINDEXDATABASE
           
static java.lang.String BOOTSTRAP_SERVER
          The IP address of the bootstrap server.
static java.lang.String BOOTSTRAP_SERVER_LIST
          The list of the bootstraps.
static int BOOTSTRAP_SERVER_PORT
          The port of the bootstrap server used for monitoring network events.
static java.lang.String COMMON_VALUE
           
static java.sql.Connection conn_bestpeerdb
           
static java.sql.Connection conn_bestpeerindexdb
           
static java.sql.Connection conn_exportDatabase
           
static java.sql.Connection conn_globalSchema
           
static java.sql.Connection conn_localSchema
           
static java.sql.Connection conn_metabestpeerdb
           
static java.sql.Connection conn_schemaMapping
           
static java.lang.String dbtype_db2
           
static java.lang.String dbtype_mysql
          Database Type added by Han Xixian
static java.lang.String dbtype_oracle
           
static java.lang.String dbtype_postgreSQL
           
static java.lang.String dbtype_sqlserver
           
static boolean DEBUG
          The signal used for determine whether allows to print debug information.
static java.lang.String ERP_DB_DRIVER
          The driver to access the erp database on this superpeer
static java.lang.String ERP_DB_NAME
           
static java.lang.String ERP_DB_PASS
          The password to access the erp database on this superpeer
static java.lang.String ERP_DB_URL
          The location of the erp database on this superpeer
static java.lang.String ERP_DB_USER
          The username to access the erp database on this superpeer
static java.lang.String EXPORTED_DB
           
static java.lang.String GLOBAL_DB
           
static java.lang.String MATCHES_DB
           
static java.lang.String METABESTPEERDB
           
static java.lang.String SERVER_DB_DRIVER
          The driver to access the local database on this superpeer
static java.lang.String SERVER_DB_NAME
          The name of the database holding the schema matches between the local and the global schemas The name of our view of the global schema (i.e.
static java.lang.String SERVER_DB_PASS
          The password to access the database on this superpeer
static java.lang.String SERVER_DB_PORT
           
static java.lang.String SERVER_DB_URL
          The location of the database on this superpeer
static java.lang.String SERVER_DB_USER
          The username to access the database on this superpeer
static int TIME_TO_CHECK_IMBALANCE
          Interval time of checking imbalance at a node
static int TIME_TO_RECOVER_FAILED_NODE
          Time for a failed node to be recovered to a stable position
static int TIME_TO_STABLE_POSITION
          Time for a node to become stable once it changes the posision
static int TIME_TO_STABLE_STATE
          Time for a node to become stable once it joins/rejoins the system
 
Fields inherited from class sg.edu.nus.peer.AbstractPeer
CAPACITY, LOCAL_SERVER_PORT
 
Constructor Summary
ServerPeer(AbstractMainFrame gui, java.lang.String peerType)
           
 
Method Summary
 void addListItem(TreeNode treeNode)
          Add a TreeNode into the nodeList for retrieving.
 void forceOut(java.lang.String ip, int port)
          Force a peer out the network with its IP address and port.
 ActivateStablePosition getActivateStablePosition()
          Get the instance of ActivateStablePosition.
static java.lang.String getIndexDir()
          Returns the string that represents the Lucene directory.
 TreeNode getListItem(int idx)
          Get an instance of TreeNode from the container of the tree nodes.
 int getListSize()
          Get the size of the container of the tree nodes.
 java.lang.String getLogStore()
          Returns the directory of the system logs.
 int getOrder()
          Get the order that is used for determining if perform load balance operation.
 ServerRequestManager getRequestManager()
           
 java.lang.String getServerPeerAdminName()
           
 ServerRequestManager getServerRequestManager()
           
 TreeNode getTreeNode(LogicalInfo dest)
          Get the tree node whose logical information equals to the specified logical information.
 TreeNode[] getTreeNodes()
          Returns all tree nodes maintained by the server peer.
static void load()
          Load system-defined value.
 boolean performCancelJoinRequest()
          Perform a JOIN_FAILURE request to the bootstrap server.
 boolean performJoinRequest(java.lang.String ip, int port)
          Perform a SP_JOIN request to the bootstrap server.
 void performLoginRequest(LoginPanel window, java.lang.String user, java.lang.String pwd)
          Perform the LOGIN request to the bootstrap server.
 boolean performLogoutRequest()
          Perform the I_WILL_LEAVE request to other peers.
 void performRefreshRequest()
          Perform the REFRESH request to update the status of all super peers who are in its routing table.
 void performRegisterRequest(java.awt.Window window, java.lang.String user, java.lang.String pwd, java.lang.String email)
          Perform the REGISTER request to the bootstrap server.
 void performRoleSynchronize()
          Perform the ROLE SYNCHRONIZE request to the bootstrap server
 void performSchemaUpdate(java.lang.String newSchema)
          added by mihai, june 2nd
 void performStabilizeRequest()
          Perform the SP_STABILIZE request to for all other super peers, who are in its routing table, to perform stabilization operation.
 boolean performSuccessJoinRequest()
          Perform a JOIN_SUCCESS request to the bootstrap server.
 TreeNode removeListItem(int idx)
          Remove an instance of TreeNode from the container of the tree node.
 void setActivateStablePosition(ActivateStablePosition activateStablePosition)
          Set the instance of ActivateStablePosition.
 void setRequestManager(ServerRequestManager requestManager)
           
 boolean startEventManager(int port, int capacity)
          Start the network monitoring service.
 boolean startUDPServer(int port, int capacity, long period)
          Starts the UDP service by specify the port and the number of threads that can handle incoming and outgoing UDP packets at the same time.
 void stopActivateStablePosition()
          Stop stabilizing.
 void troubleshoot(boolean toBoot, boolean toServer, boolean toClient)
          When the peer exits the system for some reason, it will broadcast a TROUBLESHOOT message to all relevant peers for its leave.
static void write()
          Write user-defined values to file.
 
Methods inherited from class sg.edu.nus.peer.AbstractPeer
checkInet, clearSession, createLogStore, getMainFrame, getPeerType, getPhysicalInfo, initSession, isEventManagerAlive, isUDPServerAlive, scheduleUDPSender, sendMessage, stopEventManager, stopUDPServer
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BOOTSTRAP_SERVER_LIST

public static java.lang.String BOOTSTRAP_SERVER_LIST
The list of the bootstraps.


BOOTSTRAP_SERVER

public static java.lang.String BOOTSTRAP_SERVER
The IP address of the bootstrap server.


BOOTSTRAP_SERVER_PORT

public static int BOOTSTRAP_SERVER_PORT
The port of the bootstrap server used for monitoring network events.


DEBUG

public static boolean DEBUG
The signal used for determine whether allows to print debug information.


TIME_TO_STABLE_STATE

public static int TIME_TO_STABLE_STATE
Time for a node to become stable once it joins/rejoins the system


TIME_TO_STABLE_POSITION

public static int TIME_TO_STABLE_POSITION
Time for a node to become stable once it changes the posision


TIME_TO_RECOVER_FAILED_NODE

public static int TIME_TO_RECOVER_FAILED_NODE
Time for a failed node to be recovered to a stable position


TIME_TO_CHECK_IMBALANCE

public static int TIME_TO_CHECK_IMBALANCE
Interval time of checking imbalance at a node


ERP_DB_DRIVER

public static java.lang.String ERP_DB_DRIVER
The driver to access the erp database on this superpeer


SERVER_DB_DRIVER

public static java.lang.String SERVER_DB_DRIVER
The driver to access the local database on this superpeer


ERP_DB_NAME

public static java.lang.String ERP_DB_NAME

ERP_DB_URL

public static java.lang.String ERP_DB_URL
The location of the erp database on this superpeer


SERVER_DB_URL

public static java.lang.String SERVER_DB_URL
The location of the database on this superpeer


ERP_DB_USER

public static java.lang.String ERP_DB_USER
The username to access the erp database on this superpeer


SERVER_DB_USER

public static java.lang.String SERVER_DB_USER
The username to access the database on this superpeer


ERP_DB_PASS

public static java.lang.String ERP_DB_PASS
The password to access the erp database on this superpeer


SERVER_DB_PASS

public static java.lang.String SERVER_DB_PASS
The password to access the database on this superpeer


SERVER_DB_PORT

public static java.lang.String SERVER_DB_PORT

SERVER_DB_NAME

public static java.lang.String SERVER_DB_NAME
The name of the database holding the schema matches between the local and the global schemas The name of our view of the global schema (i.e. what has been sent from bootstrap)


MATCHES_DB

public static java.lang.String MATCHES_DB

GLOBAL_DB

public static java.lang.String GLOBAL_DB

EXPORTED_DB

public static java.lang.String EXPORTED_DB

BESTPEERDB

public static java.lang.String BESTPEERDB

BESTPEERINDEXDATABASE

public static java.lang.String BESTPEERINDEXDATABASE

METABESTPEERDB

public static java.lang.String METABESTPEERDB

conn_localSchema

public static java.sql.Connection conn_localSchema

conn_globalSchema

public static java.sql.Connection conn_globalSchema

conn_schemaMapping

public static java.sql.Connection conn_schemaMapping

conn_exportDatabase

public static java.sql.Connection conn_exportDatabase

conn_bestpeerdb

public static java.sql.Connection conn_bestpeerdb

conn_bestpeerindexdb

public static java.sql.Connection conn_bestpeerindexdb

conn_metabestpeerdb

public static java.sql.Connection conn_metabestpeerdb

COMMON_VALUE

public static java.lang.String COMMON_VALUE

dbtype_mysql

public static java.lang.String dbtype_mysql
Database Type added by Han Xixian


dbtype_oracle

public static java.lang.String dbtype_oracle

dbtype_sqlserver

public static java.lang.String dbtype_sqlserver

dbtype_db2

public static java.lang.String dbtype_db2

dbtype_postgreSQL

public static java.lang.String dbtype_postgreSQL
Constructor Detail

ServerPeer

public ServerPeer(AbstractMainFrame gui,
                  java.lang.String peerType)
Method Detail

load

public static void load()
Load system-defined value.


write

public static void write()
Write user-defined values to file. Notice that this function must be called after user applies the change.


startEventManager

public boolean startEventManager(int port,
                                 int capacity)
Description copied from class: AbstractPeer
Start the network monitoring service.

Specified by:
startEventManager in class AbstractPeer
Parameters:
port - the port used for monitoring network events
capacity - the maximum capacity that serves the incoming socket connections at the same time
Returns:
if success, return true; otherwise, return false

startUDPServer

public boolean startUDPServer(int port,
                              int capacity,
                              long period)
Description copied from class: AbstractPeer
Starts the UDP service by specify the port and the number of threads that can handle incoming and outgoing UDP packets at the same time.

Specified by:
startUDPServer in class AbstractPeer
Parameters:
port - the port to be used for starting the UDP service
capacity - the number of threads that can handle incoming and outgoing UDP packets at the same time
Returns:
true if the UDP service is started; otherwise, return false

troubleshoot

public void troubleshoot(boolean toBoot,
                         boolean toServer,
                         boolean toClient)
Description copied from class: AbstractPeer
When the peer exits the system for some reason, it will broadcast a TROUBLESHOOT message to all relevant peers for its leave.

Specified by:
troubleshoot in class AbstractPeer
Parameters:
toBoot - if true, send messages to bootstrapper
toServer - if true, send messages to server peers
toClient - if true, send messages to client peers

forceOut

public void forceOut(java.lang.String ip,
                     int port)
Description copied from class: AbstractPeer
Force a peer out the network with its IP address and port.

Specified by:
forceOut in class AbstractPeer
Parameters:
ip - the IP address of the peer to be forced out the network
port - the port where the network service is running

getIndexDir

public static java.lang.String getIndexDir()
Returns the string that represents the Lucene directory.

Returns:
the string represents the Lucene directory

getOrder

public int getOrder()
Get the order that is used for determining if perform load balance operation.

Returns:
the order

getListSize

public int getListSize()
Get the size of the container of the tree nodes.

Returns:
the size of the container of the tree nodes

getTreeNodes

public TreeNode[] getTreeNodes()
Returns all tree nodes maintained by the server peer.

Returns:
all tree nodes maintained by the server peer

addListItem

public void addListItem(TreeNode treeNode)
Add a TreeNode into the nodeList for retrieving.

Parameters:
treeNode - the TreeNode

getListItem

public TreeNode getListItem(int idx)
Get an instance of TreeNode from the container of the tree nodes.

Returns:
the instance of TreeNode

removeListItem

public TreeNode removeListItem(int idx)
Remove an instance of TreeNode from the container of the tree node.

Parameters:
idx - the position of the item to be removed
Returns:
the instance of TreeNode to be removed

getTreeNode

public TreeNode getTreeNode(LogicalInfo dest)
Get the tree node whose logical information equals to the specified logical information.

Parameters:
dest - the logical information
Returns:
if find a tree node whose logical information equals to the specified logical information, return the TreeNode; otherwise, return null

getActivateStablePosition

public ActivateStablePosition getActivateStablePosition()
Get the instance of ActivateStablePosition.

Returns:
the instance of ActivateStablePosition

setActivateStablePosition

public void setActivateStablePosition(ActivateStablePosition activateStablePosition)
Set the instance of ActivateStablePosition.

Parameters:
activateStablePosition -

stopActivateStablePosition

public void stopActivateStablePosition()
Stop stabilizing.


getLogStore

public java.lang.String getLogStore()
Description copied from class: AbstractPeer
Returns the directory of the system logs.

Specified by:
getLogStore in class AbstractPeer
Returns:
returns the directory of the system logs

performLoginRequest

public void performLoginRequest(LoginPanel window,
                                java.lang.String user,
                                java.lang.String pwd)
Perform the LOGIN request to the bootstrap server. The method simply invokes the same function of the ServerRequestManager.

Parameters:
window - the handler of the login window
user - the user to be sign in the system
pwd - the password

getServerPeerAdminName

public java.lang.String getServerPeerAdminName()

performRoleSynchronize

public void performRoleSynchronize()
Perform the ROLE SYNCHRONIZE request to the bootstrap server


performRegisterRequest

public void performRegisterRequest(java.awt.Window window,
                                   java.lang.String user,
                                   java.lang.String pwd,
                                   java.lang.String email)
Perform the REGISTER request to the bootstrap server. The method simply invokes the same function of the ServerRequestManager.

Parameters:
window - the handler of the register window
user - the user to be sign in the system
pwd - the password
email - the email address of this user

performLogoutRequest

public boolean performLogoutRequest()
Perform the I_WILL_LEAVE request to other peers. All online peers who receive such message will update the online peers in the PeerMaintainer. The method simply invokes the same function of the ServerRequestManager.

Returns:
if logout successfully, return true; otherwise, return false

performJoinRequest

public boolean performJoinRequest(java.lang.String ip,
                                  int port)
Perform a SP_JOIN request to the bootstrap server. The method simply invokes the same function of the ServerRequestManager.

Parameters:
ip - the IP address of an online super peer
port - the port of the online super peer
Returns:
if success, return true; otherwise, return false

performSuccessJoinRequest

public boolean performSuccessJoinRequest()
Perform a JOIN_SUCCESS request to the bootstrap server. The method simply invokes the same function of the ServerRequestManager.

Returns:
if join operation is success, return true; otherwise, return false

performCancelJoinRequest

public boolean performCancelJoinRequest()
Perform a JOIN_FAILURE request to the bootstrap server. The method simply invokes the same function of the ServerRequestManager.

Returns:
if join operation is canceled, return true; otherwise, return false

performStabilizeRequest

public void performStabilizeRequest()
Perform the SP_STABILIZE request to for all other super peers, who are in its routing table, to perform stabilization operation.


performRefreshRequest

public void performRefreshRequest()
Perform the REFRESH request to update the status of all super peers who are in its routing table. If any inconsistency happens, the super peer will perform statilization operation to maintain the correctness of the super peer network.


getServerRequestManager

public ServerRequestManager getServerRequestManager()

performSchemaUpdate

public void performSchemaUpdate(java.lang.String newSchema)
added by mihai, june 2nd


getRequestManager

public ServerRequestManager getRequestManager()
Returns:
the requestManager

setRequestManager

public void setRequestManager(ServerRequestManager requestManager)
Parameters:
requestManager - the requestManager to set