This repository has been archived by the owner on Jun 12, 2020. It is now read-only.
-
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.
Add the facility to override the request timeout per include and rout…
…e. (#28)
- Loading branch information
Showing
20 changed files
with
294 additions
and
71 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
50 changes: 50 additions & 0 deletions
50
src/main/java/com/rewedigital/composer/composing/FetchContext.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,50 @@ | ||
package com.rewedigital.composer.composing; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.time.Duration; | ||
import java.util.Optional; | ||
|
||
/** | ||
* A simple parameter object for {@link ContentFetcher}s. | ||
*/ | ||
public class FetchContext { | ||
|
||
private final String path; | ||
private final String fallback; | ||
private final Optional<Duration> ttl; | ||
|
||
private FetchContext(final String path, final String fallback, final Optional<Duration> ttl) { | ||
this.path = path; | ||
this.fallback = fallback; | ||
this.ttl = requireNonNull(ttl); | ||
} | ||
|
||
/** | ||
* Builds a simple parameter object for {@link ContentFetcher}s. | ||
* | ||
* @param path to fetch from. | ||
* @param fallback the fallback returned in case of an error. | ||
* @param ttl how long the fetch should take. | ||
* @return the parameter object. | ||
*/ | ||
public static FetchContext of(final String path, final String fallback, final Optional<Duration> ttl) { | ||
return new FetchContext(path, fallback, ttl); | ||
} | ||
|
||
public boolean hasEmptyPath() { | ||
return path == null || path().trim().isEmpty(); | ||
} | ||
|
||
public String path() { | ||
return path; | ||
} | ||
|
||
public String fallback() { | ||
return fallback; | ||
} | ||
|
||
public Optional<Duration> ttl() { | ||
return ttl; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,63 @@ | ||
package com.rewedigital.composer.routing; | ||
|
||
import java.time.Duration; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
public class Match { | ||
|
||
private final String backend; | ||
private final Optional<Duration> ttl; | ||
private final RouteTypeName routeType; | ||
|
||
private Match(final String backend, final RouteTypeName routeType) { | ||
private Match(final String backend, final Optional<Duration> ttl, final RouteTypeName routeType) { | ||
this.backend = backend; | ||
this.ttl = ttl; | ||
this.routeType = routeType; | ||
} | ||
|
||
public static Match of(final String backend, final RouteTypeName routeType) { | ||
return new Match(backend, routeType); | ||
return new Match(backend, Optional.empty(), routeType); | ||
} | ||
|
||
public static Match of(final String backend, final Duration ttl, final RouteTypeName routeType) { | ||
return new Match(backend, Optional.of(ttl), routeType); | ||
} | ||
|
||
public static Match of(final String backend, final Optional<Duration> ttl, final RouteTypeName routeType) { | ||
return new Match(backend, ttl, routeType); | ||
} | ||
|
||
public String backend() { | ||
return backend; | ||
} | ||
|
||
public Optional<Duration> ttl() { | ||
return ttl; | ||
} | ||
|
||
public RouteType routeType(final RouteTypes routeTypes) { | ||
return routeType.from(routeTypes); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(backend, routeType); | ||
return Objects.hash(backend, ttl, routeType); | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object obj) { | ||
if (this == obj) | ||
if (this == obj) { | ||
return true; | ||
if (obj == null) | ||
} | ||
if (obj == null) { | ||
return false; | ||
if (getClass() != obj.getClass()) | ||
} | ||
if (getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
final Match other = (Match) obj; | ||
return Objects.equals(backend, other.backend) && routeType == other.routeType; | ||
return Objects.equals(backend, other.backend) && routeType == other.routeType && Objects.equals(ttl, other.ttl); | ||
} | ||
|
||
|
||
} |
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.