Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose jetty thread pool details (#5871)
- Loading branch information
Alex Rodriguez
committed
Dec 13, 2017
1 parent
9cf1fdf
commit 189cfd7
Showing
4 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
modules/web/web-api/src/main/java/com/enonic/xp/web/thread/ThreadPoolInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.enonic.xp.web.thread; | ||
|
||
public interface ThreadPoolInfo | ||
{ | ||
int getThreads(); | ||
|
||
int getIdleThreads(); | ||
|
||
boolean isLowOnThreads(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
modules/web/web-jetty/src/main/java/com/enonic/xp/web/jetty/impl/ThreadPoolInfoImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
modules/web/web-jetty/src/test/java/com/enonic/xp/web/jetty/impl/ThreadPoolInfoImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() ); | ||
} | ||
} |