Apache Directory Project - MINA FactoryBeans

This is Interesting: Free IT Magazines  
Home > Archive > Apache Directory Project > December 2005 > MINA FactoryBeans





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author MINA FactoryBeans
Ither Seed

2005-12-21, 5:45 pm

> From: Niklas Therning <niklas-8FIgwK2HfyIwFerOooGFRg@public.gmane.org>
> To: Apache Directory Developers List <dev-aYN4UCa7k1r1N9kud6OZbmD2FQJk+8+b@public.gmane.org>
> Date: Wed, 21 Dec 2005 07:38:20 +0100
> Subject: Re: [MINA] getting accesss to the IoSession from another Thread
> Chris Allen wrote:
>
> Hi Chris,
>
> At the moment there are a number of Spring FactoryBeans in
> org.apache.mina.integration.spring which simplifies the
> configuration of
> IoAcceptors and IoConnectors using Spring. There are also some
> FactoryBeans which helps you set up KeyStores and SSLContexts for use
> with the SSLFilter. Have a look at the Javadocs for
> SocketAcceptorFactoryBean for a short example on how to use it. If you
> have any further questions or suggestions for improvements please let me
> know.
>
> BTW, the Spring integration package was introduced in 0.9.0.
>
> /Niklas


Hi, people. I'm trying to use the FactoryBeans of MINA 0.9.0. I read
the javadoc in the SocketAcceptorFactoryBean class and I successfully
create a SocketAcceptor using it but I don't know how to make it wait
for connections. All the examples use the ServiceRegistry interface
for this. am I missing something? Thanks in advance.

Kaspar Luethi

2005-12-21, 5:45 pm

hello Ither Seed

>Hi, people. I'm trying to use the FactoryBeans of MINA 0.9.0. I read
>the javadoc in the SocketAcceptorFactoryBean class and I successfully
>create a SocketAcceptor using it but I don't know how to make it wait
>for connections. All the examples use the ServiceRegistry interface
>for this. am I missing something? Thanks in advance.


have a look at the config below, works for me.
maybe you left out the "bindings"-part? show me your xml

the logging-filter is unused in this config, you could activate it this way:

<property name="filters">
<list>
<ref local="threadPoolFilter"/>
<ref local="loggingFilter"/>
</list>
</property>


by the way:
niklas, there are some typos in the javadocs, wrong class names
(i.e. org.apache.mina.spring.integration.Binding).
i like the spring integration, thanks.

kaspar


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>

<!-- Shockwave IoHandler implementation -->
<bean id="smusHandler"
class="ch.shinypixel.server.ShockwaveProtocolHandler"/>

<!-- AdminProtocol IoHandler implementation -->
<bean id="adminHandler" class="ch.shinypixel.server.AdminProtocolHandler"/>

<!-- Create a thread pool filter -->
<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="4"/>
</bean>

<!-- Create logging filter -->
<bean id="loggingFilter" class="org.apache.mina.filter.LoggingFilter">
</bean>

<!-- Create the SocketAcceptor -->
<bean id="socketAcceptor"
class="org.apache.mina.integration.spring.SocketAcceptorFactoryBean">
<property name="filters">
<list>
<ref local="threadPoolFilter"/>
</list>
</property>
<property name="bindings">
<list>
<bean class="org.apache.mina.integration.spring.Binding">
<property name="address" value="127.0.0.1:1626"/>
<property name="handler" ref="smusHandler"/>
</bean>
<bean class="org.apache.mina.integration.spring.Binding">
<property name="address" value="127.0.0.1:8888"/>
<property name="handler" ref="smusHandler"/>
</bean>
<bean class="org.apache.mina.integration.spring.Binding">
<property name="address" value="127.0.0.1:8282"/>
<property name="handler" ref="adminHandler"/>
</bean>
</list>
</property>
</bean>

</beans>
--
---------------------------------------------
http://www.humantools.com

Niklas Therning

2005-12-21, 5:45 pm

