Skip to content

Commit

Permalink
bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
sanity committed Jul 9, 2018
1 parent 09ff8fa commit 26d51a2
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 8 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'io.kweb'
version '0.2.17'
version '0.2.18'

buildscript {
ext.kotlin_version = '1.2.50'
Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/io/kweb/shoebox/OrderedViewSet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ class OrderedViewSet<T : Any>(val view : View<T>, val viewKey : String, val comp
removeListeners.values.forEach { it(binarySearchResult.index, keyValue) }
orderedList.removeAt(binarySearchResult.index)
}
is Between -> throw RuntimeException("remove listener called for unknown value")
is Between -> {
throw RuntimeException("$keyValue not found in orderedList $orderedList")
}
}
} else {
// On very rare occasions the View callback doesn't supply the value that was removed, in this case
Expand Down
8 changes: 5 additions & 3 deletions src/main/kotlin/io/kweb/shoebox/stores/DirectoryStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package io.kweb.shoebox.stores
import com.fatboyindustrial.gsonjavatime.Converters
import com.google.common.cache.*
import com.google.gson.GsonBuilder
import com.google.gson.reflect.TypeToken
import io.kweb.shoebox.*
import java.nio.file.*
import java.nio.file.attribute.FileTime
import java.time.Duration
import java.util.concurrent.TimeUnit
import kotlin.reflect.KClass



/**
* Created by ian on 3/22/17.
*/
Expand All @@ -22,7 +22,9 @@ class DirectoryStore<T : Any>(val directory : Path, private val kc : KClass<T>)
const private val LOCK_FILENAME = "shoebox.lock"
const private val LOCK_TOUCH_TIME_MS = 2000.toLong()
const private val LOCK_STALE_TIME = LOCK_TOUCH_TIME_MS * 2
private val gson = Converters.registerAll(GsonBuilder()).create()
private val gson = Converters.registerAll(GsonBuilder()).let {
it.registerTypeAdapter(object : TypeToken<Duration>() {}.type, DurationConverter())
}.create()
}

internal val cache: LoadingCache<String, T?> = CacheBuilder.newBuilder().build<String, T?>(
Expand Down
46 changes: 43 additions & 3 deletions src/main/kotlin/io/kweb/shoebox/utils.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package io.kweb.shoebox

import com.google.gson.*
import io.kweb.shoebox.BinarySearchResult.*
import java.nio.file.Files
import java.nio.file.OpenOption
import java.nio.file.Path
import java.lang.reflect.Type
import java.nio.file.*
import java.time.*
import java.time.format.DateTimeFormatter
import java.util.*
import java.util.concurrent.Executors
import java.util.concurrent.atomic.AtomicLong
Expand Down Expand Up @@ -81,4 +83,42 @@ private fun toBinarySearchResult(result: Int): BinarySearchResult {
val insertionPoint = -result - 1
Between(insertionPoint - 1, insertionPoint)
}
}


/**
* GSON serialiser/deserialiser for converting [Instant] objects.
*/
class DurationConverter : JsonSerializer<Duration>, JsonDeserializer<Duration> {

override fun serialize(src: Duration, typeOfSrc: Type, context: JsonSerializationContext): JsonElement {
return JsonPrimitive(src.toMillis())
}

/**
* Gson invokes this call-back method during deserialization when it encounters a field of the
* specified type.
*
*
*
* In the implementation of this call-back method, you should consider invoking
* [JsonDeserializationContext.deserialize] method to create objects
* for any non-trivial field of the returned object. However, you should never invoke it on the
* the same type passing `json` since that will cause an infinite loop (Gson will call your
* call-back method again).
*
* @param json The Json data being deserialized
* @param typeOfT The type of the Object to deserialize to
* @return a deserialized object of the specified type typeOfT which is a subclass of `T`
* @throws JsonParseException if json is not in the expected format of `typeOfT`
*/
@Throws(JsonParseException::class)
override fun deserialize(json: JsonElement, typeOfT: Type, context: JsonDeserializationContext): Duration {
return Duration.ofNanos(json.asLong)
}

companion object {
/** Formatter. */
private val FORMATTER = DateTimeFormatter.ISO_INSTANT
}
}

0 comments on commit 26d51a2

Please sign in to comment.