Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Refactored ServerGroup. Made acceptor and worker thread pools configu…
…rable. Eliminated synchronization when servicing requests. Extracted static inner classes.
- Loading branch information
Showing
12 changed files
with
956 additions
and
334 deletions.
There are no files selected for viewing
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
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
14 changes: 0 additions & 14 deletions
14
src/main/java/org/littleshoot/proxy/UnknownTransportProtocolError.java
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
src/main/java/org/littleshoot/proxy/UnknownTransportProtocolException.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,12 @@ | ||
package org.littleshoot.proxy; | ||
|
||
/** | ||
* This exception indicates that the system was asked to use a TransportProtocol that it didn't know how to handle. | ||
*/ | ||
public class UnknownTransportProtocolException extends RuntimeException { | ||
private static final long serialVersionUID = 1L; | ||
|
||
public UnknownTransportProtocolException(TransportProtocol transportProtocol) { | ||
super(String.format("Unknown TransportProtocol: %1$s", transportProtocol)); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/main/java/org/littleshoot/proxy/impl/CategorizedThreadFactory.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,52 @@ | ||
package org.littleshoot.proxy.impl; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.concurrent.ThreadFactory; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
/** | ||
* A ThreadFactory that adds LittleProxy-specific information to the threads' names. | ||
*/ | ||
public class CategorizedThreadFactory implements ThreadFactory { | ||
private static final Logger log = LoggerFactory.getLogger(CategorizedThreadFactory.class); | ||
|
||
private final String name; | ||
private final String category; | ||
private final int uniqueServerGroupId; | ||
|
||
private AtomicInteger threadCount = new AtomicInteger(0); | ||
|
||
/** | ||
* Exception handler for proxy threads. Logs the name of the thread and the exception that was caught. | ||
*/ | ||
private static final Thread.UncaughtExceptionHandler UNCAUGHT_EXCEPTION_HANDLER = new Thread.UncaughtExceptionHandler() { | ||
@Override | ||
public void uncaughtException(Thread t, Throwable e) { | ||
log.error("Uncaught throwable in thread: {}", t.getName(), e); | ||
} | ||
}; | ||
|
||
|
||
/** | ||
* @param name the user-supplied name of this proxy | ||
* @param category the type of threads this factory is creating (acceptor, client-to-proxy worker, proxy-to-server worker) | ||
* @param uniqueServerGroupId a unique number for the server group creating this thread factory, to differentiate multiple proxy instances with the same name | ||
*/ | ||
public CategorizedThreadFactory(String name, String category, int uniqueServerGroupId) { | ||
this.category = category; | ||
this.name = name; | ||
this.uniqueServerGroupId = uniqueServerGroupId; | ||
} | ||
|
||
@Override | ||
public Thread newThread(Runnable r) { | ||
Thread t = new Thread(r, name + "-" + uniqueServerGroupId + "-" + category + "-" + threadCount.getAndIncrement()); | ||
|
||
t.setUncaughtExceptionHandler(UNCAUGHT_EXCEPTION_HANDLER); | ||
|
||
return t; | ||
} | ||
|
||
} |
Oops, something went wrong.