Kaspar Luethi wrote:
....
>
>
> by the way:
> niklas, there are some typos in the javadocs, wrong class names
> (i.e. org.apache.mina.spring.integration.Binding).
> i like the spring integration, thanks.
>
> kaspar


Thanks for letting me know! And thanks for the exmaple Spring XML. I'm
glad that the Spring integration stuff is working for you. Just let me
know if there's anything more that is in need of being fixed or if you
have any suggestions for improvements.

/Niklas

Niklas Therning

2005-12-21, 5:45 pm

Ither Seed wrote:
>
>
> Hi, people. I'm trying to use the FactoryBeans of MINA 0.9.0. I read
> the javadoc in the SocketAcceptorFactoryBean class and I successfully
> create a SocketAcceptor using it but I don't know how to make it wait
> for connections. All the examples use the ServiceRegistry interface
> for this. am I missing something? Thanks in advance.


You don't have to do anything! SocketAcceptor.bind() will be called for
each of the Bindings you set on your SocketAcceptor in your Spring file.
Just make sure you have configured some bindings.

If you are using Spring's FileSystemApplicationContext to load you
Spring XML file all the beans you define will be automatically created
at load time. For other ApplicationContext implementations you may have
to call refresh() on it for the beans to be instantiated.

If you are using a BeanFactory such as XmlBeanFactory Spring will
instantiate your beans lazily when retrieved from the BeanFactory. In
that case you will have to call getBean() on the BeanFactory and supply
the id of the SocketAcceptorFactoryBean before Spring will create it.

HTH
/Niklas

Chris Allen

2005-12-21, 8:45 pm

Hi Niklas,

I took a look at the Spring integration package today as you suggested, and
it looks very promising.

One of my implementations of MINA is as a client, so I assume that the
*SocketConnectorFactoryBean
*class is what I would need to use to get my Socket connection going. It
looks kind of incomplete at the moment. Is that the case? I couldn't find
the AbstractIoConnectorFactoryBean class in the JavaDocs and so therefore
I'm not sure how you would configure it. Also, will there be a way to add a
custom ProtocolCodecFactory to the filterChain and configure that with
Spring?

Any information on this would be extremely appreciated.

Another thing that I would love to see happen is for you guys to add some
complete Spring examples on the website here:
http://directory.apache.org/subproj...ng_started.html

All in good time I'm sure. ;-)

Anyway, keep up the great work!

-Chris





On 12/21/05, Niklas Therning <niklas-8FIgwK2HfyIwFerOooGFRg@public.gmane.org> wrote:
>
> Ither Seed wrote:
>
> You don't have to do anything! SocketAcceptor.bind() will be called for
> each of the Bindings you set on your SocketAcceptor in your Spring file.
> Just make sure you have configured some bindings.
>
> If you are using Spring's FileSystemApplicationContext to load you
> Spring XML file all the beans you define will be automatically created
> at load time. For other ApplicationContext implementations you may have
> to call refresh() on it for the beans to be instantiated.
>
> If you are using a BeanFactory such as XmlBeanFactory Spring will
> instantiate your beans lazily when retrieved from the BeanFactory. In
> that case you will have to call getBean() on the BeanFactory and supply
> the id of the SocketAcceptorFactoryBean before Spring will create it.
>
> HTH
> /Niklas
>


Niklas Therning

2005-12-22, 7:45 am

Chris Allen wrote:
> Hi Niklas,
>=20
> I took a look at the Spring integration package today as you suggested,=


> and it looks very promising.=20
>=20
> One of my implementations of MINA is as a client, so I assume that the
> *SocketConnectorFactoryBean *class is what I would need to use to get m=

y
> Socket connection going. It looks kind of incomplete at the moment. I=

s
> that the case? I couldn't find the |AbstractIoConnectorFactoryBean
> |class in the JavaDocs and so therefore I'm not sure how you would
> configure it. Also, will there be a way to add a custom
> ProtocolCodecFactory to the filterChain and configure that with Spring?=


>=20
> Any information on this would be extremely appreciated.


The SocketConnectorFactoryBean lets you configure the filter chain of
your SocketConnector and set the connection timeout. Unfortunately the
Javadocs for the org.apache.mina.integration.spring.support package
don't seem to be included when the docs are generated for the web page.
Any reason for that, Trustin? (I can see that all 'support' packages
have been left out)

In the meantime you can have a look at the code instead. What you need
are these classes:

http://directory.apache.org/subproj...ache/mina/inte=
gration/spring/support/AbstractIoSessionManagerFactoryBean.html
http://directory.apache.org/subproj...ache/mina/inte=
gration/spring/support/AbstractIoConnectorFactoryBean.html

The filter chain of a SocketConnectorFactoryBean is configured exactly
like a SocketAcceptorFactoryBean's chain. To use a ProtocolCodecFactory
your Spring config should look something like:

<bean id=3D"myProtocolCodecFactory" class=3D"MyProtocolCodecFactory">
...
</bean>

<bean id=3D"protocolCodecFilter"
class=3D"org.apache.mina.filter.codec.ProtocolCodecFilter">
<constructor-arg ref=3D"myProtocolCodecFactory"/>
</bean>

<bean id=3D"socketConnector"
class=3D"org.apache.mina.integration.spring.SocketConnectorFactoryBean"=
>

<property name=3D"filters">
<list>
<ref local=3D"threadPoolFilter"/>
<ref local=3D"protocolCodecFilter"/>
</list>
</property>
<property name=3D"connectTimeout" value=3D"30"/>
</bean>

Then all you need to do is to call connect() on the Spring configured
connector in your Java code.

Please let me know if there are things which could be improved here.

> Another thing that I would love to see happen is for you guys to add
> some complete Spring examples on the website here:
> http://directory.apache.org/subproj...ng_started.html


Yes, we should definitely do that. I will add an issue to JIRA.

/Niklas

>=20
> All in good time I'm sure. ;-)
>=20
> Anyway, keep up the great work!
>=20
> -Chris
>=20
>=20
>=20
>=20
>=20
> On 12/21/05, *Niklas Therning* <niklas-8FIgwK2HfyIwFerOooGFRg@public.gmane.org
> <mailto:niklas-8FIgwK2HfyIwFerOooGFRg@public.gmane.org>> wrote:
>=20
> Ither Seed wrote:
=2Ese>>[vbcol=seagreen]
> <mailto:dev-aYN4UCa7k1r1N9kud6OZbmD2FQJk+8+b@public.gmane.org>>
[vbcol=seagreen]
> Thread
erms[vbcol=seagreen]
map[vbcol=seagreen]
use[vbcol=seagreen]
f[vbcol=seagreen]
> you
[vbcol=seagreen]
> let me
ead[vbcol=seagreen]
ully[vbcol=seagreen]
wait[vbcol=seagreen]
ce[vbcol=seagreen]
>=20
> You don't have to do anything! SocketAcceptor.bind() will be called=

for
> each of the Bindings you set on your SocketAcceptor in your Spring
> file.
> Just make sure you have configured some bindings.
>=20
> If you are using Spring's FileSystemApplicationContext to load you
> Spring XML file all the beans you define will be automatically crea=

ted
> at load time. For other ApplicationContext implementations you may =

have
> to call refresh() on it for the beans to be instantiated.
>=20
> If you are using a BeanFactory such as XmlBeanFactory Spring will
> instantiate your beans lazily when retrieved from the BeanFactory. =

In
> that case you will have to call getBean() on the BeanFactory and su=

pply
> the id of the SocketAcceptorFactoryBean before Spring will create i=

t.
>=20
> HTH
> /Niklas
>=20
>=20



--=20
Med v=E4nlig h=E4lsning

Niklas Therning
Software Architect

niklas-8FIgwK2HfyIwFerOooGFRg@public.gmane.org
Mobil: +46 739 75 05 73

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


Chris Allen

2005-12-22, 5:45 pm

Hi Niklas,

Once again, thank you for your thorough answers. This looks very
flexible indeed. It's much better than the simple wrapper class that
I'm using to configure MINA using Spring.

