3 Replies Latest reply on Jul 15, 2008 4:16 AM by Mathias Chouet

    Aspectization via XML seems to fail

    Mathias Chouet Newbie

      Hi everyone.

      I'm a beginner with JBoss Cache (in general) and I'm currently using Pojo Edition in a clustered environment.
      The fact is I'm encountering problems trying to attach(...) a homemade object.
      I've made this Pojo "Replicable" using the adequate annotation, but it contains references to non-homemade, non-serializable objects, especially "sun.awt.image.ByteInterleavedRaster" (extending "java.awt.image.Raster").
      Therefore I tried to specify the following lines in pojocache-aop.xml:

      <prepare expr="field(* $instanceof{java.awt.image.Raster}->*)" />
      <prepare expr="field(* $instanceof{sun.awt.image.ByteInterleavedRaster}->*)" />

      But... I'm still getting an "org.jboss.cache.pojo.PojoCacheException" during the call to attach(...) telling me the object is not aspectized!

      The command run is java -Djboss.aop.path=. -javaagent:lib/jboss-aop.jar -jar MyJar.jar
      (the current folder is containing the file pojocache-aop.xml)

      And the exception stack trace is (abstract):
      org.jboss.cache.pojo.PojoCacheException: PojoCache operation will be rollback. id: /tiles/904625697166532779881401250224994128512259476472989730470355274416529335103/0-1. Operation: attach
       at org.jboss.cache.pojo.interceptors.PojoTxInterceptor.invoke(PojoTxInterceptor.java:91)
       at ...
      Caused by: java.lang.IllegalArgumentException: PojoCache.putObject(): Object type is neither aspectized nor Serializable nor an array of primitives. Object class name is sun.awt.image.ByteInterleavedRaster
       at org.jboss.cache.pojo.util.AopUtil.checkObjectType(AopUtil.java:125)
       at ...

      I've certainly missed something. If you have any idea, it would be very nice and greatly helpful.
      Thanks in advance


        • 1. Re: Aspectization via XML seems to fail
          Mathias Chouet Newbie

          I'm sorry to post again so soon, but I thought I could add a precision:

          When adding

          <attribute name="marshallNonSerializable">True</attribute>

          to pojocache-aop.xml, I don't get the "org.jboss.cache.pojo.PojoCacheException" anymore during call to

          Nevertheless, any call to

          returns null, no matter if the cache instance is the one I used to attach(...) or a remote instance.

          I'm very surprised because I easily managed to replicate homemade, non-serializable pojo's and this example doesn't work...
          Thanks in advance, any help would be very appreciated.


          • 2. Re: Aspectization via XML seems to fail
            Jason Greene Master

            You ask a very good question. The problem is that you can't advise anything in the bootclasspath, which the awt image stuff is. You would have to weave the classes offline, and then use the Xbootclasspath option, which is technically a violation of the JRE.

            A simpler approach is to wrap the image with a custom serializer type like so:

            public static class ImageWrapper implements Serializable {
             private RenderedImage image;
             public ImageWrapper(RenderedImage image) {
             this.image = image;
             public RenderedImage getImage() {
             return image;
             private void writeObject(java.io.ObjectOutputStream out) throws IOException {
             ImageIO.write(image, "javax_imageio_1.0", out);
             private void readObject(java.io.ObjectInputStream in)
             throws IOException, ClassNotFoundException {
             image = ImageIO.read(in);

            You can then declare your field as the wrapper class and use the extra indirection, or alternatively you can mark the non-serializable field as transient, and use the wrapper in a new field, which is used to lazily initialize the transient field.

            • 3. Re: Aspectization via XML seems to fail
              Mathias Chouet Newbie

              First, thank you very much for your answer, which helps me a lot!

              I think I had not understood well the nature of the operations performed by the agent at JVM boot. Actually, I see now the necessity of using offline weaving then the -Xbootclasspath option; it is certainly not acceptable as it is violating the JRE.

              Therefore I'll try your solution, which seems perfectly suitable in my case. Thanks again for your explanation, for the rest it's a pleasure to use JBossCache.