#1511 extract commons-server module

This commit is contained in:
Woonduk Kang
2016-02-02 18:24:33 +09:00
parent 7e86a683a7
commit 10ad72b0a2
44 changed files with 1279 additions and 1147 deletions
-3
View File
@@ -70,9 +70,6 @@
<filters>
<filter>
<artifact>com.navercorp.pinpoint:pinpoint-commons</artifact>
<excludes>
<exclude>com/navercorp/pinpoint/common/bo/**</exclude>
</excludes>
</filter>
</filters>
</configuration>
+4
View File
@@ -21,6 +21,10 @@
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-commons</artifactId>
</dependency>
<dependency>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-commons-server</artifactId>
</dependency>
<dependency>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-commons-hbase</artifactId>
+5
View File
@@ -0,0 +1,5 @@
/.settings/
/*.iml
/.project
/target/
/.classpath
+5
View File
@@ -0,0 +1,5 @@
RMRqrdbgbKFhbaVnDxHUdDQvrOQXxIBklnvcmahheubVC
mh2KM35CLkwUHS4DH7QVhxy52J5hnWbyEm6Cyd3KkF<mV
RmmnSVOqOMnOnMMrmMqwXomoroNrqPNRrPSsWwtUxXuUU
sRONqpnmqmUUnqonmstsmmmmmUUnqonmstsmmmmmUUGfk
mlfkqUUnmmmm
+3
View File
@@ -0,0 +1,3 @@
<FindBugsFilter>
</FindBugsFilter>
+77
View File
@@ -0,0 +1,77 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pom</artifactId>
<version>1.5.2-SNAPSHOT</version>
</parent>
<artifactId>pinpoint-commons-server</artifactId>
<name>pinpoint-commons-server</name>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-thrift</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-commons</artifactId>
<scope>compile</scope>
</dependency>
<!-- commons module may be used at agent so there will be problems. you should set optional -->
<dependency>
<groupId>org.apache.thrift</groupId>
<artifactId>libthrift</artifactId>
<optional>true</optional>
</dependency>
<!-- Logging dependencies -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<optional>true</optional>
</dependency>
<!-- thrift logging lib -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<scope>test</scope>
</dependency>
<!--<dependency> -->
<!--<groupId>org.slf4j</groupId> -->
<!--<artifactId>slf4j-jdk14</artifactId> -->
<!--<version>1.6.6</version> -->
<!--<scope>test</scope> -->
<!--</dependency> -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
@@ -1,141 +1,141 @@
/*
* Copyright 2015 NAVER Corp.
*
* 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 com.navercorp.pinpoint.common.bo;
import com.navercorp.pinpoint.common.util.AgentEventType;
/**
* @author HyunGil Jeong
*/
public class AgentEventBo {
public static final int CURRENT_VERSION = 0;
private final byte version;
private final String agentId;
private final long startTimestamp;
private final long eventTimestamp;
private final AgentEventType eventType;
private byte[] eventBody;
public AgentEventBo(String agentId, long startTimestamp, long eventTimestamp, AgentEventType eventType) {
this(CURRENT_VERSION, agentId, startTimestamp, eventTimestamp, eventType);
}
public AgentEventBo(int version, String agentId, long startTimestamp, long eventTimestamp, AgentEventType eventType) {
if (version < 0 || version > 255) {
throw new IllegalArgumentException("version out of range (0~255)");
}
if (agentId == null) {
throw new IllegalArgumentException("agentId cannot be null");
}
if (agentId.isEmpty()) {
throw new IllegalArgumentException("agentId cannot be empty");
}
if (startTimestamp < 0) {
throw new IllegalArgumentException("startTimestamp cannot be less than 0");
}
if (eventTimestamp < 0) {
throw new IllegalArgumentException("eventTimestamp cannot be less than 0");
}
if (eventType == null) {
throw new IllegalArgumentException("agentEventType cannot be null");
}
this.version = (byte)(version & 0xFF);
this.agentId = agentId;
this.startTimestamp = startTimestamp;
this.eventTimestamp = eventTimestamp;
this.eventType = eventType;
}
public int getVersion() {
return this.version & 0xFF;
}
public String getAgentId() {
return agentId;
}
public long getStartTimestamp() {
return startTimestamp;
}
public long getEventTimestamp() {
return eventTimestamp;
}
public AgentEventType getEventType() {
return eventType;
}
public byte[] getEventBody() {
return eventBody;
}
public void setEventBody(byte[] eventBody) {
this.eventBody = eventBody;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((agentId == null) ? 0 : agentId.hashCode());
result = prime * result + (int)(eventTimestamp ^ (eventTimestamp >>> 32));
result = prime * result + ((eventType == null) ? 0 : eventType.hashCode());
result = prime * result + (int)(startTimestamp ^ (startTimestamp >>> 32));
result = prime * result + version;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
AgentEventBo other = (AgentEventBo)obj;
if (agentId == null) {
if (other.agentId != null)
return false;
} else if (!agentId.equals(other.agentId))
return false;
if (eventTimestamp != other.eventTimestamp)
return false;
if (eventType != other.eventType)
return false;
if (startTimestamp != other.startTimestamp)
return false;
if (version != other.version)
return false;
return true;
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("AgentEventBo{");
sb.append("version=").append(this.version);
sb.append(", agentId='").append(this.agentId).append('\'');
sb.append(", startTimestamp=").append(this.startTimestamp);
sb.append(", eventTimestamp=").append(this.eventTimestamp);
sb.append(", eventType='").append(this.getEventType().getDesc()).append('\'');
return sb.toString();
}
}
/*
* Copyright 2015 NAVER Corp.
*
* 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 com.navercorp.pinpoint.common.bo;
import com.navercorp.pinpoint.common.util.AgentEventType;
/**
* @author HyunGil Jeong
*/
public class AgentEventBo {
public static final int CURRENT_VERSION = 0;
private final byte version;
private final String agentId;
private final long startTimestamp;
private final long eventTimestamp;
private final AgentEventType eventType;
private byte[] eventBody;
public AgentEventBo(String agentId, long startTimestamp, long eventTimestamp, AgentEventType eventType) {
this(CURRENT_VERSION, agentId, startTimestamp, eventTimestamp, eventType);
}
public AgentEventBo(int version, String agentId, long startTimestamp, long eventTimestamp, AgentEventType eventType) {
if (version < 0 || version > 255) {
throw new IllegalArgumentException("version out of range (0~255)");
}
if (agentId == null) {
throw new IllegalArgumentException("agentId cannot be null");
}
if (agentId.isEmpty()) {
throw new IllegalArgumentException("agentId cannot be empty");
}
if (startTimestamp < 0) {
throw new IllegalArgumentException("startTimestamp cannot be less than 0");
}
if (eventTimestamp < 0) {
throw new IllegalArgumentException("eventTimestamp cannot be less than 0");
}
if (eventType == null) {
throw new IllegalArgumentException("agentEventType cannot be null");
}
this.version = (byte)(version & 0xFF);
this.agentId = agentId;
this.startTimestamp = startTimestamp;
this.eventTimestamp = eventTimestamp;
this.eventType = eventType;
}
public int getVersion() {
return this.version & 0xFF;
}
public String getAgentId() {
return agentId;
}
public long getStartTimestamp() {
return startTimestamp;
}
public long getEventTimestamp() {
return eventTimestamp;
}
public AgentEventType getEventType() {
return eventType;
}
public byte[] getEventBody() {
return eventBody;
}
public void setEventBody(byte[] eventBody) {
this.eventBody = eventBody;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((agentId == null) ? 0 : agentId.hashCode());
result = prime * result + (int)(eventTimestamp ^ (eventTimestamp >>> 32));
result = prime * result + ((eventType == null) ? 0 : eventType.hashCode());
result = prime * result + (int)(startTimestamp ^ (startTimestamp >>> 32));
result = prime * result + version;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
AgentEventBo other = (AgentEventBo)obj;
if (agentId == null) {
if (other.agentId != null)
return false;
} else if (!agentId.equals(other.agentId))
return false;
if (eventTimestamp != other.eventTimestamp)
return false;
if (eventType != other.eventType)
return false;
if (startTimestamp != other.startTimestamp)
return false;
if (version != other.version)
return false;
return true;
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("AgentEventBo{");
sb.append("version=").append(this.version);
sb.append(", agentId='").append(this.agentId).append('\'');
sb.append(", startTimestamp=").append(this.startTimestamp);
sb.append(", eventTimestamp=").append(this.eventTimestamp);
sb.append(", eventType='").append(this.getEventType().getDesc()).append('\'');
return sb.toString();
}
}
@@ -1,105 +1,105 @@
/*
* Copyright 2015 NAVER Corp.
*
* 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 com.navercorp.pinpoint.common.bo;
import com.navercorp.pinpoint.common.util.AgentLifeCycleState;
/**
* @author HyunGil Jeong
*/
public class AgentLifeCycleBo {
public static final int CURRENT_VERSION = 0;
private final byte version;
private final String agentId;
private final long startTimestamp;
private final long eventTimestamp;
private final long eventIdentifier;
private final AgentLifeCycleState agentLifeCycleState;
public AgentLifeCycleBo(String agentId, long startTimestamp, long eventTimestamp, long eventIdentifier, AgentLifeCycleState agentLifeCycleState) {
this(CURRENT_VERSION, agentId, startTimestamp, eventTimestamp, eventIdentifier, agentLifeCycleState);
}
public AgentLifeCycleBo(int version, String agentId, long startTimestamp, long eventTimestamp, long eventIdentifier, AgentLifeCycleState agentLifeCycleState) {
if (version < 0 || version > 255) {
throw new IllegalArgumentException("version out of range (0~255)");
}
if (agentId == null) {
throw new IllegalArgumentException("agentId cannot be null");
}
if (agentId.isEmpty()) {
throw new IllegalArgumentException("agentId cannot be empty");
}
if (startTimestamp < 0) {
throw new IllegalArgumentException("startTimestamp cannot be less than 0");
}
if (eventTimestamp < 0) {
throw new IllegalArgumentException("eventTimestamp cannot be less than 0");
}
if (eventIdentifier < 0) {
throw new IllegalArgumentException("eventIdentifier cannot be less than 0");
}
if (agentLifeCycleState == null) {
throw new IllegalArgumentException("agentLifeCycleState cannot be null");
}
this.version = (byte)(version & 0xFF);
this.agentId = agentId;
this.startTimestamp = startTimestamp;
this.eventTimestamp = eventTimestamp;
this.eventIdentifier = eventIdentifier;
this.agentLifeCycleState = agentLifeCycleState;
}
public int getVersion() {
return this.version & 0xFF;
}
public String getAgentId() {
return agentId;
}
public long getStartTimestamp() {
return startTimestamp;
}
public long getEventTimestamp() {
return eventTimestamp;
}
public long getEventIdentifier() {
return this.eventIdentifier;
}
public AgentLifeCycleState getAgentLifeCycleState() {
return this.agentLifeCycleState;
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("AgentLifeCycleBo{");
sb.append("version=").append(this.getVersion());
sb.append(", agentId='").append(this.getAgentId()).append('\'');
sb.append(", startTimestamp=").append(this.getStartTimestamp());
sb.append(", eventTimestamp=").append(this.getEventTimestamp());
sb.append(", eventIdentifier=").append(this.eventIdentifier);
sb.append(", state=").append(this.agentLifeCycleState.toString());
return sb.toString();
}
}
/*
* Copyright 2015 NAVER Corp.
*
* 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 com.navercorp.pinpoint.common.bo;
import com.navercorp.pinpoint.common.util.AgentLifeCycleState;
/**
* @author HyunGil Jeong
*/
public class AgentLifeCycleBo {
public static final int CURRENT_VERSION = 0;
private final byte version;
private final String agentId;
private final long startTimestamp;
private final long eventTimestamp;
private final long eventIdentifier;
private final AgentLifeCycleState agentLifeCycleState;
public AgentLifeCycleBo(String agentId, long startTimestamp, long eventTimestamp, long eventIdentifier, AgentLifeCycleState agentLifeCycleState) {
this(CURRENT_VERSION, agentId, startTimestamp, eventTimestamp, eventIdentifier, agentLifeCycleState);
}
public AgentLifeCycleBo(int version, String agentId, long startTimestamp, long eventTimestamp, long eventIdentifier, AgentLifeCycleState agentLifeCycleState) {
if (version < 0 || version > 255) {
throw new IllegalArgumentException("version out of range (0~255)");
}
if (agentId == null) {
throw new IllegalArgumentException("agentId cannot be null");
}
if (agentId.isEmpty()) {
throw new IllegalArgumentException("agentId cannot be empty");
}
if (startTimestamp < 0) {
throw new IllegalArgumentException("startTimestamp cannot be less than 0");
}
if (eventTimestamp < 0) {
throw new IllegalArgumentException("eventTimestamp cannot be less than 0");
}
if (eventIdentifier < 0) {
throw new IllegalArgumentException("eventIdentifier cannot be less than 0");
}
if (agentLifeCycleState == null) {
throw new IllegalArgumentException("agentLifeCycleState cannot be null");
}
this.version = (byte)(version & 0xFF);
this.agentId = agentId;
this.startTimestamp = startTimestamp;
this.eventTimestamp = eventTimestamp;
this.eventIdentifier = eventIdentifier;
this.agentLifeCycleState = agentLifeCycleState;
}
public int getVersion() {
return this.version & 0xFF;
}
public String getAgentId() {
return agentId;
}
public long getStartTimestamp() {
return startTimestamp;
}
public long getEventTimestamp() {
return eventTimestamp;
}
public long getEventIdentifier() {
return this.eventIdentifier;
}
public AgentLifeCycleState getAgentLifeCycleState() {
return this.agentLifeCycleState;
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("AgentLifeCycleBo{");
sb.append("version=").append(this.getVersion());
sb.append(", agentId='").append(this.getAgentId()).append('\'');
sb.append(", startTimestamp=").append(this.getStartTimestamp());
sb.append(", eventTimestamp=").append(this.getEventTimestamp());
sb.append(", eventIdentifier=").append(this.eventIdentifier);
sb.append(", state=").append(this.agentLifeCycleState.toString());
return sb.toString();
}
}
@@ -1,169 +1,169 @@
/*
* Copyright 2014 NAVER Corp.
*
* 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 com.navercorp.pinpoint.common.bo;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import com.navercorp.pinpoint.common.buffer.AutomaticBuffer;
import com.navercorp.pinpoint.common.buffer.Buffer;
import com.navercorp.pinpoint.common.buffer.FixedBuffer;
/**
* @author hyungil.jeong
*/
public class ServerMetaDataBo {
private final String serverInfo;
private final List<String> vmArgs;
private final List<ServiceInfoBo> serviceInfos;
private ServerMetaDataBo(Builder builder) {
this.serverInfo = builder.serverInfo;
this.vmArgs = builder.vmArgs;
this.serviceInfos = builder.serviceInfos;
}
public String getServerInfo() {
return this.serverInfo;
}
public List<String> getVmArgs() {
return this.vmArgs;
}
public List<ServiceInfoBo> getServiceInfos() {
return this.serviceInfos;
}
public byte[] writeValue() {
final Buffer buffer = new AutomaticBuffer();
buffer.put2PrefixedString(this.serverInfo);
final int numVmArgs = this.vmArgs == null ? 0 : this.vmArgs.size();
buffer.putVar(numVmArgs);
if (this.vmArgs != null) {
for (String vmArg : this.vmArgs) {
buffer.put2PrefixedString(vmArg);
}
}
final int numServiceInfos = this.serviceInfos == null ? 0 : this.serviceInfos.size();
buffer.putVar(numServiceInfos);
if (this.serviceInfos != null) {
for (ServiceInfoBo serviceInfo : this.serviceInfos) {
buffer.putPrefixedBytes(serviceInfo.writeValue());
}
}
return buffer.getBuffer();
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder("ServerMetaDataBo{");
sb.append("serverInfo='").append(this.serverInfo).append('\'');
sb.append(", vmArgs=").append(this.vmArgs);
sb.append(", serviceInfos=").append(this.serviceInfos.toString());
return sb.toString();
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((serverInfo == null) ? 0 : serverInfo.hashCode());
result = prime * result + ((serviceInfos == null) ? 0 : serviceInfos.hashCode());
result = prime * result + ((vmArgs == null) ? 0 : vmArgs.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ServerMetaDataBo other = (ServerMetaDataBo)obj;
if (serverInfo == null) {
if (other.serverInfo != null)
return false;
} else if (!serverInfo.equals(other.serverInfo))
return false;
if (serviceInfos == null) {
if (other.serviceInfos != null)
return false;
} else if (!serviceInfos.equals(other.serviceInfos))
return false;
if (vmArgs == null) {
if (other.vmArgs != null)
return false;
} else if (!vmArgs.equals(other.vmArgs))
return false;
return true;
}
public static class Builder {
private String serverInfo;
private List<String> vmArgs;
private List<ServiceInfoBo> serviceInfos;
public Builder() {
}
public Builder(final byte[] value) {
final Buffer buffer = new FixedBuffer(value);
this.serverInfo = buffer.read2PrefixedString();
final int numVmArgs = buffer.readVarInt();
this.vmArgs = new ArrayList<String>(numVmArgs);
for (int i = 0; i < numVmArgs; ++i) {
this.vmArgs.add(buffer.read2PrefixedString());
}
final int numServiceInfos = buffer.readVarInt();
this.serviceInfos = new ArrayList<ServiceInfoBo>(numServiceInfos);
for (int i = 0; i < numServiceInfos; ++i) {
ServiceInfoBo serviceInfoBo = new ServiceInfoBo.Builder(buffer.readPrefixedBytes()).build();
this.serviceInfos.add(serviceInfoBo);
}
}
public void serverInfo(String serverInfo) {
this.serverInfo = serverInfo;
}
public void vmArgs(List<String> vmArgs) {
this.vmArgs = vmArgs;
}
public void serviceInfos(List<ServiceInfoBo> serviceInfos) {
this.serviceInfos = serviceInfos;
}
public ServerMetaDataBo build() {
if (this.serverInfo == null) {
this.serverInfo = "";
}
if (this.vmArgs == null) {
this.vmArgs = Collections.emptyList();
}
if (this.serviceInfos == null) {
this.serviceInfos = Collections.emptyList();
}
return new ServerMetaDataBo(this);
}
}
}
/*
* Copyright 2014 NAVER Corp.
*
* 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 com.navercorp.pinpoint.common.bo;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import com.navercorp.pinpoint.common.buffer.AutomaticBuffer;
import com.navercorp.pinpoint.common.buffer.Buffer;
import com.navercorp.pinpoint.common.buffer.FixedBuffer;
/**
* @author hyungil.jeong
*/
public class ServerMetaDataBo {
private final String serverInfo;
private final List<String> vmArgs;
private final List<ServiceInfoBo> serviceInfos;
private ServerMetaDataBo(Builder builder) {
this.serverInfo = builder.serverInfo;
this.vmArgs = builder.vmArgs;
this.serviceInfos = builder.serviceInfos;
}
public String getServerInfo() {
return this.serverInfo;
}
public List<String> getVmArgs() {
return this.vmArgs;
}
public List<ServiceInfoBo> getServiceInfos() {
return this.serviceInfos;
}
public byte[] writeValue() {
final Buffer buffer = new AutomaticBuffer();
buffer.put2PrefixedString(this.serverInfo);
final int numVmArgs = this.vmArgs == null ? 0 : this.vmArgs.size();
buffer.putVar(numVmArgs);
if (this.vmArgs != null) {
for (String vmArg : this.vmArgs) {
buffer.put2PrefixedString(vmArg);
}
}
final int numServiceInfos = this.serviceInfos == null ? 0 : this.serviceInfos.size();
buffer.putVar(numServiceInfos);
if (this.serviceInfos != null) {
for (ServiceInfoBo serviceInfo : this.serviceInfos) {
buffer.putPrefixedBytes(serviceInfo.writeValue());
}
}
return buffer.getBuffer();
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder("ServerMetaDataBo{");
sb.append("serverInfo='").append(this.serverInfo).append('\'');
sb.append(", vmArgs=").append(this.vmArgs);
sb.append(", serviceInfos=").append(this.serviceInfos.toString());
return sb.toString();
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((serverInfo == null) ? 0 : serverInfo.hashCode());
result = prime * result + ((serviceInfos == null) ? 0 : serviceInfos.hashCode());
result = prime * result + ((vmArgs == null) ? 0 : vmArgs.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ServerMetaDataBo other = (ServerMetaDataBo)obj;
if (serverInfo == null) {
if (other.serverInfo != null)
return false;
} else if (!serverInfo.equals(other.serverInfo))
return false;
if (serviceInfos == null) {
if (other.serviceInfos != null)
return false;
} else if (!serviceInfos.equals(other.serviceInfos))
return false;
if (vmArgs == null) {
if (other.vmArgs != null)
return false;
} else if (!vmArgs.equals(other.vmArgs))
return false;
return true;
}
public static class Builder {
private String serverInfo;
private List<String> vmArgs;
private List<ServiceInfoBo> serviceInfos;
public Builder() {
}
public Builder(final byte[] value) {
final Buffer buffer = new FixedBuffer(value);
this.serverInfo = buffer.read2PrefixedString();
final int numVmArgs = buffer.readVarInt();
this.vmArgs = new ArrayList<String>(numVmArgs);
for (int i = 0; i < numVmArgs; ++i) {
this.vmArgs.add(buffer.read2PrefixedString());
}
final int numServiceInfos = buffer.readVarInt();
this.serviceInfos = new ArrayList<ServiceInfoBo>(numServiceInfos);
for (int i = 0; i < numServiceInfos; ++i) {
ServiceInfoBo serviceInfoBo = new ServiceInfoBo.Builder(buffer.readPrefixedBytes()).build();
this.serviceInfos.add(serviceInfoBo);
}
}
public void serverInfo(String serverInfo) {
this.serverInfo = serverInfo;
}
public void vmArgs(List<String> vmArgs) {
this.vmArgs = vmArgs;
}
public void serviceInfos(List<ServiceInfoBo> serviceInfos) {
this.serviceInfos = serviceInfos;
}
public ServerMetaDataBo build() {
if (this.serverInfo == null) {
this.serverInfo = "";
}
if (this.vmArgs == null) {
this.vmArgs = Collections.emptyList();
}
if (this.serviceInfos == null) {
this.serviceInfos = Collections.emptyList();
}
return new ServerMetaDataBo(this);
}
}
}
@@ -1,134 +1,134 @@
/*
* Copyright 2014 NAVER Corp.
*
* 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 com.navercorp.pinpoint.common.bo;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import com.navercorp.pinpoint.common.buffer.AutomaticBuffer;
import com.navercorp.pinpoint.common.buffer.Buffer;
import com.navercorp.pinpoint.common.buffer.FixedBuffer;
/**
* @author hyungil.jeong
*/
public class ServiceInfoBo {
private final String serviceName;
private final List<String> serviceLibs;
private ServiceInfoBo(Builder builder) {
this.serviceName = builder.serviceName;
this.serviceLibs = builder.serviceLibs;
}
public String getServiceName() {
return this.serviceName;
}
public List<String> getServiceLibs() {
return this.serviceLibs;
}
public byte[] writeValue() {
final Buffer buffer = new AutomaticBuffer();
buffer.put2PrefixedString(this.serviceName);
int numServiceLibs = this.serviceLibs == null ? 0 : this.serviceLibs.size();
buffer.putVar(numServiceLibs);
for (int i = 0; i < numServiceLibs; ++i) {
buffer.put2PrefixedString(this.serviceLibs.get(i));
}
return buffer.getBuffer();
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder("ServiceInfoBo{");
sb.append("serviceName='").append(this.serviceName).append('\'');
sb.append(", serviceLibs=").append(this.serviceLibs).append('}');
return sb.toString();
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((serviceLibs == null) ? 0 : serviceLibs.hashCode());
result = prime * result + ((serviceName == null) ? 0 : serviceName.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ServiceInfoBo other = (ServiceInfoBo)obj;
if (serviceLibs == null) {
if (other.serviceLibs != null)
return false;
} else if (!serviceLibs.equals(other.serviceLibs))
return false;
if (serviceName == null) {
if (other.serviceName != null)
return false;
} else if (!serviceName.equals(other.serviceName))
return false;
return true;
}
public static class Builder {
private String serviceName;
private List<String> serviceLibs;
public Builder() {}
public Builder(final byte[] value) {
final Buffer buffer = new FixedBuffer(value);
this.serviceName = buffer.read2PrefixedString();
final int numServiceLibs = buffer.readVarInt();
this.serviceLibs = new ArrayList<String>(numServiceLibs);
for (int i = 0; i < numServiceLibs; ++i) {
this.serviceLibs.add(buffer.read2PrefixedString());
}
}
public Builder serviceName(String serviceName) {
this.serviceName = serviceName;
return this;
}
public Builder serviceLibs(List<String> serviceLibs) {
this.serviceLibs = serviceLibs;
return this;
}
public ServiceInfoBo build() {
if (this.serviceName == null) {
this.serviceName = "";
}
if (this.serviceLibs == null) {
this.serviceLibs = Collections.<String>emptyList();
}
return new ServiceInfoBo(this);
}
}
}
/*
* Copyright 2014 NAVER Corp.
*
* 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 com.navercorp.pinpoint.common.bo;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import com.navercorp.pinpoint.common.buffer.AutomaticBuffer;
import com.navercorp.pinpoint.common.buffer.Buffer;
import com.navercorp.pinpoint.common.buffer.FixedBuffer;
/**
* @author hyungil.jeong
*/
public class ServiceInfoBo {
private final String serviceName;
private final List<String> serviceLibs;
private ServiceInfoBo(Builder builder) {
this.serviceName = builder.serviceName;
this.serviceLibs = builder.serviceLibs;
}
public String getServiceName() {
return this.serviceName;
}
public List<String> getServiceLibs() {
return this.serviceLibs;
}
public byte[] writeValue() {
final Buffer buffer = new AutomaticBuffer();
buffer.put2PrefixedString(this.serviceName);
int numServiceLibs = this.serviceLibs == null ? 0 : this.serviceLibs.size();
buffer.putVar(numServiceLibs);
for (int i = 0; i < numServiceLibs; ++i) {
buffer.put2PrefixedString(this.serviceLibs.get(i));
}
return buffer.getBuffer();
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder("ServiceInfoBo{");
sb.append("serviceName='").append(this.serviceName).append('\'');
sb.append(", serviceLibs=").append(this.serviceLibs).append('}');
return sb.toString();
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((serviceLibs == null) ? 0 : serviceLibs.hashCode());
result = prime * result + ((serviceName == null) ? 0 : serviceName.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ServiceInfoBo other = (ServiceInfoBo)obj;
if (serviceLibs == null) {
if (other.serviceLibs != null)
return false;
} else if (!serviceLibs.equals(other.serviceLibs))
return false;
if (serviceName == null) {
if (other.serviceName != null)
return false;
} else if (!serviceName.equals(other.serviceName))
return false;
return true;
}
public static class Builder {
private String serviceName;
private List<String> serviceLibs;
public Builder() {}
public Builder(final byte[] value) {
final Buffer buffer = new FixedBuffer(value);
this.serviceName = buffer.read2PrefixedString();
final int numServiceLibs = buffer.readVarInt();
this.serviceLibs = new ArrayList<String>(numServiceLibs);
for (int i = 0; i < numServiceLibs; ++i) {
this.serviceLibs.add(buffer.read2PrefixedString());
}
}
public Builder serviceName(String serviceName) {
this.serviceName = serviceName;
return this;
}
public Builder serviceLibs(List<String> serviceLibs) {
this.serviceLibs = serviceLibs;
return this;
}
public ServiceInfoBo build() {
if (this.serviceName == null) {
this.serviceName = "";
}
if (this.serviceLibs == null) {
this.serviceLibs = Collections.<String>emptyList();
}
return new ServiceInfoBo(this);
}
}
}
@@ -1,59 +1,59 @@
/*
* Copyright 2015 NAVER Corp.
*
* 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 com.navercorp.pinpoint.common.util;
import java.io.UnsupportedEncodingException;
import org.apache.thrift.TBase;
import org.apache.thrift.TException;
import com.navercorp.pinpoint.thrift.io.DeserializerFactory;
import com.navercorp.pinpoint.thrift.io.HeaderTBaseDeserializer;
import com.navercorp.pinpoint.thrift.util.SerializationUtils;
/**
* @author HyunGil Jeong
*/
public class AgentEventMessageDeserializer {
private final DeserializerFactory<HeaderTBaseDeserializer> tBaseDeserializerFactory;
public AgentEventMessageDeserializer(DeserializerFactory<HeaderTBaseDeserializer> tBaseDeserializerFactory) {
this.tBaseDeserializerFactory = tBaseDeserializerFactory;
}
public Object deserialize(AgentEventType agentEventType, byte[] eventBody) throws UnsupportedEncodingException {
if (agentEventType == null) {
throw new NullPointerException("agentEventType must not be null");
}
Class<?> eventMessageType = agentEventType.getMessageType();
if (eventMessageType == Void.class) {
return null;
}
if (TBase.class.isAssignableFrom(eventMessageType)) {
try {
return SerializationUtils.deserialize(eventBody, this.tBaseDeserializerFactory);
} catch (TException e) {
throw new UnsupportedEncodingException(e.getMessage());
}
} else if (String.class.isAssignableFrom(eventMessageType)) {
return BytesUtils.toString(eventBody);
}
throw new UnsupportedEncodingException("Unsupported event message type [" + eventMessageType.getName() + "]");
}
}
/*
* Copyright 2015 NAVER Corp.
*
* 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 com.navercorp.pinpoint.common.util;
import java.io.UnsupportedEncodingException;
import org.apache.thrift.TBase;
import org.apache.thrift.TException;
import com.navercorp.pinpoint.thrift.io.DeserializerFactory;
import com.navercorp.pinpoint.thrift.io.HeaderTBaseDeserializer;
import com.navercorp.pinpoint.thrift.util.SerializationUtils;
/**
* @author HyunGil Jeong
*/
public class AgentEventMessageDeserializer {
private final DeserializerFactory<HeaderTBaseDeserializer> tBaseDeserializerFactory;
public AgentEventMessageDeserializer(DeserializerFactory<HeaderTBaseDeserializer> tBaseDeserializerFactory) {
this.tBaseDeserializerFactory = tBaseDeserializerFactory;
}
public Object deserialize(AgentEventType agentEventType, byte[] eventBody) throws UnsupportedEncodingException {
if (agentEventType == null) {
throw new NullPointerException("agentEventType must not be null");
}
Class<?> eventMessageType = agentEventType.getMessageType();
if (eventMessageType == Void.class) {
return null;
}
if (TBase.class.isAssignableFrom(eventMessageType)) {
try {
return SerializationUtils.deserialize(eventBody, this.tBaseDeserializerFactory);
} catch (TException e) {
throw new UnsupportedEncodingException(e.getMessage());
}
} else if (String.class.isAssignableFrom(eventMessageType)) {
return BytesUtils.toString(eventBody);
}
throw new UnsupportedEncodingException("Unsupported event message type [" + eventMessageType.getName() + "]");
}
}
@@ -1,71 +1,71 @@
/*
* Copyright 2015 NAVER Corp.
*
* 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 com.navercorp.pinpoint.common.util;
import java.io.UnsupportedEncodingException;
import org.apache.thrift.TBase;
import org.apache.thrift.TException;
import com.navercorp.pinpoint.thrift.io.HeaderTBaseSerializer;
import com.navercorp.pinpoint.thrift.io.SerializerFactory;
import com.navercorp.pinpoint.thrift.util.SerializationUtils;
/**
* @author HyunGil Jeong
*/
public class AgentEventMessageSerializer {
private static final byte[] EMPTY_BYTES = new byte[0];
private final SerializerFactory<HeaderTBaseSerializer> tBaseSerializerFactory;
public AgentEventMessageSerializer(SerializerFactory<HeaderTBaseSerializer> tBaseSerializerFactory) {
this.tBaseSerializerFactory = tBaseSerializerFactory;
}
public byte[] serialize(AgentEventType agentEventType, Object eventMessage) throws UnsupportedEncodingException {
if (agentEventType == null) {
throw new NullPointerException("agentEventType must not be null");
}
Class<?> eventMessageType = agentEventType.getMessageType();
if (eventMessageType == Void.class) {
return EMPTY_BYTES;
} else {
if (eventMessage == null) {
throw new NullPointerException("eventMessage of type [" + eventMessageType.getName() + "] expected, but was null");
}
}
if (!eventMessageType.isAssignableFrom(eventMessage.getClass())) {
throw new IllegalArgumentException("Unexpected eventMessage of type [" + eventMessage.getClass().getName() + "] received. Expected : ["
+ eventMessageType.getClass().getName() + "]");
}
if (eventMessage instanceof TBase) {
try {
return SerializationUtils.serialize((TBase<?, ?>)eventMessage, this.tBaseSerializerFactory);
} catch (TException e) {
throw new UnsupportedEncodingException(e.getMessage());
}
} else if (eventMessage instanceof String) {
return BytesUtils.toBytes((String)eventMessage);
}
throw new UnsupportedEncodingException("Unsupported event message type [" + eventMessage.getClass().getName() + "]");
}
}
/*
* Copyright 2015 NAVER Corp.
*
* 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 com.navercorp.pinpoint.common.util;
import java.io.UnsupportedEncodingException;
import org.apache.thrift.TBase;
import org.apache.thrift.TException;
import com.navercorp.pinpoint.thrift.io.HeaderTBaseSerializer;
import com.navercorp.pinpoint.thrift.io.SerializerFactory;
import com.navercorp.pinpoint.thrift.util.SerializationUtils;
/**
* @author HyunGil Jeong
*/
public class AgentEventMessageSerializer {
private static final byte[] EMPTY_BYTES = new byte[0];
private final SerializerFactory<HeaderTBaseSerializer> tBaseSerializerFactory;
public AgentEventMessageSerializer(SerializerFactory<HeaderTBaseSerializer> tBaseSerializerFactory) {
this.tBaseSerializerFactory = tBaseSerializerFactory;
}
public byte[] serialize(AgentEventType agentEventType, Object eventMessage) throws UnsupportedEncodingException {
if (agentEventType == null) {
throw new NullPointerException("agentEventType must not be null");
}
Class<?> eventMessageType = agentEventType.getMessageType();
if (eventMessageType == Void.class) {
return EMPTY_BYTES;
} else {
if (eventMessage == null) {
throw new NullPointerException("eventMessage of type [" + eventMessageType.getName() + "] expected, but was null");
}
}
if (!eventMessageType.isAssignableFrom(eventMessage.getClass())) {
throw new IllegalArgumentException("Unexpected eventMessage of type [" + eventMessage.getClass().getName() + "] received. Expected : ["
+ eventMessageType.getClass().getName() + "]");
}
if (eventMessage instanceof TBase) {
try {
return SerializationUtils.serialize((TBase<?, ?>)eventMessage, this.tBaseSerializerFactory);
} catch (TException e) {
throw new UnsupportedEncodingException(e.getMessage());
}
} else if (eventMessage instanceof String) {
return BytesUtils.toBytes((String)eventMessage);
}
throw new UnsupportedEncodingException("Unsupported event message type [" + eventMessage.getClass().getName() + "]");
}
}
@@ -1,100 +1,100 @@
/*
* Copyright 2015 NAVER Corp.
*
* 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 com.navercorp.pinpoint.common.util;
import static com.navercorp.pinpoint.common.util.AgentEventTypeCategory.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import com.navercorp.pinpoint.thrift.dto.command.TCommandThreadDumpResponse;
/**
* @author HyunGil Jeong
*/
public enum AgentEventType {
AGENT_CONNECTED(10100, "Agent connected", Void.class, DURATIONAL, AGENT_LIFECYCLE),
AGENT_PING(10199, "Agent ping", Void.class, AGENT_LIFECYCLE),
AGENT_SHUTDOWN(10200, "Agent shutdown", Void.class, DURATIONAL, AGENT_LIFECYCLE),
AGENT_UNEXPECTED_SHUTDOWN(10201, "Agent unexpected shutdown", Void.class, DURATIONAL, AGENT_LIFECYCLE),
AGENT_CLOSED_BY_SERVER(10300, "Agent connection closed by server", Void.class, DURATIONAL, AGENT_LIFECYCLE),
AGENT_UNEXPECTED_CLOSE_BY_SERVER(10301, "Agent connection unexpectedly closed by server", Void.class, DURATIONAL, AGENT_LIFECYCLE),
USER_THREAD_DUMP(20100, "Thread dump by user", TCommandThreadDumpResponse.class, USER_REQUEST, THREAD_DUMP),
OTHER(-1, "Other event", String.class, AgentEventTypeCategory.OTHER);
private final int code;
private final String desc;
private final Class<?> messageType;
private final Set<AgentEventTypeCategory> category;
AgentEventType(int code, String desc, Class<?> messageType, AgentEventTypeCategory... category) {
this.code = code;
this.desc = desc;
this.messageType = messageType;
if (category == null || category.length == 0) {
this.category = Collections.emptySet();
} else {
this.category = new HashSet<AgentEventTypeCategory>(Arrays.asList(category));
}
}
public int getCode() {
return this.code;
}
public String getDesc() {
return desc;
}
public Class<?> getMessageType() {
return this.messageType;
}
public Set<AgentEventTypeCategory> getCategory() {
return Collections.unmodifiableSet(this.category);
}
public boolean isCategorizedAs(AgentEventTypeCategory category) {
return this.category.contains(category);
}
@Override
public String toString() {
return desc;
}
public static AgentEventType getTypeByCode(int code) {
for (AgentEventType eventType : AgentEventType.values()) {
if (eventType.code == code) {
return eventType;
}
}
return null;
}
public static Set<AgentEventType> getTypesByCatgory(AgentEventTypeCategory category) {
Set<AgentEventType> eventTypes = new HashSet<AgentEventType>();
for (AgentEventType eventType : AgentEventType.values()) {
if (eventType.category.contains(category)) {
eventTypes.add(eventType);
}
}
return eventTypes;
}
}
/*
* Copyright 2015 NAVER Corp.
*
* 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 com.navercorp.pinpoint.common.util;
import static com.navercorp.pinpoint.common.util.AgentEventTypeCategory.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import com.navercorp.pinpoint.thrift.dto.command.TCommandThreadDumpResponse;
/**
* @author HyunGil Jeong
*/
public enum AgentEventType {
AGENT_CONNECTED(10100, "Agent connected", Void.class, DURATIONAL, AGENT_LIFECYCLE),
AGENT_PING(10199, "Agent ping", Void.class, AGENT_LIFECYCLE),
AGENT_SHUTDOWN(10200, "Agent shutdown", Void.class, DURATIONAL, AGENT_LIFECYCLE),
AGENT_UNEXPECTED_SHUTDOWN(10201, "Agent unexpected shutdown", Void.class, DURATIONAL, AGENT_LIFECYCLE),
AGENT_CLOSED_BY_SERVER(10300, "Agent connection closed by server", Void.class, DURATIONAL, AGENT_LIFECYCLE),
AGENT_UNEXPECTED_CLOSE_BY_SERVER(10301, "Agent connection unexpectedly closed by server", Void.class, DURATIONAL, AGENT_LIFECYCLE),
USER_THREAD_DUMP(20100, "Thread dump by user", TCommandThreadDumpResponse.class, USER_REQUEST, THREAD_DUMP),
OTHER(-1, "Other event", String.class, AgentEventTypeCategory.OTHER);
private final int code;
private final String desc;
private final Class<?> messageType;
private final Set<AgentEventTypeCategory> category;
AgentEventType(int code, String desc, Class<?> messageType, AgentEventTypeCategory... category) {
this.code = code;
this.desc = desc;
this.messageType = messageType;
if (category == null || category.length == 0) {
this.category = Collections.emptySet();
} else {
this.category = new HashSet<AgentEventTypeCategory>(Arrays.asList(category));
}
}
public int getCode() {
return this.code;
}
public String getDesc() {
return desc;
}
public Class<?> getMessageType() {
return this.messageType;
}
public Set<AgentEventTypeCategory> getCategory() {
return Collections.unmodifiableSet(this.category);
}
public boolean isCategorizedAs(AgentEventTypeCategory category) {
return this.category.contains(category);
}
@Override
public String toString() {
return desc;
}
public static AgentEventType getTypeByCode(int code) {
for (AgentEventType eventType : AgentEventType.values()) {
if (eventType.code == code) {
return eventType;
}
}
return null;
}
public static Set<AgentEventType> getTypesByCatgory(AgentEventTypeCategory category) {
Set<AgentEventType> eventTypes = new HashSet<AgentEventType>();
for (AgentEventType eventType : AgentEventType.values()) {
if (eventType.category.contains(category)) {
eventTypes.add(eventType);
}
}
return eventTypes;
}
}
@@ -1,28 +1,28 @@
/*
* Copyright 2015 NAVER Corp.
*
* 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 com.navercorp.pinpoint.common.util;
/**
* @author HyunGil Jeong
*/
public enum AgentEventTypeCategory {
DURATIONAL,
AGENT_LIFECYCLE,
USER_REQUEST,
THREAD_DUMP,
OTHER
}
/*
* Copyright 2015 NAVER Corp.
*
* 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 com.navercorp.pinpoint.common.util;
/**
* @author HyunGil Jeong
*/
public enum AgentEventTypeCategory {
DURATIONAL,
AGENT_LIFECYCLE,
USER_REQUEST,
THREAD_DUMP,
OTHER
}
@@ -1,55 +1,55 @@
/*
* Copyright 2015 NAVER Corp.
*
* 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 com.navercorp.pinpoint.common.util;
public enum AgentLifeCycleState {
RUNNING((short)100, "Running"),
SHUTDOWN((short)200, "Shutdown"),
UNEXPECTED_SHUTDOWN((short)201, "Unexpected Shutdown"),
DISCONNECTED((short)300, "Disconnected"),
UNKNOWN((short)-1, "Unknown");
private final short code;
private final String desc;
AgentLifeCycleState(short code, String desc) {
this.code = code;
this.desc = desc;
}
public short getCode() {
return this.code;
}
public String getDesc() {
return this.desc;
}
@Override
public String toString() {
return this.desc;
}
public static AgentLifeCycleState getStateByCode(short code) {
for (AgentLifeCycleState state : AgentLifeCycleState.values()) {
if (state.code == code) {
return state;
}
}
return UNKNOWN;
}
/*
* Copyright 2015 NAVER Corp.
*
* 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 com.navercorp.pinpoint.common.util;
public enum AgentLifeCycleState {
RUNNING((short)100, "Running"),
SHUTDOWN((short)200, "Shutdown"),
UNEXPECTED_SHUTDOWN((short)201, "Unexpected Shutdown"),
DISCONNECTED((short)300, "Disconnected"),
UNKNOWN((short)-1, "Unknown");
private final short code;
private final String desc;
AgentLifeCycleState(short code, String desc) {
this.code = code;
this.desc = desc;
}
public short getCode() {
return this.code;
}
public String getDesc() {
return this.desc;
}
@Override
public String toString() {
return this.desc;
}
public static AgentLifeCycleState getStateByCode(short code) {
for (AgentLifeCycleState state : AgentLifeCycleState.values()) {
if (state.code == code) {
return state;
}
}
return UNKNOWN;
}
}
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.navercorp.pinpoint.common.util;
package com.navercorp.pinpoint.common.bo;
import com.navercorp.pinpoint.common.bo.SqlMetaDataBo;
@@ -35,7 +35,6 @@ public class RowKeyUtilsTest {
SqlMetaDataBo sqlId = new SqlMetaDataBo();
sqlId.readRowKey(agents);
Assert.assertEquals(sqlId.getAgentId(), "agent");
Assert.assertEquals(sqlId.getHashCode(), 1);
Assert.assertEquals(sqlId.getStartTime(), startTime);
@@ -1,65 +1,65 @@
/*
* Copyright 2014 NAVER Corp.
*
* 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 com.navercorp.pinpoint.common.bo;
import static org.junit.Assert.*;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;
import com.navercorp.pinpoint.common.bo.ServerMetaDataBo;
import com.navercorp.pinpoint.common.bo.ServiceInfoBo;
/**
* @author hyungil.jeong
*/
public class ServerMetaDataBoTest {
@Test
public void testByteArrayConversion() {
// Given
final ServerMetaDataBo testBo = createTestBo("testServer", Arrays.asList("arg1", "arg2"),
Arrays.asList(ServiceInfoBoTest.createTestBo("testService", Arrays.asList("lib1", "lib2"))));
// When
final byte[] serializedBo = testBo.writeValue();
final ServerMetaDataBo deserializedBo = new ServerMetaDataBo.Builder(serializedBo).build();
// Then
assertEquals(testBo, deserializedBo);
}
@Test
public void testByteArrayConversionNullValues() {
// Given
final ServerMetaDataBo testBo = createTestBo(null, null, null);
// When
final byte[] serializedBo = testBo.writeValue();
final ServerMetaDataBo deserializedBo = new ServerMetaDataBo.Builder(serializedBo).build();
// Then
assertEquals(testBo, deserializedBo);
}
static ServerMetaDataBo createTestBo(String serverInfo, List<String> vmArgs, List<ServiceInfoBo> serviceInfos) {
final ServerMetaDataBo.Builder builder = new ServerMetaDataBo.Builder();
builder.serverInfo(serverInfo);
builder.vmArgs(vmArgs);
builder.serviceInfos(serviceInfos);
return builder.build();
}
}
/*
* Copyright 2014 NAVER Corp.
*
* 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 com.navercorp.pinpoint.common.bo;
import static org.junit.Assert.*;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;
import com.navercorp.pinpoint.common.bo.ServerMetaDataBo;
import com.navercorp.pinpoint.common.bo.ServiceInfoBo;
/**
* @author hyungil.jeong
*/
public class ServerMetaDataBoTest {
@Test
public void testByteArrayConversion() {
// Given
final ServerMetaDataBo testBo = createTestBo("testServer", Arrays.asList("arg1", "arg2"),
Arrays.asList(ServiceInfoBoTest.createTestBo("testService", Arrays.asList("lib1", "lib2"))));
// When
final byte[] serializedBo = testBo.writeValue();
final ServerMetaDataBo deserializedBo = new ServerMetaDataBo.Builder(serializedBo).build();
// Then
assertEquals(testBo, deserializedBo);
}
@Test
public void testByteArrayConversionNullValues() {
// Given
final ServerMetaDataBo testBo = createTestBo(null, null, null);
// When
final byte[] serializedBo = testBo.writeValue();
final ServerMetaDataBo deserializedBo = new ServerMetaDataBo.Builder(serializedBo).build();
// Then
assertEquals(testBo, deserializedBo);
}
static ServerMetaDataBo createTestBo(String serverInfo, List<String> vmArgs, List<ServiceInfoBo> serviceInfos) {
final ServerMetaDataBo.Builder builder = new ServerMetaDataBo.Builder();
builder.serverInfo(serverInfo);
builder.vmArgs(vmArgs);
builder.serviceInfos(serviceInfos);
return builder.build();
}
}
@@ -1,60 +1,60 @@
/*
* Copyright 2014 NAVER Corp.
*
* 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 com.navercorp.pinpoint.common.bo;
import static org.junit.Assert.*;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;
import com.navercorp.pinpoint.common.bo.ServiceInfoBo;
/**
* @author hyungil.jeong
*/
public class ServiceInfoBoTest {
@Test
public void testByteArrayConversion() {
// Given
final ServiceInfoBo testBo = createTestBo("testService", Arrays.asList("lib1", "lib2"));
// When
final byte[] serializedBo = testBo.writeValue();
final ServiceInfoBo deserializedBo = new ServiceInfoBo.Builder(serializedBo).build();
// Then
assertEquals(testBo, deserializedBo);
}
@Test
public void testByteArrayConversionNullValues() {
// Given
final ServiceInfoBo testBo = createTestBo(null, null);
// When
final byte[] serializedBo = testBo.writeValue();
final ServiceInfoBo deserializedBo = new ServiceInfoBo.Builder(serializedBo).build();
// Then
assertEquals(testBo, deserializedBo);
}
static ServiceInfoBo createTestBo(String serviceName, List<String> serviceLibs) {
final ServiceInfoBo.Builder builder = new ServiceInfoBo.Builder();
return builder.serviceName(serviceName).serviceLibs(serviceLibs).build();
}
}
/*
* Copyright 2014 NAVER Corp.
*
* 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 com.navercorp.pinpoint.common.bo;
import static org.junit.Assert.*;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;
import com.navercorp.pinpoint.common.bo.ServiceInfoBo;
/**
* @author hyungil.jeong
*/
public class ServiceInfoBoTest {
@Test
public void testByteArrayConversion() {
// Given
final ServiceInfoBo testBo = createTestBo("testService", Arrays.asList("lib1", "lib2"));
// When
final byte[] serializedBo = testBo.writeValue();
final ServiceInfoBo deserializedBo = new ServiceInfoBo.Builder(serializedBo).build();
// Then
assertEquals(testBo, deserializedBo);
}
@Test
public void testByteArrayConversionNullValues() {
// Given
final ServiceInfoBo testBo = createTestBo(null, null);
// When
final byte[] serializedBo = testBo.writeValue();
final ServiceInfoBo deserializedBo = new ServiceInfoBo.Builder(serializedBo).build();
// Then
assertEquals(testBo, deserializedBo);
}
static ServiceInfoBo createTestBo(String serviceName, List<String> serviceLibs) {
final ServiceInfoBo.Builder builder = new ServiceInfoBo.Builder();
return builder.serviceName(serviceName).serviceLibs(serviceLibs).build();
}
}
@@ -1,156 +1,173 @@
/*
* Copyright 2015 NAVER Corp.
*
* 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 com.navercorp.pinpoint.common.util;
import static org.junit.Assert.*;
import java.io.UnsupportedEncodingException;
import java.lang.management.LockInfo;
import java.lang.management.MonitorInfo;
import java.lang.management.ThreadInfo;
import org.apache.thrift.protocol.TCompactProtocol;
import org.apache.thrift.protocol.TProtocolFactory;
import org.junit.Test;
import com.navercorp.pinpoint.common.Version;
import com.navercorp.pinpoint.thrift.dto.command.TCommandThreadDumpResponse;
import com.navercorp.pinpoint.thrift.dto.command.TMonitorInfo;
import com.navercorp.pinpoint.thrift.dto.command.TThreadDump;
import com.navercorp.pinpoint.thrift.dto.command.TThreadState;
import com.navercorp.pinpoint.thrift.io.DeserializerFactory;
import com.navercorp.pinpoint.thrift.io.HeaderTBaseDeserializer;
import com.navercorp.pinpoint.thrift.io.HeaderTBaseDeserializerFactory;
import com.navercorp.pinpoint.thrift.io.HeaderTBaseSerializer;
import com.navercorp.pinpoint.thrift.io.HeaderTBaseSerializerFactory;
import com.navercorp.pinpoint.thrift.io.SerializerFactory;
import com.navercorp.pinpoint.thrift.io.TCommandRegistry;
import com.navercorp.pinpoint.thrift.io.TCommandTypeVersion;
/**
* @author HyunGil Jeong
*/
public class AgentEventMessageSerDesTest {
private static final String TEST_PINPOINT_VERSION = Version.VERSION;
private final TProtocolFactory protocolFactory = new TCompactProtocol.Factory();
private final TCommandRegistry commandTbaseRegistry = new TCommandRegistry(TCommandTypeVersion.getVersion(TEST_PINPOINT_VERSION));
private final SerializerFactory<HeaderTBaseSerializer> serializerFactory = new HeaderTBaseSerializerFactory(true,
HeaderTBaseSerializerFactory.DEFAULT_STREAM_SIZE, true, this.protocolFactory, this.commandTbaseRegistry);
private final DeserializerFactory<HeaderTBaseDeserializer> deserializerFactory = new HeaderTBaseDeserializerFactory(this.protocolFactory,
this.commandTbaseRegistry);
private final AgentEventMessageSerializer serializer = new AgentEventMessageSerializer(serializerFactory);
private final AgentEventMessageDeserializer deserializer = new AgentEventMessageDeserializer(deserializerFactory);
@Test
public void Void_event_messages_should_serialized_and_deserialize_into_null() throws UnsupportedEncodingException {
final Class<Void> messageTypeToTest = Void.class;
final Object expectedEventMessage = null;
verifyEventMessageSerDer(messageTypeToTest, expectedEventMessage);
}
@Test
public void String_event_messages_should_serialize_and_deserialize_correctly() throws UnsupportedEncodingException {
final Class<String> messageTypeToTest = String.class;
final String expectedEventMessage = "TEST_EVENT_MESSAGE";
verifyEventMessageSerDer(messageTypeToTest, expectedEventMessage);
}
@Test
public void TCommandThreadDumpResponse_event_messages_should_serialize_and_deserialize_correctly() throws UnsupportedEncodingException {
final Class<TCommandThreadDumpResponse> messageTypeToTest = TCommandThreadDumpResponse.class;
final TCommandThreadDumpResponse expectedEventMessage = createTCommandThreadDumpResponse();
verifyEventMessageSerDer(messageTypeToTest, expectedEventMessage);
}
private void verifyEventMessageSerDer(Class<?> messageTypeToTest, Object expectedEventMessage) throws UnsupportedEncodingException {
for (AgentEventType agentEventType : AgentEventType.values()) {
if (agentEventType.getMessageType() == messageTypeToTest) {
// when
byte[] serializedMessage = this.serializer.serialize(agentEventType, expectedEventMessage);
Object deserializedMessage = this.deserializer.deserialize(agentEventType, serializedMessage);
// then
assertEquals(expectedEventMessage, deserializedMessage);
}
}
}
private TCommandThreadDumpResponse createTCommandThreadDumpResponse() {
final TCommandThreadDumpResponse threadDumpResponse = new TCommandThreadDumpResponse();
ThreadInfo[] threadInfos = ThreadMXBeanUtils.dumpAllThread();
for (ThreadInfo threadInfo : threadInfos) {
final TThreadDump threadDump = createTThreadDump(threadInfo);
threadDumpResponse.addToThreadDumps(threadDump);
}
return threadDumpResponse;
}
private TThreadDump createTThreadDump(ThreadInfo info) {
TThreadDump dump = new TThreadDump();
dump.setThreadName(info.getThreadName());
dump.setThreadId(info.getThreadId());
dump.setBlockedTime(info.getBlockedTime());
dump.setBlockedCount(info.getBlockedCount());
dump.setWaitedTime(info.getWaitedTime());
dump.setWaitedCount(info.getWaitedCount());
dump.setLockName(info.getLockName());
dump.setLockOwnerId(info.getLockOwnerId());
dump.setLockOwnerName(info.getLockOwnerName());
dump.setInNative(info.isInNative());
dump.setSuspended(info.isSuspended());
dump.setThreadState(getThreadState(info));
StackTraceElement[] stackTraceElements = info.getStackTrace();
for (StackTraceElement each : stackTraceElements) {
dump.addToStackTrace(each.toString());
}
MonitorInfo[] monitorInfos = info.getLockedMonitors();
for (MonitorInfo each : monitorInfos) {
TMonitorInfo tMonitorInfo = new TMonitorInfo();
tMonitorInfo.setStackDepth(each.getLockedStackDepth());
tMonitorInfo.setStackFrame(each.getLockedStackFrame().toString());
dump.addToLockedMonitors(tMonitorInfo);
}
LockInfo[] lockInfos = info.getLockedSynchronizers();
for (LockInfo lockInfo : lockInfos) {
dump.addToLockedSynchronizers(lockInfo.toString());
}
return dump;
}
private TThreadState getThreadState(ThreadInfo info) {
String stateName = info.getThreadState().name();
for (TThreadState state : TThreadState.values()) {
if (state.name().equalsIgnoreCase(stateName)) {
return state;
}
}
return null;
}
}
/*
* Copyright 2016 NAVER Corp.
*
* 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.
*/
/*
* Copyright 2015 NAVER Corp.
*
* 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 com.navercorp.pinpoint.common.util;
import static org.junit.Assert.*;
import java.io.UnsupportedEncodingException;
import java.lang.management.LockInfo;
import java.lang.management.MonitorInfo;
import java.lang.management.ThreadInfo;
import com.navercorp.pinpoint.common.util.ThreadMXBeanUtils;
import org.apache.thrift.protocol.TCompactProtocol;
import org.apache.thrift.protocol.TProtocolFactory;
import org.junit.Test;
import com.navercorp.pinpoint.common.Version;
import com.navercorp.pinpoint.thrift.dto.command.TCommandThreadDumpResponse;
import com.navercorp.pinpoint.thrift.dto.command.TMonitorInfo;
import com.navercorp.pinpoint.thrift.dto.command.TThreadDump;
import com.navercorp.pinpoint.thrift.dto.command.TThreadState;
import com.navercorp.pinpoint.thrift.io.DeserializerFactory;
import com.navercorp.pinpoint.thrift.io.HeaderTBaseDeserializer;
import com.navercorp.pinpoint.thrift.io.HeaderTBaseDeserializerFactory;
import com.navercorp.pinpoint.thrift.io.HeaderTBaseSerializer;
import com.navercorp.pinpoint.thrift.io.HeaderTBaseSerializerFactory;
import com.navercorp.pinpoint.thrift.io.SerializerFactory;
import com.navercorp.pinpoint.thrift.io.TCommandRegistry;
import com.navercorp.pinpoint.thrift.io.TCommandTypeVersion;
/**
* @author HyunGil Jeong
*/
public class AgentEventMessageSerDesTest {
private static final String TEST_PINPOINT_VERSION = Version.VERSION;
private final TProtocolFactory protocolFactory = new TCompactProtocol.Factory();
private final TCommandRegistry commandTbaseRegistry = new TCommandRegistry(TCommandTypeVersion.getVersion(TEST_PINPOINT_VERSION));
private final SerializerFactory<HeaderTBaseSerializer> serializerFactory = new HeaderTBaseSerializerFactory(true,
HeaderTBaseSerializerFactory.DEFAULT_STREAM_SIZE, true, this.protocolFactory, this.commandTbaseRegistry);
private final DeserializerFactory<HeaderTBaseDeserializer> deserializerFactory = new HeaderTBaseDeserializerFactory(this.protocolFactory,
this.commandTbaseRegistry);
private final AgentEventMessageSerializer serializer = new AgentEventMessageSerializer(serializerFactory);
private final AgentEventMessageDeserializer deserializer = new AgentEventMessageDeserializer(deserializerFactory);
@Test
public void Void_event_messages_should_serialized_and_deserialize_into_null() throws UnsupportedEncodingException {
final Class<Void> messageTypeToTest = Void.class;
final Object expectedEventMessage = null;
verifyEventMessageSerDer(messageTypeToTest, expectedEventMessage);
}
@Test
public void String_event_messages_should_serialize_and_deserialize_correctly() throws UnsupportedEncodingException {
final Class<String> messageTypeToTest = String.class;
final String expectedEventMessage = "TEST_EVENT_MESSAGE";
verifyEventMessageSerDer(messageTypeToTest, expectedEventMessage);
}
@Test
public void TCommandThreadDumpResponse_event_messages_should_serialize_and_deserialize_correctly() throws UnsupportedEncodingException {
final Class<TCommandThreadDumpResponse> messageTypeToTest = TCommandThreadDumpResponse.class;
final TCommandThreadDumpResponse expectedEventMessage = createTCommandThreadDumpResponse();
verifyEventMessageSerDer(messageTypeToTest, expectedEventMessage);
}
private void verifyEventMessageSerDer(Class<?> messageTypeToTest, Object expectedEventMessage) throws UnsupportedEncodingException {
for (AgentEventType agentEventType : AgentEventType.values()) {
if (agentEventType.getMessageType() == messageTypeToTest) {
// when
byte[] serializedMessage = this.serializer.serialize(agentEventType, expectedEventMessage);
Object deserializedMessage = this.deserializer.deserialize(agentEventType, serializedMessage);
// then
assertEquals(expectedEventMessage, deserializedMessage);
}
}
}
private TCommandThreadDumpResponse createTCommandThreadDumpResponse() {
final TCommandThreadDumpResponse threadDumpResponse = new TCommandThreadDumpResponse();
ThreadInfo[] threadInfos = ThreadMXBeanUtils.dumpAllThread();
for (ThreadInfo threadInfo : threadInfos) {
final TThreadDump threadDump = createTThreadDump(threadInfo);
threadDumpResponse.addToThreadDumps(threadDump);
}
return threadDumpResponse;
}
private TThreadDump createTThreadDump(ThreadInfo info) {
TThreadDump dump = new TThreadDump();
dump.setThreadName(info.getThreadName());
dump.setThreadId(info.getThreadId());
dump.setBlockedTime(info.getBlockedTime());
dump.setBlockedCount(info.getBlockedCount());
dump.setWaitedTime(info.getWaitedTime());
dump.setWaitedCount(info.getWaitedCount());
dump.setLockName(info.getLockName());
dump.setLockOwnerId(info.getLockOwnerId());
dump.setLockOwnerName(info.getLockOwnerName());
dump.setInNative(info.isInNative());
dump.setSuspended(info.isSuspended());
dump.setThreadState(getThreadState(info));
StackTraceElement[] stackTraceElements = info.getStackTrace();
for (StackTraceElement each : stackTraceElements) {
dump.addToStackTrace(each.toString());
}
MonitorInfo[] monitorInfos = info.getLockedMonitors();
for (MonitorInfo each : monitorInfos) {
TMonitorInfo tMonitorInfo = new TMonitorInfo();
tMonitorInfo.setStackDepth(each.getLockedStackDepth());
tMonitorInfo.setStackFrame(each.getLockedStackFrame().toString());
dump.addToLockedMonitors(tMonitorInfo);
}
LockInfo[] lockInfos = info.getLockedSynchronizers();
for (LockInfo lockInfo : lockInfos) {
dump.addToLockedSynchronizers(lockInfo.toString());
}
return dump;
}
private TThreadState getThreadState(ThreadInfo info) {
String stateName = info.getThreadState().name();
for (TThreadState state : TThreadState.values()) {
if (state.name().equalsIgnoreCase(stateName)) {
return state;
}
}
return null;
}
}
+5
View File
@@ -23,6 +23,11 @@
<artifactId>pinpoint-profiler</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-commons-server</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
+5
View File
@@ -29,6 +29,11 @@
<artifactId>pinpoint-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-commons-server</artifactId>
<scope>test</scope>
</dependency>
<dependency>
+6
View File
@@ -48,6 +48,7 @@
<module>collector</module>
<module>commons</module>
<module>commons-hbase</module>
<module>commons-server</module>
<module>plugins</module>
<module>profiler</module>
<module>profiler-optional</module>
@@ -101,6 +102,11 @@
<artifactId>pinpoint-commons</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-commons-server</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-commons-hbase</artifactId>
+5
View File
@@ -26,6 +26,11 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-commons-server</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-thrift</artifactId>
+4
View File
@@ -23,6 +23,10 @@
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-commons</artifactId>
</dependency>
<dependency>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-commons-server</artifactId>
</dependency>
<dependency>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-commons-hbase</artifactId>