6 Replies Latest reply on Dec 1, 2006 4:49 PM by kagey

    jboss application redeployment problem

    kagey

      Jboss has my treecache service mbean running. I deploy my application and create nodes and data key/value pairs in the nodes. I can retrieve the values and cast them to the appropriate class. I redeploy my application and retrieve the same values, but this time i cant cast them to the appropriate class. If I do a getClass on the the Object, it tells me the right class, but i cant cast to that very same class. Any ideas on what is wrong?

        • 1. Re: jboss application redeployment problem
          otaylor

          Once you've redeployed, you have a new class loader, so while the classes may
          look the same (com.example.MyObject) they are actually distinct as far as the
          JVM is concerned.

          I don't have an easy fix ... clearing the cache explicitly when your app starts might
          work in some cases.

          • 2. Re: jboss application redeployment problem
            kagey

            thank you, for your answer, it makes perfect sense. If i change the class type to an array of primitives instead of my custom class, would that work? I'm not familiar on the intricacies of the classloader.

            • 3. Re: jboss application redeployment problem
              kagey

              Also i forgot to say that clearing the cache is not an option as the app will be running on multiple servers sharing the same cache.

              This brings up another question. How in the heck am i suppose to share data through the cache if i cant even get at the object data between multiple app instances?

              • 4. Re: jboss application redeployment problem
                hmesha

                I think what you should be doing is clear the local cache using JBossCache options API when undeploying your application. That will clear the cache and then start a new instance on redeployment which will have the right classes with the right defining class loader and you won't affect the other cache instances running on other instances of the application assuming that you're sharing the cache via replication, cache loader,...

                • 5. Re: jboss application redeployment problem
                  otaylor

                  - Yes, if you store primitive types rather than application types this problem won't occur
                  - This problem won't occur with remote marshalling of the class data, since object is sent in serialized form to remote nodes. This does point out another problem you are going to run into, however, which is harder to deal with than the one you've hit already ... to get sending your application classes to remote nodes to work, you need to set the class loader that the cache uses to demarshal objects read from the wire; this isn't too hard to do - use cache.registerClassLoader() - but you can't *change* the class loader for a running cache. So you basically need to either use primitive types or restart the cache for that node (not just clear it) when you redeploy your application.
                  - Are you really planning to change the code on one node of the cluster while leaving an older version running on another node? Brave.

                  • 6. Re: jboss application redeployment problem
                    kagey

                    Thanks for the info everyone. I seem to have fixed the problem by replacing my app data classes with arrays of primitives, or arrays of Objects[] which contain java library objects like Strings.