Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
doujutun3207
flink
提交
6f8f384b
F
flink
项目概览
doujutun3207
/
flink
与 Fork 源项目一致
从无法访问的项目Fork
通知
24
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
flink
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6f8f384b
编写于
7月 14, 2014
作者:
Y
Yingjun Wu
提交者:
Stephan Ewen
8月 18, 2014
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[streaming] initiate internal state for stateful operators
上级
e547f4f8
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
211 addition
and
0 deletion
+211
-0
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/examples/wordcount/WordCountKvCounter.java
...here/streaming/examples/wordcount/WordCountKvCounter.java
+59
-0
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/state/InternalState.java
...n/java/eu/stratosphere/streaming/state/InternalState.java
+27
-0
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/state/MutableInternalState.java
...eu/stratosphere/streaming/state/MutableInternalState.java
+57
-0
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/state/MutableStateIterator.java
...eu/stratosphere/streaming/state/MutableStateIterator.java
+42
-0
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/state/StateIterator.java
...n/java/eu/stratosphere/streaming/state/StateIterator.java
+26
-0
未找到文件。
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/examples/wordcount/WordCountKvCounter.java
0 → 100644
浏览文件 @
6f8f384b
/***********************************************************************************************************************
*
* Copyright (C) 2010-2014 by the Stratosphere project (http://stratosphere.eu)
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
**********************************************************************************************************************/
package
eu.stratosphere.streaming.examples.wordcount
;
import
eu.stratosphere.api.java.tuple.Tuple2
;
import
eu.stratosphere.streaming.api.invokable.UserTaskInvokable
;
import
eu.stratosphere.streaming.api.streamrecord.StreamRecord
;
import
eu.stratosphere.streaming.state.MutableInternalState
;
public
class
WordCountKvCounter
extends
UserTaskInvokable
{
private
MutableInternalState
<
String
,
Integer
>
wordCounts
=
new
MutableInternalState
<
String
,
Integer
>();
private
String
word
=
""
;
private
Integer
count
=
0
;
// private StreamRecord streamRecord = new StreamRecord(2);
private
int
i
=
0
;
private
long
time
;
private
long
prevTime
=
System
.
currentTimeMillis
();
private
StreamRecord
outRecord
=
new
StreamRecord
(
new
Tuple2
<
String
,
Integer
>());
@Override
public
void
invoke
(
StreamRecord
record
)
throws
Exception
{
word
=
record
.
getString
(
0
);
i
++;
if
(
i
%
50000
==
0
)
{
time
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
"Counter:\t"
+
i
+
"\t----Time: "
+
(
time
-
prevTime
));
prevTime
=
time
;
}
if
(
wordCounts
.
containsKey
(
word
))
{
count
=
wordCounts
.
get
(
word
)
+
1
;
wordCounts
.
put
(
word
,
count
);
}
else
{
count
=
1
;
wordCounts
.
put
(
word
,
1
);
}
outRecord
.
setString
(
0
,
word
);
outRecord
.
setInteger
(
1
,
count
);
emit
(
outRecord
);
}
}
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/state/InternalState.java
0 → 100644
浏览文件 @
6f8f384b
/***********************************************************************************************************************
*
* Copyright (C) 2010-2014 by the Stratosphere project (http://stratosphere.eu)
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
**********************************************************************************************************************/
package
eu.stratosphere.streaming.state
;
/**
* An internal state interface that supports stateful operator.
*/
public
interface
InternalState
<
K
,
V
>
{
public
void
put
(
K
key
,
V
value
);
public
V
get
(
K
key
);
public
void
delete
(
K
key
);
public
boolean
containsKey
(
K
key
);
public
StateIterator
<
K
,
V
>
getIterator
();
}
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/state/MutableInternalState.java
0 → 100644
浏览文件 @
6f8f384b
/***********************************************************************************************************************
*
* Copyright (C) 2010-2014 by the Stratosphere project (http://stratosphere.eu)
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
**********************************************************************************************************************/
package
eu.stratosphere.streaming.state
;
import
java.util.LinkedHashMap
;
import
java.util.Map
;
/**
* The most general internal state that stores data in a mutable map.
*/
public
class
MutableInternalState
<
K
,
V
>
implements
InternalState
<
K
,
V
>
{
private
Map
<
K
,
V
>
state
=
new
LinkedHashMap
<
K
,
V
>();
@Override
public
void
put
(
K
key
,
V
value
)
{
// TODO Auto-generated method stub
state
.
put
(
key
,
value
);
}
@Override
public
V
get
(
K
key
)
{
// TODO Auto-generated method stub
return
state
.
get
(
key
);
}
@Override
public
void
delete
(
K
key
)
{
// TODO Auto-generated method stub
state
.
remove
(
key
);
}
@Override
public
boolean
containsKey
(
K
key
)
{
// TODO Auto-generated method stub
return
state
.
containsKey
(
key
);
}
@Override
public
StateIterator
<
K
,
V
>
getIterator
()
{
// TODO Auto-generated method stub
return
new
MutableStateIterator
<
K
,
V
>(
state
.
entrySet
().
iterator
());
}
}
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/state/MutableStateIterator.java
0 → 100644
浏览文件 @
6f8f384b
/***********************************************************************************************************************
*
* Copyright (C) 2010-2014 by the Stratosphere project (http://stratosphere.eu)
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
**********************************************************************************************************************/
package
eu.stratosphere.streaming.state
;
import
java.util.Iterator
;
import
java.util.Map.Entry
;
import
eu.stratosphere.api.java.tuple.Tuple2
;
public
class
MutableStateIterator
<
K
,
V
>
implements
StateIterator
<
K
,
V
>{
private
Iterator
<
Entry
<
K
,
V
>>
iterator
;
public
MutableStateIterator
(
Iterator
<
Entry
<
K
,
V
>>
iter
){
iterator
=
iter
;
}
@Override
public
boolean
hasNext
()
{
// TODO Auto-generated method stub
return
iterator
.
hasNext
();
}
@Override
public
Tuple2
<
K
,
V
>
next
()
{
// TODO Auto-generated method stub
Entry
<
K
,
V
>
entry
=
iterator
.
next
();
return
new
Tuple2
<
K
,
V
>(
entry
.
getKey
(),
entry
.
getValue
());
}
}
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/state/StateIterator.java
0 → 100644
浏览文件 @
6f8f384b
/***********************************************************************************************************************
*
* Copyright (C) 2010-2014 by the Stratosphere project (http://stratosphere.eu)
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
**********************************************************************************************************************/
package
eu.stratosphere.streaming.state
;
import
eu.stratosphere.api.java.tuple.Tuple2
;
/**
* the iterator for internal states.
*/
public
interface
StateIterator
<
K
,
V
>{
public
boolean
hasNext
();
public
Tuple2
<
K
,
V
>
next
();
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录