7 Replies Latest reply on Jan 15, 2009 11:27 PM by trustin

    Microcontainer support in Netty

    alesj

      From Trustin Lee (Netty author):

      I've just finished a preliminary integration layer for Netty and
      Microcontainer. I thought about adding various metadata and things
      like that, but ended up with just providing some singletons because
      Netty is basically a framework so there's nothing much to provide in
      deployment time. Here's jboss-beans.xml I wrote:
      * http://tinyurl.com/7668pk

      A user will get a proper ChannelFactory implementation via injection:

       <deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="urn:jboss:bean-deployer
      bean-deployer_2_0.xsd"
       xmlns="urn:jboss:bean-deployer:2.0">
      
       <bean name="DiscardServer"
       class="net.gleamynode.tmp.discard.DiscardServer">
       <constructor>
       <parameter class="org.jboss.netty.channel.ChannelFactory">
       <inject
      bean="org.jboss.netty.channel.socket.ServerSocketChannelFactory" />
       </parameter>
       </constructor>
       </bean>
       </deployment>
      

      It seems to work fine so far. The next step is to write three modules:
      * Business logic handler
      * Google protobuf based protocol codec
      * A glue module that combines all together to run the server up
      (will look up proper handler and codec instances via KernelController
      - I guess it's a piece of cake, right?)

      By doing so, I'd like to show that a user can upgrade the protocol
      codec or business logic in runtime without interruption. That is,
      dropping an updated JAR into the sandbox directory should affect the
      application immediately. I think just looking for a bean via
      KernelController for every connection will not work because a JAR will
      be undeployed and deployed when a new JAR is dropped and therefore the
      bean I am looking for might disappear during the redeployment. Should
      I use some call back in this case, or does MC hide this race condition
      during upgrade (or redeployment)?

      BTW, I still didn't figure out how to hide internal beans. How can I
      exactly do that? I looked into the test cases and
      PreInstallsAction.java but I guess I'm not following the speed of your
      thought. An example would be appreciated. ;-)

      I'm also thinking about distributing a minimal JBossMC binary tarball
      with my tutorial so that a user can play with MC more easily (i.e.
      untar and drop the sample JARs etc etc). I think it might help MC
      adoption because people are really used to just downloading a Tomcat
      tarball and dropping a WAR and see it working. We already have
      something similar in jboss-demos, but I think it needs to be a binary
      form so that users can familiarize with MC quickly. I can do this
      while I write my tutorial. WDYT?

        • 1. Re: Microcontainer support in Netty
          alesj

          More from Trustin.

          Uh, one quick question just to be sure. If I drop two JARs into the
          sandbox directory, they are loaded by two classloaders, right? :-)

          • 2. Re: Microcontainer support in Netty
            alesj

             

            "trustin" wrote:

            * A glue module that combines all together to run the server up
            (will look up proper handler and codec instances via KernelController
            - I guess it's a piece of cake, right?)

            I would try to use MC's API as little as possible.
            Your stuff is all about beans, so we should be able to handle it w/o the explicit usage of MC API.
            e.g. contextual injection, callbacks, installs, value-factory, ...

            "trustin" wrote:

            Should I use some call back in this case, or does MC hide this race condition during upgrade (or redeployment)?

            I would use callback.
            e.g. callback on addProtocol(Protocol p)

            Nope, MC doesn't explicitly handle that.
            But if you would have proper dependencies, this would not matter.


            "trustin" wrote:

            BTW, I still didn't figure out how to hide internal beans. How can I
            exactly do that?

            Annotate your bean with @DeploymentScope and @ApplicationScope - via xml or directly on the class.
            This will move the bean out of main Kernel(Controller) into a scoped one.

            By default your scoped bean only 'sees' its scope and ancestors.
            But you can 'change' the lookup order with @Search markup.
            @Search takes type on how to search - currently only annotation support.
            But you need to explicitly add SearchAnnotationPlugin - see the tests on how to do it.

            "trustin" wrote:

            I'm also thinking about distributing a minimal JBossMC binary tarball
            with my tutorial so that a user can play with MC more easily (i.e.
            untar and drop the sample JARs etc etc). I think it might help MC
            adoption because people are really used to just downloading a Tomcat
            tarball and dropping a WAR and see it working. We already have
            something similar in jboss-demos, but I think it needs to be a binary
            form so that users can familiarize with MC quickly. I can do this
            while I write my tutorial. WDYT?

            I would add your example directly under mc-demos.
            Simply create new netty sub-module and hack all the stuff there.

            See my previous examples on how to do this, following the same concept.
            Glue code:
            - bootstrap
            - jmx
            - classloading
            Actual example code:
            - models
            - ioc
            - classpath

            Then simply link the tutorial to that code.
            Or even better, write a simple article about it at DZone,
            could be even part of my MC series - more than welcome to 'host' it.


            • 3. Re: Microcontainer support in Netty
              alesj

               

              "trustin" wrote:

              Uh, one quick question just to be sure. If I drop two JARs into the
              sandbox directory, they are loaded by two classloaders, right? :-)

              Yes.
              But you can share their domain - via proper jboss-classloading.xml.

              • 4. Re: Microcontainer support in Netty
                trustin

                 

                "alesj" wrote:
                "trustin" wrote:
                BTW, I still didn't figure out how to hide internal beans. How can I exactly do that?
                Annotate your bean with @DeploymentScope and @ApplicationScope - via xml or directly on the class. This will move the bean out of main Kernel(Controller) into a scoped one.

                By default your scoped bean only 'sees' its scope and ancestors. But you can 'change' the lookup order with @Search markup. @Search takes type on how to search - currently only annotation support. But you need to explicitly add SearchAnnotationPlugin - see the tests on how to do it.

                OK. This forum post seem to be related: http://www.jboss.com/index.html?module=bb&op=viewtopic&t=147051 It would be great if there's an easier way to add an annotation plugin without using callbacks though.

                "alesj" wrote:
                "trustin" wrote:
                I'm also thinking about distributing a minimal JBossMC binary tarball with my tutorial so that a user can play with MC more easily (i.e. untar and drop the sample JARs etc etc). I think it might help MC adoption because people are really used to just downloading a Tomcat tarball and dropping a WAR and see it working. We already have something similar in jboss-demos, but I think it needs to be a binary form so that users can familiarize with MC quickly. I can do this while I write my tutorial. WDYT?
                I would add your example directly under mc-demos. Simply create new netty sub-module and hack all the stuff there.

                See my previous examples on how to do this, following the same concept.
                Glue code:
                - bootstrap
                - jmx
                - classloading
                Actual example code:
                - models
                - ioc
                - classpath

                Then simply link the tutorial to that code. Or even better, write a simple article about it at DZone, could be even part of my MC series - more than welcome to 'host' it.

                It's a great idea to host the netty + jbossmc example under jboss-demos. I'd love to do that once I get a write permission. I'm not sure if it's a good idea to publish the tutorial as a part of your MC series though because it will be quite a lot about fast protocol prototyping and evolution as well as highlighting some MC features.

                Regarding the distribution, my point is to provide a downloadable working binary distribution of embedded microcontainer with HDScanner so that a user can play with it without building it. jboss-demos already provides everything required to build the distribution except some startup scripts. For example, Equinox is very easy to play with even for a beginner: http://tinyurl.com/7j97ak

                • 5. Re: Microcontainer support in Netty
                  trustin

                  (truncated for some reason)

                  Of course, building an OSGi bundle is another story, and I believe MC will get much more attraction than before once quickstart distribution is distributed. Who would ever want to generate MANIFEST.MF in many cases when just dropping a plain JAR is enough?

                  • 6. Re: Microcontainer support in Netty
                    alesj

                     

                    "trustin" wrote:

                    It's a great idea to host the netty + jbossmc example under jboss-demos. I'd love to do that once I get a write permission. I'm not sure if it's a good idea to publish the tutorial as a part of your MC series though because it will be quite a lot about fast protocol prototyping and evolution as well as highlighting some MC features.

                    No, I was implying that you should just host the code there.
                    The tutorial should be a separate effort, perhaps just linking the user to try the stuff via mc-demos example(s).

                    The article could be a teaser for the tutorial. ;-)

                    "trustin" wrote:

                    Regarding the distribution, my point is to provide a downloadable working binary distribution of embedded microcontainer with HDScanner so that a user can play with it without building it. jboss-demos already provides everything required to build the distribution except some startup scripts.

                    You're the script master, feel free to add them. ;-)

                    It could be even better if they could be generated via maven,
                    as it already holds all the info required to run things from IDE,
                    hence it shouldn't be a huge problem to build the classpath, etc.
                    (I'm guessing, as I've have no clue what maven can do :-))

                    • 7. Re: Microcontainer support in Netty
                      trustin

                      Cool. I know how I can attach a binary distribution to a maven module, but when would I gain the access to the jbossas SVN repository? :-)