Menu

Listeners

Help
2008-11-25
2013-04-29
  • kristjan ugrin

    kristjan ugrin - 2008-11-25

    Hello! I'm a bit new to this - so I don't really know how to properly implement a listener.
    I alredy went trough the code and I would like to have a method that would wait till the login is complete, so I
    created MsnMessengerAdapterMod which basically just extends MsnMessengerAdapter and it only has a
    loginCompleted method overriden that prints something out - nothing more.

    How do I get this working?

    I tried this way:
    MsnMessengerAdapterMod listener = new MsnMessengerAdapterMod();
    messenger.addMessengerListener(listener);
    messenger.login();

    but I never get notified about complete login, the best it would be a method that would stall until login is complete.
    What I would like to have at the end is to login, get my contacts and logout - end of story :)

     
    • gogozhao

      gogozhao - 2008-11-26

      ah, it is very easy.

      when logining complete, the JML will fire the method "loginCompleted(MsnMessenger messenger)"

      and also you can use the method "contactListInitCompleted(MsnMessenger messenger)" to get your contacts after login complete

      but first you must add the listener as follows:

      messenger.addMessengerListener(new MsnMessengerAdapter() {

                  @Override
                  public void loginCompleted(MsnMessenger messenger) {
                      log.info(messenger + ":" + messenger.getOwner().getEmail()
                              + ": loginCompleted");
                  }

                  @Override
                  public void exceptionCaught(MsnMessenger messenger,
                          Throwable throwable) {
                      log.error(messenger + ":" + messenger + "===" + throwable);
                  }

                  @Override
                  public void logout(MsnMessenger messenger) {
                      log.info(messenger + ":" + messenger + " logout");
                  }
              });

      There also have some examples in the JML, and try them.

       
      • kristjan ugrin

        kristjan ugrin - 2008-11-27

        Thank you for your reply!
        I already tried like in the sample and your code, but unfortunately it is not working.
        I'm pasting some basic code that should print something after successful login:

        MessengerService.java:
        http://pastebin.com/m5b06537c

        TestServiceMsn:
        http://pastebin.com/m47e2cd84

        What is wrong with posted examples?

         
    • kristjan ugrin

      kristjan ugrin - 2008-11-27

      I got it finally! I had to extend BasicMessenger and implement a method that sets up listeners.
      Thanks!

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.