Skip to content
Browse files

Merge branch 'master' of github.com:GPars/GPars

  • Loading branch information...
2 parents ed3e88f + dc3e026 commit 371b4bae83c047340bea32370a95e7930fed6706 @vaclav vaclav committed May 9, 2012
View
9 grails-doc/src/guide/GAE.gdoc
@@ -0,0 +1,9 @@
+GPars can be run on the "Google App Engine (GAE)":https://developers.google.com/appengine/ .
+It can be made part of Groovy and Java GAE applications as well as a plugged into Gaelyk.
+The small "GPars App Engine integration library":https://github.com/musketyr/gpars-appengine
+provides all the necessary infrastructure to hook GAE services into GPars.
+Although you'll be running on GAE threads and leveraging GAE timer services, the high-level abstractions remain the same.
+With a few restrictions you can still use GPars actors, dataflow, agents, parallel collections and other handy concepts.
+
+Please refer to the "GPars App Engine library":https://github.com/musketyr/gpars-appengine documentation for details
+on how to proceed with GPars on GAE.
View
2 grails-doc/src/guide/toc.yml
@@ -47,6 +47,8 @@ dataflow :
dataflow_classicExamples : Classic Examples
STM :
title : STM
+GAE :
+ title : Google App Engine Integration
tips :
title : Tips
tips_performance : Performance
View
35 ...ban/DemoKanbanFlowGameOfLifeSimple.groovy → ...ow/kanban/DemoKanbanFlowGameOfLife.groovy
@@ -30,17 +30,19 @@ import static groovyx.gpars.dataflow.ProcessingNode.node
* @author Dierk Koenig
*/
-def painter = node { boardOut, boardIn ->
+List<List<Integer>> makeBoard() { (0..9).collect { [0] * 10 } }
+
+def display = node { boardOut, boardIn ->
def board = boardIn.take()
- boardOut << board
+ boardOut << board // downstream can proceed concurrently
board.each { println it.join(' ') }
println()
}
def nextBoard = node { boardIn, boardOut ->
def board = boardIn.take()
- def out = board.collect {it.clone()}
- for (row in 1..8) {
+ def out = makeBoard()
+ for (row in 1..8) { // we could use eachParallel here but that is a different story
for (col in 1..8) {
out[row][col] = nextCellValue(board, row, col)
}
@@ -49,25 +51,28 @@ def nextBoard = node { boardIn, boardOut ->
}
int nextCellValue(board, row, col) {
- def aliveNeighbors = board[row - 1][col - 1] + board[row - 1][col] + board[row - 1][col + 1] +
- board[row] [col - 1] + board[row] [col + 1] +
- board[row + 1][col - 1] + board[row + 1][col] + board[row + 1][col + 1]
- def cell = board[row][col]
- if (cell && !(aliveNeighbors in [2, 3])) { return 0 }
- if (!cell && aliveNeighbors == 3) { return 1 }
- return cell
+ def aliveNeighbors =
+ board[row - 1][col - 1] + board[row - 1][col] + board[row - 1][col + 1] +
+ board[row + 0][col - 1] + board[row + 0][col + 1] +
+ board[row + 1][col - 1] + board[row + 1][col] + board[row + 1][col + 1]
+ switch(aliveNeighbors){
+ case 0..1 : return 0
+ case 2 : return board[row][col]
+ case 3 : return 1
+ case 4..8 : return 0
+ }
}
new KanbanFlow().with {
cycleAllowed = true
- def down = link painter to nextBoard
- def loop = link nextBoard to painter
+ def down = link display to nextBoard
+ def loop = link nextBoard to display
- def startBoard = (0..9).collect { [0] * 10 }
+ def startBoard = makeBoard()
[[1,2],[2,3],[3,1],[3,2],[3,3]].each { startBoard[it[0]][it[1]] = 1 } // glider
loop.downstream << new KanbanTray(link: loop, product: startBoard)
start()
- sleep 500
+ sleep 100
stop()
}

0 comments on commit 371b4ba

Please sign in to comment.
Something went wrong with that request. Please try again.