Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦中观雨
cat
提交
9d465fe0
C
cat
项目概览
梦中观雨
/
cat
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
cat
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9d465fe0
编写于
3月 06, 2012
作者:
S
sean.wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
dev...
上级
53c758a1
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
245 addition
and
0 deletion
+245
-0
cat-job/src/main/java/com/dianping/cat/job/hdfs/DefaultInputChannel.java
...n/java/com/dianping/cat/job/hdfs/DefaultInputChannel.java
+54
-0
cat-job/src/main/java/com/dianping/cat/job/hdfs/DefaultInputChannelManager.java
...com/dianping/cat/job/hdfs/DefaultInputChannelManager.java
+140
-0
cat-job/src/main/java/com/dianping/cat/job/hdfs/InputChannel.java
...src/main/java/com/dianping/cat/job/hdfs/InputChannel.java
+38
-0
cat-job/src/main/java/com/dianping/cat/job/hdfs/InputChannelManager.java
...n/java/com/dianping/cat/job/hdfs/InputChannelManager.java
+13
-0
未找到文件。
cat-job/src/main/java/com/dianping/cat/job/hdfs/DefaultInputChannel.java
0 → 100644
浏览文件 @
9d465fe0
package
com.dianping.cat.job.hdfs
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
org.jboss.netty.buffer.ChannelBuffer
;
import
org.jboss.netty.buffer.ChannelBuffers
;
import
com.dianping.cat.message.spi.MessageCodec
;
import
com.dianping.cat.message.spi.MessageTree
;
import
com.dianping.cat.message.spi.internal.DefaultMessageTree
;
import
com.site.lookup.annotation.Inject
;
public
class
DefaultInputChannel
implements
InputChannel
{
@Inject
private
MessageCodec
m_codec
;
private
InputStream
m_in
;
@Override
public
void
close
()
{
if
(
m_in
!=
null
)
{
try
{
m_in
.
close
();
m_in
=
null
;
}
catch
(
IOException
e
)
{
// ignore it
}
}
}
@Override
public
void
initialize
(
InputStream
in
)
{
m_in
=
in
;
}
@Override
public
MessageTree
read
(
int
index
,
int
length
)
throws
IOException
{
ChannelBuffer
buf
=
ChannelBuffers
.
dynamicBuffer
(
8192
);
buf
.
writeBytes
(
m_in
,
length
);
MessageTree
tree
=
new
DefaultMessageTree
();
m_codec
.
decode
(
buf
,
tree
);
return
tree
;
}
@Override
public
boolean
isExpired
()
{
// TODO Auto-generated method stub
return
false
;
}
}
cat-job/src/main/java/com/dianping/cat/job/hdfs/DefaultInputChannelManager.java
0 → 100644
浏览文件 @
9d465fe0
package
com.dianping.cat.job.hdfs
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.net.InetAddress
;
import
java.net.URI
;
import
java.net.UnknownHostException
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
org.apache.hadoop.conf.Configuration
;
import
org.apache.hadoop.fs.FSDataInputStream
;
import
org.apache.hadoop.fs.FileSystem
;
import
org.apache.hadoop.fs.Path
;
import
org.codehaus.plexus.logging.LogEnabled
;
import
org.codehaus.plexus.logging.Logger
;
import
org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable
;
import
org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException
;
import
com.dianping.cat.message.spi.MessagePathBuilder
;
import
com.dianping.cat.message.spi.MessageTree
;
import
com.site.lookup.ContainerHolder
;
import
com.site.lookup.annotation.Inject
;
public
class
DefaultInputChannelManager
extends
ContainerHolder
implements
InputChannelManager
,
Initializable
,
LogEnabled
{
@Inject
private
MessagePathBuilder
m_builder
;
@Inject
private
String
m_baseDir
=
"target/hdfs"
;
@Inject
private
URI
m_serverUri
;
private
FileSystem
m_fs
;
private
Path
m_basePath
;
private
String
m_ipAddress
;
private
Map
<
String
,
InputChannel
>
m_channels
=
new
HashMap
<
String
,
InputChannel
>();
private
Logger
m_logger
;
@Override
public
void
cleanupChannels
()
{
try
{
List
<
String
>
expired
=
new
ArrayList
<
String
>();
for
(
Map
.
Entry
<
String
,
InputChannel
>
e
:
m_channels
.
entrySet
())
{
if
(
e
.
getValue
().
isExpired
())
{
expired
.
add
(
e
.
getKey
());
}
}
for
(
String
path
:
expired
)
{
InputChannel
channel
=
m_channels
.
remove
(
path
);
closeChannel
(
channel
);
}
}
catch
(
Exception
e
)
{
m_logger
.
warn
(
"Error when doing cleanup!"
,
e
);
}
}
@Override
public
void
closeAllChannels
()
{
for
(
InputChannel
channel
:
m_channels
.
values
())
{
closeChannel
(
channel
);
}
}
@Override
public
void
closeChannel
(
InputChannel
channel
)
{
channel
.
close
();
super
.
release
(
channel
);
}
@Override
public
void
enableLogging
(
Logger
logger
)
{
m_logger
=
logger
;
}
@Override
public
void
initialize
()
throws
InitializationException
{
try
{
Configuration
config
=
new
Configuration
();
FileSystem
fs
;
config
.
setInt
(
"io.file.buffer.size"
,
8192
);
if
(
m_serverUri
==
null
)
{
fs
=
FileSystem
.
getLocal
(
config
);
}
else
{
fs
=
FileSystem
.
get
(
m_serverUri
,
config
);
// TODO Not tested yet
}
m_fs
=
fs
;
m_basePath
=
new
Path
(
m_fs
.
getWorkingDirectory
(),
m_baseDir
);
}
catch
(
Exception
e
)
{
throw
new
InitializationException
(
"Error when getting HDFS file system."
,
e
);
}
try
{
InetAddress
localHost
=
InetAddress
.
getLocalHost
();
m_ipAddress
=
localHost
.
getHostAddress
();
}
catch
(
UnknownHostException
e
)
{
m_logger
.
warn
(
"Unable to get local host!"
,
e
);
}
}
public
void
setBaseDir
(
String
baseDir
)
{
m_baseDir
=
baseDir
;
}
public
void
setServerUri
(
String
serverUri
)
{
m_serverUri
=
URI
.
create
(
serverUri
);
}
@Override
public
InputChannel
openChannel
(
String
messageId
)
throws
IOException
{
String
path
=
m_builder
.
getHdfsPath
(
tree
,
m_ipAddress
);
InputChannel
channel
=
m_channels
.
get
(
path
);
if
(
channel
==
null
)
{
Path
file
=
new
Path
(
m_basePath
,
path
+
"-0"
);
FSDataInputStream
in
=
m_fs
.
open
(
file
);
channel
=
lookup
(
InputChannel
.
class
);
channel
.
initialize
(
in
);
m_channels
.
put
(
path
,
channel
);
}
return
channel
;
}
}
cat-job/src/main/java/com/dianping/cat/job/hdfs/InputChannel.java
0 → 100644
浏览文件 @
9d465fe0
package
com.dianping.cat.job.hdfs
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
com.dianping.cat.message.spi.MessageTree
;
public
interface
InputChannel
{
/**
* Close the channel.
*/
public
void
close
();
/**
* Initialize the channel with an output stream.
*
* @param out
*/
public
void
initialize
(
InputStream
in
);
/**
* Check if the channel is expired.
*
* @return true if the channel is expired, false otherwise.
*/
public
boolean
isExpired
();
/**
* Fetch message tree from hdfs.
*
* @param index
* @param length
* @return
* @throws IOException
*/
public
MessageTree
read
(
int
index
,
int
length
)
throws
IOException
;
}
cat-job/src/main/java/com/dianping/cat/job/hdfs/InputChannelManager.java
0 → 100644
浏览文件 @
9d465fe0
package
com.dianping.cat.job.hdfs
;
import
java.io.IOException
;
public
interface
InputChannelManager
{
public
void
cleanupChannels
();
public
void
closeAllChannels
();
public
void
closeChannel
(
InputChannel
channel
);
public
InputChannel
openChannel
(
String
messageId
)
throws
IOException
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录