From 64427c53d16ad71deb740fa81a2cb30a70fd741b Mon Sep 17 00:00:00 2001 From: minjing Date: Tue, 23 May 2017 10:48:35 +0800 Subject: [PATCH] #16 Update app API usage base on new APIs and add push script --- push.sh | 61 +++++++++++++++++++++++++++++++++++++++++++++++++ zh/basic/app.md | 60 ++++++++++++++++++++++++++++++++++++------------ 2 files changed, 106 insertions(+), 15 deletions(-) create mode 100644 push.sh diff --git a/push.sh b/push.sh new file mode 100644 index 0000000..f9865ea --- /dev/null +++ b/push.sh @@ -0,0 +1,61 @@ +#! /bin/bash + +usedBranch="" + +branches=`git branch` +oldIFS="$IFS" +IFS=' +' +lines=( $branches ) +IFS="$oldIFS" + +branch="" +for line in "${lines[@]}" +do + isCurrentBranch=false + #t=`expr substr "$line" 1 1` + t=${line:0:1} + if [ "$t" = "*" ] + then + isCurrentBranch=true + fi + #branch=`expr substr "$line" 3 "${#line}"` + branch=${line:2} + if test -z "$1" + then + if [ "$isCurrentBranch" = true ] + then + usedBranch="$branch" + break + fi + else + if [ "$1" = "$branch" ] + then + usedBranch="$branch" + break + fi + fi +done + +if test -z "$usedBranch" +then + if test -z "$1" + then + echo "Push failed: working branch was not found, are you under gir repository?" + echo "Usage: push [branch name]" + exit 1 + else + echo "Push failed: specified branch is not valid - $1" + echo "Usage: push [branch name]" + exit 1 + fi +fi + +repositories=`git remote` +for repository in ${repositories[@]} +do + echo ">>> push change to $repository for branch $usedBranch <<<" + git push $repository $1 +done + +exit 0 diff --git a/zh/basic/app.md b/zh/basic/app.md index ed231fb..68602ab 100644 --- a/zh/basic/app.md +++ b/zh/basic/app.md @@ -59,43 +59,73 @@ public class Terminator { protected IResponsibleRegistry _respReg; @Inject - protected IEventBus _eventBus; + protected ILogger _logger; @OnActivate public void activate() { IResponsible resp = this._respReg.register("Terminator"); resp.newBehavior("Do Something", AppStartupEvent.class, AppStartupEvent.TOPIC) - .then(TerminateApp.actionId) - .traceable(true) + .then(StartUp.actionId) + .onSuccess((input, ctx) -> new ExitSystemRequest("Terminator")) .build(); - BehaviorFinishedEventHandler finHandler = (event) -> new ExitSystemRequest("Terminator"); - resp.on(finHandler); + resp.newBehavior("Shutdown flow", AppShutdownEvent.class, AppShutdownEvent.TOPIC) + .then(CleanUp.actionId) + .build(); + } + + @OnDeactivate + public void deactivate() { + this._logger.info("The service is deactivated - {}", Terminator.class.getName()); } @Service @Action @Tag("Terminator") - public static class TerminateApp { + public static class StartUp { - private static final ActionIdentify actionId = ActionIdentify.toActionId(TerminateApp.class); + private static final ActionIdentify actionId = ActionIdentify.toActionId(StartUp.class); + + @Inject + protected ILogger _logger; @ActionDo - public boolean doSomething(AppStartupEvent event) throws Exception { + public void doSomething(AppStartupEvent event) throws Exception { + this._logger.info("Do start up action"); Thread.sleep(1000); - return true; + } + } + + @Service + @Action + @Tag("Terminator") + public static class CleanUp { + + private static final ActionIdentify actionId = ActionIdentify.toActionId(CleanUp.class); + + @Inject + protected ILogger _logger; + + @ActionDo + public void cleanUp(AppShutdownEvent event) { + this._logger.info("Do clean up action"); } } } ``` -该代码当应用启动后,会调用TerminateApp的Action,该Action会让现成睡眠一秒钟,然后Responsible接收到该Behavior处理结束通知,此时该Responsible向系统发出了退出应用的请求的事件,当UAPI接收到该事件后启动退出系统的动作。 +该代码当应用启动后,会调用StartUp的Action,该Action会输出一行日志,然后让线程睡眠一秒钟,然后当该Behavior处理结束后会发送ExitSystemRequest的请求,当UAPI接收到该请求后启动退出系统的动作。 +退出动作首先会发送AppShutdownEvent,所有需要清理资源的Responsible都需要定义相应的Behavior来处理资源清理的过程,当所有的资源清理的Behavior都执行完毕后,UAPI框架会调用所有Service的OnDeactivate注解标注的方法。 上述代码执行的输出: ``` -16:06:24.550 [ForkJoinPool.commonPool-worker-1] INFO u.c.internal.FileBasedConfigProvider - Config update cli.config -> conf/terminate-app-config.yaml -16:06:24.597 [ForkJoinPool.commonPool-worker-1] INFO u.c.internal.FileBasedConfigProvider - Config path is conf/terminate-app-config.yaml -16:06:24.628 [ForkJoinPool-1-worker-1] INFO uapi.app.internal.ProfileManager - Active profile is - TerminateAppProfile -16:06:24.628 [ForkJoinPool-1-worker-1] INFO uapi.app.internal.StartupApplication - The application is launched -16:06:25.629 [ForkJoinPool-1-worker-0] DEBUG u.a.internal.ApplicationConstructor - Application is going to shutdown +10:36:55.875 [ForkJoinPool.commonPool-worker-1] INFO u.c.internal.FileBasedConfigProvider - Config update cli.config -> conf/terminate-app-config.yaml +10:36:55.937 [ForkJoinPool.commonPool-worker-1] INFO u.c.internal.FileBasedConfigProvider - Config path is conf/terminate-app-config.yaml +10:36:55.953 [ForkJoinPool-1-worker-1] INFO u.a.i.ApplicationConstructor$StartupApplication - Application is going to startup... +10:36:55.953 [ForkJoinPool-1-worker-1] INFO uapi.app.internal.ProfileManager - Active profile is - TerminateAppProfile +10:36:55.969 [ForkJoinPool-1-worker-1] INFO u.a.i.ApplicationConstructor$StartupApplication - The application is launched +10:36:55.969 [ForkJoinPool-1-worker-1] INFO u.a.internal.ApplicationConstructor - Application startup success. +10:36:55.969 [ForkJoinPool-1-worker-1] INFO uapi.tutorial.app.Terminator$StartUp - Do start up action +10:36:56.975 [ForkJoinPool-1-worker-1] INFO u.a.internal.ApplicationConstructor - Application is going to shutdown... +10:36:56.975 [ForkJoinPool-1-worker-2] INFO uapi.tutorial.app.Terminator$CleanUp - Do clean up action Process finished with exit code 0 ```