📄 mqconnection.java
字号:
out.write(Safmq.CMD_SEEK_ID);
params.write(out);
out.flush();
ret = getResponseCode();
} catch (IOException e) {
ret = Safmq.EC_NETWORKERROR;
}
return ret;
}
/**
* Determines whether the cursor indicated by <code>cursorID</code> is still
* a valid cursor, and has not been invalidated by other queue readers.
*
* @param cursorID The cursor which should be be evaluated
* @return <code>Safmq.EC_NOERROR</code> upon success, otherwise errors returned
* could be but are not limited to:<br>
*<table border=0 cellpadding=3 cellspacing=0>
*<tr><td><code>Safmq.EC_NETWORKERROR</code></td>
* <td>A networking error has occurred and the conneciton
* is nolonger valid.
* </td></tr>
*<tr><td><code>Safmq.EC_NOTOPEN</code></td>
* <td>The queue specified has not been opened by this connection.
* </td></tr>
*<tr><td><code>Safmq.EC_CURSORINVALIDATED</code></td>
* <td>The cursor is no longer valid.
* </td></tr>
*</table>
*
* @see #OpenQueue(String, QueueHandle)
*/
public int TestCursor(QueueHandle qhandle, CursorHandle cursorID) {
int ret = Safmq.EC_NOERROR;
CLOSE_CURSOR_ADVANCE_CURSOR_TEST_CURSOR_PARAMS params = new CLOSE_CURSOR_ADVANCE_CURSOR_TEST_CURSOR_PARAMS();
params.queueID = qhandle.handle;
params.cursorID = cursorID.handle;
try {
out.write(Safmq.CMD_TEST_CURSOR);
params.write(out);
out.flush();
ret = getResponseCode();
} catch (IOException e) {
ret = Safmq.EC_NETWORKERROR;
}
return ret;
}
/**
* Begins a transaction which causes all Retrieve & Enqueue operations to be committed
* atomically.
*
* @return <code>Safmq.EC_NOERROR</code>, <code>Safmq.EC_NETWORKERROR</code>,
* <code>Safmq.EC_ALREADYOPEN</code> if a transaction is already open
*/
public int BeginTransaction() {
try {
out.write(Safmq.CMD_BEGIN_TRANSACTION);
out.writeInt(0);
out.flush();
return getResponseCode();
} catch (IOException e) {
return Safmq.EC_NETWORKERROR;
}
}
/**
* Commits a group of Retrieve & Enqueue operations atomically.
*
* @return <code>Safmq.EC_NOERROR</code>, <code>Safmq.EC_NETWORKERROR</code>
*/
public int CommitTransaction() {
try {
out.write(Safmq.CMD_COMMIT_TRANSACTION);
out.writeInt(0);
out.flush();
return getResponseCode();
} catch (IOException e) {
return Safmq.EC_NETWORKERROR;
}
}
/**
* Rolls back or "undoes" a group of Retrieve & Enqueue operations atomically.
*
* @return <code>Safmq.EC_NOERROR</code>, <code>Safmq.EC_NETWORKERROR</code>
*/
public int RollbackTransaction() {
try {
out.write(Safmq.CMD_ROLLBACK_TRANSACTION);
out.writeInt(0);
out.flush();
return getResponseCode();
} catch (IOException e) {
return Safmq.EC_NETWORKERROR;
}
}
/**
* Commits and closes a group of Retrieve & Enqueue operations.
*
* @return <code>Safmq.EC_NOERROR</code>, <code>Safmq.EC_NETWORKERROR</code>,
* <code>Safmq.EC_NOTOPEN</code> in the case that a transaction was not open.
*/
public int EndTransaction() {
try {
out.write(Safmq.CMD_END_TRANSACTION);
out.writeInt(0);
out.flush();
return getResponseCode();
} catch (IOException e) {
return Safmq.EC_NETWORKERROR;
}
}
////////////////////////////////////////////////////////////////////////////////////////
/**
* Retrieves a list of all queues served by the connection and the queue's owner.
* The passed <code>Vector qnames</code> receives <Code>MQConnection.QueueData</code>
* objects to enumerate the queue.
*
* @param qnames The vector which will be emptied then populated with <code>MQconnection.QueueData</code> objects.
*
* @return <code>Safmq.EC_NOERROR</code> upon success, otherwise errors returned
* could be but are not limited to:<br>
*<table border=0 cellpadding=3 cellspacing=0>
*<tr><td><code>Safmq.EC_NETWORKERROR</code></td>
* <td>A networking error has occurred and the conneciton
* is nolonger valid.
* </td></tr>
*</table>
*
* @see MQConnection.QueueData
*/
public int EnumerateQueues(Vector qnames) {
int ret = Safmq.EC_NETWORKERROR;
qnames.clear();
try {
out.write(Safmq.CMD_ENUM_QUEUES);
out.flush();
ret = getResponseCode();
if (ret == Safmq.EC_NOERROR) {
int nqueues = in.readInt();
QUEUE_CONFIG_ENTRY qent = new QUEUE_CONFIG_ENTRY();
for(int x=0; x < nqueues; x++) {
qent.read(in);
qnames.add(new QueueData(new String(qent.queuename,0,zlength(qent.queuename)),new String(qent.owner,0,zlength(qent.owner))));
}
}
} catch (IOException e) {
ret = Safmq.EC_NETWORKERROR;
}
return ret;
}
/**
* Retrieves a list of users which may access the SAFMQ server. The result
* user information is in the form of <code>MQConnection.UserDescription</code>
* objects placed in the passed <code>Vector, users</code>.
*
* @param users The vector which will be emptied then populated with <code>MQConnection.UserDescription</code> objects
*
* @return <code>Safmq.EC_NOERROR</code> upon success, otherwise errors returned
* could be but are not limited to:<br>
*<table border=0 cellpadding=3 cellspacing=0>
*<tr><td><code>Safmq.EC_NETWORKERROR</code></td>
* <td>A networking error has occurred and the conneciton
* is nolonger valid.
* </td></tr>
*</table>
*
* @see MQConnection.UserDescription
*/
public int EnumerateUsers(Vector users) {
int ret = Safmq.EC_NETWORKERROR;
users.clear();
try {
out.write(Safmq.CMD_ENUM_USERS);
out.flush();
ret = getResponseCode();
if (ret == Safmq.EC_NOERROR) {
int nUsers = in.readInt();
byte username[] = new byte[Safmq.USER_NAME_LENGTH];
byte description[] = new byte[Safmq.DESCRIPTION_LENGTH];
for(int x=0;x < nUsers; x++) {
in.readFully(username);
in.readFully(description);
users.add(new UserDescription(new String(username,0,zlength(username)),new String(description,0,zlength(description))));
}
}
} catch (IOException e) {
ret = Safmq.EC_NETWORKERROR;
}
return ret;
}
/**
* Retrieves a list of all groups available on the SAFMQ server. The result
* group information is in the form of <code>String</code> objects representing
* the name of the group.
*
* @param groups The vector which will be emptied then populated with
* <code>String</code> objects containing the names of the
* groups.
* @return <code>Safmq.EC_NOERROR</code> upon success, otherwise errors returned
* could be but are not limited to:<br>
*<table border=0 cellpadding=3 cellspacing=0>
*<tr><td><code>Safmq.EC_NETWORKERROR</code></td>
* <td>A networking error has occurred and the conneciton
* is nolonger valid.
* </td></tr>
*</table>
*/
public int EnumerateGroups(Vector groups) {
int ret = Safmq.EC_NETWORKERROR;
groups.clear();
try {
out.write(Safmq.CMD_ENUM_GROUPS);
out.flush();
ret = getResponseCode();
if (ret == Safmq.EC_NOERROR) {
int nGroups = in.readInt();
byte groupname[] = new byte[Safmq.GROUP_NAME_LENGTH];
for(int x=0; x < nGroups; x++) {
in.readFully(groupname);
groups.add(new String(groupname,0,zlength(groupname)));
}
}
} catch (IOException e) {
ret = Safmq.EC_NETWORKERROR;
}
return ret;
}
/**
* Create a new user by providing a user name, password and description.
*
* @param username The name of the new user
* @param password The password for the new user, cannot be null
* @param description The description for the new user.
* @return <code>Safmq.EC_NOERROR</code> upon success, otherwise errors returned
* could be but are not limited to:<br>
*<table border=0 cellpadding=3 cellspacing=0>
*<tr><td><code>Safmq.EC_NETWORKERROR</code></td>
* <td>A networking error has occurred and the conneciton
* is nolonger valid.
* </td></tr>
*<tr><td><code>Safmq.EC_ALREADYDEFINED</code></td>
* <td>A user with this name already exists
* </td></tr>
*<tr><td><code>Safmq.EC_NOTAUTHORIZED</code></td>
* <td>The current logged in user is not authorized to create users.
* </td></tr>
*</table>
*
*/
public int CreateUser(String username, String password, String description) {
USER_CREATE_PARAMS params = new USER_CREATE_PARAMS();
int ret = Safmq.EC_NETWORKERROR;
paramutil.arrayCopy(params.username,username);
paramutil.arrayCopy(params.password,password);
paramutil.arrayCopy(params.description,description);
try {
out.write(Safmq.CMD_USER_CREATE);
params.write(out);
out.flush();
ret = getResponseCode();
} catch (IOException e) {
ret = Safmq.EC_NETWORKERROR;
}
return ret;
}
/**
* Delete a user from the SAFMQ server.
* @param username The name of the suer to delete.
* @return <code>Safmq.EC_NOERROR</code> upon success, otherwise errors returned
* could be but are not limited to:<br>
*<table border=0 cellpadding=3 cellspacing=0>
*<tr><td><code>Safmq.EC_NETWORKERROR</code></td>
* <td>A networking error has occurred and the conneciton
* is nolonger valid.
* </td></tr>
*<tr><td><code>Safmq.EC_NOTAUTHORIZED</code></td>
* <td>The current logged in user is not authorized to create users.
* </td></tr>
*<tr><td><code>Safmq.EC_DOESNOTEXIST</code></td>
* <td>The user specified does not exist.
* </td></tr>
*</table>
*/
public int DeleteUser(String username) {
USER_DELETE_USER_GET_PERMS_USER_GET_GROUPS_PARAMS params = new USER_DELETE_USER_GET_PERMS_USER_GET_GROUPS_PARAMS();
int ret = Safmq.EC_NETWORKERROR;
paramutil.arrayCopy(params.username,username);
try {
out.write(Safmq.CMD_USER_DELETE);
params.write(out);
out.flush();
ret = getResponseCode();
} catch (IOException e) {
ret = Safmq.EC_NETWORKERROR;
}
return ret;
}
/**
* Change the user's permissions to those specified.
*
* @param username Name of the user to change
* @param modifyqueues Allow the user to create queues
* @param modifyusers Allow the user to create and delete users and set permmsions
* @param modifygroups Allow the user to create, delete, and change group membership and permissions
*
* @return <code>Safmq.EC_NOERROR</code> upon success, otherwise errors returned
* could be but are not limited to:<br>
*<table border=0 cellpadding=3 cellspacing=0>
*<tr><td><code>Safmq.EC_NETWORKERROR</code></td>
* <td>A networking error has occurred and the conneciton
* is nolonger valid.
* </td></tr>
*<tr><td><code>Safmq.EC_NOTAUTHORIZED</code></td>
* <td>The current logged in user is not authorized to modify user permissions.
* </td></tr>
*<tr><td><code>Safmq.EC_DOESNOTEXIST</code></td>
* <td>The specified user does not exist on the SAFMQ server.
* </td></tr>
*</table>
*/
public int UserSetPermissions(String username, boolean modifyqueues, boolean modifyusers, boolean modifygroups) {
USER_SET_PERMS_PARAMS params = new USER_SET_PERMS_PARAMS();
int ret = Safmq.EC_NETWORKERROR;
paramutil.arrayCopy(params.username,username);
params.modify_queues = (byte)(modifyqueues?1:0);
params.modify_users = (byte)(modifyusers?1:0);
params.modify_groups = (byte)(modifygroups?1:0);
try {
out.write(Safmq.CMD_USER_SET_PERMS);
params.write(out);
out.flush();
ret = getResponseCode();
} catch (IOException e) {
ret = Safmq.EC_NETWORKERROR;
}
return ret;
}
/**
* Retrieve the permissions for a specific user.
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -