Manage a connection to an EMG server. More...
Public Member Functions | |
| ConnHandler (String theHost, String theUser, String thePassword, int thePort, boolean withSsl) | |
| Normal constructor. | |
| void | init (String str) |
| Sets the systemtype to be sent to the server. | |
| void | sessionInvalidate () |
| Close the connection to the server. | |
| OptionHolder | getLoginOptions () |
| Gets the MGP options from the current MgpSession. | |
| boolean | isAdmin () throws MgpException |
| Returns true if and only if the current user has full administration rights. | |
| int | getAdminFlags () throws MgpException |
| String | getClientConfig () throws MgpException |
Returns the MGP option client_config. | |
| String | getRemoteIp () throws MgpException |
Returns the MGP option remoteip. | |
| void | sendOperation (int operand, OptionHolder oph) throws MgpException |
| Sends an operation with parameters to the server. | |
| void | sendOperation (int operand, OptionHolder oph, boolean doFlush) throws MgpException |
| Sends an operation with parameters to the server. | |
| void | readOperation (OptionHolder oph) throws MgpException |
| Reads the reply from the EMG server from the previous operation. | |
| int | sendMess (Message msg) throws MgpException |
| Send an MGP Message to the server. | |
| java.sql.ResultSet | dbexec (String profile, String sql) throws MgpException |
| Sends an SQL string to the server, to be executed by the given database profile. | |
| OptionHolder | execute (int operation, OptionHolder options) throws MgpException |
| boolean | havePermission (int mask, boolean all) throws MgpException |
| Checks the permission of the currently logged in user. | |
| boolean | test () throws MgpException, java.io.IOException, Exception |
| Fetches the connection parameters from Setting, and calls test(String,int,String,String,boolean). | |
| boolean | test (String host, int port, String user, String pwd, boolean ssl) throws MgpException |
| Close the current session, and reconnect. | |
| void | setEmgDebug (boolean inBool) |
| Sets the debug level for the MgpSession, if any. | |
| final String | getHost () |
| final String | getPassword () |
| final int | getPort () |
| final boolean | isSsl () |
| final String | getUser () |
Private Member Functions | |
| void | checkConn (String theHost, int thePort, String theUser, String thePassword, boolean withSsl) throws MgpException |
| void | checkConn () throws MgpException |
Private Attributes | |
| String | syncer = "" |
| MgpSession | session = null |
| String | systemtype = null |
| String | sClientConfig = null |
| OptionHolder | loginOptions = null |
| String | host = "" |
| String | user = "" |
| String | password = "" |
| int | port = 0 |
| boolean | ssl = false |
Manage a connection to an EMG server.
Connection parameters are taken from the Settings class, using the following parameters.
host - the hostname of the server user - the username valid for the server pwd - the corresponding password port - the IP port number ssl - true if SSL should be used, otherwise false | com::nmt::mgp::ConnHandler::ConnHandler | ( | String | theHost, | |
| String | theUser, | |||
| String | thePassword, | |||
| int | thePort, | |||
| boolean | withSsl | |||
| ) | [inline] |
| void com::nmt::mgp::ConnHandler::checkConn | ( | String | theHost, | |
| int | thePort, | |||
| String | theUser, | |||
| String | thePassword, | |||
| boolean | withSsl | |||
| ) | throws MgpException [inline, private] |
| void com::nmt::mgp::ConnHandler::checkConn | ( | ) | throws MgpException [inline, private] |
References host, password, port, ssl, and user.
Referenced by dbexec(), execute(), getAdminFlags(), getClientConfig(), getRemoteIp(), havePermission(), readOperation(), sendMess(), sendOperation(), and test().
| java.sql.ResultSet com::nmt::mgp::ConnHandler::dbexec | ( | String | profile, | |
| String | sql | |||
| ) | throws MgpException [inline] |
Sends an SQL string to the server, to be executed by the given database profile.
The connection to the server is restored if necessary.
| profile | the database profile name | |
| sql | the sql string |
| MgpException | if the connection failes, or there is something wrong with the sql statement |
References checkConn(), com::nmt::mgp::MgpSession::dbexec(), com::nmt::mgp::MgpException::getErrno(), session, sessionInvalidate(), and syncer.
| OptionHolder com::nmt::mgp::ConnHandler::execute | ( | int | operation, | |
| OptionHolder | options | |||
| ) | throws MgpException [inline] |
| int com::nmt::mgp::ConnHandler::getAdminFlags | ( | ) | throws MgpException [inline] |
References checkConn(), com::nmt::mgp::MgpSession::getAdminFlags(), session, and syncer.
Referenced by isAdmin().
| String com::nmt::mgp::ConnHandler::getClientConfig | ( | ) | throws MgpException [inline] |
Returns the MGP option client_config.
A connection to the server is made if necessary.
| MgpException | If a connection can't be made. |
References checkConn(), com::nmt::mgp::MgpSession::getClientConfig(), session, and syncer.
| final String com::nmt::mgp::ConnHandler::getHost | ( | ) | [inline] |
References host.
| OptionHolder com::nmt::mgp::ConnHandler::getLoginOptions | ( | ) | [inline] |
Gets the MGP options from the current MgpSession.
References loginOptions.
| final String com::nmt::mgp::ConnHandler::getPassword | ( | ) | [inline] |
References password.
| final int com::nmt::mgp::ConnHandler::getPort | ( | ) | [inline] |
References port.
| String com::nmt::mgp::ConnHandler::getRemoteIp | ( | ) | throws MgpException [inline] |
Returns the MGP option remoteip.
A connection to the server is made if necessary.
| MgpException | If a connection can't be made. |
References checkConn(), com::nmt::mgp::MgpSession::getRemoteIp(), session, and syncer.
| final String com::nmt::mgp::ConnHandler::getUser | ( | ) | [inline] |
References user.
| boolean com::nmt::mgp::ConnHandler::havePermission | ( | int | mask, | |
| boolean | all | |||
| ) | throws MgpException [inline] |
Checks the permission of the currently logged in user.
The connection to the server is restored if necessary.
| mask | the bitmask of permissions | |
| all | if all bits must match |
| MgpException | if the connection failes |
References checkConn(), com::nmt::mgp::MgpException::getErrno(), com::nmt::mgp::MgpSession::havePermission(), session, sessionInvalidate(), and syncer.
| void com::nmt::mgp::ConnHandler::init | ( | String | str | ) | [inline] |
| boolean com::nmt::mgp::ConnHandler::isAdmin | ( | ) | throws MgpException [inline] |
Returns true if and only if the current user has full administration rights.
A connection to the server is made if necessary.
| MgpException | If a connection can't be made. |
References getAdminFlags().
| final boolean com::nmt::mgp::ConnHandler::isSsl | ( | ) | [inline] |
References ssl.
| void com::nmt::mgp::ConnHandler::readOperation | ( | OptionHolder | oph | ) | throws MgpException [inline] |
Reads the reply from the EMG server from the previous operation.
If readOperation() is called before sendOperation(), the application will hang waiting for the non-existent reply.
| oph | the container to store the replies in |
| MgpException | the connection fails |
References checkConn(), com::nmt::mgp::MgpException::getErrno(), com::nmt::mgp::MgpSession::readOperation(), session, and sessionInvalidate().
| int com::nmt::mgp::ConnHandler::sendMess | ( | Message | msg | ) | throws MgpException [inline] |
Send an MGP Message to the server.
If an MgpException is caught, the connection is closed, reopened, and a second attempt is made. No third attempt is made.
| msg | the message to send |
| MgpException | if anything is wrong with the message or the connection can't be established. |
References checkConn(), com::nmt::mgp::MgpException::getErrno(), com::nmt::mgp::MgpSession::sendMessage(), session, and sessionInvalidate().
| void com::nmt::mgp::ConnHandler::sendOperation | ( | int | operand, | |
| OptionHolder | oph | |||
| ) | throws MgpException [inline] |
Sends an operation with parameters to the server.
A connection to the server is made if necessary.
| operand | the operation number | |
| oph | the parameters |
| MgpException | If a connection can't be made. |
| void com::nmt::mgp::ConnHandler::sendOperation | ( | int | operand, | |
| OptionHolder | oph, | |||
| boolean | doFlush | |||
| ) | throws MgpException [inline] |
Sends an operation with parameters to the server.
A connection to the server is made if necessary.
| operand | the operation number | |
| oph | the parameters | |
| doFlush | if the data should be flushed |
| MgpException | If a connection can't be made. |
References checkConn(), com::nmt::mgp::MgpException::getErrno(), com::nmt::mgp::MgpSession::sendOperation(), session, sessionInvalidate(), and com::nmt::mgp::MgpSession::setDebug().
| void com::nmt::mgp::ConnHandler::sessionInvalidate | ( | ) | [inline] |
Close the connection to the server.
References com::nmt::mgp::MgpSession::close(), com::nmt::mgp::MgpSession::debug, com::nmt::mgp::MgpException::getErrno(), and session.
Referenced by checkConn(), dbexec(), execute(), havePermission(), readOperation(), sendMess(), sendOperation(), and test().
| void com::nmt::mgp::ConnHandler::setEmgDebug | ( | boolean | inBool | ) | [inline] |
Sets the debug level for the MgpSession, if any.
References session, and com::nmt::mgp::MgpSession::setDebug().
| boolean com::nmt::mgp::ConnHandler::test | ( | ) | throws MgpException, java.io.IOException, Exception [inline] |
Fetches the connection parameters from Setting, and calls test(String,int,String,String,boolean).
| boolean com::nmt::mgp::ConnHandler::test | ( | String | host, | |
| int | port, | |||
| String | user, | |||
| String | pwd, | |||
| boolean | ssl | |||
| ) | throws MgpException [inline] |
Close the current session, and reconnect.
References checkConn(), com::nmt::mgp::MgpException::getErrno(), host, port, session, sessionInvalidate(), ssl, and user.
String com::nmt::mgp::ConnHandler::host = "" [private] |
Referenced by checkConn(), ConnHandler(), getHost(), and test().
OptionHolder com::nmt::mgp::ConnHandler::loginOptions = null [private] |
Referenced by checkConn(), and getLoginOptions().
String com::nmt::mgp::ConnHandler::password = "" [private] |
Referenced by checkConn(), ConnHandler(), and getPassword().
int com::nmt::mgp::ConnHandler::port = 0 [private] |
Referenced by checkConn(), ConnHandler(), getPort(), and test().
String com::nmt::mgp::ConnHandler::sClientConfig = null [private] |
Referenced by checkConn().
MgpSession com::nmt::mgp::ConnHandler::session = null [private] |
Referenced by checkConn(), dbexec(), execute(), getAdminFlags(), getClientConfig(), getRemoteIp(), havePermission(), readOperation(), sendMess(), sendOperation(), sessionInvalidate(), setEmgDebug(), and test().
boolean com::nmt::mgp::ConnHandler::ssl = false [private] |
Referenced by checkConn(), ConnHandler(), isSsl(), and test().
String com::nmt::mgp::ConnHandler::syncer = "" [private] |
Referenced by dbexec(), execute(), getAdminFlags(), getClientConfig(), getRemoteIp(), and havePermission().
String com::nmt::mgp::ConnHandler::systemtype = null [private] |
Referenced by checkConn(), and init().
String com::nmt::mgp::ConnHandler::user = "" [private] |
Referenced by checkConn(), ConnHandler(), getUser(), and test().
1.7.1