Return-Path: Delivered-To: apmail-directory-dev-archive@www.apache.org Received: (qmail 89371 invoked from network); 22 Dec 2005 22:59:14 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 22 Dec 2005 22:59:14 -0000 Received: (qmail 42950 invoked by uid 500); 22 Dec 2005 22:59:13 -0000 Delivered-To: apmail-directory-dev-archive@directory.apache.org Received: (qmail 42894 invoked by uid 500); 22 Dec 2005 22:59:13 -0000 Mailing-List: contact dev-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Apache Directory Developers List" Delivered-To: mailing list dev@directory.apache.org Received: (qmail 42877 invoked by uid 99); 22 Dec 2005 22:59:12 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 Dec 2005 14:59:12 -0800 X-ASF-Spam-Status: No, hits=0.8 required=10.0 tests=HTML_MESSAGE,INFO_TLD,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of mrchrisallen@gmail.com designates 64.233.184.194 as permitted sender) Received: from [64.233.184.194] (HELO wproxy.gmail.com) (64.233.184.194) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 Dec 2005 14:59:11 -0800 Received: by wproxy.gmail.com with SMTP id 57so443869wri for ; Thu, 22 Dec 2005 14:58:50 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=I8EKM30PoBw/XC8OOmjPO/tzdyyHg1SGejZFb6rZN5hiq45AIG5OG8HlKFMVx650qv7OQTXapQeVj15Nr0Fv+Z8JbPfkZOjHZs+dz84kOSW1pK8axmGEXXdBla0IFXCLMKlt/tmFVP9QFuqKbiDNSbELiyniG1dwbjv5+Z+YdAw= Received: by 10.54.123.3 with SMTP id v3mr2916689wrc; Thu, 22 Dec 2005 14:58:50 -0800 (PST) Received: by 10.54.72.7 with HTTP; Thu, 22 Dec 2005 14:58:50 -0800 (PST) Message-ID: Date: Thu, 22 Dec 2005 17:58:50 -0500 From: Chris Allen To: Apache Directory Developers List Subject: Re: MINA FactoryBeans In-Reply-To: <43AB2B68.7040503@trillian.se> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_8614_28237598.1135292330147" References: <43A96AB1.5050802@trillian.se> <43AA4D55.9010909@trillian.se> <43AB2B68.7040503@trillian.se> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N ------=_Part_8614_28237598.1135292330147 Content-Type: multipart/alternative; boundary="----=_Part_8615_28992737.1135292330147" ------=_Part_8615_28992737.1135292330147 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hey Niklas, I knew that I was missing something here. ;-) Okay, you are absolutely right that I'm setting up the ProtocolCodecFilter in my IoHandler. It's being done in its sessionCreated() method. I based the implementation off of the SumupServer example that you guys have. I think that I'm now starting to understand a little more about how this is put together. Anyway, attached is the IoHandler implementation that I'm using. I will try and work out using the Spring integration stuff again based on the information you just gave me. Thanks, Chris On 12/22/05, Niklas Therning wrote: > > Hi, > > First of all the two examples aren't identical. The pure Java version > hasn't got a ProtocolCodecFilter in its filter chain like the Spring > version has. It seems to have a second thread pool instead. Are you > perhaps modifying the filter chain in sessionCreated() in your IoHandler? > > Second of all, I think you should call join() on the ConnectFuture > before calling getSession(). Have a look at the Javadocs for > ConnectFuture for an example. And your current connectTimeout in the > Spring case is 6 minutes. Is that intended? > > There are two ways of configuring a filter chain using Spring, either > using explicit filter names or automatically generated names. You are > using option 2 at the moment. To use your own names when configuring > your filter chain using Spring you need to use the IoFilterMapping class > and the *filterMapping* property instead of *filters*: > > > > > > > > > > > > > > > > > > > I really prefer the less verbose way using auto generated names but if > needed this gives you the option to specify the names for your filters > in the chain. > > Please, if possible post the code of your IoHandler as well. > > /Niklas > > Chris Allen wrote: > > Niklas, > > > > Okay, well I have now tried using the > > org.apache.mina.integration.spring.SocketConnectorFactoryBean with my > > Client implementation and it doesn't work for what I'm trying to do. > > Or, I quite simply might not know what I'm doing ;-) > > > > Anyway, here are two methods that I use to create the client socket > > connection. The first works and doesn't use Spring to configure it. > > The second is using the technique that you described in your previous > > email, but never connects, or at least never passes events to my > > handler. Also note that the way that I configure the filters in the > > first method has a name value relationship that I can't seem to create > > using the Spring configuration in XML. Perhaps this is the problem? > > Anyway, here's the code: > > > > public void connect() { > > log.info("connecting to Jabber..."); > > ThreadPoolFilter ioThreadPoolFilter =3D new ThreadPoolFilter(); > > ThreadPoolFilter protocolThreadPoolFilter =3D new > ThreadPoolFilter(); > > IoConnector connector =3D new SocketConnector(); //notice that = I > > use new here > > log.debug("connector: " + connector); //returns connector: > > org.apache.mina.transport.socket.nio.SocketConnector@530cf2 > > connector.getFilterChain().addFirst("ioThreadPool", > > ioThreadPoolFilter); > > connector.getFilterChain().addLast("protocolThreadPool", > > protocolThreadPoolFilter); > > > > connector.setConnectTimeout(connectTimeOut); > > > > try { > > ConnectFuture future =3D connector.connect(new > InetSocketAddress( > > bridgeAccountDAO.getJabberServerHostName(), > > bridgeAccountDAO.getJabberServerPort()), > > (IoHandler) sessionHandler); > > > > session =3D future.getSession(); > > // set the globally accessable version for other threads to > > // access: > > Scope.setJabberSession(session); > > } catch (IOException e) { > > System.err.println("Failed to connect."); > > e.printStackTrace(); > > } > > } > > > > public void connectUsingSpring() { > > log.info("connecting to Jabber with Spring..."); > > IoConnector connector =3D (IoConnector) > > ctx.getBean("socketConnector"); //I use the ApplicationContext to > > retrieve the bean > > log.debug("connector: " + connector); //also returns connector= : > > org.apache.mina.transport.socket.nio.SocketConnector > > ConnectFuture future =3D connector.connect(new InetSocketAddres= s( > > bridgeAccountDAO.getJabberServerHostName(), > > bridgeAccountDAO.getJabberServerPort()), > > (IoHandler) sessionHandler); > > try { > > session =3D future.getSession(); > > } catch (IOException e) { > > // TODO Auto-generated catch block > > e.printStackTrace(); > > } > > // set the globally accessable version for other threads to > > // access: > > Scope.setJabberSession(session); > > } > > > > > > Here are the MINA references in the XML config that I'm using for the > > ApplicationContext: > > > > > class=3D"edu.harvard.mgh.lcs.servers.bridge.JabberSessionHandlerImpl"> > > > > > > > > > > > > > > > > > > > > > > > > > > > class=3D"org.apache.mina.integration.spring.SocketConnectorFactoryBean"= > > > > > > > > > > > > > > > > > > > > > > class=3D" > edu.harvard.mgh.lcs.servers.bridge.codecfilters.JabberCodecFactory"> > > > > > > > > > class=3D"org.apache.mina.filter.codec.ProtocolCodecFilter"> > > > > > > > > > class=3D"org.apache.mina.filter.ThreadPoolFilter"> > > > > > > > > > > > > > > > > I'm probably missing something obvious here, so let me know if you see > > anything. > > > > Thanks, > > Chris > > > -- > Med v=E4nlig h=E4lsning > > Niklas Therning > Software Architect > > niklas@trillian.se > Mobil: +46 739 75 05 73 > > Trillian - Software Design at its best > www.trillian.se > > ------=_Part_8615_28992737.1135292330147 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hey Niklas,

I knew that I was missing something here. ;-)

