[Asterisk-java-users] AsteriskServer as a service / in a spring context ?
Brought to you by:
srt
From: Gaëtan M. <gm...@ea...> - 2008-04-05 13:39:11
|
Hi Stefan We are using the AsteriskServerImpl class inside a spring application. We however faced some problems as the stock AsteriskServerImpl seemed no so spring-friendly. The main problems I faced are the following: 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. Is there a good reason to call initializeIfNeeded() in the addAsteriskServerListener() method (and as a consequence have it potentially throw a MCE) ? 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 :) I recently tried to clean all these modifications to ease my weekly merge against your trunk revision. Here is a patch against head as of today. This is clearly not a request for inclusion but just meant to illustrate how I worked around the problem. Indeed it is really not correct regarding object programing patterns but only meant to be small and not intrusive so you can easily see what I'm trying to implement. If you think that kind of functionality is interesting, maybe I could write some cleaner code and submit it ? In that event, I'd like to have your idea on the subject before I start. I personally think common functionality should then be moved to an abstract AbstractAsterikServerImpl class, with the child AsteriskServerImpl class maintaining the same behavior and semantic as the current one, and another one implementing the other "service- oriented" approach. What do you think ? Kind regards Thanks for your great work. Gaetan |