com.seajas.search.contender.service.monitoring.MonitoringService.java Source code

Java tutorial

Introduction

Here is the source code for com.seajas.search.contender.service.monitoring.MonitoringService.java

Source

/**
 * Copyright (C) 2013 Seajas, the Netherlands.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 3, as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.seajas.search.contender.service.monitoring;

import java.util.concurrent.BlockingQueue;

import javax.management.JMException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;

import com.seajas.search.contender.http.ExclusiveConnectionManager;

/**
 * Integration monitoring service.
 * 
 * @author Jasper van Veghel <jasper@seajas.com
 */
@Service
public class MonitoringService {
    /**
     * Enricher processing executor pool.
     */
    @Autowired
    private ThreadPoolTaskExecutor enricherExecutorPool;

    /**
     * Retrieval connection manager.
     */
    @Autowired
    private ExclusiveConnectionManager retrievalConnectionManager;

    /**
     * Enricher connection manager.
     */
    @Autowired
    private ExclusiveConnectionManager enricherConnectionManager;

    /**
     * Count the number of active threads within the enricher executor pool.
     * 
     * @return Long
     * @throws JMException
     */
    public Long countActiveEnricherExecutorPoolThreads() {
        return (long) enricherExecutorPool.getActiveCount();
    }

    /**
     * Count the remaining queue capacity within the enricher executor pool.
     * 
     * @return Long
     * @throws JMException
     */
    public Long countEnricherExecutorPoolRemainingQueueCapacity() {
        BlockingQueue<Runnable> queue = enricherExecutorPool.getThreadPoolExecutor().getQueue();

        return (long) queue.remainingCapacity();
    }

    /**
     * Count the available retrieval connections.
     * 
     * @return Long
     */
    public Long countAvailableRetrievalConnections() {
        return (long) retrievalConnectionManager.getTotalStats().getAvailable();
    }

    /**
     * Count the leased retrieval connections.
     * 
     * @return Long
     */
    public Long countLeasedRetrievalConnections() {
        return (long) retrievalConnectionManager.getTotalStats().getLeased();
    }

    /**
     * Count the pending retrieval connections.
     * 
     * @return Long
     */
    public Long countPendingRetrievalConnections() {
        return (long) retrievalConnectionManager.getTotalStats().getPending();
    }

    /**
     * Count the maximum retrieval connections.
     * 
     * @return Long
     */
    public Long countMaximumRetrievalConnections() {
        return (long) retrievalConnectionManager.getTotalStats().getMax();
    }

    /**
     * Count the available enricher connections.
     * 
     * @return Long
     */
    public Long countAvailableEnricherConnections() {
        return (long) enricherConnectionManager.getTotalStats().getAvailable();
    }

    /**
     * Count the leased enricher connections.
     * 
     * @return Long
     */
    public Long countLeasedEnricherConnections() {
        return (long) enricherConnectionManager.getTotalStats().getLeased();
    }

    /**
     * Count the pending enricher connections.
     * 
     * @return Long
     */
    public Long countPendingEnricherConnections() {
        return (long) enricherConnectionManager.getTotalStats().getPending();
    }

    /**
     * Count the maximum enricher connections.
     * 
     * @return Long
     */
    public Long countMaximumEnricherConnections() {
        return (long) enricherConnectionManager.getTotalStats().getMax();
    }
}