-
Notifications
You must be signed in to change notification settings - Fork 18
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
42 changed files
with
834 additions
and
516 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
19 changes: 11 additions & 8 deletions
19
app/com/m3/octoparts/cache/versioning/InMemoryLatestVersionCache.scala
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,27 +1,30 @@ | ||
package com.m3.octoparts.cache.versioning | ||
|
||
import scala.collection.concurrent.TrieMap | ||
import com.google.common.cache.{ Cache, CacheBuilder } | ||
|
||
/** | ||
* A simple implementation of [[LatestVersionCache]] that holds the latest versions as Maps | ||
*/ | ||
class InMemoryLatestVersionCache extends LatestVersionCache { | ||
class InMemoryLatestVersionCache(maxCacheKeys: Long) extends LatestVersionCache { | ||
|
||
import com.m3.octoparts.cache.versioning.LatestVersionCache._ | ||
|
||
private val partVersions = new TrieMap[PartId, Version] | ||
private val paramVersions = new TrieMap[VersionedParamKey, Version] | ||
private[versioning] val partVersions = configureMemoryCache(CacheBuilder.newBuilder()).build[PartId, java.lang.Long]() | ||
private[versioning] val paramVersions = configureMemoryCache(CacheBuilder.newBuilder()).build[VersionedParamKey, java.lang.Long]() | ||
|
||
override def updatePartVersion(partId: PartId, version: Version): Unit = { | ||
def updatePartVersion(partId: PartId, version: Version): Unit = { | ||
partVersions.put(partId, version) | ||
} | ||
|
||
override def updateParamVersion(versionedParamKey: VersionedParamKey, version: Version): Unit = { | ||
def updateParamVersion(versionedParamKey: VersionedParamKey, version: Version): Unit = { | ||
paramVersions.put(versionedParamKey, version) | ||
} | ||
|
||
override def getPartVersion(partId: PartId) = partVersions.get(partId) | ||
def getPartVersion(partId: PartId) = Option(partVersions.getIfPresent(partId)).map(Long.unbox) | ||
|
||
override def getParamVersion(versionedParamKey: VersionedParamKey) = paramVersions.get(versionedParamKey) | ||
def getParamVersion(versionedParamKey: VersionedParamKey) = Option(paramVersions.getIfPresent(versionedParamKey)).map(Long.unbox) | ||
|
||
private def configureMemoryCache(builder: CacheBuilder[Object, Object]): CacheBuilder[Object, Object] = { | ||
builder.maximumSize(maxCacheKeys) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.m3.octoparts.logging | ||
|
||
import com.beachape.logging.LTSVable | ||
import com.m3.octoparts.model._ | ||
|
||
object LTSVables extends LogUtil { | ||
|
||
implicit val requestMetaLTSVable: LTSVable[RequestMeta] = new LTSVable[RequestMeta] { | ||
def toPairs(o: RequestMeta): Seq[(String, Any)] = Seq( | ||
"RequestMeta id" -> o.id, | ||
"RequestMeta requestUrl" -> o.requestUrl, | ||
"RequestMeta timeout" -> o.timeout.map(toRelevantUnit(_)), | ||
"RequestMeta serviceId" -> o.serviceId, | ||
"RequestMeta sessionId" -> o.sessionId, | ||
"RequestMeta" -> o | ||
) | ||
} | ||
|
||
implicit val aggregateRequestLTSVable: LTSVable[AggregateRequest] = new LTSVable[AggregateRequest] { | ||
def toPairs(o: AggregateRequest): Seq[(String, Any)] = | ||
requestMetaLTSVable.toPairs(o.requestMeta) :+ "Requests length" -> o.requests.length | ||
} | ||
|
||
implicit val responseMetaLTSVable: LTSVable[ResponseMeta] = new LTSVable[ResponseMeta] { | ||
def toPairs(o: ResponseMeta): Seq[(String, Any)] = Seq( | ||
"ResponseMeta id" -> o.id, | ||
"ResponseMeta processTime" -> toRelevantUnit(o.processTime), | ||
"ResponseMeta" -> o | ||
) | ||
} | ||
|
||
implicit val aggregateResponseLTSVable: LTSVable[AggregateResponse] = new LTSVable[AggregateResponse] { | ||
def toPairs(o: AggregateResponse): Seq[(String, Any)] = | ||
responseMetaLTSVable.toPairs(o.responseMeta) :+ "Responses length" -> o.responses.length | ||
} | ||
|
||
implicit val partResponseLTSVable: LTSVable[PartResponse] = new LTSVable[PartResponse] { | ||
def toPairs(o: PartResponse): Seq[(String, Any)] = Seq( | ||
"PartResponse id" -> o.id, | ||
"PartResponse partId" -> o.partId, | ||
"PartResponse errors" -> o.errors, | ||
"PartResponse warnings" -> o.warnings, | ||
"PartResponse statusCode" -> o.statusCode, | ||
"PartResponse cacheControl" -> o.cacheControl, | ||
"PartResponse retrievedFromCache" -> o.retrievedFromCache | ||
) | ||
} | ||
|
||
/** | ||
* If we need more, add more of these | ||
*/ | ||
implicit def pairsLTSVable[A: LTSVable, B: LTSVable]: LTSVable[(A, B)] = new LTSVable[(A, B)] { | ||
def toPairs(o: (A, B)): Seq[(String, Any)] = implicitly[LTSVable[A]].toPairs(o._1) ++ implicitly[LTSVable[B]].toPairs(o._2) | ||
} | ||
|
||
} |
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.