This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rhbz988202 - ensure when exception occur semaphore is released
- Loading branch information
Patrick Huang
committed
Mar 10, 2014
1 parent
af5e1d6
commit c891a56
Showing
14 changed files
with
249 additions
and
12 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
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
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
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
35 changes: 35 additions & 0 deletions
35
zanata-war/src/main/java/org/zanata/rest/RateLimitingAwareExceptionMapper.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,35 @@ | ||
package org.zanata.rest; | ||
|
||
|
||
/** | ||
* This should be the base of ALL REST exception mapper once we introduce rate | ||
* limiting. | ||
* | ||
* Note: I can't use template method pattern here to enforce all subclass has | ||
* called releaseSemaphore method in toResponse method. RESTeasy looks at | ||
* generic interface and grab the type out of there. Child class has to provide | ||
* a toResponse method with exact exception as argument. Therefore this class | ||
* mainly serve as an marker mechanism where there is a test to scan all | ||
* ExceptionMapper implementation and ensure they are all subclass of this type | ||
* (so that when developers implement new mapper they won't forget to call | ||
* release semaphore) | ||
* | ||
* @see <a href= | ||
* "http://stackoverflow.com/questions/13937998/resteasy-post-process-interceptor-chain-not-traversed-when-response-created-by-e">RestEasy | ||
* Post Process Interceptor chain not traversed when response created by | ||
* ExceptionMapper</a> | ||
* | ||
* @see org.jboss.resteasy.spi.ResteasyProviderFactory#addExceptionMapper(javax.ws.rs.ext.ExceptionMapper, java.lang.Class) | ||
* | ||
* @author Patrick Huang <a | ||
* href="mailto:pahuang@redhat.com">pahuang@redhat.com</a> | ||
*/ | ||
public abstract class RateLimitingAwareExceptionMapper { | ||
|
||
/** | ||
* Just remember to call this method before returning your Response. | ||
*/ | ||
protected void releaseSemaphoreBeforeReturnResponse() { | ||
RateLimiterHolder.getInstance().releaseSemaphoreForCurrentThread(); | ||
} | ||
} |
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
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
Oops, something went wrong.