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 FactoryBeans
Date Thu, 22 Dec 2005 22:58:50 GMT
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 <niklas@trillian.se> 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*:
>
> <property name="filterMappings">
>   <list>
>     <bean class="org.apache.mina.integration.spring.IoFilterMapping">
>       <property name="name" value="ioThreadPool"/>
>       <property name="filter">
>         <ref local="threadPoolFilter"/>
>       </property>
>     </bean>
>     <bean class="org.apache.mina.integration.spring.IoFilterMapping">
>       <property name="name" value="protocolCodec"/>
>       <property name="filter">
>         <ref local="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
> 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 = new ThreadPoolFilter();
> >         ThreadPoolFilter protocolThreadPoolFilter = new
> ThreadPoolFilter();
> >         IoConnector connector = 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 = connector.connect(new
> InetSocketAddress(
> >                     bridgeAccountDAO.getJabberServerHostName(),
> >                     bridgeAccountDAO.getJabberServerPort()),
> >                     (IoHandler) sessionHandler);
> >
> >             session = 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 = (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 = connector.connect(new InetSocketAddress(
> >                 bridgeAccountDAO.getJabberServerHostName(),
> >                 bridgeAccountDAO.getJabberServerPort()),
> >                 (IoHandler) sessionHandler);
> >         try {
> >             session = 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:
> >
> >  <bean id="sessionHandler"
> > class="edu.harvard.mgh.lcs.servers.bridge.JabberSessionHandlerImpl">
> >         <property name="bridgeAccountDAO">
> >             <ref local="bridgeAccountDAO"/>
> >         </property>
> >         <property name="jabbberMessageProcessor">
> >             <ref local="jabberMessageProcessor"/>
> >         </property>
> >         <property name="protocolCodecFactory">
> >             <ref local="protocolCodecFactory"/>
> >         </property>
> >     </bean>
> >
> >     <bean id="socketConnector"
> >
> > class="org.apache.mina.integration.spring.SocketConnectorFactoryBean">
> >         <property name="filters">
> >             <list>
> >                 <ref local="threadPoolFilter"/> <!-- notice that I can't
> > do a mapping like it's done with Java code -->
> >                 <ref local="protocolCodecFilter"/>
> >             </list>
> >         </property>
> >         <property name="connectTimeout" value="300000"/>
> >     </bean>
> >
> >     <bean id="protocolCodecFactory"
> > class="
> edu.harvard.mgh.lcs.servers.bridge.codecfilters.JabberCodecFactory">
> >         <property name="charsetName" value="UTF-8"/>
> >     </bean>
> >
> >     <bean id="protocolCodecFilter"
> >         class="org.apache.mina.filter.codec.ProtocolCodecFilter">
> >         <constructor-arg ref="protocolCodecFactory"/>
> >     </bean>
> >
> >     <bean id="threadPoolFilter"
> >         class="org.apache.mina.filter.ThreadPoolFilter">
> >         <!-- Threads will be named IoWorker-1, IoWorker-2, etc -->
> >         <constructor-arg value="IoWorker"/>
> >         <property name="maximumPoolSize" value="10"/>
> >     </bean>
> >
> >
> >
> > I'm probably missing something obvious here, so let me know if you see
> > anything.
> >
> > Thanks,
> > Chris
>
>
> --
> Med vänlig hälsning
>
> Niklas Therning
> Software Architect
>
> niklas@trillian.se
> Mobil: +46 739 75 05 73
>
> Trillian - Software Design at its best
> www.trillian.se
>
>

Mime
View raw message