Hazelcast IAtomicReference.alter lambda

128 views Asked by At

I am trying to populate another atomic reference based on existing cache. I want to use lambdas for code simplicity (less boiler code required) but it doesn't seem to be working.

This works:

class PutFunction implements IFunction<Graph<Long,Long>,Graph<Long,Long>>{
    private Long key;

    public PutFunction(Long key) {
        this.key = key;
    }

    public Graph<Long,Long> apply(Graph<Long,Long> graph){
        graph.addVertex(key);
        return graph;
    }
}

getGraphCache().alter(new IFunction<Graph<Long,Long>,Graph<Long,Long>>(){
    public Graph<Long,Long> apply(Graph<Long,Long> graph){
       graph.addVertex(event.getValue().getId());
       return graph;
    }
});

When I switch to lambda syntax below it gives serialization error:

getGraphCache().alter((IFunction<Graph<Long, Long>, Graph<Long, Long>>) graph -> {
   graph.removeVertex(event.getValue().getId());
   return graph;
});

ERROR
com.hazelcast.nio.serialization.HazelcastSerializationException: Failed to serialize 'com.portal.objects.ObjectGraphEntryListener$$Lambda$61/1840645556'

Has anybody gotten it to work with lambdas?

ObjectGraphEntryListener

hazelcast.xml

0

There are 0 answers