Este conteúdo não está disponível no idioma selecionado.
4.3. Grouping API Configuration
In order to use the Grouping API in JBoss Data Grid, first enable groups.
Programmatic configuration
To configure JBoss Data Grid using the programmatic API, call the following:
Configuration c = new ConfigurationBuilder().clustering().hash().groups().enabled().build();
Configuration c = new ConfigurationBuilder().clustering().hash().groups().enabled().build();
XML configuration
To configure JBoss Data Grid using XML, use the following:
<clustering>
<hash>
<groups enabled="true" />
</hash>
</clustering>
<clustering>
<hash>
<groups enabled="true" />
</hash>
</clustering>
If the class definition of the key is alterable, and the group's determination is not an orthogonal concern to the key class, use an intrinsic group. Use the
@Group annotation within the method to specify the intrinsic group. For example:
Note
The group must be a
String.
Without key class control, or in a case where the determination of the group is an orthogonal concern to the key class, use an extrinsic group. Specify an extrinsic group by implementing the
Grouper interface. The computeGroup method within the Grouper interface returns the group.
Grouper operates as an interceptor and passes previously computed values to the computeGroup() method. If defined, @Group determines which group is passed to the first Grouper, providing improved group control when using intrinsic groups.
To use a
grouper to determine a key's group, its keyType must be assignable from the target key.
The following is an example of a
Grouper:
In this example, a simple
grouper uses the key class to extract the group from a key using a pattern. Information specified on the key class is ignored. Each grouper must be registered to be used.
Programmatic configuration
When configuring JBoss Data Grid programmatically:
Configuration c = new ConfigurationBuilder().clustering().hash().groups().addGrouper(new KXGrouper()).build();
Configuration c = new ConfigurationBuilder().clustering().hash().groups().addGrouper(new KXGrouper()).build();
XML Configuration
Or when configuring JBoss Data Grid using XML: