6 Replies Latest reply on Jun 8, 2009 9:26 AM by adrian.brock

    Locating the current DeploymentUnit

    dmlloyd

      Is there, or could we create, a mechanism by which the DeploymentUnit (if any) assocaited with the current executing thread can be located statically?

      Such a mechanism would possibly use a ThreadLocal which is set before calling any lifecycle or injection methods. Then I can use JBoss Threads to cover the other cases (tasks submitted to Executors).

      This will be necessary to make per-deployment logging setups work right.

        • 1. Re: Locating the current DeploymentUnit
          dmlloyd

          One challenge will be if and when one deployment unit calls into another. Maybe a reflection-based stack introspection would be better, but I don't believe there's a portable API to accomplish that.

          • 2. Re: Locating the current DeploymentUnit
            dmlloyd

            OK how about this. What is the mechanism to find the DeploymentUnit that a Class belongs to? Does jboss-cl give us something which does this?

            • 3. Re: Locating the current DeploymentUnit
              jaikiran

               

              "david.lloyd@jboss.com" wrote:


              This will be necessary to make per-deployment logging setups work right.


              From what i remember, in AS-4.x this was done with a TCL log4j filter (not sure how credible that used to work). How is this being done in AS-5?


              • 4. Re: Locating the current DeploymentUnit
                alesj

                 

                "david.lloyd@jboss.com" wrote:
                OK how about this. What is the mechanism to find the DeploymentUnit that a Class belongs to? Does jboss-cl give us something which does this?

                You can do this:
                (1) Get CL for the class
                (2) Get the Module for CL
                (3) Search all DUs for matching Module
                --> the one that has that Module as an attachment is your DU

                There might be a faster way, but I need to check the code,
                as this was off the top of my head. :-)

                • 5. Re: Locating the current DeploymentUnit
                  bob.mcwhirter

                  fwiw, TorqueBox (jboss-rails) is one of those that has a DU that creates another DU.

                  Something stack-ish would be appropriate in my use-case, perhaps.

                  • 6. Re: Locating the current DeploymentUnit

                    You can't use a thread local because

                    1) the deployers/micrcontainer can cause other deployments/contexts to be processed
                    when dependencies are satisfied. e.g. deploying the transaction manager will cause
                    many other other services to start.

                    2) Outside the deployment framework callbacks there will be no "current deployment"

                    Also Classes don't necessarily belong to any deployment unit,
                    e.g. the bootstrap classes

                    I'd suggest the easiest way to implement this feature would be write a new deployer
                    that runs "post classlaoder". This would mainatain a map of
                    ClassLoader->DeploymentUnit
                    for any DeploymentUnit (including subdeployments like wars) that have a Module
                    attachment and hence their own classloader.

                    You can then use this map in whatever you want to do.