S4-服务的启动和具体示例的运行(单节点)

[quote="AliKevin"]
本系列文章不涉及过多的S4的理论内容,因为s4论文中描述相当清楚(我认为我实在是说的不会比论文中更清楚了:)呵呵),论文信息请看论文[url]http://dl.iteye.com/topics/download/704e5924-0dd8-34df-b44f-2efbc91de071[/url][/quote]

这一节我们主要运行一下官方提供的两个实例,主要关注s4的功能,故以单节点的方式演示s4的实例功能。

[b]一.speech01 示例[/b]

speech01 简单的监听事件流的产生,并将事件流的相关内容打印到控制台上。执行如下代码进行示例的运行:

a.启动s4服务
[code]
root@slave:/kevin/s4/build/s4-image# rm -fr $S4_IMAGE/s4-core/conf/lock/*
root@slave:/kevin/s4/build/s4-image# rm -fr $S4_IMAGE/s4-apps/*
root@slave:/kevin/s4/build/s4-image# cp -r $S4_IMAGE/s4-example-apps/s4-example-
speech01 $S4_IMAGE/s4-apps/
$S4_IMAGE/scripts/start-s4.sh -r client-adapter (这里没有带&,非后台启动)
....
....
kevin/s4/build/s4-image/s4-apps -e /kevin/s4/build/s4-image/s4-exts -t default -d wall
appName=s4
dequeuer number: 6
[]
[/kevin/s4/build/s4-image/s4-apps/s4-example-speech01/s4-example-speech01-conf.xml]
Adding processing element with bean name eventCatcher, id eventCatcher
adding pe: io.s4.example.speech01.SentenceReceiverPE@987a33
Using ConMapPersister ..
[/code]
如上信息证明服务已经启动成功,并加载了s4-example-speech01-conf.xml应用配置。再打开一个shell窗口,用以启动adapter.

b.启动adapter服务
[code]
root@slave:/kevin/s4# $S4_IMAGE/scripts/run-client-adapter.sh -s client-adapter \
> -g s4 -d $S4_IMAGE/s4-core/conf/default/client-stub-conf.xml
...
...
lt -c /kevin/s4/build/s4-image/s4-core -d /kevin/s4/build/s4-image/s4-core/conf/default/client-stub-conf.xml
appName=client-adapter
dequeuer number: 12
Adding InputStub genericStub
Adding OutputStub genericStub
[/code]
如上信息证明adapter已经启动成功。

c.查看一下日志

重新启动一个shell,执行如下命令:[code]
root@slave:/kevin/s4/build/s4-image/s4-core# cd $S4_IMAGE
root@slave:/kevin/s4/build/s4-image# cd s4-core/logs/s4-core
root@slave:/kevin/s4/build/s4-image/s4-core/logs/s4-core# tail -f *.log
.....
2011-10-17 00:15:39,493 s4 INFO (Dispatcher.java:95) Event count is 0; rate 0.0
2011-10-17 00:15:39,493 s4 INFO (Dispatcher.java:97) Raw event count is 0; rate 0.0
2011-10-17 00:15:39,498 s4 INFO (Dispatcher.java:95) Event count is 0; rate 0.0
2011-10-17 00:15:39,499 s4 INFO (Dispatcher.java:97) Raw event count is 0; rate 0.0
2011-10-17 00:15:39,592 s4 INFO (Dispatcher.java:95) Event count is 0; rate 0.0
2011-10-17 00:15:39,593 s4 INFO (Dispatcher.java:97) Raw event count is 0; rate 0.0
2011-10-17 00:15:39,626 s4 INFO (Watcher.java:85) 0 waiting processing
2011-10-17 00:15:39,626 s4 INFO (Watcher.java:90) Total: 837222400, max 2095
....[/code]
如果没有异常发生证明我们服务和应用已经成功部署,接下来我们可以发布事件了。:)

d.加载测试数据,产生事件流。

