This repository has been archived by the owner on Jul 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 231
Allow subclassing of common classes #509
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
jaeger-core/src/main/java/io/jaegertracing/internal/JaegerObjectFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright (c) 2018, The Jaeger Authors | ||
* | ||
* 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 io.jaegertracing.internal; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* Implements abstract factory pattern for creating spans, span contexts, and span builders. This | ||
* pattern allows subclasses of JaegerSpan, JaegerSpanContext, and JaegerTracer.SpanBuilder to be | ||
* used consistently in the trace instead of the base class. | ||
* | ||
* <p>Example usage:</p> | ||
* | ||
* <pre>{@code | ||
* public class CustomObjectFactory extends JaegerObjectFactory { | ||
* \@Override | ||
* public JaegerSpan createSpan(...) { | ||
* return new CustomSpan(...); | ||
* } | ||
* | ||
* // Override other methods... | ||
* } | ||
* }</pre> | ||
*/ | ||
public class JaegerObjectFactory { | ||
public JaegerSpan createSpan( | ||
JaegerTracer tracer, | ||
String operationName, | ||
JaegerSpanContext context, | ||
long startTimeMicroseconds, | ||
long startTimeNanoTicks, | ||
boolean computeDurationViaNanoTicks, | ||
Map<String, Object> tags, | ||
List<Reference> references) { | ||
return new JaegerSpan( | ||
tracer, | ||
operationName, | ||
context, | ||
startTimeMicroseconds, | ||
startTimeNanoTicks, | ||
computeDurationViaNanoTicks, | ||
tags, | ||
references); | ||
} | ||
|
||
public JaegerSpanContext createSpanContext( | ||
long traceId, | ||
long spanId, | ||
long parentId, | ||
byte flags, | ||
Map<String, String> baggage, | ||
String debugId) { | ||
return new JaegerSpanContext(traceId, spanId, parentId, flags, baggage, debugId, this); | ||
} | ||
|
||
public JaegerTracer.SpanBuilder createSpanBuilder(JaegerTracer tracer, String operationName) { | ||
return tracer.new SpanBuilder(operationName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@isaachier I don't think this will be enough, is it? I.e. you'd also need an overridable method that actually creates the object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer if you accompany this with a unit test showing the working subclassing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a lot more. The test definitely helped me determine what was necessary.