Problem with IMap<K,V>.keySet( Predicate )

121 views
Skip to first unread message

Pavel Fila

unread,
Dec 18, 2009, 8:23:12 AM12/18/09
to Hazelcast
Hi,
I'm trying to retrieve keys of a map that are older than specified
amount of time.
I want to use the keySet( Predicate ) method to get the set of the
keys by using my own EntryExpiredPredicate. But this approach gives me
an exception. Other approach with entrySet( Predicate ) seems to be
OK, but I'm interested only in keys, so this is not optimal for me.

I am doing something wrong?

Pavel F.

--- excerpt of my code ---
IMap<Integer, Record> recordMap;

recordMap.keySet(new EntryExpiredPredicate( System.currentSystemMillis
() - 3600 )

class EntryExpiredPredicate implements Predicate
{
private long expireBefore;

public EntryExpiredPredicate( long expireBefore ) {
this.expireBefore = expireBefore;
}

public boolean apply(MapEntry entry) {
return entry.getLastAccessTime() < expireBefore;
}

}

-- the exception --

SEVERE: ClusterDistributedStorage
java.io.NotSerializableException: ClusterDistributedStorage
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:
1156)
at java.io.ObjectOutputStream.defaultWriteFields
(ObjectOutputStream.java:1509)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:
1474)
at java.io.ObjectOutputStream.writeOrdinaryObject
(ObjectOutputStream.java:1392)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:
1150)
at java.io.ObjectOutputStream.writeUnshared(ObjectOutputStream.java:
393)
at com.hazelcast.nio.Serializer$ObjectSerializer.write
(Serializer.java:287)
at com.hazelcast.nio.Serializer.writeObject(Serializer.java:97)
at com.hazelcast.impl.ThreadContext.toData(ThreadContext.java:131)
at com.hazelcast.nio.IOUtil.toData(IOUtil.java:58)
at com.hazelcast.impl.BaseManager$RequestBasedCall.setLocal
(BaseManager.java:611)
at com.hazelcast.impl.ConcurrentMapManager$MGetEntries.<init>
(ConcurrentMapManager.java:1268)
at com.hazelcast.impl.ConcurrentMapManager
$MIterate.createNewTargetAwareOp(ConcurrentMapManager.java:1239)
at com.hazelcast.impl.BaseManager$MultiCall.call(BaseManager.java:
877)
at com.hazelcast.impl.FactoryImpl$MProxyImpl$MProxyReal.iterate
(FactoryImpl.java:2373)
at com.hazelcast.impl.FactoryImpl$MProxyImpl$MProxyReal.keySet
(FactoryImpl.java:2348)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.hazelcast.impl.FactoryImpl$MProxyImpl$Invoker.invoke
(FactoryImpl.java:1727)
at com.hazelcast.impl.$Proxy0.keySet(Unknown Source)
at com.hazelcast.impl.FactoryImpl$MProxyImpl.keySet(FactoryImpl.java:
1930)
at ClusterDistributedStorage.removeExpiredEntries
(ClusterDistributedStorage.java:180)

Fuad Malikov

unread,
Dec 18, 2009, 10:00:51 AM12/18/09
to haze...@googlegroups.com
Hi Pavel,

First of all EntryExpiredPredicate has to be serializable. 
Do you have a class named ClusterDistributedStorage? What is it for? And is it serializable?

Fuad


--

You received this message because you are subscribed to the Google Groups "Hazelcast" group.
To post to this group, send email to haze...@googlegroups.com.
To unsubscribe from this group, send email to hazelcast+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/hazelcast?hl=en.



Pavel Fila

unread,
Dec 18, 2009, 10:34:16 AM12/18/09
to Hazelcast
Hi Fuad,
thanks for the prompt answer.
Actually it's solved now. The problem was that EntryExpiredPredicate
has been an inner class of ClusterDistributedStorage, therefore it has
had a hidden reference to it. The ClusterDistributedStorage is one
implementation of a Storage interface which stored the data
clusterwide.
I have made the EntryExpiredPredicate a regular class implementing
Predicate interface (Predicate itself extends Serializable), so now it
works. I was misreading the exception message. Thanks for pointing
out.

Regards
Pavel

On 18 pro, 16:00, Fuad Malikov <f...@hazelcast.com> wrote:
> Hi Pavel,
>
> First of all EntryExpiredPredicate has to be serializable.
> Do you have a class named ClusterDistributedStorage? What is it for? And is
> it serializable?
>
> Fuad
>

> > hazelcast+...@googlegroups.com<hazelcast%2Bunsu...@googlegroups.com>

Reply all
Reply to author
Forward
0 new messages