Skip navigation
Toggle Sidebar

Architectural overview

At the core of PackRat lies annotation-based code generator. User supplies his annotated POJO class and code generator generates classes required to pack and store this POJO in the space.

For each POJO class, two classes will be generated. Name of new classes will be constructed by adding suffixes "Packer" and "Packed". Class with suffix "Packed" is partly serialized form of initial class and will be stored in the space. Class with suffix "Packer" contains transformation and compression code from initial object to packed object and vice versa.

For example, lets assume you have ExamplePojo class. Code generator will create two classes from it: ExamplePojoPacker and ExamplePojoPacked.

ExamplePojo pojo = new ExamplePojo();
ExamplePojoPacker packer = new ExamplePojoPacker();

ExamplePojoPacked packedPojo = packer.pack(pojo);
ExamplePojo pojoNew = packer.unpack(packedPojo);

This mechanism has one defect. For code generator to work, a compiled POJO classes should be classloaded. For initial code generation this is not a big deal. But when changes in initial classes influence generated classes, you will need re-generate or manually change them. So you need to delete generated classes and generate new ones, but application code is already interacts with generated classes and stops compiling...

To avoid this problems a factory pattern should be used: Packer factory class automatically chooses needed type of packer for object and uses it for pack and unpack operations, returning ready-to-use Entries or POJOs.

Packer packer = new Packer();
ExamplePojo pojo = new ExamplePojo();

Entry packedPojo = packer.pack(pojo);
ExamplePojo pojoNew = packer.<ExamplePojo>unpack(packedPojo);

To make it possible to use space template matching, Packer should transform template POJO into packed template entry with wildcard binary field:

ExamplePojo template = new ExamplePojo();
 // set template fields here
 template.setIntegerField(42);
 Entry[] entries = space.readMultiple(packer.packForTemplate(template), null, 1000);
  for(Entry entry:entries){
      ExamplePojo res = packer.unpack(entry);
  }

Described architecture also allows runtime packer creation to make packing process fully transparent. This is a subject of PackRat 2.0

Adaptavist Theme Builder Powered by Atlassian Confluence