Class CMServerStub
- See Also:
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
Connects to the default server.boolean
Disconnects from the default server.getBlockSocketChannel
(int nChKey, String strUserName) Returns a blocking socket (TCP) channel to a client.gets the string representation of current channels information.getFileSyncHome
(String userName) gets the synchronization home directory of the specified user.Returns the list of currently logged-in users in this server.Gets server address from the server configuration file.int
Gets server port number from the server configuration file.boolean
Deregisters an additional server from the default server.boolean
requestServerReg
(String server) Registers an additional server to the default server.void
setAttachDownloadScheme
(String strUserName, int nScheme) Sets the download scheme for attached images of SNS content.boolean
setServerAddress
(String strAddress) Sets server address to the server configuration file.boolean
setServerInfo
(String strAddress, int nPort) Sets server address and port number to the server configuration file.boolean
setServerPort
(int nPort) Sets server port number to the server configuration file.boolean
Sets the default file path for file transfer.boolean
startCM()
Initializes and starts the server CM.void
Terminates the server CM.Methods inherited from class kr.ac.konkuk.ccslab.cm.stub.CMStub
addBlockDatagramChannel, addMulticastChannel, addNonBlockDatagramChannel, broadcast, broadcast, broadcast, cancelPullFile, cancelPushFile, cast, cast, cast, cast, cast, cast, castrecv, findServiceManager, getAppEventHandler, getBlockDatagramChannel, getCMInfo, getConfigurationHome, getDefaultServerName, getMyself, getThreadInfo, getTransferedFileHome, init, measureInputThroughput, measureOutputThroughput, multicast, pushFile, pushFile, receive, receive, removeAdditionalMulticastChannel, removeBlockDatagramChannel, removeNonBlockDatagramChannel, replyEvent, requestFile, requestFile, send, send, send, send, send, send, send, send, sendrecv, setAppEventHandler, setConfigurationHome
-
Constructor Details
-
CMServerStub
public CMServerStub()Creates an instance of the CMServerStub class.This method just called the default constructor of the super class, CMStub.
-
-
Method Details
-
setTransferedFileHome
Sets the default file path for file transfer.
This method updates the transfered-file path information in CM and the FILE_PATH field in the CM configuration file.CM applications that directly connect to each other can exchange a file with the CMStub class that is the parent class of the CMClientStub and the CMServerStub classes. In the client-server architecture, a client can push or pull a file to/from a server and vice versa. When CM is initialized by an application, the default directory is configured by the path information that is set in the configuration file (the FILE_PATH field). If the default directory does not exist, CM creates it. If the FILE_PATH field is not set, the default path is set to the current working directory (".").
If the file transfer is requested, a sender (the server or the client) searches for the file in the default file path. If a client receives a file, CM stores the file in this file path. If a server receives a file, CM stores the file in a sub-directory of the default path. The sub-directory name is a sender (client) name.
- Parameters:
dir
- - the file path- Returns:
- true if the file path is successfully updated both in the CMConfigurationInfo class and the configuration file (cm-server.conf), or false otherwise.
- See Also:
-
setServerAddress
Sets server address to the server configuration file.This method must be called before an application starts CM because it updates the value of "SERVER_ADDR" field in the server configuration file (cm-server.conf).
- Parameters:
strAddress
- - the server IP address- Returns:
- true if the server address is successfully set, or false otherwise.
- See Also:
-
getServerAddress
Gets server address from the server configuration file.- Returns:
- server address
- See Also:
-
setServerPort
public boolean setServerPort(int nPort) Sets server port number to the server configuration file.This method must be called before an application starts CM because it updates the value of "SERVER_PORT" field in the server configuration file (cm-server.conf).
- Parameters:
nPort
- - the server port number- Returns:
- true if the server port is successfully set, or false otherwise.
- See Also:
-
getServerPort
public int getServerPort()Gets server port number from the server configuration file.- Returns:
- server port number
- See Also:
-
setServerInfo
Sets server address and port number to the server configuration file.This method must be called before an application starts CM because it updates the values of "SERVER_ADDR" and "SERVER_PORT" fields in the server configuration file (cm-server.conf).
- Parameters:
strAddress
- - the server IP addressnPort
- - the server port number- Returns:
- true if the server address and port number are successfully set, or false otherwise.
- See Also:
-
startCM
public boolean startCM()Initializes and starts the server CM.Before the server CM starts, it initializes the configuration and the interaction manager. Then, it starts two separate threads for receiving and processing CM events.
- Returns:
- true if the initialization of CM succeeds, or false if the initialization of CM fails.
- See Also:
-
terminateCM
public void terminateCM()Terminates the server CM.
A server application calls this method when it does not need to use CM any more. The server releases all the resources that are used by CM.- Overrides:
terminateCM
in classCMStub
- See Also:
-
requestServerReg
Registers an additional server to the default server.When an additional server starts, it automatically connects to the default server. The additional server then needs to request for registration to the default server in order to participate in current CM network.
Only an additional server should call the requestServerReg method with a desired server name. Because the default server has the reserved name, "SERVER", the additional server must specify a different name as the parameter of this method.
In order for a requesting server to check the result of the registration request, the server can catch the RES_SERVER_REG event of the CMMultiServerEvent class in its event handler routine. The event fields of this event are described below.CMMultiServerEvent.RES_SERVER_REG event Event type CMInfo.CM_MULTI_SERVER_EVENT Event ID CMMultiServerEvent.RES_SERVER_REG Event field Field data type Field definition Get method server name String the requester server name getServerName() return code int result code of the registration request
1: succeeded
0: failedgetReturnCode() - Parameters:
server
- - the server name- Returns:
- true if the request is successfully sent to the default server; false otherwise.
- See Also:
-
requestServerDereg
public boolean requestServerDereg()Deregisters an additional server from the default server.If an additional server leaves current CM network, it can request to deregister from the default server. Although it leaves the CM network, the additional server still maintains the connection with the default server. If required, this connection can also be managed by the
connectToServer()
and thedisconnectFromServer()
methods.
In order for a requesting server to check the result of the deregistration request, the server can catch the RES_SERVER_DEREG event of the CMMultiServerEvent class in its event handler routine. The event fields of this event are described below.CMMultiServerEvent.RES_SERVER_DEREG event Event type CMInfo.CM_MULTI_SERVER_EVENT Event ID CMMultiServerEvent.RES_SERVER_DEREG Event field Field data type Field definition Get method server name String the requester server name getServerName() return code int result code of the deregistration request
1: succeeded
0: failedgetReturnCode() - Returns:
- true is the request is successfully sent to the default server; false otherwise
- See Also:
-
connectToServer
public boolean connectToServer()Connects to the default server.An additional server can call this method to establish a connection to the default server.
- Returns:
- true if the connection is successfully established, or false otherwise.
- See Also:
-
disconnectFromServer
public boolean disconnectFromServer()Disconnects from the default server.An additional server can call this method to disconnect the connection from the default server.
- Returns:
- true if the connection is successfully disconnected, or false otherwise.
- See Also:
-
setAttachDownloadScheme
Sets the download scheme for attached images of SNS content.The detailed information about the attachment download scheme can be found in the following reference:
Mingyu Lim, "Multi-level Content Transmission Mechanism for Intelligent Quality of Service in Social Networking Services," The Transactions on the Korean Institute of Electrical Engineers, Vol. 65, No. 8, August 2016, pp.1407-1417.- Parameters:
strUserName
- - the target user name
The attachment download scheme is applied to 'strUserName'. If the value is null, the download scheme is applied to all users.nScheme
- - the download scheme
The possible value is CMInfo.SNS_ATTACH_FULL(or 0), CMInfo.SNS_ATTACH_PARTIAL(or 1), CMInfo.SNS_ATTACH_PREFETCH(or 2) and CMInfo.SNS_ATTACH_NONE(or 3).Download scheme of attached images of SNS content download scheme description CMInfo.SNS_ATTACH_FULL The CM server sends images with the original quality to the client. CMInfo.SNS_ATTACH_PARTIAL The server sends thumbnail images instead of the original images. CMInfo.SNS_ATTACH_PREFETCH The server sends thumbnail images to the client, and sends also original images that the client is interested in. CMInfo.SNS_ATTACH_NONE The server sends only text links to images. - See Also:
-
getBlockSocketChannel
Returns a blocking socket (TCP) channel to a client.When a client adds a blocking socket channel, the server also creates and adds a corresponding blocking socket channel to communicate with the client. The server can retrieve such a blocking socket channel with this method.
- Parameters:
nChKey
- - the channel key.strUserName
- - the user name to which the socket channel is connected.- Returns:
- the blocking socket channel, or null if the channel is not found.
- See Also:
-
getCurrentChannelInfo
gets the string representation of current channels information.This method overrides the
CMStub.getCurrentChannelInfo()
method. It firstly calls the parent method to get the current datagram channel information, and then also gets the current blocking/non-blocking socket channel mostly to connected clients.- Overrides:
getCurrentChannelInfo
in classCMStub
- Returns:
- string of current channels information if successful, or null otherwise.
- See Also:
-
getLoginUsers
Returns the list of currently logged-in users in this server.- Returns:
- the list of logged-in users.
-
getFileSyncHome
gets the synchronization home directory of the specified user.The server maintains a synchronization home directory per user. The server also specifies the “FileSyncHome” directory in the transferred file home of a user. The transferred file home is set in the FILE_PATH field of CM server configuration file (cm-server.conf). For example, if the transferred file home of a user “ccslab” is “./server-file-path”, then the synchronization home directory is “./server-file-path/ccslab/FileSyncHome”.
- Parameters:
userName
- user name- Returns:
- synchronization home directory of the user.
This method return null if the userName argument is null.
-