From 1bdacfb65efe4e9681295b7b9879fbecb76e1b9d Mon Sep 17 00:00:00 2001 From: Matt Tucker Date: Tue, 16 Dec 2008 22:33:57 +0000 Subject: [PATCH] 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 --- .../smackx/commands/AdHocCommand.java | 17 ++++++++++- .../smackx/commands/RemoteCommand.java | 29 +++++++++++-------- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/source/org/jivesoftware/smackx/commands/AdHocCommand.java b/source/org/jivesoftware/smackx/commands/AdHocCommand.java index d4ea6cf6b..fce5b83d8 100755 --- a/source/org/jivesoftware/smackx/commands/AdHocCommand.java +++ b/source/org/jivesoftware/smackx/commands/AdHocCommand.java @@ -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 timeout 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 response. This form must be the answer form of the diff --git a/source/org/jivesoftware/smackx/commands/RemoteCommand.java b/source/org/jivesoftware/smackx/commands/RemoteCommand.java index 5001a5cd6..7478a2ca8 100755 --- a/source/org/jivesoftware/smackx/commands/RemoteCommand.java +++ b/source/org/jivesoftware/smackx/commands/RemoteCommand.java @@ -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 null 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();