forked from swisspost/gateleen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SDCISA-15833, swisspost/vertx-redisques#170] Introduce ExceptionFactory
- Loading branch information
1 parent
cd579e0
commit 7d1e970
Showing
10 changed files
with
185 additions
and
14 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
...en-core/src/main/java/org/swisspush/gateleen/core/exception/GateleenExceptionFactory.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,40 @@ | ||
package org.swisspush.gateleen.core.exception; | ||
|
||
import io.vertx.core.eventbus.ReplyException; | ||
import io.vertx.core.eventbus.ReplyFailure; | ||
|
||
|
||
/** | ||
* Applies dependency inversion for exception instantiation. | ||
* | ||
* This class did arise because we had different use cases in different | ||
* applications. One of them has the need to perform fine-grained error | ||
* reporting. Whereas in the other application this led to performance issues. | ||
* So now through this abstraction, both applications can choose the behavior | ||
* they need. | ||
* | ||
* If dependency-injection gets applied properly, an app can even provide its | ||
* custom implementation to fine-tune the exact behavior even further. | ||
*/ | ||
public interface GateleenExceptionFactory { | ||
|
||
public Exception newException(String message, Throwable cause); | ||
|
||
public ReplyException newReplyException(ReplyFailure failureType, int failureCode, String message); | ||
|
||
|
||
/** | ||
* See {@link GateleenThriftyExceptionFactory}. | ||
*/ | ||
public static GateleenExceptionFactory newGateleenThriftyExceptionFactory() { | ||
return new GateleenThriftyExceptionFactory(); | ||
} | ||
|
||
/** | ||
* See {@link GateleenWastefulExceptionFactory}. | ||
*/ | ||
public static GateleenExceptionFactory newGateleenWastefulExceptionFactory() { | ||
return new GateleenWastefulExceptionFactory(); | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
...re/src/main/java/org/swisspush/gateleen/core/exception/GateleenNoStackReplyException.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,30 @@ | ||
package org.swisspush.gateleen.core.exception; | ||
|
||
import io.vertx.core.eventbus.ReplyFailure; | ||
|
||
/** | ||
* There was once a fix in vertx for this (https://github.com/eclipse-vertx/vert.x/issues/4840) | ||
* but for whatever reason in our case we still see stack-trace recordings. Passing | ||
* this subclass to {@link io.vertx.core.eventbus.Message#reply(Object)} seems to | ||
* do the trick. | ||
*/ | ||
public class GateleenNoStackReplyException extends io.vertx.core.eventbus.ReplyException { | ||
|
||
public GateleenNoStackReplyException(ReplyFailure failureType, int failureCode, String message) { | ||
super(failureType, failureCode, message); | ||
} | ||
|
||
public GateleenNoStackReplyException(ReplyFailure failureType, String message) { | ||
this(failureType, -1, message); | ||
} | ||
|
||
public GateleenNoStackReplyException(ReplyFailure failureType) { | ||
this(failureType, -1, null); | ||
} | ||
|
||
@Override | ||
public Throwable fillInStackTrace() { | ||
return this; | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
...re/src/main/java/org/swisspush/gateleen/core/exception/GateleenNoStacktraceException.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,28 @@ | ||
package org.swisspush.gateleen.core.exception; | ||
|
||
/** | ||
* Basically same as in vertx, But adding the forgotten contructors. | ||
*/ | ||
public class GateleenNoStacktraceException extends RuntimeException { | ||
|
||
public GateleenNoStacktraceException() { | ||
} | ||
|
||
public GateleenNoStacktraceException(String message) { | ||
super(message); | ||
} | ||
|
||
public GateleenNoStacktraceException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
public GateleenNoStacktraceException(Throwable cause) { | ||
super(cause); | ||
} | ||
|
||
@Override | ||
public Throwable fillInStackTrace() { | ||
return this; | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
.../src/main/java/org/swisspush/gateleen/core/exception/GateleenThriftyExceptionFactory.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,28 @@ | ||
package org.swisspush.gateleen.core.exception; | ||
|
||
import io.vertx.core.eventbus.ReplyException; | ||
import io.vertx.core.eventbus.ReplyFailure; | ||
|
||
/** | ||
* Trades maintainability for speed. For example prefers lightweight | ||
* exceptions without stacktrace recording. It may even decide to drop 'cause' | ||
* or other details. If an app needs more error details it should use | ||
* {@link GateleenWastefulExceptionFactory}. If none of those fits the apps needs, it | ||
* can provide its own implementation. | ||
*/ | ||
class GateleenThriftyExceptionFactory implements GateleenExceptionFactory { | ||
|
||
GateleenThriftyExceptionFactory() { | ||
} | ||
|
||
public Exception newException(String message, Throwable cause) { | ||
if (cause instanceof Exception) return (Exception) cause; | ||
return new GateleenNoStacktraceException(message, cause); | ||
} | ||
|
||
@Override | ||
public ReplyException newReplyException(ReplyFailure failureType, int failureCode, String message) { | ||
return new GateleenNoStackReplyException(failureType, failureCode, message); | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
...src/main/java/org/swisspush/gateleen/core/exception/GateleenWastefulExceptionFactory.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,28 @@ | ||
package org.swisspush.gateleen.core.exception; | ||
|
||
import io.vertx.core.eventbus.ReplyException; | ||
import io.vertx.core.eventbus.ReplyFailure; | ||
|
||
/** | ||
* Trades speed for maintainability. For example invests more resources like | ||
* recording stack traces (which likely provocates more logs) to get easier | ||
* to debug error messages and better hints of what is happening. It also | ||
* keeps details like 'causes' and 'suppressed' exceptions. If an app needs | ||
* more error details it should use {@link GateleenWastefulExceptionFactory}. If none | ||
* of those fits the apps needs, it can provide its own implementation. | ||
*/ | ||
class GateleenWastefulExceptionFactory implements GateleenExceptionFactory { | ||
|
||
GateleenWastefulExceptionFactory() { | ||
} | ||
|
||
public Exception newException(String message, Throwable cause) { | ||
return new Exception(message, cause); | ||
} | ||
|
||
@Override | ||
public ReplyException newReplyException(ReplyFailure failureType, int failureCode, String message) { | ||
return new ReplyException(failureType, failureCode, message); | ||
} | ||
|
||
} |
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