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 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split Inject and Extract Builtin interfaces (#316)
If we had separate formats for inject and extract this refactor would have been much cleaner. This allows us to better avoid partially implementing the TextMap interface and throwing an exception for the other method. Since Binary is a new addition, I applied a similar refactoring to that. Closes #315.
- Loading branch information
1 parent
e7ef15c
commit 639dd06
Showing
20 changed files
with
285 additions
and
134 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
41 changes: 41 additions & 0 deletions
41
opentracing-api/src/main/java/io/opentracing/propagation/BinaryExtract.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,41 @@ | ||
/* | ||
* Copyright 2016-2018 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; | ||
|
||
/** | ||
* {@link BinaryExtract} is an interface defining the required operations for a binary carrier for | ||
* {@link Tracer#extract} only. {@link BinaryExtract} is defined as inbound (extraction). | ||
* | ||
* When called with {@link Tracer#extract}, {@link #extractionBuffer} will be called to retrieve the {@link ByteBuffer} | ||
* containing the data used for {@link SpanContext} extraction. | ||
* | ||
* @see Format.Builtin#BINARY | ||
* @see io.opentracing.Tracer#extract(Format, Object) | ||
*/ | ||
public interface BinaryExtract { | ||
|
||
/** | ||
* Gets the buffer containing the data used for {@link SpanContext} extraction. | ||
* | ||
* It is an error to call this method when Binary is used | ||
* for {@link SpanContext} injection. | ||
* | ||
* @return The buffer used for {@link SpanContext} extraction. | ||
*/ | ||
ByteBuffer extractionBuffer(); | ||
} |
47 changes: 47 additions & 0 deletions
47
opentracing-api/src/main/java/io/opentracing/propagation/BinaryInject.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,47 @@ | ||
/* | ||
* Copyright 2016-2018 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; | ||
|
||
/** | ||
* {@link BinaryInject} is an interface defining the required operations for a binary carrier for | ||
* {@link Tracer#inject} only. {@link BinaryInject} is defined as outbound (injection). | ||
* | ||
* When called with {@link Tracer#inject}, {@link #injectionBuffer} will be called | ||
* to retrieve the actual {@link ByteBuffer} used for the {@link SpanContext} injection. | ||
* | ||
* @see Format.Builtin#BINARY | ||
* @see io.opentracing.Tracer#inject(SpanContext, Format, Object) | ||
*/ | ||
public interface BinaryInject { | ||
/** | ||
* Gets the buffer used to store data as part of {@link SpanContext} injection. | ||
* | ||
* The lenght parameter hints the buffer length required for | ||
* {@link SpanContext} injection. The user may use this to allocate a new | ||
* ByteBuffer or resize an existing one. | ||
* | ||
* It is an error to call this method when Binary is used | ||
* for {@link SpanContext} extraction. | ||
* | ||
* @param length The buffer length required for {@link SpanContext} injection. | ||
* It needs to be larger than zero. | ||
* | ||
* @return The buffer used for {@link SpanContext} injection. | ||
*/ | ||
ByteBuffer injectionBuffer(int length); | ||
} |
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
35 changes: 35 additions & 0 deletions
35
opentracing-api/src/main/java/io/opentracing/propagation/TextMapAdapter.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,35 @@ | ||
/* | ||
* Copyright 2016-2018 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.util.Map; | ||
|
||
/** | ||
* A {@link TextMap} carrier for use with {@link Tracer#inject} and {@link Tracer#extract}. | ||
* | ||
* @see Tracer#inject(SpanContext, Format, Object) | ||
* @see Tracer#extract(Format, Object) | ||
*/ | ||
public class TextMapAdapter extends TextMapExtractAdapter implements TextMap { | ||
public TextMapAdapter(Map<String, String> map) { | ||
super(map); | ||
} | ||
|
||
@Override | ||
public void put(String key, String value) { | ||
map.put(key, value); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
opentracing-api/src/main/java/io/opentracing/propagation/TextMapExtract.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,40 @@ | ||
/* | ||
* Copyright 2016-2018 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.util.Iterator; | ||
import java.util.Map; | ||
|
||
/** | ||
* {@link TextMapExtract} is a built-in carrier for {@link Tracer#extract} only. | ||
* {@link TextMapExtract} implementations allows Tracers to write key:value String | ||
* pairs to arbitrary underlying sources of data. | ||
* | ||
* @see io.opentracing.Tracer#extract(Format, Object) | ||
*/ | ||
public interface TextMapExtract extends Iterable<Map.Entry<String, String>> { | ||
/** | ||
* 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>> iterator(); | ||
} |
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.