-
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.
- Loading branch information
Showing
21 changed files
with
93 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
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,6 +1,7 @@ | ||
dependencies { | ||
compile project(":components:rest-support") | ||
compile "org.springframework:spring-jdbc:$springVersion" | ||
compile "com.netflix.hystrix:hystrix-javanica:1.5.6" | ||
|
||
testCompile project(":components:test-support") | ||
} |
28 changes: 23 additions & 5 deletions
28
components/allocations/src/main/java/io/pivotal/pal/tracker/allocations/ProjectClient.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,18 +1,36 @@ | ||
package io.pivotal.pal.tracker.allocations; | ||
|
||
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.web.client.RestOperations; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
public class ProjectClient { | ||
|
||
private final Logger logger = LoggerFactory.getLogger(getClass()); | ||
private final Map<Long, ProjectInfo> projectsCache = new ConcurrentHashMap<>(); | ||
private final RestOperations restOperations; | ||
private final String registrationServerEndpoint; | ||
private final String endpoint; | ||
|
||
public ProjectClient(RestOperations restOperations, String registrationServerEndpoint) { | ||
this.restOperations= restOperations; | ||
this.registrationServerEndpoint = registrationServerEndpoint; | ||
this.restOperations = restOperations; | ||
this.endpoint = registrationServerEndpoint; | ||
} | ||
|
||
@HystrixCommand(fallbackMethod = "getProjectFromCache") | ||
public ProjectInfo getProject(long projectId) { | ||
return restOperations.getForObject(registrationServerEndpoint + "/projects/" + projectId, ProjectInfo.class); | ||
ProjectInfo project = restOperations.getForObject(endpoint + "/projects/" + projectId, ProjectInfo.class); | ||
|
||
projectsCache.put(projectId, project); | ||
|
||
return project; | ||
} | ||
|
||
public ProjectInfo getProjectFromCache(long projectId) { | ||
logger.info("Getting project with id {} from cache", projectId); | ||
return projectsCache.get(projectId); | ||
} | ||
} | ||
} |
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,6 +1,7 @@ | ||
dependencies { | ||
compile project(":components:rest-support") | ||
compile "org.springframework:spring-jdbc:$springVersion" | ||
compile "com.netflix.hystrix:hystrix-javanica:1.5.6" | ||
|
||
testCompile project(":components:test-support") | ||
} |
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,6 +1,7 @@ | ||
dependencies { | ||
compile project(":components:rest-support") | ||
compile "org.springframework:spring-jdbc:$springVersion" | ||
compile "com.netflix.hystrix:hystrix-javanica:1.5.6" | ||
|
||
testCompile project(":components:test-support") | ||
} |
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