我们的测试数据来源于$S4_IMAGE/s4-example-testinput/speeches.txt 文件,s4为我们提供了数据加载工具。重新打开一个shell窗口,执行如下命令:[code]
root@slave:~# head -20 $S4_IMAGE/s4-example-testinput/speeches.txt | sh $S4_IMAGE/s4-tools-loadgenerator/scripts/generate-load.sh -r 2 -a localhost:2334 -d 1500 -
[: 27: ==: unexpected operator
[: 57: xlocalhost:2334: unexpected operator
[: 61: x2: unexpected operator
[: 65: x1500: unexpected operator
[: 69: x: unexpected operator
{0=io.s4.tools.loadgenerator.LoadGenerator$EventTypeInfo@60420f, 1=io.s4.tools.loadgenerator.LoadGenerator$EventTypeInfo@19106c7, 2=io.s4.tools.loadgenerator.LoadGenerator$EventTypeInfo@540408}
Emitted 19 events
root@slave:~#[/code]
同时查看s4服务的shell窗口会打印如下信息:[code]
...
Sentence is 'But in a larger sense, we cannot dedicate, we cannot consecrate, we cannot hallow this ground.', location null
Sentence is 'The brave men, living and dead who struggled here have consecrated it far above our poor power to add or detract.', location null
Sentence is 'The world will little note nor long remember what we say here, but it can never forget what they did here.', location null
Sentence is 'It is for us the living rather to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced.', location null
...[/code]

e.speech01的事件处理流程如下:
[img]http://dl.iteye.com/upload/attachment/572276/c1e94c5a-a8df-3b8f-9da6-251cf6c156ca.png[/img]

f.这些信息证明我们的speech01示例已经运行成功。该示例的整体运行截图如下:
[img]http://dl.iteye.com/upload/attachment/572272/a3618ee0-8c00-326c-bec0-4470c1f83b4c.jpg[/img]

[b] 二、speech02 示例[/b]

speech02 示例主要是接收 Sentence 事件和Speech事件,并且Sentenc事件会结合(join)Speech事件,获取Sentence所对应的属性(location)。
  运行如下操作进行speech20示例的演示:

a.启动s4服务
[code]
root@slave:/kevin/s4/build/s4-image# rm -fr $S4_IMAGE/s4-apps/*
root@slave:/kevin/s4/build/s4-image# rm $S4_IMAGE/s4-core/logs/s4-core/*
root@slave:/kevin/s4/build/s4-image# rm $S4_IMAGE/s4-core/lock/*
root@slave:/kevin/s4/build/s4-image# cp -r $S4_IMAGE/s4-example-apps/s4-example-speech02 $S4_IMAGE/s4-apps/
root@slave:/kevin/s4/build/s4-image# $S4_IMAGE/scripts/start-s4.sh -r client-adapter
appName=s4
dequeuer number: 6
[]
[/kevin/s4/build/s4-image/s4-apps/s4-example-speech02/s4-example-speech02-conf.xml]
Adding processing element with bean name eventCatcher, id eventCatcher
adding pe: io.s4.example.speech01.SentenceReceiverPE@c2ee15
Using ConMapPersister ..
Adding processing element with bean name rerouteSentencePE, id rerouteSentencePE
adding pe: io.s4.processor.ReroutePE@149105b
Using ConMapPersister ..
Adding processing element with bean name rerouteSpeechPE, id rerouteSpeechPE
adding pe: io.s4.processor.ReroutePE@196f4b5
Using ConMapPersister ..
Adding processing element with bean name sentenceJoinPE, id sentenceJoinPE
adding pe: io.s4.processor.JoinPE@1bfc4fc
Using ConMapPersister ..[/code]
如上信息说明s4已经启动并且加载了speech02的配置文件[]

b.启动.启动adapter服务
[code]
root@slave:/kevin/s4# $S4_IMAGE/scripts/run-client-adapter.sh -s client-adapter -g s4 -d $S4_IMAGE/s4-core/conf/default/client-stub-conf.xml
...
...
t default -c /kevin/s4/build/s4-image/s4-core -d /kevin/s4/build/s4-image/s4-core/conf/default/client-stub-conf.xml
appName=client-adapter
dequeuer number: 12
Adding InputStub genericStub
Adding OutputStub genericStub
[/code]
如上证明adapter已经启动。

c.查看一下日志

重新启动一个shell,执行如下命令:[code]
root@slave:/kevin/s4/build/s4-image/s4-core# cd $S4_IMAGE
root@slave:/kevin/s4/build/s4-image# cd s4-core/logs/s4-core
root@slave:/kevin/s4/build/s4-image/s4-core/logs/s4-core# tail -f *.log
.....
0.0
2011-10-17 01:07:26,552 s4 INFO (PEContainer.java:348) PE count 0
2011-10-17 01:07:26,575 s4 INFO (Watcher.java:85) 0 waiting processing
2011-10-17 01:07:26,575 s4 INFO (Watcher.java:90) Total: 837222400, max 2095513600, free 827424576
2011-10-17 01:07:26,940 s4 INFO (Dispatcher.java:95) Event count is 0; rate 0.0
2011-10-17 01:07:26,945 s4 INFO (Dispatcher.java:97) Raw event count is 0; rate 0.0

==> s4-core_8924.log <==
2011-10-17 01:07:32,032 s4 INFO (Dispatcher.java:95) Event count is 0; rate 0.0
2011-10-17 01:07:32,032 s4 INFO (Dispatcher.java:97) Raw event count is 0; rate 0.0
....[/code]
如果没有异常发生证明我们服务和应用已经成功部署,接下来我们可以发布事件了。:)

d.加载测试数据,发布事件流[code]
root@slave:~# head -30 $S4_IMAGE/s4-example-testinput/speeches.txt | sh $S4_IMAGE/s4-tools-loadgenerator/scripts/generate-load.sh -r 2 -a localhost:2334 -d 1500 -
[: 27: ==: unexpected operator
[: 57: xlocalhost:2334: unexpected operator
[: 61: x2: unexpected operator
[: 65: x1500: unexpected operator
[: 69: x: unexpected operator
{0=io.s4.tools.loadgenerator.LoadGenerator$EventTypeInfo@60420f, 1=io.s4.tools.loadgenerator.LoadGenerator$EventTypeInfo@19106c7, 2=io.s4.tools.loadgenerator.LoadGenerator$EventTypeInfo@540408}
Emitted 29 events[/code]
同时查看s4控制台信息如下:[code]
...
Sentence is 'This is preeminently the time to speak the truth, the whole truth, frankly and boldly.', location washington, dc, us
Sentence is 'Nor need we shrink from honestly facing conditions in our country today.', location washington, dc, us
Sentence is 'This great Nation will endure, as it has endured, will revive and will prosper.', location washington, dc, us
Sentence is 'So, first of all, let me assert my firm belief that the only thing we have to fear is fear itself -- nameless, unreasoning, unjustified terror which paralyzes needed efforts to convert retreat into advance.', location washington, dc, us
...[/code]此时打印的信息和speech01相似,只是在location中有了不是null而是具体的信息。如: location washington, dc, us

e.speech02的事件处理流程如下:

[img]http://dl.iteye.com/upload/attachment/572278/d860d8e6-a679-30bc-8721-02c8c93dc385.png[/img]

f.这些信息证明我们的speech02示例已经运行成功。该示例的整体运行截图如下:


[img]http://dl.iteye.com/upload/attachment/572274/5bab221d-9e6f-3053-93b1-90045fb5792e.jpg[/img]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值