Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
doujutun3207
flink
提交
1cb9016d
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,发现更多精彩内容 >>
提交
1cb9016d
编写于
7月 14, 2014
作者:
M
Márton Balassi
提交者:
Stephan Ewen
8月 18, 2014
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[streaming] StreamComponentHelper refactor to Generics
上级
e53d45e0
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
38 addition
and
187 deletion
+38
-187
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/streamcomponent/StreamComponentFactory.java
...streaming/api/streamcomponent/StreamComponentFactory.java
+0
-168
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/streamcomponent/StreamSink.java
...tratosphere/streaming/api/streamcomponent/StreamSink.java
+8
-2
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/streamcomponent/StreamSource.java
...atosphere/streaming/api/streamcomponent/StreamSource.java
+14
-7
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/streamcomponent/StreamTask.java
...tratosphere/streaming/api/streamcomponent/StreamTask.java
+16
-10
未找到文件。
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/streamcomponent/StreamComponentFactory.java
已删除
100644 → 0
浏览文件 @
e53d45e0
package
eu.stratosphere.streaming.api.streamcomponent
;
import
java.util.List
;
import
eu.stratosphere.configuration.Configuration
;
import
eu.stratosphere.nephele.event.task.EventListener
;
import
eu.stratosphere.nephele.io.ChannelSelector
;
import
eu.stratosphere.nephele.io.RecordReader
;
import
eu.stratosphere.nephele.io.RecordWriter
;
import
eu.stratosphere.streaming.api.AckEvent
;
import
eu.stratosphere.streaming.api.AckEventListener
;
import
eu.stratosphere.streaming.api.FailEvent
;
import
eu.stratosphere.streaming.api.FailEventListener
;
import
eu.stratosphere.streaming.api.FaultTolerancyBuffer
;
import
eu.stratosphere.streaming.api.invokable.DefaultSinkInvokable
;
import
eu.stratosphere.streaming.api.invokable.DefaultTaskInvokable
;
import
eu.stratosphere.streaming.api.invokable.StreamInvokable
;
import
eu.stratosphere.streaming.api.invokable.UserSinkInvokable
;
import
eu.stratosphere.streaming.partitioner.DefaultPartitioner
;
import
eu.stratosphere.streaming.partitioner.FieldsPartitioner
;
import
eu.stratosphere.types.Key
;
import
eu.stratosphere.types.Record
;
import
eu.stratosphere.types.StringValue
;
public
final
class
StreamComponentFactory
{
public
static
void
setAckListener
(
FaultTolerancyBuffer
recordBuffer
,
String
sourceInstanceID
,
List
<
RecordWriter
<
Record
>>
outputs
)
{
EventListener
eventListener
=
new
AckEventListener
(
sourceInstanceID
,
recordBuffer
);
for
(
RecordWriter
<
Record
>
output
:
outputs
)
{
// TODO: separate outputs
output
.
subscribeToEvent
(
eventListener
,
AckEvent
.
class
);
}
}
public
static
void
setFailListener
(
FaultTolerancyBuffer
recordBuffer
,
String
sourceInstanceID
,
List
<
RecordWriter
<
Record
>>
outputs
)
{
EventListener
eventListener
=
new
FailEventListener
(
sourceInstanceID
,
recordBuffer
);
for
(
RecordWriter
<
Record
>
output
:
outputs
)
{
// TODO: separate outputs
output
.
subscribeToEvent
(
eventListener
,
FailEvent
.
class
);
}
}
// for StreamTask
public
static
int
setConfigInputs
(
StreamTask
taskBase
,
Configuration
taskConfiguration
,
List
<
RecordReader
<
Record
>>
inputs
)
{
int
numberOfInputs
=
taskConfiguration
.
getInteger
(
"numberOfInputs"
,
0
);
for
(
int
i
=
0
;
i
<
numberOfInputs
;
i
++)
{
inputs
.
add
(
new
RecordReader
<
Record
>(
taskBase
,
Record
.
class
));
}
return
numberOfInputs
;
}
// this function can be removed as duplication of the above function if
// modification on kernel is allowed.
// for StreamSink
public
static
int
setConfigInputs
(
StreamSink
taskBase
,
Configuration
taskConfiguration
,
List
<
RecordReader
<
Record
>>
inputs
)
{
int
numberOfInputs
=
taskConfiguration
.
getInteger
(
"numberOfInputs"
,
0
);
for
(
int
i
=
0
;
i
<
numberOfInputs
;
i
++)
{
inputs
.
add
(
new
RecordReader
<
Record
>(
taskBase
,
Record
.
class
));
}
return
numberOfInputs
;
}
// for StreamTask
public
static
int
setConfigOutputs
(
StreamTask
taskBase
,
Configuration
taskConfiguration
,
List
<
RecordWriter
<
Record
>>
outputs
,
List
<
ChannelSelector
<
Record
>>
partitioners
)
{
int
numberOfOutputs
=
taskConfiguration
.
getInteger
(
"numberOfOutputs"
,
0
);
for
(
int
i
=
1
;
i
<=
numberOfOutputs
;
i
++)
{
StreamComponentFactory
.
setPartitioner
(
taskConfiguration
,
i
,
partitioners
);
}
for
(
ChannelSelector
<
Record
>
outputPartitioner
:
partitioners
)
{
outputs
.
add
(
new
RecordWriter
<
Record
>(
taskBase
,
Record
.
class
,
outputPartitioner
));
}
return
numberOfOutputs
;
}
// this function can be removed as duplication of the above function if
// modification on kernel is allowed.
// for StreamSource
public
static
int
setConfigOutputs
(
StreamSource
taskBase
,
Configuration
taskConfiguration
,
List
<
RecordWriter
<
Record
>>
outputs
,
List
<
ChannelSelector
<
Record
>>
partitioners
)
{
int
numberOfOutputs
=
taskConfiguration
.
getInteger
(
"numberOfOutputs"
,
0
);
for
(
int
i
=
1
;
i
<=
numberOfOutputs
;
i
++)
{
StreamComponentFactory
.
setPartitioner
(
taskConfiguration
,
i
,
partitioners
);
}
for
(
ChannelSelector
<
Record
>
outputPartitioner
:
partitioners
)
{
outputs
.
add
(
new
RecordWriter
<
Record
>(
taskBase
,
Record
.
class
,
outputPartitioner
));
}
return
numberOfOutputs
;
}
public
static
UserSinkInvokable
setUserFunction
(
Configuration
taskConfiguration
)
{
Class
<?
extends
UserSinkInvokable
>
userFunctionClass
=
taskConfiguration
.
getClass
(
"userfunction"
,
DefaultSinkInvokable
.
class
,
UserSinkInvokable
.
class
);
UserSinkInvokable
userFunction
=
null
;
try
{
userFunction
=
userFunctionClass
.
newInstance
();
}
catch
(
Exception
e
)
{
}
return
userFunction
;
}
public
static
StreamInvokable
setUserFunction
(
Configuration
taskConfiguration
,
List
<
RecordWriter
<
Record
>>
outputs
,
String
instanceID
,
FaultTolerancyBuffer
recordBuffer
)
{
//Default value is a TaskInvokable even if it was called from a source
Class
<?
extends
StreamInvokable
>
userFunctionClass
=
taskConfiguration
.
getClass
(
"userfunction"
,
DefaultTaskInvokable
.
class
,
StreamInvokable
.
class
);
StreamInvokable
userFunction
=
null
;
try
{
userFunction
=
userFunctionClass
.
newInstance
();
userFunction
.
declareOutputs
(
outputs
,
instanceID
,
recordBuffer
);
}
catch
(
Exception
e
)
{
}
return
userFunction
;
}
public
static
void
setPartitioner
(
Configuration
taskConfiguration
,
int
nrOutput
,
List
<
ChannelSelector
<
Record
>>
partitioners
)
{
Class
<?
extends
ChannelSelector
<
Record
>>
partitioner
=
taskConfiguration
.
getClass
(
"partitionerClass_"
+
nrOutput
,
DefaultPartitioner
.
class
,
ChannelSelector
.
class
);
try
{
if
(
partitioner
.
equals
(
FieldsPartitioner
.
class
))
{
int
keyPosition
=
taskConfiguration
.
getInteger
(
"partitionerIntParam_"
+
nrOutput
,
1
);
Class
<?
extends
Key
>
keyClass
=
taskConfiguration
.
getClass
(
"partitionerClassParam_"
+
nrOutput
,
StringValue
.
class
,
Key
.
class
);
partitioners
.
add
(
partitioner
.
getConstructor
(
int
.
class
,
Class
.
class
).
newInstance
(
keyPosition
,
keyClass
));
}
else
{
partitioners
.
add
(
partitioner
.
newInstance
());
}
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"partitioner error"
+
" "
+
"partitioner_"
+
nrOutput
);
System
.
out
.
println
(
e
);
}
}
}
\ No newline at end of file
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/streamcomponent/StreamSink.java
浏览文件 @
1cb9016d
...
...
@@ -40,8 +40,14 @@ public class StreamSink extends AbstractOutputTask {
@Override
public
void
registerInputOutput
()
{
Configuration
taskConfiguration
=
getTaskConfiguration
();
StreamComponentFactory
.
setConfigInputs
(
this
,
taskConfiguration
,
inputs
);
userFunction
=
StreamComponentFactory
.
setUserFunction
(
taskConfiguration
);
StreamComponentHelper
<
StreamSink
>
streamSinkHelper
=
new
StreamComponentHelper
<
StreamSink
>();
try
{
streamSinkHelper
.
setConfigInputs
(
this
,
taskConfiguration
,
inputs
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
userFunction
=
streamSinkHelper
.
getUserFunction
(
taskConfiguration
);
}
@Override
...
...
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/streamcomponent/StreamSource.java
浏览文件 @
1cb9016d
...
...
@@ -59,15 +59,22 @@ public class StreamSource extends AbstractInputTask<RandIS> {
@Override
public
void
registerInputOutput
()
{
Configuration
taskConfiguration
=
getTaskConfiguration
();
StreamComponentFactory
.
setConfigOutputs
(
this
,
taskConfiguration
,
outputs
,
partitioners
);
recordBuffer
=
new
FaultTolerancyBuffer
(
outputs
,
sourceInstanceID
);
userFunction
=
(
UserSourceInvokable
)
StreamComponentFactory
.
setUserFunction
(
taskConfiguration
,
outputs
,
sourceInstanceID
,
StreamComponentHelper
<
StreamSource
>
streamSourceHelper
=
new
StreamComponentHelper
<
StreamSource
>();
try
{
streamSourceHelper
.
setConfigOutputs
(
this
,
taskConfiguration
,
outputs
,
partitioners
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
recordBuffer
=
new
FaultTolerancyBuffer
(
outputs
,
sourceInstanceID
);
userFunction
=
(
UserSourceInvokable
)
streamSourceHelper
.
getUserFunction
(
taskConfiguration
,
outputs
,
sourceInstanceID
,
recordBuffer
);
StreamComponentFactory
.
setAckListener
(
recordBuffer
,
sourceInstanceID
,
streamSourceHelper
.
setAckListener
(
recordBuffer
,
sourceInstanceID
,
outputs
);
StreamComponentFactory
.
setFailListener
(
recordBuffer
,
sourceInstanceID
,
streamSourceHelper
.
setFailListener
(
recordBuffer
,
sourceInstanceID
,
outputs
);
}
...
...
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/streamcomponent/StreamTask.java
浏览文件 @
1cb9016d
...
...
@@ -55,17 +55,23 @@ public class StreamTask extends AbstractTask {
@Override
public
void
registerInputOutput
()
{
Configuration
taskConfiguration
=
getTaskConfiguration
();
StreamComponentHelper
<
StreamTask
>
streamTaskHelper
=
new
StreamComponentHelper
<
StreamTask
>();
StreamComponentFactory
.
setConfigInputs
(
this
,
taskConfiguration
,
inputs
);
StreamComponentFactory
.
setConfigOutputs
(
this
,
taskConfiguration
,
outputs
,
partitioners
);
try
{
streamTaskHelper
.
setConfigInputs
(
this
,
taskConfiguration
,
inputs
);
streamTaskHelper
.
setConfigOutputs
(
this
,
taskConfiguration
,
outputs
,
partitioners
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
recordBuffer
=
new
FaultTolerancyBuffer
(
outputs
,
taskInstanceID
);
userFunction
=
(
UserTaskInvokable
)
StreamComponentFactory
.
setUserFunction
(
taskConfiguration
,
outputs
,
taskInstanceID
,
recordBuffer
);
StreamComponentFactory
.
setAckListener
(
recordBuffer
,
taskInstanceID
,
outputs
);
StreamComponentFactory
.
setFailListener
(
recordBuffer
,
taskInstanceID
,
userFunction
=
(
UserTaskInvokable
)
streamTaskHelper
.
getUserFunction
(
taskConfiguration
,
outputs
,
taskInstanceID
,
recordBuffer
);
streamTaskHelper
.
setAckListener
(
recordBuffer
,
taskInstanceID
,
outputs
);
streamTaskHelper
.
setFailListener
(
recordBuffer
,
taskInstanceID
,
outputs
);
}
...
...
@@ -83,8 +89,8 @@ public class StreamTask extends AbstractTask {
// records
try
{
userFunction
.
invoke
(
streamRecord
.
getRecord
());
System
.
out
.
println
(
this
.
getClass
().
getName
()
+
"-"
+
taskInstanceID
);
System
.
out
.
println
(
this
.
getClass
().
getName
()
+
"-"
+
taskInstanceID
);
System
.
out
.
println
(
recordBuffer
.
getRecordBuffer
());
System
.
out
.
println
(
"---------------------"
);
input
.
publishEvent
(
new
AckEvent
(
id
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录