Your implementation might be missing one critical feature in order to
get this to work with my application. I need access to the IoSession
object that is contained in the ConnectFuture that is returned when
calling connect(). Does the Spring version indeed return the same
thing and I would be able to get access to the IoSession the same way?
Actually, after looking at it again, it does look like we are
configuring the same exact class, so this should be the case. Sorry
for the rambling ;-) I will just test it out.

I will try and implement my stuff using the Spring
SocketConnectorFactoryBean. I will let you know if I run into any
problems with it or have any suggestions on how it can be improved.

Thanks again.





On 12/22/05, Niklas Therning <niklas-8FIgwK2HfyIwFerOooGFRg@public.gmane.org> wrote:
> Chris Allen wrote:
y[vbcol=seagreen]
s[vbcol=seagreen]
>
> The SocketConnectorFactoryBean lets you configure the filter chain of
> your SocketConnector and set the connection timeout. Unfortunately the
> Javadocs for the org.apache.mina.integration.spring.support package
> don't seem to be included when the docs are generated for the web page.
> Any reason for that, Trustin? (I can see that all 'support' packages
> have been left out)
>
> In the meantime you can have a look at the code instead. What you need
> are these classes:
>
> http://directory.apache.org/subproj...ache/mina/inte=

gration/spring/support/AbstractIoSessionManagerFactoryBean.html
> http://directory.apache.org/subproj...ache/mina/inte=

gration/spring/support/AbstractIoConnectorFactoryBean.html
>
> The filter chain of a SocketConnectorFactoryBean is configured exactly
> like a SocketAcceptorFactoryBean's chain. To use a ProtocolCodecFactory
> your Spring config should look something like:
>
> <bean id=3D"myProtocolCodecFactory" class=3D"MyProtocolCodecFactory">
> ...
> </bean>
>
> <bean id=3D"protocolCodecFilter"
> class=3D"org.apache.mina.filter.codec.ProtocolCodecFilter">
> <constructor-arg ref=3D"myProtocolCodecFactory"/>
> </bean>
>
> <bean id=3D"socketConnector"
> class=3D"org.apache.mina.integration.spring.SocketConnectorFactoryBean"=
>
> <property name=3D"filters">
> <list>
> <ref local=3D"threadPoolFilter"/>
> <ref local=3D"protocolCodecFilter"/>
> </list>
> </property>
> <property name=3D"connectTimeout" value=3D"30"/>
> </bean>
>
> Then all you need to do is to call connect() on the Spring configured
> connector in your Java code.
>
> Please let me know if there are things which could be improved here.
>
>
> Yes, we should definitely do that. I will add an issue to JIRA.
>
> /Niklas
>
..se>>[vbcol=seagreen]
erms[vbcol=seagreen]
map[vbcol=seagreen]
use[vbcol=seagreen]
f[vbcol=seagreen]
ead[vbcol=seagreen]
ully[vbcol=seagreen]
wait[vbcol=seagreen]
ce[vbcol=seagreen]
for[vbcol=seagreen]
ted[vbcol=seagreen]
have[vbcol=seagreen]
In[vbcol=seagreen]
pply[vbcol=seagreen]
t.[vbcol=seagreen]
>
>
> --
> Med v=E4nlig h=E4lsning
>
> Niklas Therning
> Software Architect
>
> niklas-8FIgwK2HfyIwFerOooGFRg@public.gmane.org
> Mobil: +46 739 75 05 73
>
> Trillian - Software Design at its best
> www.trillian.se
>
>


Chris Allen

2005-12-22, 5:45 pm

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

Niklas Therning

