akka.stream.alpakka.geode.internal.GeodeCache.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of akka-stream-alpakka-geode_2.11 Show documentation
Show all versions of akka-stream-alpakka-geode_2.11 Show documentation
Alpakka is a Reactive Enterprise Integration library for Java and Scala, based on Reactive Streams and Akka.
/*
* Copyright (C) 2016-2018 Lightbend Inc.
*/
package akka.stream.alpakka.geode.internal
import akka.stream.alpakka.geode.GeodeSettings
import akka.stream.alpakka.geode.internal.pdx.DelegatingPdxSerializer
import org.apache.geode.cache.client.{ClientCache, ClientCacheFactory}
import org.apache.geode.pdx.PdxSerializer
/**
* Base of all geode client.
*
*/
abstract class GeodeCache(geodeSettings: GeodeSettings) {
private lazy val serializer = new DelegatingPdxSerializer(geodeSettings.pdxCompat)
protected def registerPDXSerializer[V](pdxSerializer: PdxSerializer, clazz: Class[V]): Unit =
serializer.register(pdxSerializer, clazz)
/**
* This method will overloaded to provide server event subscription.
*
* @return
*/
protected def configure(factory: ClientCacheFactory): ClientCacheFactory
/**
* Return ClientCacheFactory:
*
* - with PDX support
* - configured by sub classes
* - customized by client application
*
*
*/
final protected def newCacheFactory(): ClientCacheFactory = {
val factory = configure(new ClientCacheFactory().setPdxSerializer(serializer))
geodeSettings.configure.map(_(factory)).getOrElse(factory)
}
lazy val cache: ClientCache = newCacheFactory().create()
def close(keepAlive: Boolean = false): Unit = cache.close(keepAlive)
}