This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait ConfigComponent { | |
trait Config { | |
def get[T](key: String): T | |
} | |
val config: Config | |
} | |
trait ConfigComponentImpl extends ConfigComponent { | |
class ConfigImpl extends Config { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.photon.login | |
import com.twitter.util.Future | |
trait NetClient { | |
type NetService | |
def service: NetService | |
def closeFuture: Future[this.type] |