Okay, you are absolutely right that I'm setting up the ProtocolCodecFilter in my IoHandler.  It's being done in its sessionCreated() method.  I based the implementation off of the SumupServer example that you guys have.  I think that I'm now starting to understand a little more about how this is put together. 

Anyway, attached is the IoHandler implementation that I'm using.

 I will try and work out using the Spring integration stuff again base= d on the information you just gave me.

Thanks,
Chris


On 12/22/05, Niklas Therning <nikl= as@trillian.se> wrote:
Hi,

First of all the two examples aren't identical. The pure Java ve= rsion
hasn't got a ProtocolCodecFilter in its filter chain like the Spri= ng
version has. It seems to have a second thread pool instead. Are you
perhaps modifying the filter chain in sessionCreated() in your IoHandle= r?

Second of all, I think you should call join() on the ConnectFutur= e
before calling getSession(). Have a look at the Javadocs for
Connec= tFuture for an example. And your current connectTimeout in the
Spring case is 6 minutes. Is that intended?

There are two ways o= f configuring a filter chain using Spring, either
using explicit filter = names or automatically generated names. You are
using option 2 at the mo= ment. To use your own names when configuring
your filter chain using Spring you need to use the IoFilterMapping clas= s
and the *filterMapping* property instead of *filters*:

