James Hutchinson
James Hutchinson

Reputation: 881

Liberty profile POJO caching

I am attempting to set up liberty profile server so I can cache POJOs. My question is how do I access the DistributedMap within my java code?

My server.xml:

<featureManager>
    <feature>jsp-2.2</feature>
    <feature>jaxrs-1.1</feature>
    <feature>localConnector-1.0</feature>
    <feature>appSecurity-2.0</feature>
    <feature>jpa-2.0</feature>
    <feature>jdbc-4.0</feature>
    <feature>jndi-1.0</feature>
    <feature>cdi-1.0</feature>
    <feature>webCache-1.0</feature>
    <feature>distributedMap-1.0</feature>
</featureManager>

<distributedMap id="baseCache" libraryRef="TSPlib" memorySizeInMB="500" jndiName="services/cache/baseCache">
    <diskCache></diskCache>
</distributedMap>

<library id="TSPlib">
    <folder dir="C:\TSP\bin"></folder>
</library>

I tried this code below (which admittedly is for WAS), but I can't find the correct namespace for DistributedMap, nor the jar that it's in.

public class CachingService {

private DistributedMap cache = null;

public CachingService() {
    InitialContext ctx;
    try {
    ctx = new InitialContext();
          cache = (DistributedMap) ctx.lookup("services/cache/baseCache");
    } catch (NamingException e) {
          e.printStackTrace();
    }
}

Upvotes: 0

Views: 1021

Answers (1)

Gas
Gas

Reputation: 18050

Looks like a typo, as in distributedMap configuration you provided jndiName="services/cache/baseCache" and in lookup you use: ctx.lookup("services/cache/TestCache")

If you would not provide custom jndiName, then the default services/cache/distributedmap. See distributedMap-1.0

Upvotes: 1

Related Questions