Re: [Asterisk-java-users] how to monitor asterisk events for ever
Brought to you by:
srt
|
From: MT <moh...@gm...> - 2014-12-16 05:32:51
|
thank you so much wayne,
you help me a lot.
On Mon, Dec 15, 2014 at 8:14 PM, Wayne Merricks <
way...@th...> wrote:
>
> Even with AsteriskServerListener you still need a class that is running
> to keep the connections open. As soon as your main thread dies, all the
> objects are killed off and you're back to square one.
>
> I use the Asterisk Live interface with the server listener just because
> you can do things in one line of code that the older stuff took several to
> do.
>
> I have a page on github if you want to look through it but there is a lot
> of code there that does all sorts of weird stuff that you won't be
> interested in. Effectively I have a variation of the previous example
> that goes something like this:
>
> public class Server extends Thread implements AsteriskServerListener {
>
> private AsteriskServer asterisk;
>
> public Server(){
>
> asterisk = new DefaultAsteriskServer("host", "user", "pass");
>
> }
>
> public void connect() throws ManagerCommunicationException {
>
> asterisk.initialize();
> asterisk.addAsteriskServerListener(this);
>
> }
>
> public void disconnect(){
>
> asterisk.shutdown();
>
> }
>
> public static void main(String[] args) throws ManagerCommunicationException {
>
> Server srv = new Server();
> srv.connect();
>
> boolean go = true;
>
> while(go){
>
> try{
>
> sleep(1000);
>
> }catch(InterruptedException e){
>
> go = false;
> e.printStackTrace();
>
> }
>
> }
>
> srv.disconnect();
>
> }
>
> //AsteriskServerListener
> public void onNewAsteriskChannel(AsteriskChannel channel){
>
> //Do stuff with the new channel here (probably add a property change listener)
>
> }
>
> public void onNewQueueEntry(AsteriskQueueEntry entry){
>
> //Do stuff with the queue entries here
>
> }
>
> }
>
>
> Beware of typos, I've just cut and paste this from previous code and may
> have missed stuff out.
>
> Wayne Merricks
> The Voice Asia
>
> On 15/12/14 15:43, MT wrote:
>
> thanks again,
>
> do you suggest using loop and sleep or AsteriskServerListener?
>
> On Mon, Dec 15, 2014 at 7:06 PM, Wayne Merricks <
> way...@th...> wrote:
>>
>> Apologies I missed off the while loop at the top e.g:
>>
>> boolean go = true;
>>
>> //Do any prep work here
>>
>> while(go){
>>
>> try{
>> sleep(1000);
>> }catch(InterruptedException e){
>> go = false;
>> e.printStackTrace();
>> }
>>
>> }
>>
>> //Do any clean up here
>>
>> Wayne Merricks
>> The Voice Asia
>>
>> On 15/12/14 15:26, MT wrote:
>>
>> hi wayne,
>>
>> thanks for your reply,
>> I need to monitor events forever not just for a period of time
>>
>> On Mon, Dec 15, 2014 at 6:22 PM, Wayne Merricks <
>> way...@th...> wrote:
>>>
>>> You could just loop the sleep bit.
>>>
>>> I use the live interfaces which makes things a bit more readable but it
>>> still boils down to having a class somewhere that just does:
>>>
>>> public void run() {
>>>
>>> try{
>>> sleep(whatever amount of time);
>>> }catch(InterruptedException e){
>>> e.printStackTrace();
>>> }
>>>
>>> }
>>>
>>> Wayne Merricks
>>> The Voice Asia
>>>
>>> On 15/12/14 14:05, MT wrote:
>>>
>>> Hi,
>>>
>>> I use very long thread.sleep for listening to events for a long time and
>>> when times out with some daemon tools I start application again, I want to
>>> know is there any better solution?
>>>
>>> I use following way:
>>>
>>> public class Monitor extends AbstractManagerEventListener {
>>>
>>> private ManagerConnection managerConnection;
>>>
>>> public Monitor() throws IOException {
>>> ManagerConnectionFactory factory = new ManagerConnectionFactory(
>>> "localhost", "user", "pass");
>>> this.managerConnection = factory.createManagerConnection();
>>> }
>>>
>>> public void run() throws IOException, AuthenticationFailedException,
>>> TimeoutException, InterruptedException {
>>>
>>> managerConnection.addEventListener(this);
>>> managerConnection.login();
>>> Thread.sleep(new Long(1000000000));
>>> }
>>>
>>> public static void main(String[] args) throws Exception {
>>> Monitor helloEvents;
>>>
>>> helloEvents = new Monitor();
>>> helloEvents.run();
>>> }
>>>
>>> public void onManagerEvent(ManagerEvent event) {
>>> // Do Something
>>> }
>>>
>>>
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
>>> from Actuate! Instantly Supercharge Your Business Reports and Dashboards
>>> with Interactivity, Sharing, Native Excel Exports, App Integration & more
>>> Get technology previously reserved for billion-dollar corporations, FREEhttp://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
>>>
>>>
>>>
>>> _______________________________________________
>>> Asterisk-java-users mailing lis...@li...://lists.sourceforge.net/lists/listinfo/asterisk-java-users
>>>
>>>
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
>>> from Actuate! Instantly Supercharge Your Business Reports and Dashboards
>>> with Interactivity, Sharing, Native Excel Exports, App Integration & more
>>> Get technology previously reserved for billion-dollar corporations, FREE
>>>
>>> http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
>>> _______________________________________________
>>> Asterisk-java-users mailing list
>>> Ast...@li...
>>> https://lists.sourceforge.net/lists/listinfo/asterisk-java-users
>>>
>>>
>>
>> ------------------------------------------------------------------------------
>> Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
>> from Actuate! Instantly Supercharge Your Business Reports and Dashboards
>> with Interactivity, Sharing, Native Excel Exports, App Integration & more
>> Get technology previously reserved for billion-dollar corporations, FREEhttp://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
>>
>>
>>
>> _______________________________________________
>> Asterisk-java-users mailing lis...@li...://lists.sourceforge.net/lists/listinfo/asterisk-java-users
>>
>>
>>
>>
>> ------------------------------------------------------------------------------
>> Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
>> from Actuate! Instantly Supercharge Your Business Reports and Dashboards
>> with Interactivity, Sharing, Native Excel Exports, App Integration & more
>> Get technology previously reserved for billion-dollar corporations, FREE
>>
>> http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
>> _______________________________________________
>> Asterisk-java-users mailing list
>> Ast...@li...
>> https://lists.sourceforge.net/lists/listinfo/asterisk-java-users
>>
>>
>
> ------------------------------------------------------------------------------
> Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
> from Actuate! Instantly Supercharge Your Business Reports and Dashboards
> with Interactivity, Sharing, Native Excel Exports, App Integration & more
> Get technology previously reserved for billion-dollar corporations, FREEhttp://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
>
>
>
> _______________________________________________
> Asterisk-java-users mailing lis...@li...://lists.sourceforge.net/lists/listinfo/asterisk-java-users
>
>
>
>
> ------------------------------------------------------------------------------
> Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
> from Actuate! Instantly Supercharge Your Business Reports and Dashboards
> with Interactivity, Sharing, Native Excel Exports, App Integration & more
> Get technology previously reserved for billion-dollar corporations, FREE
>
> http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
> _______________________________________________
> Asterisk-java-users mailing list
> Ast...@li...
> https://lists.sourceforge.net/lists/listinfo/asterisk-java-users
>
>
|