JBoss.org Community Documentation

- Prev
- Next

## 3.6. Array Mapping

As of 2.2, array fields of any attached object are updated transparently, provided that the array is written/read from a class marked with `@Replicable`. If this is the case, only the indexes of the array that are modified are replicated. However, if the array is passed externally to a class that is not marked as `@Replicable`, then the changes will not be noticed. For this reason, it is recommended to abstract access to the array where possible (i.e. setItem(item, index)). If an external, non-replicable class needs access to the array, then it is recommended to pass a copy, and add a method to the container object that reapplies the changes. Also, due to JVM limitations, an array can not be monitored if it is directly attached to the cache (i.e. a first class object). POJO Cache still allows this, but they are treated as a serializable type. As with other serializable type, they must be reattached after every change.

The following code snippet illustrates accessing a replicated array through abstraction:

    @Replicable public class Team
    {
       private String[] members = new String[10];

       public String getMember(int index)
       {
          return members[index];
       }

       public void setMember(int index, String member)
       {
          members[index] = member;
       }
    }

    public class SomeExternalClass
    {
       ...
       public void someMethod()
       {
         Team team = new Team();
         cache.attach("/team/1", team);

         team.setMember(0, "John");
         team.setMember(1, "Joe");
       }
    }

- Prev3.5.1. Limitations
- Top of page
- Front page
- NextChapter 4. API Overview