Skip to content

Instantly share code, notes, and snippets.

View nsengupta's full-sized avatar

Nirmalya Sengupta nsengupta

View GitHub Profile
@nsengupta
nsengupta / JSON-F1450.schema
Created March 30, 2015 11:00
F1450 Schma (WIP)
{
"schema": "http://json-schema.org/draft-04/schema#",
"title": "F1450FormFields",
"description": "Representation of the fields from ClaimForm F1450",
"type": "object",
"definitions": {
"IHTDetails" :{
"type": "object",
"properties":
{
@nsengupta
nsengupta / Example-LDiEdge
Created July 17, 2015 17:01
Example of creating a labeled, directed edge
def setRelationWithLabel(source: LobbyNode,target: LobbyNode,label: String) =
LDiEdge(source, target)(label)
@nsengupta
nsengupta / LDiEdge-P-T
Created July 17, 2015 17:22
Setting Two-way relationship between two Nodes
IndexedSeq[LDiEdge[LobbyNode]](
setRelationWithLabel(p,t,"IsPlayingAt"),
setRelationWithLabel(t,p,"seatOccupiedBy")
)
@nsengupta
nsengupta / add-list-triples
Created July 17, 2015 17:33
Example of adding Node-Edge-Node triples to a graph
def assignPlayersToTable(pairs: List[(Player,GameTable)]) = {
lobby = lobby ++
pairs.foldLeft(IndexedSeq[LDiEdge[LobbyNode]]())((holder,nextPair) => {
val rootToPlayer = setRelationWithLabel(playerRootNode,nextPair._1,"IsAPlayer")
val playerToRoot = setRelationWithLabel(nextPair._1,playerRootNode,"RootedAt")
(holder :+ rootToPlayer :+ playerToRoot) ++ giveSeatToPlayer(nextPair._1,nextPair._2)
}).toList
}
@nsengupta
nsengupta / add-list-triples
Created July 17, 2015 17:36
Example of adding Node-Edge-Node triples to a graph
def assignPlayersToTable(pairs: List[(Player,GameTable)]) = {
lobby = lobby ++
pairs.foldLeft(IndexedSeq[LDiEdge[LobbyNode]]())((holder,nextPair) => {
(holder :+ rootToPlayer :+ playerToRoot) ++ giveSeatToPlayer(nextPair._1,nextPair._2)
}).toList
}
def giveSeatToPlayer(p: Player, t: GameTable) = {
IndexedSeq[LDiEdge[LobbyNode]](
setRelationWithLabel(p,t,"IsPlayingAt"),
@nsengupta
nsengupta / add-list-triples
Created July 17, 2015 17:38
Example of adding Node-Edge-Node triples to a graph
def assignPlayersToTable(pairs: List[(Player,GameTable)]) = {
lobby = lobby ++
pairs.foldLeft(IndexedSeq[LDiEdge[LobbyNode]]())((holder,nextPair) => {
(holder) ++ giveSeatToPlayer(nextPair._1,nextPair._2)
}).toList
}
def giveSeatToPlayer(p: Player, t: GameTable) = {
IndexedSeq[LDiEdge[LobbyNode]](
@nsengupta
nsengupta / gist:2a99819895ae0e9a9563
Created July 17, 2015 17:43
Logic to retrieve all players sitting on a given table.
def retrieveAllPlayersOnTable(tableToSearch: GameTable) = {
val innerTableNode = retrieveAllTablesInner
.view
.filter(nextTable => nextTable == tableToSearch)
.head
innerTableNode.outgoing
.view.filter(nextOut => nextOut.label == "seatOccupiedBy")
.view.map(e => e.target)
@nsengupta
nsengupta / retrieve-tables-of-player
Created July 18, 2015 02:08
Retrieving the tables (possibly multiple) tables, a player is playing at
def retrieveTablesPlayerIsAt(p: Player) = {
lobby.get(p).outgoing.view
.filter(e => e.label == "IsPlayingAt")
.map(e => e.target)
.map(_.value)
.collect { case t: GameTable => t }
.toList
}
@nsengupta
nsengupta / CB_Reqestor_ask_Handling.java
Last active April 9, 2017 08:02
CircuitBreaker: Requestor's handling of ask() responses
PatternsCS.pipe(
PatternsCS.ask(
circuitBreakerJeeves,
new InteractionProtocol.RetrievableClubIDMessageWithFinalDeliveryAddress(
clubID, getSender()
),
ASK_TIMEOUT
)
.handle((messageOK, exceptionReported) -> {
@nsengupta
nsengupta / CB_Requestor_handle_self_messages.java
Created April 9, 2017 08:07
CircuitBreaker: Requestor's receive function handles self-directed messages
if ( arg0 instanceof ClubDetailsFromXternalSource) {
ClubDetailsFromXternalSource m = (ClubDetailsFromXternalSource)arg0;
ActorRef originalSender = m.originallyAskedBy;
String details = m.clubInfoAsJSON;
originalSender.tell (details, getSelf());
} else
if ( arg0 instanceof TimedOutClubDetails ) {
TimedOutClubDetails m = (TimedOutClubDetails) arg0;
m.toBSentTo.tell("Service unresponsive, try again later", getSelf());