directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Allen <mrchrisal...@gmail.com>
Subject Re: [MINA] getting accesss to the IoSession from another Thread
Date Wed, 21 Dec 2005 05:20:45 GMT
Hey Trustin,

No problem at all.  Sometimes just writing out the problem in an email
like this is helpful enough to figure out the problem.

In another topic, I'm curious about what you guys are doing in terms
of Spring integration.  I saw that this was listed on your road map
and I would like to learn more about it.

Anyway, I must say again, MINA is really incredible.  It has saved me
a ton of time and greatly simplified the NIO stuff on this project,
and I'm also working on Red5 ( http://osflash.org/red5 ), and I can't
say how much we appreciate having this library there.

Keep up the great work!

-Chris

On 12/20/05, Trustin Lee <trustin@gmail.com> wrote:
> Sorry for not replying to your message.  I was busy catching up previous
> messages. :(
>
> It's good to hear that you figured out how to do it.
>
> Cheers,
> Trustin
>
>
> 2005/12/21, Chris Allen <mrchrisallen@gmail.com>:
> > Hey,
> >
> > Okay, I figured it out.  I had misunderstood what the ThreadLocal actually
> does, I've now just set it up with simple static getters and setters:
> >
> > public class Scope {
> >
> >     private static IoSession jabberSession;
> >
> >     public static IoSession getJabberSession() {
> >         return jabberSession;
> >     }
> >
> >     public static void setJabberSession(IoSession session) {
> >         Scope.jabberSession = session;
> >     }
> > }
> >
> > It works perfectly now.  Thanks to anyone that was looking into this for
> me.
> >
> > -Chris
> >
> >
> >
> > On 12/19/05, Chris Allen <mrchrisallen@gmail.com > wrote:
> > > Hi,
> > >
> > > First of all, sorry for such a long email.  Also, I'm really happy
> > > with using MINA, it's saving me a whole bunch of time; thanks very
> > > much for creating this wonderful tool.
> > >
> > > Anyway, now for my problem: I'm using MINA to create a Jabber XMPP
> > > client that acts as a proxy to post the messages to a web server.
> > > Another feature of this application is that it allows one to post to a
> > > servlet an XMPP packet to be sent to the Jabber server. I'm using
> > > Jetty for this.  The Jabber client running with MINA works great, and
> > > Jetty also works great as I can run a servlet that accepts these http
> > > requests.
> > >
> > > The problem that I'm experiencing is that I can't seem to get a
> > > reference to the IoSession object that MINA is using to write to the
> > > Jabber server.  I'm using the following to set up the socket
> > > connection and it does return an IoSession:
> > >
> > >   ConnectFuture future = connector.connect(new InetSocketAddress(
> > >
> bridgeAccountDAO.getJabberServerHostName(),
> > >
> bridgeAccountDAO.getJabberServerPort()),
> > > (IoHandler) sessionHandler);
> > >
> > >              future.join();
> > >              session = future.getSession();
> > >              //also set the globally accessable version for other
> threads:
> > >              Scope.setJabberSession(session);
> > >
> > > //here is the Scope class:
> > > public class Scope {
> > >
> > >      private static ThreadLocal<IoSession> jabberSessionLocal = new
> > > ThreadLocal<IoSession>();
> > >
> > >      public static IoSession getJabberSession() {
> > >          System.out.println ("getting the Jabber session");
> > >          return jabberSessionLocal.get();
> > >      }
> > >
> > >      public static void setJabberSession(IoSession session) {
> > >          System.out.println("Setting the jabber session....");
> > >          jabberSessionLocal.set(session);
> > >      }
> > > }
> > >
> > > //  and here is how it's being used in the servlet:
> > >
> > >   public void doGet(HttpServletRequest request, HttpServletResponse
> response)
> > >              throws ServletException, IOException {
> > >          PrintWriter out = response.getWriter();
> > >          response.setContentType ("text/xml");
> > >          IoSession session = Scope.getJabberSession();
> > >          //test sending this message
> > >          session.write("<presence from=\"bridge@xmppdev.partners.org\"
> > > type=\"available\"/>");
> > >
> > >          //out.println("<error>Hi! no post data was passed to the
> > > servlet</error>");
> > >      }
> > >
> > >   I get a NullPointerException to the  Scope.getJabberSession(); when
> > > called from the servlet.  I've tried a few different approaches to get
> > > access to the IoSession besides using the ThreadLocal technique above,
> > > all of which have the same NullPointerException.  One of these
> > > approaches was using Spring applicationContext to get access to the
> > > IoSession as a property of that bean.  Still, no dice. ;-)
> > >
> > > Any ideas on why this is happening?
> > >
> > > Thanks very much in advance for any suggestions.
> > >
> > > -Chris
> > >
> >
> >
>
>
>
> --
> what we call human nature is actually human habit
> --
>  http://gleamynode.net/
> PGP Key ID: 0x854B996C

Mime
View raw message