<prop= erty name=3D"filterMappings">
  <list>
&= nbsp;   <bean class=3D" org.apache.mina.integration.spring.IoFilterMapping">
  = ;    <property name=3D"name" value=3D"= ;ioThreadPool"/>
      <propert= y name=3D"filter">
      &nbs= p; <ref local=3D"threadPoolFilter"/>
      </property>
  &n= bsp; </bean>
    <bean class=3D"o= rg.apache.mina.integration.spring.IoFilterMapping">
  =     <property name=3D"name" value=3D"= protocolCodec"/>
      <property name=3D"filter"&= gt;
        <ref local=3D&quo= t;protocolCodecFilter"/>
      <= ;/property>
    </bean>
  <= /list>
</property>

I really prefer the less verbose way = using auto generated names but if
needed this gives you the option to specify the names for your filters<= br>in the chain.

Please, if possible post the code of your IoHandler= as well.

/Niklas

Chris Allen wrote:
> Niklas,
>
> Okay, well I have now tried using the
> org.apache.mina.inte= gration.spring.SocketConnectorFactoryBean with my
> Client implementa= tion and it doesn't work for what I'm trying to do.
> Or, I quite sim= ply might not know what I'm doing ;-)
>
> Anyway,  here are two methods that I use to crea= te the client socket
> connection.  The first works and doe= sn't use Spring to configure it.
> The second is using the technique = that you described in your previous
> email, but never connects, or at least never passes events to my> handler.  Also note that the way that I configure the filt= ers in the
> first method has a name value relationship that I can't = seem to create
> using the Spring configuration in XML.  Perhaps this is = the problem?
> Anyway, here's the code:
>
> public void c= onnect() {
>         log.info= ("connecting to Jabber...");
>     = ;    ThreadPoolFilter ioThreadPoolFilter =3D new ThreadPoolF= ilter();
>         ThreadPoolFilter p= rotocolThreadPoolFilter =3D new ThreadPoolFilter();
>  &nbs= p;      IoConnector connector =3D new SocketConnec= tor(); //notice that I
> use new here
>    =      log.debug("connector: " + connector); //= returns  connector:
> org.apache.mina.transport.socket.nio.SocketConnector@530cf2
>= ;         connector.getFilterChain(= ).addFirst("ioThreadPool",
> ioThreadPoolFilter);
>&n= bsp;        connector.getFilterChain().a= ddLast("protocolThreadPool",
>           &= nbsp;     protocolThreadPoolFilter);
>
>&nb= sp;        connector.setConnectTimeout(c= onnectTimeOut);
>
>       &n= bsp; try {
>         &nb= sp;   ConnectFuture future =3D connector.connect(new InetSocketAddress(
>&n= bsp;            = ;        bridgeAccountDAO.getJabberServerHostName(),
>    =             &nb= sp;    bridgeAccountDAO.getJabberServerPort()),
>    &nb= sp;            =     (IoHandler) sessionHandler);
>
>     &= nbsp;       session =3D future.getSession();<= br>>           &n= bsp; // set the globally accessable version for other threads to
> &n= bsp;           // access:=
>           &= nbsp; Scope.setJabberSession(session);
>     = ;    } catch (IOException e) {
>   &nbs= p;         System.err.println ("Failed to connect.");
>     &nbs= p;       e.printStackTrace();
> &n= bsp;       }
>     = }
>
>     public void connectUsingSpring() = {
>         log.info("co= nnecting to Jabber with Spring...");
>         IoConnector connec= tor =3D (IoConnector)
> ctx.getBean("socketConnector"); //I= use the ApplicationContext to
> retrieve the bean
>  = ;       log.debug("connector: " + c= onnector); //also returns  connector:
> org.apache.mina.transport.socket.nio.SocketConnector
> =         ConnectFuture future =3D connect= or.connect(new InetSocketAddress(
>     &nbs= p;           bridgeAccountDAO.getJabberServerHostName(),
>    =              bridgeAccountDAO.getJabberServerPort()),
>    &nb= sp;            (IoHandler) sessionHandler);
>      &nb= sp;  try {
>        &nbs= p;    session =3D future.getSession();
>  &n= bsp;      } catch (IOException e) {
> &= nbsp;           // TODO A= uto-generated catch block
>       =       e.printStackTrace ();
>         }
> =         // set the globally accessable v= ersion for other threads to
>      &nbs= p;  // access:
>        = Scope.setJabberSession(session);
>     }
>=
>
> Here are the MINA references in the XML config that I'm us= ing for the
> ApplicationContext:
>
>  <bean id=3D"= ;sessionHandler"
> class=3D"edu.harvard.mgh.lcs.servers.bri= dge.JabberSessionHandlerImpl">
>     = ;    <property name=3D"bridgeAccountDAO">
>           &= nbsp; <ref local=3D"bridgeAccountDAO"/>
>  =        </property>
>  &= nbsp;      <property name=3D"jabbberMessag= eProcessor">
>        = ;     <ref local=3D"jabberMessageProcessor"= ;/>
>         </property><= br>>         <property name= =3D"protocolCodecFactory">
>    &nbs= p;        <ref local=3D"protocol= CodecFactory"/>
>       &n= bsp; </property>
>     </bean>
>
>     <bean id=3D"socketConnecto= r"
>
> class=3D"org.apache.mina.integration.spring.So= cketConnectorFactoryBean">
>     &nb= sp;   <property name=3D"filters">
>            = ; <list>
>         = ;        <ref local=3D"threadPoolFilter"/> <!-- notice that I can= 't
> do a mapping like it's done with Java code -->
> &= nbsp;           &nbs= p;   <ref local=3D"protocolCodecFilter"/>
>  &nb= sp;          </list>
= >         </property>
&= gt;         <property name=3D&qu= ot;connectTimeout" value=3D"300000"/>
>  =    </bean>
>
>     <bean id=3D"protocolCodecF= actory"
> class=3D"edu.harvard.mgh.lcs.servers.bridge.codec= filters.JabberCodecFactory">
>     &= nbsp;   <property name=3D"charsetName" value=3D"= ;UTF-8"/>
>     </bean>
>
>  &= nbsp;  <bean id=3D"protocolCodecFilter"
> &nbs= p;       class=3D"org.apache.mina.filter= .codec.ProtocolCodecFilter">
>     &= nbsp;   <constructor-arg ref=3D"protocolCodecFactory"= ;/>
>     </bean>
>
>  &= nbsp;  <bean id=3D"threadPoolFilter"
>  &= nbsp;      class=3D"org.apache.mina.filter.Th= readPoolFilter">
>       &= nbsp; <!-- Threads will be named IoWorker-1, IoWorker-2, etc -->
>         <constructor-ar= g value=3D"IoWorker"/>
>     &n= bsp;   <property name=3D"maximumPoolSize" value=3D&q= uot;10"/>
>     </bean>
>
= >
>
> I'm probably missing something obvious here, so let me= know if you see
> anything.
>
> Thanks,
> Chris


