Skip to content

Instantly share code, notes, and snippets.

View volgar1x's full-sized avatar

Antoine Chauvin volgar1x

View GitHub Profile
package org.photon;
import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import java.io.IOException;
import java.util.*;
public class Main {
package org.photon.common
import scala.collection.mutable
import java.util.concurrent.locks.ReentrantReadWriteLock
import java.util.concurrent.{Executors, Executor}
object Observable {
type Listener = Any => Any
}
class UserRepositoryImpl extends BaseRepository[User] with UserRepository {
val executor = self.executor
val tableName = "users"
val columns = Seq("id", "name", "password", "nickname", "secret_question", "secret_answer", "community_id", "subscription_end")
protected def create(rset: ResultSet) = User(
rset.getLong("id"),
rset.getString("name"),
rset.getString("password"),
package org.photon.login
import com.twitter.util.Future
import org.photon.common.Async
import java.sql.{PreparedStatement, Timestamp, ResultSet}
import org.joda.time.Instant
trait UserRepositoryComponentImpl extends UserRepositoryComponent { self: DatabaseComponent with ExecutorComponent =>
implicit def timestamp2instant(t: java.sql.Timestamp) = new Instant(t.getTime)
implicit def instant2timestamp(i: org.joda.time.Instant) = new Timestamp(i.getMillis)
18:37:21.052 [nioEventLoopGroup-3-1] DEBUG o.p.l.NetworkComponentImpl$NetworkLoggerImpl - connect /127.0.0.1:35522
18:37:21.064 [nioEventLoopGroup-3-1] DEBUG o.p.l.NetworkComponentImpl$NetworkLoggerImpl - send HelloConnectMessage(tsnsvgwldrmawdntiatcfqkoibdfoaui) to /127.0.0.1:35522
18:37:21.077 [nioEventLoopGroup-3-1] DEBUG o.p.l.NetworkComponentImpl$NetworkLoggerImpl - receive VersionMessage(1.29.1) from /127.0.0.1:35522
18:37:21.089 [nioEventLoopGroup-3-1] DEBUG o.p.l.NetworkComponentImpl$NetworkLoggerImpl - receive AuthenticationMessage(test,66500554) from /127.0.0.1:35522
18:37:27.291 [nioEventLoopGroup-3-1] DEBUG o.p.l.NetworkComponentImpl$NetworkLoggerImpl - send SetNicknameMessage(test) to /127.0.0.1:35522
type Transaction = mutable.Builder[Any, _]
def transaction[R](fn: Transaction => R): Future[NetworkSession] = {
val buf = List.newBuilder[Any]
fn(buf)
@tailrec
def rec(fut: Future[NetworkSession], buf: List[Any]): Future[NetworkSession] = buf match {
case head :: tail => rec(fut.flatMap(_.write(head)), tail)
case Nil => fut
/**
* should speed up Map implementations
*/
sealed class Opcode(value: String) {
if (value.length != 2)
throw new IllegalArgumentException("an opcode must be a 2 fixed length string")
def toString = value
val hashCode = value(0).toByte << 8 + value(1).toByte // must be unique
package org.photon.login
import com.twitter.util.Future
trait NetworkSession {
type TFut = Future[this.type]
type NetworkService <: org.photon.login.NetworkService
def service: NetworkService
trait ConfigComponent {
trait Config {
def get[T](key: String): T
}
val config: Config
}
trait ConfigComponentImpl extends ConfigComponent {
class ConfigImpl extends Config {
package org.photon.login
import com.twitter.util.Future
trait NetClient {
type NetService
def service: NetService
def closeFuture: Future[this.type]