Simply by being on your application’s classpath, ehcache-sizeofengine will automagically be picked up by Ehcache. It replaces the SizeOfEngine implementation that ships with Ehcache (2.8.0 onwards) with the EhcacheSizeOfEngine implementation of this project, which lets you control what is then being sized.
You simply need to add the jars of the modules that you want along side this project’s jar
In order to ignore fields or instances of certain classes when sizing object graphs, you’ll have to
-
Create a ServiceLoader project, for net.sf.ehcache.sizeofengine.FilterConfigurator
-
Have your jar contain a text file named META-INF/services/net.sf.ehcache.sizeofengine.FilterConfigurator
-
The file should contain the fully qualified class name of your implementation
-
-
Implement FilterConfigurator's configure method to configure the Filter of classes and fields
-
put your jar on your application’s classpath, along side of the ehcache jar and this ehcache-sizeofengine jar
-
Use Ehcache’s Automatic Resource Control for your heap tier
public static final class StupidConfigurator implements FilterConfigurator {
@Override
public void configure(final Filter ehcacheFilter) {
// Will not size any instance of Number, and given the second arg, no subtype neither
ehcacheFilter.ignoreInstancesOf(Number.class, false);
}
}
There can be as many FilterConfigurator on the classpath as required, they’ll have configure the filter once. The Filter is shared across all SizeOfEngine instances created.
Releases are available from Maven Central.
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>sizeof</artifactId>
<version>${sizeof.version}</version>
</dependency>
Snapshots are available from the Sonatype OSS snapshots repository. In order to access the snapshots, you need to add the following repository to your pom.xml:
<repository>
<id>sonatype-nexus-snapshots</id>
<name>Sonatype Nexus Snapshots</name>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>