Re: [Asterisk-java-users] AsteriskServer as a service / in a spring context ?
Brought to you by:
srt
From: Stefan R. <ste...@re...> - 2008-04-06 08:22:11
|
Hi, > 1/ There is no "start" method on the server. Instead it starts "on > demand" when sending the first action, or worst, when one adds a > listener on it. > That means that the server automatically tries to start "too early" when > spring wires the listener into it. I think we can fix this by some refactoring and provide an implementation that initializes automatically and one that throws MCE or IllegalStateException when a method is called that requires a connection and it is not yet initialized. A simple solution might be to replace to calls to initializeIfNeeded() by calls to a new protected method called checkInitialize() of similar, that can be overridden by subclasses and either throw an exception or perform the initialization if its not yet initialized. > Is there a good reason to call initializeIfNeeded() in the > addAsteriskServerListener() method (and as a consequence have it > potentially throw a MCE) ? The idea behind this that if you register a listener and the object has not yet been initialized you won't receive any events. In fact the public initialize() method was only added later on, originally AsteriskServer was meant to work out of the box with as few lines of code as possible. - Maybe it's a bit too smart now :-) > 2/ If that very first connection fails in "initializeIfNeeded", then the > method throws an MCE that escalades to the addAsteriskServerListener > method and eventually reaches the spring context factory. As a result, > the server is down and won't start again until we try to send something. > Moreover as the exception was thrown before the actual listeners.add() > call, our listener is eventually not added. > So the application completely fails to start in spring if it can't reach > asterisk while starting. > > NB: However if later asterisk is stopped, everything is fine as the > connection handles the reconnection automatically. So I originally > worked around this using a patched ConnectionImpl that simply started in > the fake "RECONNECTING" state :) This is a bit harder. Usually I prefer things to fail early so you notice if you put in the wrong hostname or credentials. I understand that there are situations where this is not the required behavior. As you point out preventing the application from deploying due to Asterisk maintainance is not acceptable. To solve this issue we may have to add a feature to force a ManagerConnection to keep connecting. This won't probably look much different from the RECONNECTING hack, except for that it's hidden :-) How should we proceed? =Stefan -- reuter network consulting Neusser Str. 110 50760 Koeln Germany Telefon: +49 221 1305699-0 Telefax: +49 221 1305699-90 E-Mail: ste...@re... Jabber: ste...@re... WWW: http://www.reucon.com Steuernummern 215/5140/1791 USt-IdNr. DE220701760 |