1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-27 00:32:07 +01:00

Added method so that timeout can be specified when executing ad-hoc command.

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@10946 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Matt Tucker 2008-12-16 22:33:57 +00:00 committed by matt
parent bc9f0179fa
commit 1bdacfb65e
2 changed files with 33 additions and 13 deletions

View file

@ -170,6 +170,10 @@ public abstract class AdHocCommand {
data.addNote(note);
}
public String getRaw() {
return data.getChildElementXML();
}
/**
* Returns the form of the current stage. Usually it is the form that must
* be answered to execute the next action. If that is the case it should be
@ -206,10 +210,21 @@ public abstract class AdHocCommand {
* command. It is invoked on every command. If there is a problem executing
* the command it throws an XMPPException.
*
* @throws XMPPException if there is a problem executing the command.
* @throws XMPPException if there is an error executing the command.
*/
public abstract void execute() throws XMPPException;
/**
* Executes the command, waiting up to the <tt>timeout</tt> for a reply.
* This is invoked only on the first stage of the
* command. It is invoked on every command. If there is a problem executing
* the command it throws an XMPPException.
*
* @param timeout the length of time in ms to wait for a reply.
* @throws XMPPException if there is an error executing the command.
*/
public abstract void execute(long timeout) throws XMPPException;
/**
* Executes the next action of the command with the information provided in
* the <code>response</code>. This form must be the answer form of the

View file

@ -79,19 +79,23 @@ public class RemoteCommand extends AdHocCommand {
@Override
public void cancel() throws XMPPException {
executeAction(Action.cancel);
executeAction(Action.cancel, SmackConfiguration.getPacketReplyTimeout());
}
@Override
public void complete(Form form) throws XMPPException {
executeAction(Action.complete, form);
executeAction(Action.complete, form, SmackConfiguration.getPacketReplyTimeout());
}
@Override
public void execute() throws XMPPException {
executeAction(Action.execute);
executeAction(Action.execute, SmackConfiguration.getPacketReplyTimeout());
}
@Override
public void execute(long timeout) throws XMPPException {
executeAction(Action.execute, timeout);
}
/**
* Executes the default action of the command with the information provided
* in the Form. This form must be the anwser form of the previous stage. If
@ -101,21 +105,21 @@ public class RemoteCommand extends AdHocCommand {
* @throws XMPPException if an error occurs.
*/
public void execute(Form form) throws XMPPException {
executeAction(Action.execute, form);
executeAction(Action.execute, form, SmackConfiguration.getPacketReplyTimeout());
}
@Override
public void next(Form form) throws XMPPException {
executeAction(Action.next, form);
executeAction(Action.next, form, SmackConfiguration.getPacketReplyTimeout());
}
@Override
public void prev() throws XMPPException {
executeAction(Action.prev);
executeAction(Action.prev, SmackConfiguration.getPacketReplyTimeout());
}
private void executeAction(Action action) throws XMPPException {
executeAction(action, null);
private void executeAction(Action action, long timeout) throws XMPPException {
executeAction(action, null, timeout);
}
/**
@ -123,11 +127,12 @@ public class RemoteCommand extends AdHocCommand {
* The action could be any of the available actions. The form must
* be the anwser of the previous stage. It can be <tt>null</tt> if it is the first stage.
*
* @param action the action to execute
* @param form the form with the information
* @param action the action to execute.
* @param form the form with the information.
* @param timeout the amount of time to wait for a reply.
* @throws XMPPException if there is a problem executing the command.
*/
private void executeAction(Action action, Form form) throws XMPPException {
private void executeAction(Action action, Form form, long timeout) throws XMPPException {
// TODO: Check that all the required fields of the form were filled, if
// TODO: not throw the corresponding exeption. This will make a faster response,
// TODO: since the request is stoped before it's sent.
@ -147,7 +152,7 @@ public class RemoteCommand extends AdHocCommand {
connection.sendPacket(data);
Packet response = collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
Packet response = collector.nextResult(timeout);
// Cancel the collector.
collector.cancel();