2005-12-22, 5:45 pm

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=3D"filterMappings">
<list>
<bean class=3D"org.apache.mina.integration.spring.IoFilterMapping">
<property name=3D"name" value=3D"ioThreadPool"/>
<property name=3D"filter">
<ref local=3D"threadPoolFilter"/>
</property>
</bean>
<bean class=3D"org.apache.mina.integration.spring.IoFilterMapping">
<property name=3D"name" value=3D"protocolCodec"/>
<property name=3D"filter">
<ref local=3D"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,
>=20
> 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.=20
> Or, I quite simply might not know what I'm doing ;-)
>=20
> 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.=20
> 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?=20
> Anyway, here's the code:
>=20
> public void connect() {
> log.info("connecting to Jabber...");
> ThreadPoolFilter ioThreadPoolFilter =3D new ThreadPoolFilter();=


> ThreadPoolFilter protocolThreadPoolFilter =3D new ThreadPoolFil=

ter();
> 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);
>=20
> connector.setConnectTimeout(connectTimeOut);
>=20
> try {
> ConnectFuture future =3D connector.connect(new InetSocketAd=

dress(
> bridgeAccountDAO.getJabberServerHostName(),
> bridgeAccountDAO.getJabberServerPort()),
> (IoHandler) sessionHandler);
>=20
> 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();
> }
> }
> =20
> 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);
> }
>=20
>=20
> Here are the MINA references in the XML config that I'm using for the
> ApplicationContext:
>=20
> <bean id=3D"sessionHandler"
> class=3D"edu.harvard.mgh.lcs.servers.bridge.JabberSessionHandlerImpl">
> <property name=3D"bridgeAccountDAO">
> <ref local=3D"bridgeAccountDAO"/>
> </property>
> <property name=3D"jabbberMessageProcessor">
> <ref local=3D"jabberMessageProcessor"/>
> </property>
> <property name=3D"protocolCodecFactory">
> <ref local=3D"protocolCodecFactory"/>
> </property>
> </bean>
> =20
> <bean id=3D"socketConnector"
> =20
> class=3D"org.apache.mina.integration.spring.SocketConnectorFactoryBean"=
>
> <property name=3D"filters">
> <list>
> <ref local=3D"threadPoolFilter"/> <!-- notice that I ca=

n't
> do a mapping like it's done with Java code -->
> <ref local=3D"protocolCodecFilter"/>
> </list>
> </property>
> <property name=3D"connectTimeout" value=3D"300000"/>
> </bean>
> =20
> <bean id=3D"protocolCodecFactory"
> class=3D"edu.harvard.mgh.lcs.servers.bridge.codecfilters.JabberCodecFac=

tory">
> <property name=3D"charsetName" value=3D"UTF-8"/>
> </bean>
> =20
> <bean id=3D"protocolCodecFilter"
> class=3D"org.apache.mina.filter.codec.ProtocolCodecFilter">
> <constructor-arg ref=3D"protocolCodecFactory"/>
> </bean>
> =20
> <bean id=3D"threadPoolFilter"
> class=3D"org.apache.mina.filter.ThreadPoolFilter">
> <!-- Threads will be named IoWorker-1, IoWorker-2, etc -->
> <constructor-arg value=3D"IoWorker"/>
> <property name=3D"maximumPoolSize" value=3D"10"/>
> </bean>
>=20
>=20
>=20
> I'm probably missing something obvious here, so let me know if you see
> anything.
>=20
> Thanks,
> Chris



--=20
Med v=E4nlig h=E4lsning

Niklas Therning
Software Architect

niklas-8FIgwK2HfyIwFerOooGFRg@public.gmane.org
Mobil: +46 739 75 05 73

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


Niklas Therning

2005-12-22, 5:45 pm

Niklas Therning wrote:
> ...
> ConnectFuture for an example. And your current connectTimeout in the
> Spring case is 6 minutes. Is that intended?


What I really meant was 5 minutes of course! ;)

/Niklas

Chris Allen

2005-12-22, 5:45 pm

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-8FIgwK2HfyIwFerOooGFRg@public.gmane.org> 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:
> ThreadPoolFilter();
> InetSocketAddress(
> edu.harvard.mgh.lcs.servers.bridge.codecfilters.JabberCodecFactory">
>
>
> --
> Med vänlig hälsning
>
> Niklas Therning
> Software Architect
>
> niklas-8FIgwK2HfyIwFerOooGFRg@public.gmane.org
> Mobil: +46 739 75 05 73
>
> Trillian - Software Design at its best
> www.trillian.se
>
>


Chris Allen

2005-12-22, 5:45 pm

Oh and the 5 minutes thing. Yes, but I could be misinterpreting what that
value really means. What I want really is to maintain state on that
connection forever. Is there a way to actually have an indefinitely
connected socket connection, rather than just a really long one? I wouldn't
want to have to go off and on with a Jabber client as this will affect the
clients presence for other users.


On 12/22/05, Niklas Therning <niklas-8FIgwK2HfyIwFerOooGFRg@public.gmane.org> wrote:
>
> Niklas Therning wrote:
>
> What I really meant was 5 minutes of course! ;)
>
> /Niklas
>


