115 строки
12 KiB
YAML
115 строки
12 KiB
YAML
### YamlMime:JavaType
|
|
uid: "com.azure.core.util.Context"
|
|
fullName: "com.azure.core.util.Context"
|
|
name: "Context"
|
|
nameWithType: "Context"
|
|
summary: "`Context` offers a means of passing arbitrary data (key-value pairs) to pipeline policies."
|
|
inheritances:
|
|
- "<xref href=\"java.lang.Object?displayProperty=fullName\" data-throw-if-not-resolved=\"False\" />"
|
|
inheritedClassMethods:
|
|
- classRef: "java.lang.<a href=\"https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html\">Object</a>"
|
|
methodsRef:
|
|
- "<a href=\"https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--\">clone</a>"
|
|
- "<a href=\"https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-\">equals</a>"
|
|
- "<a href=\"https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--\">finalize</a>"
|
|
- "<a href=\"https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--\">getClass</a>"
|
|
- "<a href=\"https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--\">hashCode</a>"
|
|
- "<a href=\"https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--\">notify</a>"
|
|
- "<a href=\"https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--\">notifyAll</a>"
|
|
- "<a href=\"https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--\">toString</a>"
|
|
- "<a href=\"https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--\">wait</a>"
|
|
- "<a href=\"https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-\">wait</a>"
|
|
- "<a href=\"https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-\">wait</a>"
|
|
syntax: "public class **Context**"
|
|
constructors:
|
|
- uid: "com.azure.core.util.Context.Context(java.lang.Object,java.lang.Object)"
|
|
fullName: "com.azure.core.util.Context.Context(Object key, Object value)"
|
|
name: "Context(Object key, Object value)"
|
|
nameWithType: "Context.Context(Object key, Object value)"
|
|
summary: "Constructs a new <xref uid=\"com.azure.core.util.Context\" data-throw-if-not-resolved=\"false\" data-raw-source=\"Context\"></xref> object."
|
|
parameters:
|
|
- description: "The key with which the specified value should be associated."
|
|
name: "key"
|
|
type: "<a href=\"https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html\">Object</a>"
|
|
- description: "The value to be associated with the specified key."
|
|
name: "value"
|
|
type: "<a href=\"https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html\">Object</a>"
|
|
syntax: "public Context(Object key, Object value)"
|
|
desc: "Constructs a new <xref uid=\"com.azure.core.util.Context\" data-throw-if-not-resolved=\"false\" data-raw-source=\"Context\"></xref> object.\n\n**Code samples**\n\n```java\n// Create an empty context having no data\n Context emptyContext = Context.NONE;\n\n // OpenTelemetry context can be optionally passed using PARENT_TRACE_CONTEXT_KEY\n // when OpenTelemetry context is not provided explicitly, ambient\n // io.opentelemetry.context.Context.current() is used\n\n // Context contextWithSpan = new Context(PARENT_TRACE_CONTEXT_KEY, openTelemetryContext);\n```"
|
|
fields:
|
|
- uid: "com.azure.core.util.Context.NONE"
|
|
fullName: "com.azure.core.util.Context.NONE"
|
|
name: "NONE"
|
|
nameWithType: "Context.NONE"
|
|
summary: "Signifies that no data needs to be passed to the pipeline."
|
|
modifiers:
|
|
- "static"
|
|
- "final"
|
|
field:
|
|
type: "<xref href=\"com.azure.core.util.Context?alt=com.azure.core.util.Context&text=Context\" data-throw-if-not-resolved=\"False\" />"
|
|
syntax: "public static final Context NONE"
|
|
desc: "Signifies that no data needs to be passed to the pipeline."
|
|
methods:
|
|
- uid: "com.azure.core.util.Context.addData(java.lang.Object,java.lang.Object)"
|
|
fullName: "com.azure.core.util.Context.addData(Object key, Object value)"
|
|
name: "addData(Object key, Object value)"
|
|
nameWithType: "Context.addData(Object key, Object value)"
|
|
summary: "Adds a new immutable <xref uid=\"com.azure.core.util.Context\" data-throw-if-not-resolved=\"false\" data-raw-source=\"Context\"></xref> object with the specified key-value pair to the existing <xref uid=\"com.azure.core.util.Context\" data-throw-if-not-resolved=\"false\" data-raw-source=\"Context\"></xref> chain."
|
|
parameters:
|
|
- description: "The key with which the specified value should be associated."
|
|
name: "key"
|
|
type: "<a href=\"https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html\">Object</a>"
|
|
- description: "The value to be associated with the specified key."
|
|
name: "value"
|
|
type: "<a href=\"https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html\">Object</a>"
|
|
syntax: "public Context addData(Object key, Object value)"
|
|
desc: "Adds a new immutable <xref uid=\"com.azure.core.util.Context\" data-throw-if-not-resolved=\"false\" data-raw-source=\"Context\"></xref> object with the specified key-value pair to the existing <xref uid=\"com.azure.core.util.Context\" data-throw-if-not-resolved=\"false\" data-raw-source=\"Context\"></xref> chain.\n\n**Code samples**\n\n```java\n// Users can pass parent trace context information and additional metadata to attach to spans created by SDKs\n // using the com.azure.core.util.Context object.\n final String hostNameValue = \"host-name-value\";\n final String entityPathValue = \"entity-path-value\";\n\n // TraceContext represents a tracing solution context type - io.opentelemetry.context.Context for OpenTelemetry.\n final TraceContext parentContext = TraceContext.root();\n Context parentSpanContext = new Context(PARENT_TRACE_CONTEXT_KEY, parentContext);\n\n // Add a new key value pair to the existing context object.\n Context updatedContext = parentSpanContext.addData(HOST_NAME_KEY, hostNameValue)\n .addData(ENTITY_PATH_KEY, entityPathValue);\n\n // Both key values found on the same updated context object\n System.out.printf(\"Hostname value: %s%n\", updatedContext.getData(HOST_NAME_KEY).get());\n System.out.printf(\"Entity Path value: %s%n\", updatedContext.getData(ENTITY_PATH_KEY).get());\n```"
|
|
returns:
|
|
description: "the new <xref uid=\"com.azure.core.util.Context\" data-throw-if-not-resolved=\"false\" data-raw-source=\"Context\"></xref> object containing the specified pair added to the set of pairs."
|
|
type: "<xref href=\"com.azure.core.util.Context?alt=com.azure.core.util.Context&text=Context\" data-throw-if-not-resolved=\"False\" />"
|
|
- uid: "com.azure.core.util.Context.getData(java.lang.Object)"
|
|
fullName: "com.azure.core.util.Context.getData(Object key)"
|
|
name: "getData(Object key)"
|
|
nameWithType: "Context.getData(Object key)"
|
|
summary: "Scans the linked-list of <xref uid=\"com.azure.core.util.Context\" data-throw-if-not-resolved=\"false\" data-raw-source=\"Context\"></xref> objects looking for one with the specified key."
|
|
parameters:
|
|
- description: "The key to search for."
|
|
name: "key"
|
|
type: "<a href=\"https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html\">Object</a>"
|
|
syntax: "public Optional<Object> getData(Object key)"
|
|
desc: "Scans the linked-list of <xref uid=\"com.azure.core.util.Context\" data-throw-if-not-resolved=\"false\" data-raw-source=\"Context\"></xref> objects looking for one with the specified key. Note that the first key found, i.e. the most recently added, will be returned.\n\n**Code samples**\n\n```java\nfinal String key1 = \"Key1\";\n final String value1 = \"first-value\";\n\n // Create a context object with given key and value\n Context context = new Context(key1, value1);\n\n // Look for the specified key in the returned context object\n Optional<Object> optionalObject = context.getData(key1);\n if (optionalObject.isPresent()) {\n System.out.printf(\"Key1 value: %s%n\", optionalObject.get());\n } else {\n System.out.println(\"Key1 does not exist or have data.\");\n }\n```"
|
|
returns:
|
|
description: "The value of the specified key if it exists."
|
|
type: "<a href=\"https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html\">Optional</a><<a href=\"https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html\">Object</a>>"
|
|
- uid: "com.azure.core.util.Context.getValues()"
|
|
fullName: "com.azure.core.util.Context.getValues()"
|
|
name: "getValues()"
|
|
nameWithType: "Context.getValues()"
|
|
summary: "Scans the linked-list of <xref uid=\"com.azure.core.util.Context\" data-throw-if-not-resolved=\"false\" data-raw-source=\"Context\"></xref> objects populating a <xref uid=\"java.util.Map\" data-throw-if-not-resolved=\"false\" data-raw-source=\"Map\"></xref> with the values of the context."
|
|
syntax: "public Map<Object,Object> getValues()"
|
|
desc: "Scans the linked-list of <xref uid=\"com.azure.core.util.Context\" data-throw-if-not-resolved=\"false\" data-raw-source=\"Context\"></xref> objects populating a <xref uid=\"java.util.Map\" data-throw-if-not-resolved=\"false\" data-raw-source=\"Map\"></xref> with the values of the context.\n\n**Code samples**\n\n```java\nfinal String key1 = \"Key1\";\n final String value1 = \"first-value\";\n final String key2 = \"Key2\";\n final String value2 = \"second-value\";\n\n Context context = new Context(key1, value1)\n .addData(key2, value2);\n\n Map<Object, Object> contextValues = context.getValues();\n if (contextValues.containsKey(key1)) {\n System.out.printf(\"Key1 value: %s%n\", contextValues.get(key1));\n } else {\n System.out.println(\"Key1 does not exist.\");\n }\n\n if (contextValues.containsKey(key2)) {\n System.out.printf(\"Key2 value: %s%n\", contextValues.get(key2));\n } else {\n System.out.println(\"Key2 does not exist.\");\n }\n```"
|
|
returns:
|
|
description: "A map containing all values of the context linked-list."
|
|
type: "<a href=\"https://docs.oracle.com/javase/8/docs/api/java/util/Map.html\">Map</a><<a href=\"https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html\">Object</a>,<a href=\"https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html\">Object</a>>"
|
|
- uid: "com.azure.core.util.Context.of(java.util.Map<java.lang.Object,java.lang.Object>)"
|
|
fullName: "com.azure.core.util.Context.of(Map<Object,Object> keyValues)"
|
|
name: "of(Map<Object,Object> keyValues)"
|
|
nameWithType: "Context.of(Map<Object,Object> keyValues)"
|
|
summary: "Creates a new immutable <xref uid=\"com.azure.core.util.Context\" data-throw-if-not-resolved=\"false\" data-raw-source=\"Context\"></xref> object with all the keys and values provided by the input <xref uid=\"java.util.Map\" data-throw-if-not-resolved=\"false\" data-raw-source=\"Map\"></xref>."
|
|
modifiers:
|
|
- "static"
|
|
parameters:
|
|
- description: "The input key value pairs that will be added to this context."
|
|
name: "keyValues"
|
|
type: "<a href=\"https://docs.oracle.com/javase/8/docs/api/java/util/Map.html\">Map</a><<a href=\"https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html\">Object</a>,<a href=\"https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html\">Object</a>>"
|
|
syntax: "public static Context of(Map<Object,Object> keyValues)"
|
|
desc: "Creates a new immutable <xref uid=\"com.azure.core.util.Context\" data-throw-if-not-resolved=\"false\" data-raw-source=\"Context\"></xref> object with all the keys and values provided by the input <xref uid=\"java.util.Map\" data-throw-if-not-resolved=\"false\" data-raw-source=\"Map\"></xref>.\n\n**Code samples**\n\n```java\nfinal String key1 = \"Key1\";\n final String value1 = \"first-value\";\n Map<Object, Object> keyValueMap = new HashMap<>();\n keyValueMap.put(key1, value1);\n\n // Create a context using the provided key value pair map\n Context keyValueContext = Context.of(keyValueMap);\n System.out.printf(\"Key1 value %s%n\", keyValueContext.getData(key1).get());\n```"
|
|
returns:
|
|
description: "Context object containing all the key-value pairs in the input map."
|
|
type: "<xref href=\"com.azure.core.util.Context?alt=com.azure.core.util.Context&text=Context\" data-throw-if-not-resolved=\"False\" />"
|
|
type: "class"
|
|
desc: "`Context` offers a means of passing arbitrary data (key-value pairs) to pipeline policies. Most applications do not need to pass arbitrary data to the pipeline and can pass `Context.NONE` or `null`.\n\nEach context object is immutable. The <xref uid=\"com.azure.core.util.Context.addData(java.lang.Object,java.lang.Object)\" data-throw-if-not-resolved=\"false\" data-raw-source=\"#addData(Object, Object)\"></xref> method creates a new `Context` object that refers to its parent, forming a linked list."
|
|
metadata: {}
|
|
package: "com.azure.core.util"
|
|
artifact: com.azure:azure-core:1.52.0
|