From dcafdaa3481192ece8e71a4dc63ef9446021e1b1 Mon Sep 17 00:00:00 2001 From: wusheng Date: Mon, 20 Mar 2017 14:45:08 +0800 Subject: [PATCH] Fix compile issue. Add new rest-service Object: SegmentsMessage.java. It uses Gson(JsonAdapter) as serialize/deserialize tool. --- pom.xml | 2 + .../eye/skywalking/trace/SegmentsMessage.java | 74 +++++++++++++++++ .../trace/TraceId/DistributedTraceId.java | 25 ------ .../trace/TraceId/DistributedTraceIds.java | 66 +++++++++++++++ .../a/eye/skywalking/trace/TraceSegment.java | 23 +++--- .../trace/TraceSegmentTestCase.java | 8 +- .../dependency-reduced-pom.xml | 41 +++------- skywalking-sniffer/skywalking-agent/pom.xml | 9 +- skywalking-sniffer/skywalking-api/pom.xml | 41 ++++------ .../eye/skywalking/api/boot/BootService.java | 2 +- .../skywalking/api/boot/ServiceManager.java | 4 +- .../api/boot/StatusBootService.java | 2 +- .../api/client/CollectorClient.java | 71 ++++++++++++++++ .../api/client/CollectorClientService.java | 54 +----------- .../com/a/eye/skywalking/api/conf/Config.java | 1 + .../api/context/ContextCarrier.java | 2 +- .../api/context/ContextManager.java | 2 +- .../skywalking/api/context/TracerContext.java | 2 +- .../api/plugin/PluginBootstrap.java | 2 +- .../ClassInstanceMethodsInterceptor.java | 2 +- .../ClassStaticMethodsInterceptor.java | 2 +- .../loader/InterceptorInstanceLoader.java | 2 +- .../api/queue/TraceSegmentProcessQueue.java | 4 +- .../api/client/HTTPRestServiceTestApp.java | 82 +++++++++++++++++++ .../api/context/ContextCarrierTestCase.java | 2 +- .../api/context/TracerContextTestCase.java | 2 +- .../api/plugin/PluginFinderTest.java | 4 +- 27 files changed, 370 insertions(+), 161 deletions(-) create mode 100644 skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/SegmentsMessage.java create mode 100644 skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/TraceId/DistributedTraceIds.java create mode 100644 skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/client/CollectorClient.java create mode 100644 skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/api/client/HTTPRestServiceTestApp.java diff --git a/pom.xml b/pom.xml index 68da304bd..a10be42bd 100644 --- a/pom.xml +++ b/pom.xml @@ -91,12 +91,14 @@ + org.apache.maven.plugins maven-compiler-plugin ${compiler.version} ${compiler.version} ${project.build.sourceEncoding} + 3.6.1 org.apache.maven.plugins diff --git a/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/SegmentsMessage.java b/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/SegmentsMessage.java new file mode 100644 index 000000000..cc2fc2bc9 --- /dev/null +++ b/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/SegmentsMessage.java @@ -0,0 +1,74 @@ +package com.a.eye.skywalking.trace; + +import com.a.eye.skywalking.trace.TraceId.PropagatedTraceId; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.TypeAdapter; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import java.io.IOException; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +/** + * The SegmentsMessage is a set of {@link TraceSegment}, + * this set provides a container, when several {@link TraceSegment}s are going to uplink to server. + * + * + * @author wusheng + */ +@JsonAdapter(SegmentsMessage.Serializer.class) +public class SegmentsMessage { + private List segments; + + public SegmentsMessage(){ + segments = new LinkedList(); + } + + public void append(TraceSegment segment){ + this.segments.add(segment); + } + + public List getSegments() { + return Collections.unmodifiableList(segments); + } + + public static class Serializer extends TypeAdapter{ + + @Override + public void write(JsonWriter out, SegmentsMessage value) throws IOException { + Gson gson = new GsonBuilder() + .excludeFieldsWithoutExposeAnnotation() + .create(); + + out.beginArray(); + try { + for (TraceSegment segment : value.segments) { + out.jsonValue(gson.toJson(segment)); + } + }finally { + out.endArray(); + } + } + + @Override + public SegmentsMessage read(JsonReader in) throws IOException { + SegmentsMessage message = new SegmentsMessage(); + in.beginArray(); + Gson gson = new GsonBuilder() + .excludeFieldsWithoutExposeAnnotation() + .create(); + try { + while (in.hasNext()) { + TraceSegment traceSegment = gson.fromJson(in, TraceSegment.class); + message.append(traceSegment); + } + } finally { + in.endArray(); + } + return message; + } + } +} diff --git a/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/TraceId/DistributedTraceId.java b/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/TraceId/DistributedTraceId.java index e17462796..b64cffaea 100644 --- a/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/TraceId/DistributedTraceId.java +++ b/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/TraceId/DistributedTraceId.java @@ -1,11 +1,5 @@ package com.a.eye.skywalking.trace.TraceId; -import com.google.gson.TypeAdapter; -import com.google.gson.annotations.JsonAdapter; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonWriter; -import java.io.IOException; - /** * The DistributedTraceId presents a distributed call chain. * @@ -19,7 +13,6 @@ import java.io.IOException; * * @author wusheng */ -@JsonAdapter(DistributedTraceId.Serializer.class) public abstract class DistributedTraceId { private String id; @@ -47,22 +40,4 @@ public abstract class DistributedTraceId { public int hashCode() { return id != null ? id.hashCode() : 0; } - - public static class Serializer extends TypeAdapter { - - @Override - public void write(JsonWriter out, DistributedTraceId value) throws IOException { - out.beginArray(); - out.value(value.get()); - out.endArray(); - } - - @Override - public DistributedTraceId read(JsonReader in) throws IOException { - in.beginArray(); - PropagatedTraceId traceId = new PropagatedTraceId(in.nextString()); - in.endArray(); - return traceId; - } - } } diff --git a/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/TraceId/DistributedTraceIds.java b/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/TraceId/DistributedTraceIds.java new file mode 100644 index 000000000..c5050f516 --- /dev/null +++ b/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/TraceId/DistributedTraceIds.java @@ -0,0 +1,66 @@ +package com.a.eye.skywalking.trace.TraceId; + +import com.google.gson.TypeAdapter; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import java.io.IOException; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +/** + * @author wusheng + */ +@JsonAdapter(DistributedTraceIds.Serializer.class) +public class DistributedTraceIds { + private LinkedList relatedGlobalTraces; + + public DistributedTraceIds() { + relatedGlobalTraces = new LinkedList(); + } + + public List getRelatedGlobalTraces() { + return Collections.unmodifiableList(relatedGlobalTraces); + } + + public void append(DistributedTraceId distributedTraceId) { + if (relatedGlobalTraces.size() > 0 && relatedGlobalTraces.getFirst() instanceof NewDistributedTraceId) { + relatedGlobalTraces.removeFirst(); + } + if (!relatedGlobalTraces.contains(distributedTraceId)) { + relatedGlobalTraces.add(distributedTraceId); + } + } + + public static class Serializer extends TypeAdapter { + + @Override + public void write(JsonWriter out, DistributedTraceIds value) throws IOException { + List globalTraces = value.getRelatedGlobalTraces(); + + if (globalTraces.size() > 0) { + out.beginArray(); + for (DistributedTraceId trace : globalTraces) { + out.value(trace.get()); + } + out.endArray(); + } + } + + @Override + public DistributedTraceIds read(JsonReader in) throws IOException { + DistributedTraceIds distributedTraceIds = new DistributedTraceIds(); + in.beginArray(); + try { + while (in.hasNext()) { + PropagatedTraceId traceId = new PropagatedTraceId(in.nextString()); + distributedTraceIds.append(traceId); + } + } finally { + in.endArray(); + } + return distributedTraceIds; + } + } +} diff --git a/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/TraceSegment.java b/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/TraceSegment.java index 424970cf6..d5c2edbcf 100644 --- a/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/TraceSegment.java +++ b/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/TraceSegment.java @@ -1,6 +1,7 @@ package com.a.eye.skywalking.trace; import com.a.eye.skywalking.trace.TraceId.DistributedTraceId; +import com.a.eye.skywalking.trace.TraceId.DistributedTraceIds; import com.a.eye.skywalking.trace.TraceId.NewDistributedTraceId; import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; @@ -86,7 +87,7 @@ public class TraceSegment { */ @Expose @SerializedName(value="gt") - private LinkedList relatedGlobalTraces; + private DistributedTraceIds relatedGlobalTraces; /** * Create a trace segment, by given segmentId. @@ -94,18 +95,18 @@ public class TraceSegment { */ public TraceSegment(String applicationCode) { this(); - this.traceSegmentId = GlobalIdGenerator.generate(ID_TYPE); this.applicationCode = applicationCode; - this.startTime = System.currentTimeMillis(); } /** * Create a default/empty trace segment */ public TraceSegment() { + this.startTime = System.currentTimeMillis(); + this.traceSegmentId = GlobalIdGenerator.generate(ID_TYPE); this.spans = new LinkedList(); - this.relatedGlobalTraces = new LinkedList(); - this.relatedGlobalTraces.add(new NewDistributedTraceId()); + this.relatedGlobalTraces = new DistributedTraceIds(); + this.relatedGlobalTraces.append(new NewDistributedTraceId()); } /** @@ -126,13 +127,8 @@ public class TraceSegment { if (distributedTraceIds == null || distributedTraceIds.size() == 0) { return; } - if (relatedGlobalTraces.getFirst() instanceof NewDistributedTraceId) { - relatedGlobalTraces.removeFirst(); - } for (DistributedTraceId distributedTraceId : distributedTraceIds) { - if(!relatedGlobalTraces.contains(distributedTraceId)){ - relatedGlobalTraces.add(distributedTraceId); - } + relatedGlobalTraces.append(distributedTraceId); } } @@ -176,7 +172,7 @@ public class TraceSegment { } public List getRelatedGlobalTraces() { - return Collections.unmodifiableList(relatedGlobalTraces); + return relatedGlobalTraces.getRelatedGlobalTraces(); } public List getSpans() { @@ -187,7 +183,8 @@ public class TraceSegment { return applicationCode; } - @Override public String toString() { + @Override + public String toString() { return "TraceSegment{" + "traceSegmentId='" + traceSegmentId + '\'' + ", startTime=" + startTime + diff --git a/skywalking-commons/skywalking-trace/src/test/java/com/a/eye/skywalking/trace/TraceSegmentTestCase.java b/skywalking-commons/skywalking-trace/src/test/java/com/a/eye/skywalking/trace/TraceSegmentTestCase.java index d941649af..dc35472bb 100644 --- a/skywalking-commons/skywalking-trace/src/test/java/com/a/eye/skywalking/trace/TraceSegmentTestCase.java +++ b/skywalking-commons/skywalking-trace/src/test/java/com/a/eye/skywalking/trace/TraceSegmentTestCase.java @@ -106,11 +106,15 @@ public class TraceSegmentTestCase { .excludeFieldsWithoutExposeAnnotation() .create(); - String json = gson.toJson(segment); + SegmentsMessage message = new SegmentsMessage(); + message.append(segment); + String json = gson.toJson(message); + System.out.println(json); + message = gson.fromJson(json, SegmentsMessage.class); - TraceSegment newSegment = gson.fromJson(json, TraceSegment.class); + TraceSegment newSegment = message.getSegments().get(0); Assert.assertEquals(segment.getSpans().size(), newSegment.getSpans().size()); Assert.assertEquals(segment.getRefs().get(0).getTraceSegmentId(), newSegment.getRefs().get(0).getTraceSegmentId()); diff --git a/skywalking-sniffer/skywalking-agent/dependency-reduced-pom.xml b/skywalking-sniffer/skywalking-agent/dependency-reduced-pom.xml index 75c853cb2..014bb63e4 100644 --- a/skywalking-sniffer/skywalking-agent/dependency-reduced-pom.xml +++ b/skywalking-sniffer/skywalking-agent/dependency-reduced-pom.xml @@ -45,41 +45,13 @@ ${shade.com.lmax.disruptor.source} ${shade.com.lmax.disruptor.target} - - ${shade.akka.source} - ${shade.akka.target} - ${shade.com.google.source} ${shade.com.google.target} - ${shade.org.agrona.source} - ${shade.org.agrona.target} - - - ${shade.org.jboss.netty.source} - ${shade.org.jboss.netty.target} - - - ${shade.org.reactivestreams.source} - ${shade.org.reactivestreams.target} - - - ${shade.org.uncommons.maths.source} - ${shade.org.uncommons.maths.target} - - - ${shade.scala.source} - ${shade.scala.target} - - - ${shade.io.aeron.source} - ${shade.io.aeron.target} - - - ${shade.com.typesafe.source} - ${shade.com.typesafe.target} + ${shade.org.apache.source} + ${shade.org.apache.target} @@ -148,8 +120,17 @@ + org.apache + com.a.eye.skywalking.dependencies + com.google + ${shade.package}.${shade.net.bytebuddy.source} + ${shade.package}.${shade.com.lmax.disruptor.source} UTF-8 + net.bytebuddy + ${shade.package}.${shade.com.google.source} + ${shade.package}.${shade.org.apache.source} com.a.eye.skywalking.agent.SkyWalkingAgent + com.lmax.disruptor diff --git a/skywalking-sniffer/skywalking-agent/pom.xml b/skywalking-sniffer/skywalking-agent/pom.xml index bbee6a933..d807e4a1f 100644 --- a/skywalking-sniffer/skywalking-agent/pom.xml +++ b/skywalking-sniffer/skywalking-agent/pom.xml @@ -22,9 +22,12 @@ net.bytebuddy ${shade.package}.${shade.net.bytebuddy.source} com.lmax.disruptor - ${shade.package}.${shade.com.lmax.disruptor.source} + ${shade.package}.${shade.com.lmax.disruptor.source} + com.google ${shade.package}.${shade.com.google.source} + org.apache + ${shade.package}.${shade.org.apache.source} @@ -133,6 +136,10 @@ ${shade.com.google.source} ${shade.com.google.target} + + ${shade.org.apache.source} + ${shade.org.apache.target} + diff --git a/skywalking-sniffer/skywalking-api/pom.xml b/skywalking-sniffer/skywalking-api/pom.xml index 08611b1c9..1649a624f 100644 --- a/skywalking-sniffer/skywalking-api/pom.xml +++ b/skywalking-sniffer/skywalking-api/pom.xml @@ -8,7 +8,6 @@ 3.0-2017 - skywalking-api jar @@ -17,6 +16,7 @@ UTF-8 + 9.4.2.v20170220 @@ -40,17 +40,26 @@ disruptor 3.3.6 + + org.apache.httpcomponents + httpclient + 4.5.3 + + + org.eclipse.jetty + jetty-server + ${jetty.version} + test + + + org.eclipse.jetty + jetty-servlet + ${jetty.version} + test + - - maven-compiler-plugin - - 1.7 - 1.7 - ${project.build.sourceEncoding} - - org.apache.maven.plugins maven-resources-plugin @@ -59,20 +68,6 @@ ${project.build.sourceEncoding} - - - org.apache.maven.plugins - maven-source-plugin - - - - attach-sources - - jar - - - - diff --git a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/boot/BootService.java b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/boot/BootService.java index 90d4dbea1..3a69211ef 100644 --- a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/boot/BootService.java +++ b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/boot/BootService.java @@ -8,5 +8,5 @@ package com.a.eye.skywalking.api.boot; * @author wusheng */ public interface BootService { - void bootUp() throws Exception; + void bootUp() throws Throwable; } diff --git a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/boot/ServiceManager.java b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/boot/ServiceManager.java index 7d56a4986..1ff1c9820 100644 --- a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/boot/ServiceManager.java +++ b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/boot/ServiceManager.java @@ -23,14 +23,14 @@ public enum ServiceManager { public void boot() { if (!isStarted) { try { - bootedServices = new HashMap<>(); + bootedServices = new HashMap(); Iterator serviceIterator = load().iterator(); while (serviceIterator.hasNext()) { BootService bootService = serviceIterator.next(); try { bootService.bootUp(); bootedServices.put(bootService.getClass(), bootService); - } catch (Exception e) { + } catch (Throwable e) { logger.error(e, "ServiceManager try to start [{}] fail.", bootService.getClass().getName()); } } diff --git a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/boot/StatusBootService.java b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/boot/StatusBootService.java index 2bf9429e4..9a3a82e06 100644 --- a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/boot/StatusBootService.java +++ b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/boot/StatusBootService.java @@ -18,7 +18,7 @@ public abstract class StatusBootService implements BootService { } @Override - public final void bootUp() throws Exception{ + public final void bootUp() throws Throwable{ try { bootUpWithStatus(); started = true; diff --git a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/client/CollectorClient.java b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/client/CollectorClient.java new file mode 100644 index 000000000..63e6a8b94 --- /dev/null +++ b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/client/CollectorClient.java @@ -0,0 +1,71 @@ +package com.a.eye.skywalking.api.client; + +import com.a.eye.skywalking.api.boot.ServiceManager; +import com.a.eye.skywalking.api.queue.TraceSegmentProcessQueue; +import com.a.eye.skywalking.logging.ILog; +import com.a.eye.skywalking.logging.LogManager; +import com.a.eye.skywalking.trace.TraceSegment; +import java.util.List; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.DefaultConnectionKeepAliveStrategy; +import org.apache.http.impl.client.HttpClients; + +/** + * The CollectorClient runs as an independency thread. + * It retrieves cached {@link TraceSegment} from {@link TraceSegmentProcessQueue}, + * and send to collector by HTTP-RESTFUL-SERVICE: POST /skywalking/trace/segment + * + * @author wusheng + */ +public class CollectorClient implements Runnable { + private static ILog logger = LogManager.getLogger(CollectorClient.class); + private static long SLEEP_TIME_MILLIS = 500; + private CloseableHttpClient httpclient; + + public CollectorClient() { + httpclient = HttpClients.custom() + .setKeepAliveStrategy(new DefaultConnectionKeepAliveStrategy()) + .build(); + } + + @Override + public void run() { + while (true) { + try { + long sleepTime = -1; + TraceSegmentProcessQueue segmentProcessQueue = ServiceManager.INSTANCE.findService(TraceSegmentProcessQueue.class); + List cachedTraceSegments = segmentProcessQueue.getCachedTraceSegments(); + if (cachedTraceSegments.size() > 0) { + for (TraceSegment segment : cachedTraceSegments) { + /** + * No receiver found, means collector server is off-line. + */ + sleepTime = SLEEP_TIME_MILLIS * 10; + break; + } + } else { + sleepTime = SLEEP_TIME_MILLIS; + } + + if (sleepTime > 0) { + try2Sleep(sleepTime); + } + } catch (Throwable t) { + logger.error(t, "Send trace segments to collector failure."); + } + } + } + + /** + * Try to sleep, and ignore the {@link InterruptedException} + * + * @param millis the length of time to sleep in milliseconds + */ + private void try2Sleep(long millis) { + try { + Thread.sleep(millis); + } catch (InterruptedException e) { + + } + } +} diff --git a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/client/CollectorClientService.java b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/client/CollectorClientService.java index dd187faf1..fff22cb6e 100644 --- a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/client/CollectorClientService.java +++ b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/client/CollectorClientService.java @@ -1,67 +1,21 @@ package com.a.eye.skywalking.api.client; -import com.a.eye.skywalking.api.boot.ServiceManager; import com.a.eye.skywalking.api.boot.StatusBootService; import com.a.eye.skywalking.api.queue.TraceSegmentProcessQueue; -import com.a.eye.skywalking.logging.ILog; -import com.a.eye.skywalking.logging.LogManager; import com.a.eye.skywalking.trace.TraceSegment; -import java.util.List; /** + * The CollectorClientService is responsible for start {@link CollectorClient}. + * * @author wusheng */ -public class CollectorClientService extends StatusBootService implements Runnable { - private static ILog logger = LogManager.getLogger(CollectorClientService.class); - private static long SLEEP_TIME_MILLIS = 500; - +public class CollectorClientService extends StatusBootService { /** * Start a new {@link Thread} to get finished {@link TraceSegment} by {@link TraceSegmentProcessQueue#getCachedTraceSegments()} */ @Override protected void bootUpWithStatus() throws Exception { - Thread collectorClientThread = new Thread(this, "collectorClientThread"); + Thread collectorClientThread = new Thread(new CollectorClient(), "collectorClientThread"); collectorClientThread.start(); } - - @Override - public void run() { - while (true) { - try { - long sleepTime = -1; - TraceSegmentProcessQueue segmentProcessQueue = ServiceManager.INSTANCE.findService(TraceSegmentProcessQueue.class); - List cachedTraceSegments = segmentProcessQueue.getCachedTraceSegments(); - if (cachedTraceSegments.size() > 0) { - for (TraceSegment segment : cachedTraceSegments) { - /** - * No receiver found, means collector server is off-line. - */ - sleepTime = SLEEP_TIME_MILLIS * 10; - break; - } - } else { - sleepTime = SLEEP_TIME_MILLIS; - } - - if (sleepTime > 0) { - try2Sleep(sleepTime); - } - } catch (Throwable t) { - logger.error(t, "Send trace segments to collector failure."); - } - } - } - - /** - * Try to sleep, and ignore the {@link InterruptedException} - * - * @param millis the length of time to sleep in milliseconds - */ - private void try2Sleep(long millis) { - try { - Thread.sleep(millis); - } catch (InterruptedException e) { - - } - } } diff --git a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/conf/Config.java b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/conf/Config.java index 283638511..e2cfae6d0 100644 --- a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/conf/Config.java +++ b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/conf/Config.java @@ -11,6 +11,7 @@ public class Config { public static String SERVERS = ""; + public static String SERVICE_NAME = "/segments"; } public static class Disruptor{ diff --git a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/context/ContextCarrier.java b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/context/ContextCarrier.java index ebe5147fd..684922194 100644 --- a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/context/ContextCarrier.java +++ b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/context/ContextCarrier.java @@ -165,7 +165,7 @@ public class ContextCarrier implements Serializable { return null; } String[] propagationTraceIdValues = text.split(","); - List traceIds = new LinkedList<>(); + List traceIds = new LinkedList(); for (String propagationTraceIdValue : propagationTraceIdValues) { traceIds.add(new PropagatedTraceId(propagationTraceIdValue)); } diff --git a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/context/ContextManager.java b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/context/ContextManager.java index 0b0a4a7e2..1fe799d4a 100644 --- a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/context/ContextManager.java +++ b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/context/ContextManager.java @@ -18,7 +18,7 @@ import com.a.eye.skywalking.trace.TraceSegment; * Created by wusheng on 2017/2/17. */ public class ContextManager implements TracerContextListener, BootService { - private static ThreadLocal CONTEXT = new ThreadLocal<>(); + private static ThreadLocal CONTEXT = new ThreadLocal(); private static TracerContext get() { TracerContext segment = CONTEXT.get(); diff --git a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/context/TracerContext.java b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/context/TracerContext.java index 2eaeb38af..e484e0d4d 100644 --- a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/context/TracerContext.java +++ b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/context/TracerContext.java @@ -186,7 +186,7 @@ public final class TracerContext { } public static class ListenerManager { - private static List listeners = new LinkedList<>(); + private static List listeners = new LinkedList(); /** * Add the given {@link TracerContextListener} to {@link #listeners} list. diff --git a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/plugin/PluginBootstrap.java b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/plugin/PluginBootstrap.java index 5926c77cb..554fba67f 100644 --- a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/plugin/PluginBootstrap.java +++ b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/plugin/PluginBootstrap.java @@ -31,7 +31,7 @@ public class PluginBootstrap { if (resources == null || resources.size() == 0) { logger.info("no plugin files (skywalking-plugin.properties) found, continue to start application."); - return new ArrayList<>(); + return new ArrayList(); } for (URL pluginUrl : resources) { diff --git a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/plugin/interceptor/enhance/ClassInstanceMethodsInterceptor.java b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/plugin/interceptor/enhance/ClassInstanceMethodsInterceptor.java index 5a2a23903..5a7e81184 100644 --- a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/plugin/interceptor/enhance/ClassInstanceMethodsInterceptor.java +++ b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/plugin/interceptor/enhance/ClassInstanceMethodsInterceptor.java @@ -46,7 +46,7 @@ public class ClassInstanceMethodsInterceptor { */ @RuntimeType public Object intercept(@This Object obj, @AllArguments Object[] allArguments, @Origin Method method, @SuperCall Callable zuper, - @FieldValue(ClassEnhancePluginDefine.contextAttrName) EnhancedClassInstanceContext instanceContext) throws Exception { + @FieldValue(ClassEnhancePluginDefine.contextAttrName) EnhancedClassInstanceContext instanceContext) throws Throwable { InstanceMethodsAroundInterceptor interceptor = InterceptorInstanceLoader .load(instanceMethodsAroundInterceptorClassName, obj.getClass().getClassLoader()); diff --git a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/plugin/interceptor/enhance/ClassStaticMethodsInterceptor.java b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/plugin/interceptor/enhance/ClassStaticMethodsInterceptor.java index 863f6d5db..c2f78cc22 100644 --- a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/plugin/interceptor/enhance/ClassStaticMethodsInterceptor.java +++ b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/plugin/interceptor/enhance/ClassStaticMethodsInterceptor.java @@ -46,7 +46,7 @@ public class ClassStaticMethodsInterceptor { * or unexpected exception in sky-walking ( This is a bug, if anything triggers this condition ). */ @RuntimeType - public Object intercept(@Origin Class clazz, @AllArguments Object[] allArguments, @Origin Method method, @SuperCall Callable zuper) throws Exception { + public Object intercept(@Origin Class clazz, @AllArguments Object[] allArguments, @Origin Method method, @SuperCall Callable zuper) throws Throwable { StaticMethodsAroundInterceptor interceptor = InterceptorInstanceLoader .load(staticMethodsAroundInterceptorClassName, clazz.getClassLoader()); diff --git a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/plugin/interceptor/loader/InterceptorInstanceLoader.java b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/plugin/interceptor/loader/InterceptorInstanceLoader.java index 4479cdb22..ae96cda85 100644 --- a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/plugin/interceptor/loader/InterceptorInstanceLoader.java +++ b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/plugin/interceptor/loader/InterceptorInstanceLoader.java @@ -30,7 +30,7 @@ import java.util.concurrent.locks.ReentrantLock; public class InterceptorInstanceLoader { private static ILog logger = LogManager.getLogger(InterceptorInstanceLoader.class); - private static ConcurrentHashMap INSTANCE_CACHE = new ConcurrentHashMap<>(); + private static ConcurrentHashMap INSTANCE_CACHE = new ConcurrentHashMap(); private static ReentrantLock instanceLoadLock = new ReentrantLock(); diff --git a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/queue/TraceSegmentProcessQueue.java b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/queue/TraceSegmentProcessQueue.java index 5f82545f4..d868de9f4 100644 --- a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/queue/TraceSegmentProcessQueue.java +++ b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/queue/TraceSegmentProcessQueue.java @@ -30,7 +30,7 @@ public class TraceSegmentProcessQueue extends StatusBootService implements Trace private volatile int cacheIndex; public TraceSegmentProcessQueue() { - disruptor = new Disruptor<>(TraceSegmentHolder.Factory.INSTANCE, Config.Disruptor.BUFFER_SIZE, DaemonThreadFactory.INSTANCE); + disruptor = new Disruptor(TraceSegmentHolder.Factory.INSTANCE, Config.Disruptor.BUFFER_SIZE, DaemonThreadFactory.INSTANCE); secondLevelCache = new TraceSegment[Config.Disruptor.BUFFER_SIZE]; cacheIndex = 0; disruptor.handleEventsWith(this); @@ -83,7 +83,7 @@ public class TraceSegmentProcessQueue extends StatusBootService implements Trace } public List getCachedTraceSegments(){ - List segmentList = new LinkedList<>(); + List segmentList = new LinkedList(); for (int i = 0; i < secondLevelCache.length; i++) { TraceSegment segment = secondLevelCache[i]; if(segment != null){ diff --git a/skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/api/client/HTTPRestServiceTestApp.java b/skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/api/client/HTTPRestServiceTestApp.java new file mode 100644 index 000000000..de4a3d068 --- /dev/null +++ b/skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/api/client/HTTPRestServiceTestApp.java @@ -0,0 +1,82 @@ +package com.a.eye.skywalking.api.client; + +import java.io.BufferedReader; +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.DefaultConnectionKeepAliveStrategy; +import org.apache.http.impl.client.HttpClients; +import org.eclipse.jetty.server.Request; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.handler.AbstractHandler; + +/** + * This is a small application, test for http restful service. + * Use APACHE HttpClient as client, nanohttpd as server. + * + * @author wusheng + */ +public class HTTPRestServiceTestApp { + public static void main(String[] args) throws Exception { + CloseableHttpClient client = null; + Server server = null; + try { + HTTPRestServiceTestApp test = new HTTPRestServiceTestApp(); + server = test.startServer(); + client = test.send(); + } finally { + if (client != null) { + client.close(); + } + if (server != null) { + server.stop(); + } + } + + } + + private CloseableHttpClient send() { + CloseableHttpClient httpclient = HttpClients.custom() + .setKeepAliveStrategy(new DefaultConnectionKeepAliveStrategy()) + .build(); + HttpPost post = new HttpPost("http://localhost:7000/segments"); + StringEntity entity = new StringEntity("[{'abc'}]", ContentType.APPLICATION_JSON); + post.setEntity(entity); + try { + CloseableHttpResponse httpResponse = httpclient.execute(post); + System.out.println(httpResponse.getStatusLine().getStatusCode()); + } catch (IOException e) { + e.printStackTrace(); + } + return httpclient; + } + + private Server startServer() throws Exception { + Server server = new Server(7000); + + server.setHandler(new AbstractHandler() { + @Override + public void handle(String target, Request baseRequest, HttpServletRequest request, + HttpServletResponse response) throws IOException, ServletException { + BufferedReader br = request.getReader(); + String str, wholeStr = ""; + while ((str = br.readLine()) != null) { + wholeStr += str; + } + System.out.println(wholeStr); + response.setContentType("text/html; charset=utf-8"); + response.setStatus(HttpServletResponse.SC_OK); + baseRequest.setHandled(true); + } + }); + //server.start(); + return server; + } + +} diff --git a/skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/api/context/ContextCarrierTestCase.java b/skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/api/context/ContextCarrierTestCase.java index 901aab1fd..269911b79 100644 --- a/skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/api/context/ContextCarrierTestCase.java +++ b/skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/api/context/ContextCarrierTestCase.java @@ -18,7 +18,7 @@ public class ContextCarrierTestCase { carrier.setSpanId(100); carrier.setApplicationCode("REMOTE_APP"); carrier.setPeerHost("10.2.3.16:8080"); - List ids = new LinkedList<>(); + List ids = new LinkedList(); ids.add(new PropagatedTraceId("Trace.global.id.123")); carrier.setDistributedTraceIds(ids); diff --git a/skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/api/context/TracerContextTestCase.java b/skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/api/context/TracerContextTestCase.java index ec557298d..7fad516d8 100644 --- a/skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/api/context/TracerContextTestCase.java +++ b/skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/api/context/TracerContextTestCase.java @@ -77,7 +77,7 @@ public class TracerContextTestCase { carrier.setSpanId(5); carrier.setApplicationCode("REMOTE_APP"); carrier.setPeerHost("10.2.3.16:8080"); - List ids = new LinkedList<>(); + List ids = new LinkedList(); ids.add(new PropagatedTraceId("Trace.global.id.123")); carrier.setDistributedTraceIds(ids); diff --git a/skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/api/plugin/PluginFinderTest.java b/skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/api/plugin/PluginFinderTest.java index f63e46eb4..ceaf27e94 100644 --- a/skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/api/plugin/PluginFinderTest.java +++ b/skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/api/plugin/PluginFinderTest.java @@ -11,7 +11,7 @@ import org.junit.Test; public class PluginFinderTest { @Test public void testFind(){ - ArrayList defines = new ArrayList<>(); + ArrayList defines = new ArrayList(); defines.add(new NewTestPlugin()); defines.add(new NewTestPlugin2()); PluginFinder finder = new PluginFinder(defines); @@ -22,7 +22,7 @@ public class PluginFinderTest { @Test(expected = PluginException.class) public void testCanNotFind(){ - ArrayList defines = new ArrayList<>(); + ArrayList defines = new ArrayList(); defines.add(new NewTestPlugin()); PluginFinder finder = new PluginFinder(defines); -- GitLab