diff options
Diffstat (limited to 'src/com/isode/stroke/adhoc/OutgoingAdHocCommandSession.java')
-rw-r--r-- | src/com/isode/stroke/adhoc/OutgoingAdHocCommandSession.java | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/com/isode/stroke/adhoc/OutgoingAdHocCommandSession.java b/src/com/isode/stroke/adhoc/OutgoingAdHocCommandSession.java index 5bccb31..4369f8e 100644 --- a/src/com/isode/stroke/adhoc/OutgoingAdHocCommandSession.java +++ b/src/com/isode/stroke/adhoc/OutgoingAdHocCommandSession.java @@ -23,6 +23,7 @@ import com.isode.stroke.queries.GenericRequest; import com.isode.stroke.queries.IQRouter; import com.isode.stroke.signals.Signal1; import com.isode.stroke.signals.Slot2; +import com.isode.stroke.signals.SignalConnection; /** * This class maintains the session between the client and the server for an @@ -71,6 +72,7 @@ public class OutgoingAdHocCommandSession { private boolean isMultiStage_; private String sessionID_; private HashMap<Action, ActionState> actionStates_ = new HashMap<Action, ActionState>(); + private SignalConnection connection_; /** * Create an Ad-Hoc command session. The initial command will be sent to the @@ -101,6 +103,13 @@ public class OutgoingAdHocCommandSession { isMultiStage_ = false; } + /** + * This method needs to be called for the object to be eligible for garbage collection. + */ + public void delete() { + connection_.disconnect(); + } + private void handleResponse(Command payload, ErrorPayload error) { if (error != null) { onError.emit(error); @@ -156,7 +165,7 @@ public class OutgoingAdHocCommandSession { public void start() { GenericRequest<Command> commandRequest = new GenericRequest<Command>( IQ.Type.Set, to_, new Command(commandNode_), iqRouter_); - commandRequest.onResponse.connect(new Slot2<Command, ErrorPayload>() { + connection_ = commandRequest.onResponse.connect(new Slot2<Command, ErrorPayload>() { public void call(Command payload, ErrorPayload error) { handleResponse(payload, error); } @@ -206,7 +215,8 @@ public class OutgoingAdHocCommandSession { GenericRequest<Command> commandRequest = new GenericRequest<Command>( IQ.Type.Set, to_, command, iqRouter_); - commandRequest.onResponse.connect(new Slot2<Command, ErrorPayload>() { + connection_.disconnect(); + connection_ = commandRequest.onResponse.connect(new Slot2<Command, ErrorPayload>() { public void call(Command payload, ErrorPayload error) { handleResponse(payload, error); } |