An implementation of the MgpSessionI interface. More...
Public Member Functions | |
| MgpSession () | |
| MgpSession (String host, int port, boolean useSsl) throws MgpException | |
| Construct a new MgpSession object, and connect to the server. | |
| void | connect (String host, int port, boolean useSsl) throws MgpException |
| Connect to the server. | |
| synchronized void | close () throws MgpException |
| Clears the session by logging off from the server and closing the current connection. | |
| void | sendOperation (int operation, OptionHolder options, boolean doFlush) throws MgpException |
| Send an operation to the EMG server. | |
| void | sendOperation (int operation, OptionHolder options) throws MgpException |
| Send an operation to the EMG server. | |
| int | readOperation (OptionHolder options) throws MgpException |
| Read an operation request from the server and store the options in the provided option holder. | |
| int | readResponse () throws MgpException |
| Read the response to the last command sent to the EMG server. | |
| synchronized OptionHolder | execute (int operation, OptionHolder options) throws MgpException |
| Send an operation with arguments to the EMG server, and wait for the response. | |
| synchronized void | login (String username, String password, String servicetype) throws MgpException |
| Login to the server using username and password for authentication. | |
| void | login (String username, String password) throws MgpException |
| Login to the server using username and password for authentication. | |
| synchronized void | logoff () throws MgpException |
| Logoff from the server. | |
| synchronized void | reload () throws MgpException |
| Reload the configuration on the server, while keeping the connection open. | |
| int | sendMessage (Message msg) throws MgpException |
| Send a message. | |
| int | queryMessage (int id) throws MgpException |
| Query the server for status of a message, identified by the specified id. | |
| void | deleteMessage (int id) throws MgpException |
| Delete a message. | |
| java.sql.ResultSet | dbexec (String profile, String sql) throws MgpException, java.sql.SQLException |
| Send an SQL string to be executed on the EMG server. | |
| boolean | isAdmin () |
| Returns whether user in session is an administrator. | |
| int | getAdminFlags () |
| Gets the full administration flags for the currently logged in user. | |
| int | getPermissions () |
| Gets the permissions for the currently logged in user. | |
| boolean | havePermission (int functions) |
| Checks if the current user has all of the given permissions. | |
| boolean | havePermission (int mask, boolean all) |
| Checks if the current user has any or all of the given permissions. | |
| String | getClientConfig () |
| Gets the client configuration string. | |
| void | setDebug (boolean on) |
| Enables/disables runtime debug output. | |
| OptionHolder | getLoginOptions () |
| Gets the current login options. | |
| String | getRemoteIp () |
| The IP number of this client, as seen by the server. | |
Protected Member Functions | |
| SSLSocket | openSSL () throws NoSuchAlgorithmException, KeyManagementException, IOException |
| Open an SSL connection, allowing any certificate that the server might offer. | |
Private Member Functions | |
| void | sendHeader (int operation) throws MgpException |
| void | sendData (OptionHolder options, boolean doFlush) throws MgpException |
| int | readHeader () throws MgpException |
| void | readData (OptionHolder options) throws MgpException |
| Read data (options). | |
Private Attributes | |
| java.net.Socket | socket = null |
| BufferedReader | in = null |
| BufferedWriter | out = null |
| String | host = null |
| int | port = -1 |
| boolean | debug = false |
| boolean | isAdmin = false |
| int | perms = 0 |
| int | adminFlags = 0 |
| boolean | useSsl = false |
| String | clientConfig = null |
| OptionHolder | loginOptions = null |
| String | remoteip = null |
| String | charset = null |
| The character set that we should send SQL statements and similar data in, and what is used for result sets. | |
Static Private Attributes | |
| static final int | A_STX = 2 |
| static final int | A_ETX = 3 |
An implementation of the MgpSessionI interface.
| com::nmt::mgp::MgpSession::MgpSession | ( | ) | [inline] |
| com::nmt::mgp::MgpSession::MgpSession | ( | String | host, | |
| int | port, | |||
| boolean | useSsl | |||
| ) | throws MgpException [inline] |
Construct a new MgpSession object, and connect to the server.
| host | the host name to connect to | |
| port | the port number to connect to | |
| useSsl | true if and only if the communication should use SSL |
| MgpException | if a communication error occurs |
| synchronized void com::nmt::mgp::MgpSession::close | ( | ) | throws MgpException [inline] |
Clears the session by logging off from the server and closing the current connection.
Implements com::nmt::mgp::MgpSessionI.
References logoff(), and socket.
Referenced by com::nmt::mgp::ConnHandler::sessionInvalidate().
| void com::nmt::mgp::MgpSession::connect | ( | String | host, | |
| int | port, | |||
| boolean | useSsl | |||
| ) | throws MgpException [inline] |
Connect to the server.
| host | the host name to connect to | |
| port | the port number to connect to | |
| useSsl | true if and only if the communication should use SSL |
| MgpException | if a communication error occurs |
Implements com::nmt::mgp::MgpSessionI.
References host, in, openSSL(), out, port, socket, and useSsl.
Referenced by MgpSession().
| java.sql.ResultSet com::nmt::mgp::MgpSession::dbexec | ( | String | profile, | |
| String | sql | |||
| ) | throws MgpException, java.sql.SQLException [inline] |
Send an SQL string to be executed on the EMG server.
| profile | the database profile name | |
| sql | the SQL string |
INSERT or UPDATE). Implements com::nmt::mgp::MgpSessionI.
References com::nmt::mgp::OptionHolder::add(), com::nmt::mgp::ResultSetMetaData::addColumn(), charset, execute(), com::nmt::mgp::OptionHolder::getIntValue(), com::nmt::mgp::ResultSet::getMetaData(), com::nmt::mgp::OptionHolder::getValues(), com::nmt::mgp::ResultSet::setData(), com::nmt::mgp::ResultSet::setDataSize(), and com::nmt::mgp::ResultSet::setLastId().
Referenced by com::nmt::mgp::ConnHandler::dbexec().
| void com::nmt::mgp::MgpSession::deleteMessage | ( | int | id | ) | throws MgpException [inline] |
Delete a message.
Shortcut for deleting the message identified by the specified id.
Returns message status on success, otherwise an MgpException is thrown.
| id | the unique identifier of the message, returned by sendMessage(Message) |
| MgpException | if the message isn't found on the server, or a communication error occurs |
Implements com::nmt::mgp::MgpSessionI.
References com::nmt::mgp::OptionHolder::add(), execute(), and com::nmt::mgp::OptionHolder::getValue().
| synchronized OptionHolder com::nmt::mgp::MgpSession::execute | ( | int | operation, | |
| OptionHolder | options | |||
| ) | throws MgpException [inline] |
Send an operation with arguments to the EMG server, and wait for the response.
The implementation of this method should be synchronized to provide a simple multithread safe access point.
| operation | the operation number, as one of MGP_OP_* from Mgp | |
| options | the input parameters, to be sent to the server |
| MgpException | if a communication error occurs |
Implements com::nmt::mgp::MgpSessionI.
References readOperation(), and sendOperation().
Referenced by dbexec(), deleteMessage(), com::nmt::mgp::ConnHandler::execute(), login(), queryMessage(), and sendMessage().
| int com::nmt::mgp::MgpSession::getAdminFlags | ( | ) | [inline] |
Gets the full administration flags for the currently logged in user.
Implements com::nmt::mgp::MgpSessionI.
References adminFlags.
Referenced by com::nmt::mgp::ConnHandler::getAdminFlags().
| String com::nmt::mgp::MgpSession::getClientConfig | ( | ) | [inline] |
Gets the client configuration string.
Implements com::nmt::mgp::MgpSessionI.
References clientConfig.
Referenced by com::nmt::mgp::ConnHandler::checkConn(), and com::nmt::mgp::ConnHandler::getClientConfig().
| OptionHolder com::nmt::mgp::MgpSession::getLoginOptions | ( | ) | [inline] |
Gets the current login options.
Implements com::nmt::mgp::MgpSessionI.
References loginOptions.
Referenced by com::nmt::mgp::ConnHandler::checkConn().
| int com::nmt::mgp::MgpSession::getPermissions | ( | ) | [inline] |
Gets the permissions for the currently logged in user.
The value is a combined bitmask of MGP_ACCESS_* from Mgp.
Implements com::nmt::mgp::MgpSessionI.
References perms.
| String com::nmt::mgp::MgpSession::getRemoteIp | ( | ) | [inline] |
The IP number of this client, as seen by the server.
Implements com::nmt::mgp::MgpSessionI.
References remoteip.
Referenced by com::nmt::mgp::ConnHandler::getRemoteIp().
| boolean com::nmt::mgp::MgpSession::havePermission | ( | int | functions | ) | [inline] |
Checks if the current user has all of the given permissions.
Implements com::nmt::mgp::MgpSessionI.
Referenced by com::nmt::mgp::ConnHandler::havePermission().
| boolean com::nmt::mgp::MgpSession::havePermission | ( | int | mask, | |
| boolean | all | |||
| ) | [inline] |
Checks if the current user has any or all of the given permissions.
The permissions should be from the MGP_ACCESS_* constants in Mgp.
| mask | the bitmask of permissions | |
| all | true if all permissions must be present |
Implements com::nmt::mgp::MgpSessionI.
References perms.
| boolean com::nmt::mgp::MgpSession::isAdmin | ( | ) | [inline] |
Returns whether user in session is an administrator.
Implements com::nmt::mgp::MgpSessionI.
References isAdmin.
| synchronized void com::nmt::mgp::MgpSession::login | ( | String | username, | |
| String | password, | |||
| String | servicetype | |||
| ) | throws MgpException [inline] |
Login to the server using username and password for authentication.
| username | the EMG username, sent as Mgp#MGP_OPTION_USERNAME | |
| password | the EMG password, sent as Mgp#MGP_OPTION_PASSWORD | |
| servicetype | the systemtype, sent as Mgp#MGP_OPTION_SYSTEMTYPE |
| MgpException | if a communication error occurs |
Implements com::nmt::mgp::MgpSessionI.
References com::nmt::mgp::OptionHolder::add(), adminFlags, charset, clientConfig, execute(), com::nmt::mgp::OptionHolder::getIntValue(), com::nmt::mgp::OptionHolder::getValue(), isAdmin(), loginOptions, perms, and remoteip.
Referenced by com::nmt::mgp::ConnHandler::checkConn(), and login().
| void com::nmt::mgp::MgpSession::login | ( | String | username, | |
| String | password | |||
| ) | throws MgpException [inline] |
Login to the server using username and password for authentication.
Overload for login(String,String,String), using null as the system type.
Implements com::nmt::mgp::MgpSessionI.
References login().
| synchronized void com::nmt::mgp::MgpSession::logoff | ( | ) | throws MgpException [inline] |
Logoff from the server.
Sends the operation Mgp#MGP_OP_LOGOFF to the EMG server.
Implements com::nmt::mgp::MgpSessionI.
References clientConfig, isAdmin(), readResponse(), and sendOperation().
Referenced by close().
| SSLSocket com::nmt::mgp::MgpSession::openSSL | ( | ) | throws NoSuchAlgorithmException, KeyManagementException, IOException [inline, protected] |
Open an SSL connection, allowing any certificate that the server might offer.
| NoSuchAlgorithmException | if no matching algorithm can be found | |
| KeyManagementException | if no key can be agreed upon | |
| IOException | if no socket can be opened on the connection |
Referenced by connect().
| int com::nmt::mgp::MgpSession::queryMessage | ( | int | id | ) | throws MgpException [inline] |
Query the server for status of a message, identified by the specified id.
Returns message status on success, otherwise an MgpException is thrown.
| id | the unique identifier of the message, returned by sendMessage(Message) |
| MgpException | if the message isn't found on the server, or a communication error occurs |
Implements com::nmt::mgp::MgpSessionI.
References com::nmt::mgp::OptionHolder::add(), execute(), and com::nmt::mgp::OptionHolder::getValue().
| void com::nmt::mgp::MgpSession::readData | ( | OptionHolder | options | ) | throws MgpException [inline, private] |
| int com::nmt::mgp::MgpSession::readHeader | ( | ) | throws MgpException [inline, private] |
References A_STX, debug, and in.
Referenced by readOperation().
| int com::nmt::mgp::MgpSession::readOperation | ( | OptionHolder | options | ) | throws MgpException [inline] |
Read an operation request from the server and store the options in the provided option holder.
| options | an empty OptionHolder, which will get filled with the parameters to the operation |
| MgpException | if a communication error occurs |
Implements com::nmt::mgp::MgpSessionI.
References debug, readData(), and readHeader().
Referenced by execute(), com::nmt::mgp::ConnHandler::readOperation(), and readResponse().
| int com::nmt::mgp::MgpSession::readResponse | ( | ) | throws MgpException [inline] |
Read the response to the last command sent to the EMG server.
Calls readOperation(OptionHolder), extracts the return code (Mgp.MGP_OPTION_RETCODE) and returns the value as an int.
| MgpException | if an error occurs when reading from the stream |
Implements com::nmt::mgp::MgpSessionI.
References com::nmt::mgp::OptionHolder::getValue(), and readOperation().
| synchronized void com::nmt::mgp::MgpSession::reload | ( | ) | throws MgpException [inline] |
Reload the configuration on the server, while keeping the connection open.
Sends the operation Mgp#MGP_OP_RELOAD to the EMG server.
Implements com::nmt::mgp::MgpSessionI.
References readResponse(), and sendOperation().
| void com::nmt::mgp::MgpSession::sendData | ( | OptionHolder | options, | |
| boolean | doFlush | |||
| ) | throws MgpException [inline, private] |
References A_ETX, debug, and out.
Referenced by sendOperation().
| void com::nmt::mgp::MgpSession::sendHeader | ( | int | operation | ) | throws MgpException [inline, private] |
Referenced by sendOperation().
| int com::nmt::mgp::MgpSession::sendMessage | ( | Message | msg | ) | throws MgpException [inline] |
Send a message.
Destination address and message data is mandatory. This is checked before the message is sent. If the message is not valid an exception is thrown.
Returns the message id on success, otherwise an MgpException is thrown.
| msg | A message with message text, destination address etc set |
| MgpException | if a communication error occurs |
Implements com::nmt::mgp::MgpSessionI.
References execute(), and com::nmt::mgp::OptionHolder::getValue().
Referenced by com::nmt::mgp::ConnHandler::sendMess().
| void com::nmt::mgp::MgpSession::sendOperation | ( | int | operation, | |
| OptionHolder | options, | |||
| boolean | doFlush | |||
| ) | throws MgpException [inline] |
Send an operation to the EMG server.
| operation | the operation number, one of Mgp.MGP_OP_* | |
| options | the list of operation parameters | |
| doFlush | true if and only if the socket stream should be flushed after the operation |
Implements com::nmt::mgp::MgpSessionI.
References debug, sendData(), and sendHeader().
Referenced by execute(), logoff(), reload(), sendOperation(), and com::nmt::mgp::ConnHandler::sendOperation().
| void com::nmt::mgp::MgpSession::sendOperation | ( | int | operation, | |
| OptionHolder | options | |||
| ) | throws MgpException [inline] |
Send an operation to the EMG server.
This is a simple overload to sendOperation(int,OptionHolder,boolean), with true used as the third argument.
| operation | the operation number, one of Mgp.MGP_OP_* | |
| options | the list of operation parameters |
Implements com::nmt::mgp::MgpSessionI.
References sendOperation().
| void com::nmt::mgp::MgpSession::setDebug | ( | boolean | on | ) | [inline] |
Enables/disables runtime debug output.
| on | true for debug out, false if not |
Implements com::nmt::mgp::MgpSessionI.
References debug.
Referenced by com::nmt::mgp::ConnHandler::checkConn(), com::nmt::mgp::ConnHandler::sendOperation(), and com::nmt::mgp::ConnHandler::setEmgDebug().
final int com::nmt::mgp::MgpSession::A_ETX = 3 [static, private] |
Referenced by readData(), and sendData().
final int com::nmt::mgp::MgpSession::A_STX = 2 [static, private] |
Referenced by readHeader(), and sendHeader().
int com::nmt::mgp::MgpSession::adminFlags = 0 [private] |
Referenced by getAdminFlags(), and login().
String com::nmt::mgp::MgpSession::charset = null [private] |
String com::nmt::mgp::MgpSession::clientConfig = null [private] |
Referenced by getClientConfig(), login(), and logoff().
boolean com::nmt::mgp::MgpSession::debug = false [private] |
Referenced by readData(), readHeader(), readOperation(), sendData(), sendOperation(), com::nmt::mgp::ConnHandler::sessionInvalidate(), and setDebug().
String com::nmt::mgp::MgpSession::host = null [private] |
Referenced by connect(), MgpSession(), and openSSL().
BufferedReader com::nmt::mgp::MgpSession::in = null [private] |
Referenced by connect(), readData(), and readHeader().
boolean com::nmt::mgp::MgpSession::isAdmin = false [private] |
Referenced by isAdmin().
OptionHolder com::nmt::mgp::MgpSession::loginOptions = null [private] |
Referenced by getLoginOptions(), and login().
BufferedWriter com::nmt::mgp::MgpSession::out = null [private] |
Referenced by connect(), sendData(), and sendHeader().
int com::nmt::mgp::MgpSession::perms = 0 [private] |
Referenced by getPermissions(), havePermission(), and login().
int com::nmt::mgp::MgpSession::port = -1 [private] |
Referenced by connect(), MgpSession(), and openSSL().
String com::nmt::mgp::MgpSession::remoteip = null [private] |
Referenced by getRemoteIp(), and login().
java.net.Socket com::nmt::mgp::MgpSession::socket = null [private] |
boolean com::nmt::mgp::MgpSession::useSsl = false [private] |
Referenced by connect(), and MgpSession().
1.7.1