Skip to content

Commit

Permalink
#16 Update app API usage base on new APIs and add push script
Browse files Browse the repository at this point in the history
  • Loading branch information
minjing committed May 23, 2017
1 parent 9043a61 commit 64427c5
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 15 deletions.
61 changes: 61 additions & 0 deletions push.sh
Original file line number Diff line number Diff line change
@@ -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
60 changes: 45 additions & 15 deletions zh/basic/app.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down

0 comments on commit 64427c5

Please sign in to comment.