Skip to content

Commit

Permalink
Adjust to new APIs (#735)
Browse files Browse the repository at this point in the history
CR: ATM
  • Loading branch information
lbwexler authored Sep 25, 2024
1 parent c39eab8 commit aaa77c4
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package io.xh.toolbox.admin
import groovy.transform.CompileStatic
import io.xh.hoist.BaseService
import io.xh.hoist.cache.Cache
import io.xh.hoist.cache.CacheValueChanged
import io.xh.hoist.cache.CacheEntryChanged

import java.time.LocalDate

Expand All @@ -17,7 +17,7 @@ class TestCacheService extends BaseService {
private Cache<LocalDate, List> resultCache = createCache(
name: 'result',
replicate: true,
onChange: {CacheValueChanged e ->
onChange: { CacheEntryChanged e ->
logDebug(e.source.name, [key: e.key, value: e.value])
}
)
Expand All @@ -27,7 +27,7 @@ class TestCacheService extends BaseService {
expireTime: {30*SECONDS},
replicate: true,
serializeOldValue: true,
onChange: { CacheValueChanged e ->
onChange: { CacheEntryChanged e ->
logDebug(e.source.name, [key: e.key, value: e.value, oldValue: e.oldValue])
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,53 @@ package io.xh.toolbox.admin

import groovy.transform.CompileStatic
import io.xh.hoist.BaseService
import io.xh.hoist.cache.CacheValueChanged
import io.xh.hoist.cache.CachedValue
import io.xh.hoist.cachedvalue.CachedValue
import io.xh.hoist.cachedvalue.CachedValueChanged

import static io.xh.hoist.util.DateTimeUtils.SECONDS
import static io.xh.toolbox.admin.TestUtils.generatePrice
import static io.xh.toolbox.admin.TestUtils.generateResultSet
import static java.lang.Thread.sleep

@CompileStatic
class TestCachedValueService extends BaseService {

private CachedValue<List> resultValue = createCachedValue(
name: 'result',
replicate: true,
onChange: {CacheValueChanged e ->
logDebug(e.source.name, [key: e.key, value: e.value])
onChange: {CachedValueChanged e ->
logDebug(e.source.name, [value: e.value])
}
)

private CachedValue<Long> priceValue = createCachedValue(
name: 'price',
expireTime: 30*SECONDS,
replicate: true,
serializeOldValue: true,
onChange: { CacheValueChanged e ->
logDebug(e.source.name, [key: e.key, value: e.value, oldValue: e.oldValue])
onChange: { CachedValueChanged e ->
logDebug(e.source.name, [value: e.value, oldValue: e.oldValue])
}
)

private List<CachedValue<?>> allValues = [resultValue, priceValue]

void init() {
super.init()
initData()
if (isPrimary) initData()
resultValue.ensureAvailable()
}

private void initData() {
if (isPrimary) {
sleep(15 * SECONDS) // Simulate delay to generate results
resultValue.set(generateResultSet())
priceValue.getOrCreate {
generatePrice()
}
resultValue.set(generateResultSet())
priceValue.getOrCreate {
generatePrice()
}
resultValue.ensureAvailable()

logInfo('Values', allValues.collectEntries { [it.name, it.get()]})
logInfo('Values', allValues.collectEntries { [it.name, it.get()] })
}

void clearCaches() {
super.clearCaches()
allValues.each {it.clear()}
initData()
if (isPrimary) initData()
}

Map getAdminStats() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.esotericsoftware.kryo.KryoSerializable
import com.esotericsoftware.kryo.io.Input
import com.esotericsoftware.kryo.io.Output
import io.xh.hoist.BaseService
import io.xh.hoist.cache.CachedValue
import io.xh.hoist.cachedvalue.CachedValue
import io.xh.hoist.log.LogSupport


Expand Down
2 changes: 1 addition & 1 deletion grails-app/services/io/xh/toolbox/app/NewsService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package io.xh.toolbox.app


import io.xh.hoist.BaseService
import io.xh.hoist.cache.CachedValue
import io.xh.hoist.cachedvalue.CachedValue
import io.xh.hoist.http.JSONClient
import io.xh.toolbox.NewsItem
import org.apache.hc.client5.http.classic.methods.HttpGet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package io.xh.toolbox.portfolio

import com.hazelcast.replicatedmap.ReplicatedMap
import io.xh.hoist.BaseService
import io.xh.hoist.cache.CachedValue
import io.xh.hoist.cachedvalue.CachedValue
import io.xh.hoist.exception.DataNotAvailableException

import java.time.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class AuthenticationService extends BaseAuthenticationService {
}

def token = request.getHeader('x-xh-idt'),
tokenResult = auth0Service.validateToken(token)
tokenResult = token ? auth0Service.validateToken(token) : null
if (tokenResult) {
def user = userService.getOrCreateFromTokenResult(tokenResult)
setUser(request, user)
Expand Down

0 comments on commit aaa77c4

Please sign in to comment.