-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from swisspush/going_async
Execute log transformation in "executeBlocking" code blocks
- Loading branch information
Showing
12 changed files
with
425 additions
and
142 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
69 changes: 69 additions & 0 deletions
69
src/main/java/org/swisspush/logtransformer/strategy/DefaultTransformStrategyFinder.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,69 @@ | ||
package org.swisspush.logtransformer.strategy; | ||
|
||
import io.vertx.core.MultiMap; | ||
import io.vertx.core.Vertx; | ||
import io.vertx.core.logging.Logger; | ||
import io.vertx.core.logging.LoggerFactory; | ||
|
||
/** | ||
* Default implementation of the {@link TransformStrategyFinder} | ||
* | ||
* @author https://github.com/mcweba [Marc-Andre Weber] | ||
*/ | ||
public class DefaultTransformStrategyFinder implements TransformStrategyFinder { | ||
|
||
private final String strategyHeader; | ||
private final Logger log = LoggerFactory.getLogger(DefaultTransformStrategyFinder.class); | ||
|
||
private Vertx vertx; | ||
|
||
private DoNothingTransformStrategy doNothingTransformStrategy; | ||
private SplitStorageExpandLogStrategy splitStorageExpandLogStrategy; | ||
|
||
public DefaultTransformStrategyFinder(Vertx vertx, String strategyHeader) { | ||
this.vertx = vertx; | ||
this.strategyHeader = strategyHeader; | ||
} | ||
|
||
/** | ||
* Returns the corresponding {@link TransformStrategy} implementation based on the provided header strategy property. | ||
* | ||
* @param headers the headers containing the name of the strategy | ||
* @return returns the corresponding {@link TransformStrategy} implementation or {@link DoNothingTransformStrategy} when no matching strategy was found | ||
*/ | ||
@Override | ||
public TransformStrategy findTransformStrategy(MultiMap headers){ | ||
String strategy = headers.get(strategyHeader); | ||
|
||
if(isEmpty(strategy)){ | ||
return getDoNothingTransformStrategy(); | ||
} else if("SplitStorageExpandLogStrategy".equalsIgnoreCase(strategy)){ | ||
return getSplitStorageExpandLogStrategy(); | ||
} | ||
|
||
log.warn("No log transform strategy found for value '" + strategy + "'. Using DoNothingTransformStrategy instead"); | ||
return getDoNothingTransformStrategy(); | ||
} | ||
|
||
private DoNothingTransformStrategy getDoNothingTransformStrategy(){ | ||
if(doNothingTransformStrategy == null){ | ||
doNothingTransformStrategy = new DoNothingTransformStrategy(vertx); | ||
} | ||
return doNothingTransformStrategy; | ||
} | ||
|
||
private SplitStorageExpandLogStrategy getSplitStorageExpandLogStrategy(){ | ||
if(splitStorageExpandLogStrategy == null){ | ||
splitStorageExpandLogStrategy = new SplitStorageExpandLogStrategy(vertx); | ||
} | ||
return splitStorageExpandLogStrategy; | ||
} | ||
|
||
private boolean isEmpty(String stringToTest){ | ||
if(stringToTest == null){ | ||
return true; | ||
} | ||
String trimmed = stringToTest.trim(); | ||
return trimmed.length() == 0; | ||
} | ||
} |
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.