ARI: Set Channel Variable does not take effect immediately

I am programing an IVR application by using Asterisk version 13.11.0~dfsg-0~ppa3 and ari4java verison 0.4.2.

I’ve found that, the ARI interface for setting channel variable has a little bit delay utill it takes effect. For example, I set channel language to german and play announcement in onSuccess() callback, but sometimes the announcement is still played in original language, and sometimes does palyed in target langauge.

Please see my example code below:

private void setChannelLanguage(String channelId, String targetLan) {
	ari.channels().setChannelVar(channelId, "CHANNEL(language)", targetLan, new AriCallback<Void>() {
		@Override
		public void onSuccess(Void result) {
			log.info("CHANNEL(language) should be switched to " + targetLan);
			//Announcement is played sometimes still in original language!
			playAnnouncement();
		}
		@Override
		public void onFailure(RestException e) {
			log.error("SetChannelVar: " + e.getLocalizedMessage());
		}
	});
}

If I apply a sleep of 200 ms on the thread before playAnnouncement(), then the announcement will be always played in target language.

Any ideal?

The playback should go into the queue and be executed after the variable set. What’s the request that playAnnouncement sends to Asterisk?

I think, I do queue the playback AFTER variable set, because I do it in the onSuccess callback.

Inside playAnnouncement method I just use

ari.channels().play(channelId, mediaUri, null, 0, 0, null, myAriCallback);

to queue the media.

I’d suggest filing an issue[1] with a description of what you’re doing and core debug (core set debug 9 and debug set to go to a file in logger.conf) attached.

[1] https://issues.asterisk.org/jira