Search code examples
gemfirespring-data-gemfire

Delta Propagation in GemFire


When I was trying to implement Delta Propagation in GemFire, I was getting Exception shown below...

Exception...

com.gemstone.gemfire.pdx.PdxSerializationException: Could not create an instance of a class DeltaTesting with root cause
java.lang.ClassNotFoundException: DeltaTesting
    at org.apache.geode.internal.ClassPathLoader.forName(ClassPathLoader.java:437)
    at org.apache.geode.internal.InternalDataSerializer.getCachedClass(InternalDataSerializer.java:4010)
    at org.apache.geode.pdx.internal.PdxType.getPdxClass(PdxType.java:235)
    at org.apache.geode.pdx.internal.PdxReaderImpl.basicGetObject(PdxReaderImpl.java:687)
    at org.apache.geode.pdx.internal.PdxReaderImpl.getObject(PdxReaderImpl.java:682)

Code...

@Region("deltaTesting")
public class DeltaTesting implements Delta,Serializable {

    private static final long serialVersionUID = 1L;

    public DeltaTesting(){

    }

public DeltaTesting(String id, String firstName, String lastName){
    this.id = id;
    this.firstName = firstName;
    this.lastName = lastName;

    }


    @Id
    private String id;
    private String firstName;
    private String lastName;


    private transient boolean stringId = false;
    private transient boolean stringFirstName = false;
    private transient boolean stringLastName = false;



    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.stringId = true;
        this.id = id;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.stringFirstName = true;
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.stringLastName = true;
        this.lastName = lastName;
    }

    @Override
    public void fromDelta(DataInput in) throws IOException, InvalidDeltaException {
        // TODO Auto-generated method stub

         System.out.println("Applying delta to " + this.toString());
            // For each field, read whether there is a change 
            if (in.readBoolean()) {
                // Read the change and apply it to the object 
                this.id = in.readLine();
                System.out.println(" Applied delta to field 'id' = "
                            + this.id);
            }

            if (in.readBoolean()) {
                // Read the change and apply it to the object 
                this.firstName = in.readLine();
                System.out.println(" Applied delta to field 'firstname' = "
                            + this.firstName);
            }
            if (in.readBoolean()) {
                // Read the change and apply it to the object 
                this.lastName = in.readLine();
                System.out.println(" Applied delta to field 'lastname' = "
                            + this.lastName);
            }
    }


    @Override
    public boolean hasDelta() {
        // TODO Auto-generated method stub
         return this.stringId || this.stringFirstName || this.stringLastName;
    }


    @Override
    public void toDelta(DataOutput out) throws IOException {

         out.writeBoolean(stringId);
        // TODO Auto-generated method stub
        if (stringId) {
            out.writeBytes(this.id);
            this.stringId = false;
            System.out.println(" Extracted delta from field 'id' = " + this.id);
        }
         out.writeBoolean(stringFirstName);
        if (stringFirstName) {
            out.writeBytes(this.firstName);
            this.stringFirstName = false;
            System.out.println(" Extracted delta from field 'firstName' = " + this.firstName);
        }
         out.writeBoolean(stringLastName);
            if (stringLastName) {
                out.writeBytes(this.lastName);
                this.stringLastName = false;
                System.out.println(" Extracted delta from field 'lastName' = " + this.lastName);
            }

    }



}
**cache.xml**   
    <pdx>
    <pdx-serializer>
    <class-name>com.gemstone.gemfire.pdx.ReflectionBasedAutoSerializer</class-
    name>
   <parameter name="classes">
   <string>com\.xxx\..+</string>
   </parameter> 

</pdx-serializer>
   </pdx>

Solution

  • @Vigneshwara-

    Delta Propagation is not supported by PDX Serialization in GemFire. You must use the GemFire Data Serialization framework (i.e. DataSerializable and DataSerializers) with Deltas instead.

    In short... if you use PDX, then you cannot use Deltas. If you use Deltas, then you cannot use PDX.

    Sorry, -j