Niklas Therning

2005-12-23, 2:45 am

Chris Allen wrote:
> Oh and the 5 minutes thing. Yes, but I could be misinterpreting what
> that value really means. What I want really is to maintain state on
> that connection forever. Is there a way to actually have an
> indefinitely connected socket connection, rather than just a really long
> one? I wouldn't want to have to go off and on with a Jabber client as
> this will affect the clients presence for other users.


The connectTimeout is just the timeout after which the connect() call
will fail. The semantics are exactly the same as for the timeout value
specified in java.net.Socket.connect(SocketAddress, int) except that
Socket.connect() blocks while SocketConnector.connect() doesn't.

What you want is some kind of keep alive, right? Is there some message
in the Jabber protocol that you could use for that? If there is you
could override the sessionIdle() callback in IoHandler and send the keep
alive message after the connection has been idle for some time. Just
don't forget to set the idle timeout on the session (e.g. in
sessionCreated()) using IoSession.setIdleTime().

We have plans to implement a ReconnectFilter for MINA. There is a patch
in JIRA but it hasn't been applied yet. It may be used to automatically
reconnect a session which has been closed.

HTH
/Niklas

>
>
> On 12/22/05, *Niklas Therning* <niklas-8FIgwK2HfyIwFerOooGFRg@public.gmane.org
> <mailto:niklas-8FIgwK2HfyIwFerOooGFRg@public.gmane.org>> wrote:
>
> Niklas Therning wrote:
>
> What I really meant was 5 minutes of course! ;)
>
> /Niklas
>
>


Chris Allen

2005-12-23, 7:45 am

That makes sense now. It also makes sense why you asked why I had
such a high number there. :-) Still learning how this all works as
using sockets and in Java is very new to me.

There is no "keep alive" message that you can send in XMPP, so I'm not
sure what I could do for that. It basically just keeps the connection
until the client disconnects once authenticated. I suppose that I
could send junk messages to its own account that I ignore. In the
worse case I suppose I can always reinitialize the connection and log
in again if it goes down, as there's an event that is triggered in the
IoHandler class.

By the way, did you get the IoHandler attachment that I sent in one of
my previous emails? I'm not sure if the apache list allows
attachments.

On 12/23/05, Niklas Therning <niklas-8FIgwK2HfyIwFerOooGFRg@public.gmane.org> wrote:
> Chris Allen wrote:
g[vbcol=seagreen]
>
> The connectTimeout is just the timeout after which the connect() call
> will fail. The semantics are exactly the same as for the timeout value
> specified in java.net.Socket.connect(SocketAddress, int) except that
> Socket.connect() blocks while SocketConnector.connect() doesn't.
>
> What you want is some kind of keep alive, right? Is there some message
> in the Jabber protocol that you could use for that? If there is you
> could override the sessionIdle() callback in IoHandler and send the keep
> alive message after the connection has been idle for some time. Just
> don't forget to set the idle timeout on the session (e.g. in
> sessionCreated()) using IoSession.setIdleTime().
>
> We have plans to implement a ReconnectFilter for MINA. There is a patch
> in JIRA but it hasn't been applied yet. It may be used to automatically
> reconnect a session which has been closed.
>
> HTH
> /Niklas
>
the[vbcol=seagreen]
>


Chris Allen

2005-12-24, 5:48 pm

Hi Niklas,

I just wanted to let you know that I got my application configured and
running correctly with your integration classes. Thanks again for
your help and for creating the spring package for MINA.

Happy Holidays!

-Chris

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com