Skip to content

Instantly share code, notes, and snippets.

Some Dude ericacm

Block or report user

Report or block ericacm

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ericacm
ericacm / oauth2_jpa_provider.scala
Created Jul 2, 2011
Security OAuth 2 Provider and JPA Domain Classes
View oauth2_jpa_provider.scala
class ProviderTokenServices(dataSource: DataSource) extends JdbcOAuth2ProviderTokenServices(dataSource) with InitializingBean {
var log: Logger = LoggerFactory.getLogger(this.getClass.getName)
@Autowired var domainManager: DomainManager = _
@Autowired var schedulerService: SchedulerService = _
@Value("${providerTokenServices.pruneSchedule:0 0 12 * * *}")
var pruneSchedule: String = _
override def storeAccessToken(token: OAuth2AccessToken, authentication: OAuth2Authentication[_ <: Authentication, _ <: Authentication]) {
View minscalaactors.scala
// ©2012 Viktor Klang
object MiniActor {
import java.util.concurrent.{ConcurrentLinkedQueue, Executor}
import java.util.concurrent.atomic.AtomicInteger
type Behavior = Any => Effect
sealed trait Effect extends (Behavior => Behavior)
case object Stay extends Effect { def apply(old: Behavior): Behavior = old }
@ericacm
ericacm / CacheSystem.scala
Created Aug 25, 2012
Auto Updating Caching System - CacheSystem
View CacheSystem.scala
class CacheSystem(name: String, updateIntervalMin: Int,
cacheManager: CacheManager) {
var caches = List.empty[Cache]
val actorSystem = ActorSystem("cache_" + name)
val DEFAULT_TTL_SEC = 86400 // 1 day
def addCache(name: String, size: Int,
ttlSeconds: Int = DEFAULT_TTL_SEC): Cache = {
@ericacm
ericacm / CachingBusinessService.scala
Created Aug 25, 2012
Auto Updating Caching System - CachingBusinessService
View CachingBusinessService.scala
class CachingBusinessService(bizService: BusinessService)
extends BusinessService {
implicit val timeout = Timeout(60 seconds)
val service1CacheActor =
cacheSystem.createCacheActor("service1", DATE_CACHE_SIZE, 0 seconds,
new Service1CacheActor(_, _, bizService))
// ... more actors created here
@ericacm
ericacm / CacheActorObject.scala
Created Aug 25, 2012
Auto Updating Caching System - CacheActorObject.scala
View CacheActorObject.scala
object CacheActor {
case class FindValue(params: Params)
trait Params {
def cacheKey: String
}
// Thread pool used by findValueForSender()
val FUTURE_POOL_SIZE = 25
@ericacm
ericacm / CacheActor.scala
Created Aug 25, 2012
Auto Updating Caching System - CacheActor.scala
View CacheActor.scala
abstract class CacheActor[V](cacheSystem: CacheSystem)
extends Actor with Logging {
def findValueReceive: Receive = {
case FindValue(params) => findValueForSender(params, sender)
}
def findValueForSender(params: Params, sender: ActorRef) {
val key = params.cacheKey
val elem = cache.get(key)
@ericacm
ericacm / DateCacheActor.scala
Created Aug 25, 2012
Auto Updating Caching System - DateCacheActor.scala
View DateCacheActor.scala
abstract class DateCacheActor[V](cacheSystem: CacheSystem)
extends CacheActor[V](cacheSystem) {
override def receive = findValueReceive orElse {
case UpdateCacheForNow =>
updateCacheForNow()
case UpdateCacheForPreviousBusinessDay =>
updateCacheForPreviousBusinessDay()
}
@ericacm
ericacm / Service1CacheActor.scala
Created Aug 25, 2012
Auto Updating Caching System - Service1CacheActor.scala
View Service1CacheActor.scala
class Service1CacheActor(val cache: Cache, cacheSystem: CacheSystem,
bizService: BusinessService)
extends DateCacheActor[JList[Service1Result]](cacheSystem) {
override def receive = super.receive
override def updateCacheForDate(date: Date) {
import DateCacheActor._
Future { findObject(new Service1Params(date, true)) }
Future { findObject(new Service1Params(date, false)) }
@ericacm
ericacm / FutureTimeoutSupport.scala
Last active Jul 11, 2016
Future timeout support
View FutureTimeoutSupport.scala
import akka.util.{Duration, NonFatal}
import akka.actor.Scheduler
import akka.dispatch.{Promise, ExecutionContext, Future}
// Copied from Akka 2.1-M1
trait FutureTimeoutSupport {
/**
* Returns a [[akka.dispatch.Future]] that will be completed with the success or failure of the provided value
* after the specified duration.
*/
You can’t perform that action at this time.