Last active
October 19, 2015 08:23
-
-
Save georgeOsdDev/7e27773131b4d6a4bad7 to your computer and use it in GitHub Desktop.
This file contains 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 quickstart.action | |
import scala.concurrent._ | |
import io.netty.channel.{ChannelFuture, ChannelFutureListener} | |
import xitrum.{Action, ActorAction, FutureAction, Config} | |
import xitrum.annotation.GET | |
import xitrum.etag.NotModified | |
@GET("") | |
class SiteIndex extends DefaultLayout { | |
def execute() { | |
respondView() | |
} | |
} | |
trait MyFilter { | |
this: Action => | |
beforeFilter { | |
logging("Before filter") | |
} | |
afterFilter { | |
logging("After filter") | |
} | |
aroundFilter { action => | |
logging("Before around filter") | |
action() | |
logging("After around filter") | |
} | |
def logging(msg: String) { | |
log.info(System.currentTimeMillis() + " " + msg + " : " + response.getStatus.code + " " + response.content.toString(Config.xitrum.request.charset)) | |
} | |
} | |
@GET("sync") | |
class SyncAction extends Action with MyFilter { | |
def execute(){ | |
NotModified.setNoClientCache(response) | |
logging("Sync action begin of execute") | |
logging("Sync action before respondText") | |
respondText("SYNC") | |
.addListener(new ChannelFutureListener { | |
def operationComplete(f: ChannelFuture) { | |
logging("Sync action complete respondText") | |
} | |
}) | |
logging("Sync action after respondText") | |
logging("Sync action end of execute") | |
} | |
} | |
@GET("async") | |
class ASyncAction extends Action with MyFilter { | |
def execute(){ | |
NotModified.setNoClientCache(response) | |
logging("Async action begin of execute") | |
val f = Future { | |
Thread.sleep(1000) | |
0 | |
} | |
f.onSuccess{ case _ => | |
logging("Async action before respondText") | |
respondText("ASYNC") | |
.addListener(new ChannelFutureListener { | |
def operationComplete(f: ChannelFuture) { | |
logging("Async action complete respondText ") | |
} | |
}) | |
logging("Async action after respondText ") | |
} | |
logging("Async action end of execute ") | |
} | |
} | |
@GET("syncActor") | |
class SyncActorAction extends ActorAction with MyFilter { | |
def execute(){ | |
NotModified.setNoClientCache(response) | |
logging("Sync actor action begin of execute") | |
logging("Sync actor action before respondText") | |
respondText("SYNC") | |
.addListener(new ChannelFutureListener { | |
def operationComplete(f: ChannelFuture) { | |
logging("Sync actor action complete respondText") | |
} | |
}) | |
logging("Sync actor action after respondText") | |
logging("Sync actor action end of execute") | |
} | |
} | |
@GET("asyncActor") | |
class ASyncActorAction extends ActorAction with MyFilter { | |
def execute(){ | |
NotModified.setNoClientCache(response) | |
logging("Async actor action begin of execute") | |
val f = Future { | |
Thread.sleep(1000) | |
0 | |
} | |
f.onSuccess{ case _ => | |
logging("Async actor action before respondText") | |
respondText("ASYNC") | |
.addListener(new ChannelFutureListener { | |
def operationComplete(f: ChannelFuture) { | |
logging("Async actor action complete respondText ") | |
} | |
}) | |
logging("Async actor action after respondText ") | |
} | |
logging("Async actor action end of execute ") | |
} | |
} | |
@GET("syncFuture") | |
class SyncFutureAction extends FutureAction with MyFilter { | |
def execute(){ | |
NotModified.setNoClientCache(response) | |
logging("Sync future action begin of execute") | |
logging("Sync future action before respondText") | |
respondText("SYNC") | |
.addListener(new ChannelFutureListener { | |
def operationComplete(f: ChannelFuture) { | |
logging("Sync future action complete respondText") | |
} | |
}) | |
logging("Sync future action after respondText") | |
logging("Sync future action end of execute") | |
} | |
} | |
@GET("asyncFuture") | |
class ASyncFutureAction extends FutureAction with MyFilter { | |
def execute(){ | |
NotModified.setNoClientCache(response) | |
logging("Async future action begin of execute") | |
val f = Future { | |
Thread.sleep(1000) | |
0 | |
} | |
f.onSuccess{ case _ => | |
logging("Async future action before respondText") | |
respondText("ASYNC") | |
.addListener(new ChannelFutureListener { | |
def operationComplete(f: ChannelFuture) { | |
logging("Async future action complete respondText ") | |
} | |
}) | |
logging("Async future action after respondText ") | |
} | |
logging("Async future action end of execute ") | |
} | |
} |
This file contains 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
ASyncAction: | |
----- | |
[INFO] 1445242783479 Before filter : 200 | |
[INFO] 1445242783481 Before around filter : 200 | |
[INFO] 1445242783484 Async action begin of execute : 200 | |
[INFO] 1445242783486 Async action end of execute : 200 | |
[INFO] 1445242783486 After around filter : 200 | |
[INFO] 1445242783486 After filter : 200 | |
[INFO] 0:0:0:0:0:0:0:1 GET /async -> quickstart.action.ASyncAction, 13 [ms] (async) | |
[INFO] 1445242784487 Async action before respondText : 200 | |
[INFO] 1445242784492 Async action after respondText : 200 ASYNC | |
[INFO] 1445242784512 Async action complete respondText : 200 | |
ASyncActorAction: | |
----- | |
[INFO] 1445242790123 Before filter : 200 | |
[INFO] 1445242790123 Before around filter : 200 | |
[INFO] 1445242790123 Async actor action begin of execute : 200 | |
[INFO] 1445242790124 Async actor action end of execute : 200 | |
[INFO] 1445242790124 After around filter : 200 | |
[INFO] 1445242790124 After filter : 200 | |
[INFO] 0:0:0:0:0:0:0:1 GET /asyncActor -> quickstart.action.ASyncActorAction, 1 [ms] (async) | |
[INFO] 1445242791126 Async actor action before respondText : 200 | |
[INFO] 1445242791126 Async actor action after respondText : 200 ASYNC | |
[INFO] 1445242791130 Async actor action complete respondText : 200 | |
ASyncFutureAction: | |
----- | |
[INFO] 1445242796771 Before filter : 200 | |
[INFO] 1445242796771 Before around filter : 200 | |
[INFO] 1445242796771 Async future action begin of execute : 200 | |
[INFO] 1445242796772 Async future action end of execute : 200 | |
[INFO] 1445242796772 After around filter : 200 | |
[INFO] 1445242796772 After filter : 200 | |
[INFO] 0:0:0:0:0:0:0:1 GET /asyncFuture -> quickstart.action.ASyncFutureAction, 1 [ms] (async) | |
[INFO] 1445242797775 Async future action before respondText : 200 | |
[INFO] 1445242797776 Async future action after respondText : 200 ASYNC | |
[INFO] 1445242797777 Async future action complete respondText : 200 | |
SyncAction | |
----- | |
[INFO] 1445242804394 Before filter : 200 | |
[INFO] 1445242804394 Before around filter : 200 | |
[INFO] 1445242804394 Sync action begin of execute : 200 | |
[INFO] 1445242804394 Sync action before respondText : 200 | |
[INFO] 1445242804395 Sync action complete respondText : 200 | |
[INFO] 1445242804395 Sync action after respondText : 200 | |
[INFO] 1445242804395 Sync action end of execute : 200 | |
[INFO] 1445242804395 After around filter : 200 | |
[INFO] 1445242804395 After filter : 200 | |
[INFO] 0:0:0:0:0:0:0:1 GET /sync -> quickstart.action.SyncAction -> 200, 2 [ms] | |
SyncActorAction: | |
----- | |
[INFO] 1445242810983 Before filter : 200 | |
[INFO] 1445242810984 Before around filter : 200 | |
[INFO] 1445242810984 Sync actor action begin of execute : 200 | |
[INFO] 1445242810984 Sync actor action before respondText : 200 | |
[INFO] 1445242810984 Sync actor action after respondText : 200 SYNC | |
[INFO] 1445242810984 Sync actor action end of execute : 200 SYNC | |
[INFO] 1445242810984 After around filter : 200 SYNC | |
[INFO] 1445242810984 After filter : 200 SYNC | |
[INFO] 0:0:0:0:0:0:0:1 GET /syncActor -> quickstart.action.SyncActorAction -> 200, 1 [ms] | |
[INFO] 1445242810985 Sync actor action complete respondText : 200 | |
SyncFutureAction: | |
----- | |
[INFO] 1445242816559 Before filter : 200 | |
[INFO] 1445242816559 Before around filter : 200 | |
[INFO] 1445242816559 Sync future action begin of execute : 200 | |
[INFO] 1445242816559 Sync future action before respondText : 200 | |
[INFO] 1445242816560 Sync future action after respondText : 200 SYNC | |
[INFO] 1445242816560 Sync future action end of execute : 200 SYNC | |
[INFO] 1445242816560 After around filter : 200 SYNC | |
[INFO] 1445242816560 After filter : 200 SYNC | |
[INFO] 0:0:0:0:0:0:0:1 GET /syncFuture -> quickstart.action.SyncFutureAction -> 200, 1 [ms] | |
[INFO] 1445242816560 Sync future action complete respondText : 200 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment