This repository has been archived by the owner on May 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 345
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from opentracing/bhs/format_type
introduce a Format type in Java
- Loading branch information
Showing
21 changed files
with
251 additions
and
241 deletions.
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
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
75 changes: 75 additions & 0 deletions
75
opentracing-api/src/main/java/io/opentracing/propagation/Format.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,75 @@ | ||
/** | ||
* Copyright 2016 The OpenTracing 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.opentracing.propagation; | ||
|
||
import io.opentracing.SpanContext; | ||
import io.opentracing.Tracer; | ||
|
||
import java.nio.ByteBuffer; | ||
|
||
/** | ||
* Format instances control the behavior of Tracer.inject and Tracer.extract (and also constrain the type of the | ||
* carrier parameter to same). | ||
* | ||
* Most OpenTracing users will only reference the Format.Builtin constants. For example: | ||
* | ||
* <pre>{@code | ||
* Tracer tracer = ... | ||
* io.opentracing.propagation.HttpHeaders httpCarrier = new AnHttpHeaderCarrier(httpRequest); | ||
* SpanContext spanCtx = tracer.extract(Format.Builtin.HTTP_HEADERS, httpHeaderReader); | ||
* }</pre> | ||
* | ||
* @see Tracer#inject(SpanContext, Format, Object) | ||
* @see Tracer#extract(Format, Object) | ||
*/ | ||
public interface Format<C> { | ||
class Builtin<C> implements Format<C> { | ||
/** | ||
* The TEXT_MAP format allows for arbitrary String->String map encoding of SpanContext state for Tracer.inject | ||
* and Tracer.extract. | ||
* | ||
* Unlike HTTP_HEADERS, the builtin TEXT_MAP format expresses no constraints on keys or values. | ||
* | ||
* @see io.opentracing.Tracer#inject(SpanContext, Format, Object) | ||
* @see io.opentracing.Tracer#extract(Format, Object) | ||
* @see Format | ||
* @see Builtin#HTTP_HEADERS | ||
*/ | ||
public final static Format<TextMap> TEXT_MAP = new Builtin<>(); | ||
|
||
/** | ||
* The HTTP_HEADERS format allows for HTTP-header-compatible String->String map encoding of SpanContext state | ||
* for Tracer.inject and Tracer.extract. | ||
* | ||
* I.e., keys written to the TextMap MUST be suitable for HTTP header keys (which are poorly defined but | ||
* certainly restricted); and similarly for values (i.e., URL-escaped and "not too long"). | ||
* | ||
* @see io.opentracing.Tracer#inject(SpanContext, Format, Object) | ||
* @see io.opentracing.Tracer#extract(Format, Object) | ||
* @see Format | ||
* @see Builtin#TEXT_MAP | ||
*/ | ||
public final static Format<TextMap> HTTP_HEADERS = new Builtin<>(); | ||
|
||
/** | ||
* The BINARY format allows for unconstrained binary encoding of SpanContext state for Tracer.inject and | ||
* Tracer.extract. | ||
* | ||
* @see io.opentracing.Tracer#inject(SpanContext, Format, Object) | ||
* @see io.opentracing.Tracer#extract(Format, Object) | ||
* @see Format | ||
*/ | ||
public final static Format<ByteBuffer> BINARY = new Builtin<>(); | ||
} | ||
} |
37 changes: 0 additions & 37 deletions
37
opentracing-api/src/main/java/io/opentracing/propagation/HttpHeaderReader.java
This file was deleted.
Oops, something went wrong.
35 changes: 0 additions & 35 deletions
35
opentracing-api/src/main/java/io/opentracing/propagation/HttpHeaderWriter.java
This file was deleted.
Oops, something went wrong.
52 changes: 52 additions & 0 deletions
52
opentracing-api/src/main/java/io/opentracing/propagation/TextMap.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,52 @@ | ||
/** | ||
* Copyright 2016 The OpenTracing 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.opentracing.propagation; | ||
|
||
import io.opentracing.SpanContext; | ||
|
||
import java.util.Iterator; | ||
import java.util.Map; | ||
|
||
/** | ||
* TextMap is a built-in carrier for Tracer.inject() and Tracer.extract(). TextMap implementations allows Tracers to | ||
* read and write key:value String pairs from arbitrary underlying sources of data. | ||
* | ||
* @see io.opentracing.Tracer#inject(SpanContext, Format, Object) | ||
* @see io.opentracing.Tracer#extract(Format, Object) | ||
*/ | ||
public interface TextMap { | ||
/** | ||
* Gets an iterator over arbitrary key:value pairs from the TextMapReader. | ||
* | ||
* @return entries in the TextMap backing store; note that for some Formats, the iterator may include entries that | ||
* were never injected by a Tracer implementation (e.g., unrelated HTTP headers) | ||
* | ||
* @see io.opentracing.Tracer#extract(Format, Object) | ||
* @see Format.Builtin#TEXT_MAP | ||
* @see Format.Builtin#HTTP_HEADERS | ||
*/ | ||
Iterator<Map.Entry<String,String>> getEntries(); | ||
|
||
/** | ||
* Puts a key:value pair into the TextMapWriter's backing store. | ||
* | ||
* @param key a String, possibly with constraints dictated by the particular Format this TextMap is paired with | ||
* @param value a String, possibly with constraints dictated by the particular Format this TextMap is paired with | ||
* | ||
* @see io.opentracing.Tracer#inject(io.opentracing.SpanContext, Format, Object) | ||
* @see Format.Builtin#TEXT_MAP | ||
* @see Format.Builtin#HTTP_HEADERS | ||
*/ | ||
void put(String key, String value); | ||
} |
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.