--
M= ed v=E4nlig h=E4lsning

Niklas Therning
Software Architect

= niklas@trillian.se
Mobil: +46 = 739 75 05 73

Trillian - Software Design at its best
www.trillian.se


------=_Part_8615_28992737.1135292330147-- ------=_Part_8614_28237598.1135292330147 Content-Type: application/octet-stream; name=JabberSessionHandlerImpl.java Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="JabberSessionHandlerImpl.java" package edu.harvard.mgh.lcs.servers.bridge; import java.util.ArrayList; import java.util.Iterator; import org.apache.log4j.Logger; import org.apache.mina.common.IoHandlerAdapter; import org.apache.mina.common.IoSession; import org.apache.mina.filter.LoggingFilter; import org.apache.mina.filter.codec.ProtocolCodecFactory; import org.apache.mina.filter.codec.ProtocolCodecFilter; import edu.harvard.mgh.lcs.servers.bridge.dao.BridgeAccountDAO; import edu.harvard.mgh.lcs.servers.bridge.processors.JabberMessageProcessor; /** * @see edu.harvard.mgh.lcs.servers.bridge.JabberSessionHandler * @author Chris Allen csallen@partners.org */ public class JabberSessionHandlerImpl extends IoHandlerAdapter implements JabberSessionHandler { private Logger log; private BridgeAccountDAO bridgeAccountDAO; private JabberMessageProcessor jabbberMessageProcessor; private ProtocolCodecFactory protocolCodecFactory; private boolean loggedIn = false; public JabberSessionHandlerImpl() { log = Logger.getLogger(JabberSessionHandlerImpl.class.getName()); } /** * @see edu.harvard.mgh.lcs.servers.bridge.JabberSessionHandler#getBridgeAcountDAO() */ public BridgeAccountDAO getBridgeAcountDAO() { return bridgeAccountDAO; } /** * @see edu.harvard.mgh.lcs.servers.bridge.JabberSessionHandler#setBridgeAcountDAO(edu.harvard.mgh.lcs.servers.bridge.dao.BridgeAccountDAO) */ public void setBridgeAccountDAO(BridgeAccountDAO bridgeAccountDAO) { this.bridgeAccountDAO = bridgeAccountDAO; } /** * @see edu.harvard.mgh.lcs.servers.bridge.JabberSessionHandler#getJabbberMessageProcessor() */ public JabberMessageProcessor getJabbberMessageProcessor() { return jabbberMessageProcessor; } /** * @see edu.harvard.mgh.lcs.servers.bridge.JabberSessionHandler#getProtocolCodecFactory() */ public ProtocolCodecFactory getProtocolCodecFactory() { return protocolCodecFactory; } /** * @see edu.harvard.mgh.lcs.servers.bridge.JabberSessionHandler#setProtocolCodecFactory(org.apache.mina.filter.codec.ProtocolCodecFactory) */ public void setProtocolCodecFactory(ProtocolCodecFactory protocolCodecFactory) { this.protocolCodecFactory = protocolCodecFactory; } /** * @see edu.harvard.mgh.lcs.servers.bridge.JabberSessionHandler#setJabbberMessageProcessor(edu.harvard.mgh.lcs.servers.bridge.dao.JabbberMessageProcessor) */ public void setJabbberMessageProcessor( JabberMessageProcessor jabbberMessageProcessor) { this.jabbberMessageProcessor = jabbberMessageProcessor; } /** * @see edu.harvard.mgh.lcs.servers.bridge.JabberSessionHandler#sessionCreated(org.apache.mina.common.IoSession) */ public void sessionCreated(IoSession session) throws Exception { session.getFilterChain().addLast("protocolFilter", new ProtocolCodecFilter(protocolCodecFactory)); session.getFilterChain().addLast("logger", new LoggingFilter()); } /** * @see edu.harvard.mgh.lcs.servers.bridge.JabberSessionHandler#sessionOpened(org.apache.mina.common.IoSession) */ public void sessionOpened(IoSession session) { // start the authentication... login(session); } /** * @see edu.harvard.mgh.lcs.servers.bridge.JabberSessionHandler#sessionClosed(org.apache.mina.common.IoSession) */ public void sessionClosed(IoSession session) { } /** * @see edu.harvard.mgh.lcs.servers.bridge.JabberSessionHandler#messageReceived(org.apache.mina.common.IoSession, * java.lang.Object) */ public void messageReceived(IoSession session, Object message) { // server only sends ResultMessage. otherwise, we will have to identify // its type using instanceof operator. String rm = (String) message; log.debug("client got this from server: " + rm); handlereceived(session, message); } private void handlereceived(IoSession session, Object message) { if (!loggedIn) { if (message.toString().indexOf(" msgs = new ArrayList(3); msgs .add("\n"); msgs .add("" + bridgeAccountDAO.getUsername() + "\n"); msgs .add("" + bridgeAccountDAO.getUsername() + "" + bridgeAccountDAO.getPassword() + "" + bridgeAccountDAO.getResource() + "\n"); msgs .add("Online5"); Iterator it = msgs.iterator(); while (it.hasNext()) { String msg = (String) it.next(); session.write(msg); } } } ------=_Part_8614_28237598.1135292330147--