On Dec 2, 12:51 pm, Andrés M. Quijano <[EMAIL PROTECTED]> wrote:
> Hi
>
> I'm trying to use Clojure with ApacheMINA. I think Clojure it's the
> ideal language to concurrently handle all the events that arrive
> intoMINA'sseparate threads.
Hi Andrés,
I bumped into Mina a couple of weeks ago, and was thinking that might
be interesting to use a non-blocking IO library from Clojure. I'm not
sure about the ideal design for coupling the Concurrency features of
Clojure with the effectful NIO Mina classes. I would be happy to
discuss it though if anyone has bright ideas ;-)
Anyway, I've managed to run the 'MinaTimeServer' from
http://mina.apache.org/mina-v20-quick-start-guide.html by implementing
the server and handler in Clojure and using the new (AOT) compile
feature to generate classes.
I've attached a zip with the source together with a 'trace' of me
making it run, which should be easy to follow...
zip: http://groups.google.com/group/clojure/web/echo-mina.zip
Kind Regards,
- Karl
Some source:
;;mina.clj
(ns clojure.examples.mina
(:gen-class)
(:import (org.apache.mina.core.session IdleStatus)
(org.apache.mina.core.service IoAcceptor)
(java.nio.charset Charset)
(java.net InetSocketAddress)
(org.apache.mina.filter.codec ProtocolCodecFilter)
(org.apache.mina.filter.codec.textline TextLineCodecFactory)
(org.apache.mina.filter.logging LoggingFilter)
(org.apache.mina.transport.socket.nio NioSocketAcceptor)))
(defn -main [s]
(doto (NioSocketAcceptor.)
(.. getFilterChain (addLast "logger" (LoggingFilter.)))
(.. getFilterChain (addLast "codec" (ProtocolCodecFilter.
(TextLineCodecFactory. (.forName Charset "UTF-8")))))
(.setHandler (clojure.examples.timeserverhandler.))
(.. getSessionConfig (setReadBufferSize 2048))
(.. getSessionConfig (setIdleTime (.BOTH_IDLE IdleStatus) 10))
(.bind (InetSocketAddress. 9123))))
;;timerserverhandler.clj
(ns clojure.examples.timeserverhandler
(:gen-class
:constructors {[] []}
:extends org.apache.mina.core.service.IoHandlerAdapter)
(:import (org.apache.mina.core.session IdleStatus
IoSession)
(org.apache.mina.core.service IoHandlerAdapter)))
(defn -exceptionCaught
[this, ses, cau]
(.printStackTrace cau))
(defn -messageReceived
[this, ses, msg]
(prn msg))
(defn -sessionIdle
[this, ses, stat]
(prn "IDLE"))
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---