All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.opentable.concurrent.ThreadPoolExecutorManagementBean Maven / Gradle / Ivy

There is a newer version: 6.0.0
Show newest version
/**
 * Copyright (C) 2012 Ness Computing, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.opentable.concurrent;

import java.time.Duration;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import org.springframework.jmx.export.annotation.ManagedAttribute;
import org.springframework.jmx.export.annotation.ManagedResource;

@ManagedResource
public class ThreadPoolExecutorManagementBean implements ExecutorServiceManagementBean
{
    private final String name;
    private final ThreadPoolExecutor service;

    ThreadPoolExecutorManagementBean(String name, ThreadPoolExecutor service)
    {
        this.name = name;
        this.service = service;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    @ManagedAttribute
    public boolean isShutdown()
    {
        return service.isShutdown();
    }

    @Override
    @ManagedAttribute
    public boolean isTerminated()
    {
        return service.isTerminated();
    }

    @Override
    @ManagedAttribute
    public boolean isTerminating()
    {
        return service.isTerminating();
    }

    @Override
    @ManagedAttribute
    public String getRejectedExecutionHandler()
    {
        return service.getRejectedExecutionHandler().toString();
    }

    @Override
    @ManagedAttribute
    public int getCorePoolSize()
    {
        return service.getCorePoolSize();
    }

    @Override
    @ManagedAttribute
    public void setCorePoolSize(int corePoolSize)
    {
        service.setCorePoolSize(corePoolSize);
    }

    @Override
    @ManagedAttribute
    public int getMaximumPoolSize()
    {
        return service.getMaximumPoolSize();
    }

    @Override
    @ManagedAttribute
    public void setMaximumPoolSize(int maximumPoolSize)
    {
        service.setMaximumPoolSize(maximumPoolSize);
    }

    @Override
    @ManagedAttribute
    public long getKeepAliveTime()
    {
        return service.getKeepAliveTime(TimeUnit.MILLISECONDS);
    }

    @Override
    @ManagedAttribute
    public void setKeepAliveTime(String keepAliveTime)
    {
        setKeepAliveTime(Duration.parse(keepAliveTime).toMillis());
    }

    @Override
    @ManagedAttribute
    public void setKeepAliveTime(long keepAliveTimeMs)
    {
        service.setKeepAliveTime(keepAliveTimeMs, TimeUnit.MILLISECONDS);
    }

    @Override
    @ManagedAttribute
    public int getQueueCurrentSize()
    {
        return service.getQueue().size();
    }

    @Override
    @ManagedAttribute
    public int getQueueRemainingSize()
    {
        return service.getQueue().remainingCapacity();
    }

    @Override
    @ManagedAttribute
    public int getCurrentPoolSize()
    {
        return service.getPoolSize();
    }

    @Override
    @ManagedAttribute
    public int getCurrentlyActiveThreads()
    {
        return service.getActiveCount();
    }

    @Override
    @ManagedAttribute
    public int getLargestPoolSize()
    {
        return service.getLargestPoolSize();
    }

    @Override
    @ManagedAttribute
    public long getEnqueuedTaskCount()
    {
        return service.getTaskCount();
    }

    @Override
    @ManagedAttribute
    public long getCompletedTaskCount()
    {
        return service.getCompletedTaskCount();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy