Developer
Developer

Reputation: 23

How to check cache status in ignite

I need to check cache status using apache ignite. I checked cache metrics as well but it has no method which can show me the status. How will i come to know whether cache is 'active' or not. Can somebody suggest?

Upvotes: 0

Views: 1352

Answers (2)

Qiyu Zhang
Qiyu Zhang

Reputation: 185

You can see the interface Ignite

    /**
     * Checks Ignite grid is active or not active.
     *
     * @return {@code True} if grid is active. {@code False} If grid is not active.
     */
    public boolean active();

Update:

The comment's right, here is to check ignite cluster'a activity, there's no default method to check a cache instance, but you can create a method like what I did below to check whether you could retrieve something, regardless it's null or not. If the cache is hung, there should be a timeout, you can throw error or log or just return false;

    public boolean isResponsive(K key) {
        try {
            CompletableFuture.supplyAsync(() -> cache.get(key)).get(10, TimeUnit.SECONDS); 
        } catch (Exception e) {
            log.error("no response from ignite cache: " + e.getMessage());
            return false;
        }
        return true;
    }

Upvotes: -1

Evgenii Zhuravlev
Evgenii Zhuravlev

Reputation: 3017

What do you mean by "active" cache? There is no such thing as status for the cache. When you need to use cache, it's enough to understand, was it created or not and create if it wasn't. In this case, you can use method Ignite.getOrCreateCache.

Upvotes: 2

Related Questions