diff --git a/appserver/payara-appserver-modules/payara-jsr107/src/main/java/fish/payara/cdi/jsr107/implementation/PayaraGeneratedCacheKey.java b/appserver/payara-appserver-modules/payara-jsr107/src/main/java/fish/payara/cdi/jsr107/implementation/PayaraGeneratedCacheKey.java index 1c2b8a1e4a2..a346e9f5408 100644 --- a/appserver/payara-appserver-modules/payara-jsr107/src/main/java/fish/payara/cdi/jsr107/implementation/PayaraGeneratedCacheKey.java +++ b/appserver/payara-appserver-modules/payara-jsr107/src/main/java/fish/payara/cdi/jsr107/implementation/PayaraGeneratedCacheKey.java @@ -2,7 +2,7 @@ DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - Copyright (c) 2016-2017 Payara Foundation. All rights reserved. + Copyright (c) 2016-2018 Payara Foundation. All rights reserved. The contents of this file are subject to the terms of the Common Development and Distribution License("CDDL") (collectively, the "License"). You @@ -79,7 +79,9 @@ public boolean equals(Object obj) { public int hashCode() { return hashCode; } - - - + + @Override + public String toString() { + return "PayaraGeneratedCacheKey{" + "values=" + Arrays.deepToString(values) + '}'; + } } diff --git a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/admin/ListCacheKeys.java b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/admin/ListCacheKeys.java index 295635724ce..ef991d5e25d 100644 --- a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/admin/ListCacheKeys.java +++ b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/admin/ListCacheKeys.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) [2016-2017] Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) [2016-2018] Payara Foundation and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -39,11 +39,15 @@ */ package fish.payara.nucleus.hazelcast.admin; +import com.hazelcast.cache.impl.CacheEntry; +import com.hazelcast.cache.impl.CacheProxy; +import com.hazelcast.cache.impl.ClusterWideIterator; import com.hazelcast.core.DistributedObject; import com.hazelcast.core.HazelcastInstance; import com.hazelcast.core.IMap; import com.sun.enterprise.config.serverbeans.Domain; import fish.payara.nucleus.hazelcast.HazelcastCore; +import java.util.Iterator; import java.util.Properties; import javax.inject.Inject; import org.glassfish.api.ActionReport; @@ -93,6 +97,7 @@ public class ListCacheKeys implements AdminCommand { protected String cacheName; @Override + @SuppressWarnings({"unchecked", "rawtypes"}) public void execute(AdminCommandContext context) { final ActionReport actionReport = context.getActionReport(); @@ -103,17 +108,28 @@ public void execute(AdminCommandContext context) { StringBuilder builder = new StringBuilder(); builder.append("{ \n"); for (DistributedObject dobject : instance.getDistributedObjects()) { + Iterator keyIterator = null; if (dobject instanceof IMap) { if (cacheName == null || cacheName.isEmpty() || cacheName.equals(((IMap) dobject).getName())) { - builder.append("Cache " + ((IMap) dobject).getName()).append("\n{"); - for (Object key : ((IMap) dobject).keySet()) { - try { - builder.append(key.toString()).append(",\n"); - } catch (Exception cnfe) { - builder.append(cnfe.getMessage()).append(",\n"); - } - } - builder.append("}\n"); + builder.append("Cache ").append(((IMap) dobject).getName()).append("\n{"); + keyIterator = ((IMap) dobject).keySet().iterator(); + } + } else if (dobject instanceof CacheProxy) { + CacheProxy jcache = (CacheProxy) dobject; + if (cacheName == null || cacheName.isEmpty() || cacheName.equals(jcache.getName())) { + builder.append("JCache ").append(jcache.getName()).append("\n{"); + keyIterator = new ClusterWideIterator<>(jcache, 10, true); + } + } + while (keyIterator != null && keyIterator.hasNext()) { + Object key = keyIterator.next(); + if(key instanceof CacheEntry) { + key = ((CacheEntry)key).getKey(); + } + try { + builder.append(key.toString()).append(",\n"); + } catch (Exception cnfe) { + builder.append(cnfe.getMessage()).append(",\n"); } } }