Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
SkyWalking
提交
046102ef
S
SkyWalking
项目概览
apache
/
SkyWalking
上一次同步 1 年多
通知
302
Star
21345
Fork
6091
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SkyWalking
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
046102ef
编写于
7月 06, 2017
作者:
wu-sheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Finish codes about ApplicationRegisterClient for register, registerRecover and heartbeat.
上级
99539695
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
122 addition
and
2 deletion
+122
-2
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/JVMService.java
...in/java/org/skywalking/apm/agent/core/jvm/JVMService.java
+1
-1
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/remote/ApplicationRegisterClient.java
...king/apm/agent/core/remote/ApplicationRegisterClient.java
+119
-0
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/remote/TraceSegmentServiceClient.java
...king/apm/agent/core/remote/TraceSegmentServiceClient.java
+1
-1
apm-sniffer/apm-agent-core/src/main/resources/META-INF/services/org.skywalking.apm.agent.core.boot.BootService
...F/services/org.skywalking.apm.agent.core.boot.BootService
+1
-0
未找到文件。
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/jvm/JVMService.java
浏览文件 @
046102ef
...
...
@@ -126,11 +126,11 @@ public class JVMService implements BootService, Runnable {
@Override
public
void
statusChanged
(
GRPCChannelStatus
status
)
{
this
.
status
=
status
;
if
(
CONNECTED
.
equals
(
status
))
{
ManagedChannel
channel
=
ServiceManager
.
INSTANCE
.
findService
(
GRPCChannelManager
.
class
).
getManagedChannel
();
stub
=
JVMMetricsServiceGrpc
.
newBlockingStub
(
channel
);
}
this
.
status
=
status
;
}
}
}
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/remote/ApplicationRegisterClient.java
0 → 100644
浏览文件 @
046102ef
package
org.skywalking.apm.agent.core.remote
;
import
io.grpc.ManagedChannel
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.ScheduledFuture
;
import
java.util.concurrent.TimeUnit
;
import
org.skywalking.apm.agent.core.boot.BootService
;
import
org.skywalking.apm.agent.core.boot.ServiceManager
;
import
org.skywalking.apm.agent.core.conf.Config
;
import
org.skywalking.apm.agent.core.conf.RemoteDownstreamConfig
;
import
org.skywalking.apm.agent.core.context.TracingContext
;
import
org.skywalking.apm.agent.core.context.TracingContextListener
;
import
org.skywalking.apm.agent.core.context.trace.TraceSegment
;
import
org.skywalking.apm.agent.core.dictionary.DictionaryUtil
;
import
org.skywalking.apm.network.proto.Application
;
import
org.skywalking.apm.network.proto.ApplicationInstance
;
import
org.skywalking.apm.network.proto.ApplicationInstanceHeartbeat
;
import
org.skywalking.apm.network.proto.ApplicationInstanceMapping
;
import
org.skywalking.apm.network.proto.ApplicationInstanceRecover
;
import
org.skywalking.apm.network.proto.ApplicationMapping
;
import
org.skywalking.apm.network.proto.ApplicationRegisterServiceGrpc
;
import
org.skywalking.apm.network.proto.InstanceDiscoveryServiceGrpc
;
import
static
org
.
skywalking
.
apm
.
agent
.
core
.
remote
.
GRPCChannelStatus
.
CONNECTED
;
/**
* @author wusheng
*/
public
class
ApplicationRegisterClient
implements
BootService
,
GRPCChannelListener
,
Runnable
,
TracingContextListener
{
private
volatile
GRPCChannelStatus
status
=
GRPCChannelStatus
.
DISCONNECT
;
private
volatile
ApplicationRegisterServiceGrpc
.
ApplicationRegisterServiceBlockingStub
applicationRegisterServiceBlockingStub
;
private
volatile
InstanceDiscoveryServiceGrpc
.
InstanceDiscoveryServiceBlockingStub
instanceDiscoveryServiceBlockingStub
;
private
volatile
ScheduledFuture
<?>
applicationRegisterFuture
;
private
volatile
boolean
needRegisterRecover
=
false
;
private
volatile
long
lastSegmentTime
=
-
1
;
@Override
public
void
statusChanged
(
GRPCChannelStatus
status
)
{
if
(
CONNECTED
.
equals
(
status
))
{
ManagedChannel
channel
=
ServiceManager
.
INSTANCE
.
findService
(
GRPCChannelManager
.
class
).
getManagedChannel
();
if
(
RemoteDownstreamConfig
.
Agent
.
APPLICATION_ID
==
DictionaryUtil
.
nullValue
())
{
applicationRegisterServiceBlockingStub
=
ApplicationRegisterServiceGrpc
.
newBlockingStub
(
channel
);
}
else
{
instanceDiscoveryServiceBlockingStub
=
InstanceDiscoveryServiceGrpc
.
newBlockingStub
(
channel
);
if
(
RemoteDownstreamConfig
.
Agent
.
APPLICATION_INSTANCE_ID
!=
DictionaryUtil
.
nullValue
())
{
needRegisterRecover
=
true
;
}
}
}
else
{
applicationRegisterServiceBlockingStub
=
null
;
}
this
.
status
=
status
;
}
@Override
public
void
beforeBoot
()
throws
Throwable
{
ServiceManager
.
INSTANCE
.
findService
(
GRPCChannelManager
.
class
).
addChannelListener
(
this
);
}
@Override
public
void
boot
()
throws
Throwable
{
applicationRegisterFuture
=
Executors
.
newSingleThreadScheduledExecutor
()
.
scheduleAtFixedRate
(
this
,
0
,
10
,
TimeUnit
.
SECONDS
);
}
@Override
public
void
afterBoot
()
throws
Throwable
{
TracingContext
.
ListenerManager
.
add
(
this
);
}
@Override
public
void
run
()
{
if
(
CONNECTED
.
equals
(
status
))
{
if
(
RemoteDownstreamConfig
.
Agent
.
APPLICATION_ID
==
DictionaryUtil
.
nullValue
())
{
if
(
applicationRegisterServiceBlockingStub
!=
null
)
{
ApplicationMapping
applicationMapping
=
applicationRegisterServiceBlockingStub
.
register
(
Application
.
newBuilder
().
addApplicationCode
(
Config
.
Agent
.
APPLICATION_CODE
).
build
());
if
(
applicationMapping
.
getApplicationCount
()
>
0
)
{
RemoteDownstreamConfig
.
Agent
.
APPLICATION_ID
=
applicationMapping
.
getApplication
(
0
).
getValue
();
}
}
}
else
{
if
(
RemoteDownstreamConfig
.
Agent
.
APPLICATION_INSTANCE_ID
==
DictionaryUtil
.
nullValue
())
{
if
(
instanceDiscoveryServiceBlockingStub
!=
null
)
{
ApplicationInstanceMapping
instanceMapping
=
instanceDiscoveryServiceBlockingStub
.
register
(
ApplicationInstance
.
newBuilder
()
.
setApplicationId
(
RemoteDownstreamConfig
.
Agent
.
APPLICATION_ID
)
.
setRegisterTime
(
System
.
currentTimeMillis
())
.
build
());
if
(
instanceMapping
.
getApplicationInstanceId
()
!=
DictionaryUtil
.
nullValue
())
{
RemoteDownstreamConfig
.
Agent
.
APPLICATION_INSTANCE_ID
=
instanceMapping
.
getApplicationInstanceId
();
}
}
}
else
{
if
(
needRegisterRecover
)
{
instanceDiscoveryServiceBlockingStub
.
registerRecover
(
ApplicationInstanceRecover
.
newBuilder
()
.
setApplicationId
(
RemoteDownstreamConfig
.
Agent
.
APPLICATION_ID
)
.
setApplicationInstanceId
(
RemoteDownstreamConfig
.
Agent
.
APPLICATION_INSTANCE_ID
)
.
setRegisterTime
(
System
.
currentTimeMillis
())
.
build
());
}
else
{
if
(
lastSegmentTime
-
System
.
currentTimeMillis
()
>
60
*
1000
)
{
instanceDiscoveryServiceBlockingStub
.
heartbeat
(
ApplicationInstanceHeartbeat
.
newBuilder
()
.
setApplicationInstanceId
(
RemoteDownstreamConfig
.
Agent
.
APPLICATION_INSTANCE_ID
)
.
setHeartbeatTime
(
System
.
currentTimeMillis
())
.
build
());
}
}
}
}
}
}
@Override
public
void
afterFinished
(
TraceSegment
traceSegment
)
{
lastSegmentTime
=
System
.
currentTimeMillis
();
}
}
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/remote/TraceSegmentServiceClient.java
浏览文件 @
046102ef
...
...
@@ -124,10 +124,10 @@ public class TraceSegmentServiceClient implements BootService, IConsumer<TraceSe
@Override
public
void
statusChanged
(
GRPCChannelStatus
status
)
{
this
.
status
=
status
;
if
(
CONNECTED
.
equals
(
status
))
{
ManagedChannel
channel
=
ServiceManager
.
INSTANCE
.
findService
(
GRPCChannelManager
.
class
).
getManagedChannel
();
serviceStub
=
TraceSegmentServiceGrpc
.
newStub
(
channel
);
}
this
.
status
=
status
;
}
}
apm-sniffer/apm-agent-core/src/main/resources/META-INF/services/org.skywalking.apm.agent.core.boot.BootService
浏览文件 @
046102ef
...
...
@@ -4,3 +4,4 @@ org.skywalking.apm.agent.core.remote.CollectorDiscoveryService
org.skywalking.apm.agent.core.sampling.SamplingService
org.skywalking.apm.agent.core.remote.GRPCChannelManager
org.skywalking.apm.agent.core.jvm.JVMService
org.skywalking.apm.agent.core.remote.ApplicationRegisterClient
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录