9 Replies Latest reply: Sep 19, 2013 12:22 AM by user13541594 RSS

    3.6 nested POF question

    725968
      Hi guys,

      I see you've added nested POF to 3.6 - really nice. Should allow us to get around some of the Inheritance issues.
      pofReader.createNestedPofReader(0)
      I created a Parent and Child class and got that working nicely.

      Next I added readRemainder to the Parent and that worked fine.

      However, if I add it to the Child I get
      Caused by: java.io.EOFException: user type POF stream terminated
           at com.tangosol.io.pof.PofBufferWriter$UserTypeWriter.writeUserTypeInfo(PofBufferWriter.java:2621)
           at com.tangosol.io.pof.PofBufferWriter$UserTypeWriter.writeRemainder(PofBufferWriter.java:2497)
           at com.tangosol.io.pof.PortableObjectSerializer.serialize(PortableObjectSerializer.java:96)
           at com.tangosol.io.pof.PofBufferWriter.writeUserType(PofBufferWriter.java:1667)
      Is this is as expected - I can see the Parent is probably reading the remainder, but it seems unfortunate...

      Best, Andrew.
        • 1. Re: 3.6 nested POF question
          698451
          Hi Andrew

          As soon as you touch the parent stream of a nested stream, the stream will be terminated. So I'm guessing you're intermixing accesses to the parent and child streams.

          Cheers
          /Charlie
          • 2. Re: 3.6 nested POF question
            725968
            Hmm, so I can only do one readRemainder in the class hierarchy, which seems intrinsically wrong...

            I confirmed this by adding a 3rd GrandParent class.

            A.
            • 3. Re: 3.6 nested POF question
              698451
              Hi Andrew

              No, you can do a readRemainder for each level in the stream. However you must read the remainder of the child, before accessing the parent stream. The behavior is similar to the progressive behavior of a pof steam where you only may access successive indices.

              So you can do

              PofReader child = parent.createNestedPofReader(0);
              int childId = child.readInt(0);
              Binary childRemainder = child.readRemainder();
              int parentId = parent.readInt(1); // <=This call will implicitly close the child stream.
              Binary parentRemainder = parent.readRemainder();
              • 4. Re: 3.6 nested POF question
                698451
                Andrew

                After looking a bit more thorough at your trace it seems like you are using the PortableObjectSerializer, which isn't aware that your code will call read/write-Remainder() itself. Because the POS will call this method itself and try to set the remainder using the Evolvable interface (if it exists).

                I believe that what you do want to do is to write your own serializer which knows how to read the hierarchy level by level. Most importantly is that each level needs to assign/persist their own Evolution in a Binary field.

                Cheers
                /Charlie
                • 5. Re: 3.6 nested POF question
                  859102
                  Yeah apparently you're not supposed to call readRemainder or writeRemainder from within the PortableObject methods, too bad the documentation does not mention this.

                  Here is a better idea of what a subclass's PortableObject methods should look like:
                  ...
                      @Override
                      public void readExternal(PofReader in) throws IOException {
                          super.readExternal(in.createNestedPofReader(0));
                  
                          myObj = (MyType) in.readObject(1);
                      }
                  
                      @Override
                      public void writeExternal(PofWriter out) throws IOException {
                          super.writeExternal(out.createNestedPofWriter(0));
                  
                          out.writeObject(1, myObj);
                      }
                  Since you cannot read or write the remainder, the way that you support PortableObjects that need to evolve is by implementing the Evolvable interface. Coherence will detect that your object is an instanceof Evolvable, and will handle reading/writing the remainder/futureData and dataVersion for you.
                  • 6. Re: 3.6 nested POF question
                    robvarga
                    rehevkor5 wrote:
                    Yeah apparently you're not supposed to call readRemainder or writeRemainder from within the PortableObject methods, too bad the documentation does not mention this.

                    Here is a better idea of what a subclass's PortableObject methods should look like:
                    ...
                    @Override
                    public void readExternal(PofReader in) throws IOException {
                    super.readExternal(in.createNestedPofReader(0));
                    
                    myObj = (MyType) in.readObject(1);
                    }
                    
                    @Override
                    public void writeExternal(PofWriter out) throws IOException {
                    super.writeExternal(out.createNestedPofWriter(0));
                    
                    out.writeObject(1, myObj);
                    }
                    Since you cannot read or write the remainder, the way that you support PortableObjects that need to evolve is by implementing the Evolvable interface. Coherence will detect that your object is an instanceof Evolvable, and will handle reading/writing the remainder/futureData and dataVersion for you.
                    Yep. Otherwise, if you have handled the remainder in a PortableObject, you would not be able to sensibly override that method which handled the remainder.

                    Best regards,

                    Robert
                    • 7. Re: 3.6 nested POF question
                      user13541594

                      Hi All,

                       

                      I am having the same problem i get

                      Error Message : (Wrapped) (Wrapped) user type POF stream terminated, Cause : (Wrapped) java.io.IOException: (Wrapped) user type POF stream terminated

                       

                      I have a object which extends another class.

                      I have implemented the portableObject in both the classes.

                       

                      Consider class A extends ClassB

                      I am calling super of B from A but i am confused on the indexing of the read and writes i tried from 0 for class B also from max value based on the parameters of the classA.

                      In classA also tried with 0 and max of the class B parameters but i still get that error.I am not calling anyother method in the read and writeExternal.Pease help.

                       

                      Thanks and Regards,

                      Namita

                      • 8. Re: 3.6 nested POF question
                        user13541594

                        I would like to add the error trace

                        at com.tangosol.util.ExternalizableHelper.toBinary(ExternalizableHelper.java:215)

                            at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.partitionedService.PartitionedCache$ConverterValueToBinary.convert(PartitionedCache.CDB:3)

                            at com.tangosol.util.ConverterCollections$AbstractConverterEntry.getValue(ConverterCollections.java:3548)

                            at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.partitionedService.PartitionedCache$BinaryMap.putAll(PartitionedCache.CDB:21)

                            at com.tangosol.util.ConverterCollections$ConverterMap.putAll(ConverterCollections.java:1703)

                            at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.partitionedService.PartitionedCache$ViewMap.putAll(PartitionedCache.CDB:1)

                            at com.tangosol.coherence.component.util.SafeNamedCache.putAll(SafeNamedCache.CDB:1)

                         

                        Also it fails at the point where the  i try do putAll on one of the non DB caches.

                        • 9. Re: 3.6 nested POF question
                          user13541594

                          The solution mentioned above in the chat worrks in had missed one of the classes while doing the change