Skip to content

Commit

Permalink
Merge pull request #3420 from mulderbaba/PAYARA-3046-Listing-Cache-Ke…
Browse files Browse the repository at this point in the history
…ys-not-working

Payara 3046 listing cache keys not working
  • Loading branch information
arjantijms authored Nov 14, 2018
2 parents e650670 + b1034e6 commit 1bbb804
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -79,7 +79,9 @@ public boolean equals(Object obj) {
public int hashCode() {
return hashCode;
}




@Override
public String toString() {
return "PayaraGeneratedCacheKey{" + "values=" + Arrays.deepToString(values) + '}';
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -103,17 +108,28 @@ public void execute(AdminCommandContext context) {
StringBuilder builder = new StringBuilder();
builder.append("{ \n");
for (DistributedObject dobject : instance.getDistributedObjects()) {
Iterator<Object> keyIterator = null;
if (dobject instanceof IMap) {
if (cacheName == null || cacheName.isEmpty() || cacheName.equals(((IMap<Object, Object>) dobject).getName())) {
builder.append("Cache " + ((IMap<Object, Object>) dobject).getName()).append("\n{");
for (Object key : ((IMap<Object, Object>) 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<Object, Object>) dobject).getName()).append("\n{");
keyIterator = ((IMap<Object, Object>) 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");
}
}
}
Expand Down

0 comments on commit 1bbb804

Please sign in to comment.