Skip to content

Commit

Permalink
Expose jetty thread pool details (#5871)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Rodriguez committed Dec 13, 2017
1 parent 9cf1fdf commit 189cfd7
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 0 deletions.
@@ -0,0 +1,10 @@
package com.enonic.xp.web.thread;

public interface ThreadPoolInfo
{
int getThreads();

int getIdleThreads();

boolean isLowOnThreads();
}
Expand Up @@ -14,6 +14,7 @@

import com.enonic.xp.status.StatusReporter;
import com.enonic.xp.web.dispatch.DispatchServlet;
import com.enonic.xp.web.thread.ThreadPoolInfo;

@Component(immediate = true, service = JettyController.class, configurationPid = "com.enonic.xp.web.jetty")
public final class JettyActivator
Expand Down Expand Up @@ -47,6 +48,7 @@ public void activate( final BundleContext context, final JettyConfig config )

publishController();
publishStatusReporter();
publishThreadPoolInfo();
}

@Deactivate
Expand Down Expand Up @@ -90,6 +92,12 @@ private void publishStatusReporter()
this.statusReporterReg = this.context.registerService( StatusReporter.class, statusReporter, new Hashtable<>() );
}

private void publishThreadPoolInfo()
{
final ThreadPoolInfoImpl threadPoolInfo = new ThreadPoolInfoImpl( this.service.server.getThreadPool() );
this.statusReporterReg = this.context.registerService( ThreadPoolInfo.class, threadPoolInfo, new Hashtable<>() );
}

@Reference
public void setDispatchServlet( final DispatchServlet dispatchServlet )
{
Expand Down
@@ -0,0 +1,34 @@
package com.enonic.xp.web.jetty.impl;

import org.eclipse.jetty.util.thread.ThreadPool;

import com.enonic.xp.web.thread.ThreadPoolInfo;

public class ThreadPoolInfoImpl
implements ThreadPoolInfo
{
private final ThreadPool threadPool;

public ThreadPoolInfoImpl( final ThreadPool threadPool )
{
this.threadPool = threadPool;
}

@Override
public int getThreads()
{
return threadPool.getThreads();
}

@Override
public int getIdleThreads()
{
return threadPool.getIdleThreads();
}

@Override
public boolean isLowOnThreads()
{
return threadPool.isLowOnThreads();
}
}
@@ -0,0 +1,51 @@
package com.enonic.xp.web.jetty.impl;

import org.eclipse.jetty.util.thread.ThreadPool;
import org.junit.Test;

import static org.junit.Assert.*;

public class ThreadPoolInfoImplTest
{

@Test
public void getThreadPoolDetails()
{
final ThreadPoolInfoImpl threadPoolInfo = new ThreadPoolInfoImpl( new ThreadPool()
{
@Override
public void join()
throws InterruptedException
{
}

@Override
public int getThreads()
{
return 1;
}

@Override
public int getIdleThreads()
{
return 2;
}

@Override
public boolean isLowOnThreads()
{
return true;
}

@Override
public void execute( final Runnable command )
{

}
} );

assertEquals( 1, threadPoolInfo.getThreads() );
assertEquals( 2, threadPoolInfo.getIdleThreads() );
assertEquals( true, threadPoolInfo.isLowOnThreads() );
}
}

0 comments on commit 189cfd7

Please sign in to comment.