Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust to new APIs #735

Merged
merged 2 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading