Skip to content

Instantly share code, notes, and snippets.

Avatar

Some Dude ericacm

View GitHub Profile
View RemoteActorResolver.scala
import java.util.concurrent.atomic.AtomicInteger
import concurrent.{Future, Promise}
import akka.actor._
import concurrent.duration._
import util.control.NoStackTrace
object RemoteActorResolver {
val resolverCount = new AtomicInteger(0)
type LookupMap = Map[ActorPath, Promise[ActorRef]]
View MyTweets.scala
import java.text.SimpleDateFormat
import twitter4j.{Paging, TwitterFactory}
import collection.JavaConverters._
object MyTweets extends App {
val twitter = TwitterFactory.getSingleton
val sdf = new SimpleDateFormat("yyyy-MM-dd")
var maxId = Long.MaxValue
(1 to 6) foreach { i =>
@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 / 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 / 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 / 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)) }
You can’t perform that action at this time.