-
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.
- Loading branch information
Showing
7 changed files
with
246 additions
and
82 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
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
55 changes: 3 additions & 52 deletions
55
src/main/java/org/swisspush/logtransformer/strategy/TransformStrategyFinder.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 |
---|---|---|
@@ -1,68 +1,19 @@ | ||
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; | ||
|
||
/** | ||
* Manages the mapping of the {@link TransformStrategy} implementations to their strategy name (metadata) | ||
* | ||
* @author https://github.com/mcweba [Marc-Andre Weber] | ||
*/ | ||
public class TransformStrategyFinder { | ||
|
||
private final String strategyHeader; | ||
private final Logger log = LoggerFactory.getLogger(TransformStrategyFinder.class); | ||
|
||
private Vertx vertx; | ||
|
||
private DoNothingTransformStrategy doNothingTransformStrategy; | ||
private SplitStorageExpandLogStrategy splitStorageExpandLogStrategy; | ||
|
||
public TransformStrategyFinder(Vertx vertx, String strategyHeader) { | ||
this.vertx = vertx; | ||
this.strategyHeader = strategyHeader; | ||
} | ||
public interface TransformStrategyFinder { | ||
|
||
/** | ||
* 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 | ||
* @return returns the corresponding {@link TransformStrategy} implementation | ||
*/ | ||
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; | ||
} | ||
TransformStrategy findTransformStrategy(MultiMap headers); | ||
} |
Oops, something went wrong.