DialogStateManager Class

  • java.lang.Object
    • com.microsoft.bot.dialogs.memory.DialogStateManager

Implements

java.util.Map<java.lang.String,java.lang.Object>

public class DialogStateManager
implements java.util.Map<java.lang.String,java.lang.Object>

The DialogStateManager manages memory scopes and pathresolvers MemoryScopes are named root level Objects, which can exist either in the dialogcontext or off of turn state PathResolvers allow for shortcut behavior for mapping things like $foo to dialog.foo.

Constructor Summary

Constructor Description
DialogStateManager(DialogContext dc)

Initializes a new instance of the DialogStateManager class.

DialogStateManager(DialogContext dc, DialogStateManagerConfiguration configuration)

Initializes a new instance of the DialogStateManager class.

Method Summary

Modifier and Type Method and Description
T <T>getValue(String pathExpression, T defaultValue, Class<T> clsType)

Get the value from memory using path expression (NOTE: This always returns clone of value).

ResultPair<TypeT> <TypeT>tryGetValue(String path, Class<TypeT> clsType)

Get the value from memory using path expression (NOTE: This always returns clone of value).

void add(String key, Object value)

Adds an element to the dialog state manager.

void add(AbstractMap.SimpleEntry<String,Object> item)

Adds an item to the dialog state manager.

java.lang.Boolean anyPathChanged(int counter, Iterable<String> paths)

Check to see if any path has changed since watermark.

void clear()

Removes all items from the dialog state manager.

java.lang.Boolean contains(AbstractMap.SimpleEntry<String,Object> item)

Determines whether the dialog state manager contains a specific value.

final boolean containsKey(Object key)
java.lang.Boolean containsKey(String key)

Determines whether the dialog state manager contains an element with the specified key.

final boolean containsValue(Object value)
void copyTo(AbstractMap.SimpleEntry<String,Object>[] array, int arrayIndex)

Copies the elements of the dialog state manager to an array starting at a particular index.

java.util.concurrent.CompletableFuture<java.lang.Void> deleteScopesMemory(String name)

Delete the memory for a scope.

final java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Object>> entrySet()
final java.lang.Object get(Object key)
java.lang.Boolean getBoolValue(String pathExpression, Boolean defaultValue)

Get a boolean value from memory using a path expression.

DialogStateManagerConfiguration getConfiguration()

Sets the configured path resolvers and memory scopes for the dialog.

java.lang.Object getElement(String key)

Gets the elements with the specified key.

java.lang.Iterable<java.util.AbstractMap.SimpleEntry<java.lang.String,java.lang.Object>> getEnumerator()

Returns an Iterator that iterates through the collection.

int getIntValue(String pathExpression, int defaultValue)

Get a int value from memory using a path expression.

java.lang.Boolean getIsReadOnly()

Gets a value indicating whether the dialog state manager is read-only.

MemoryScope getMemoryScope(String name)

Get MemoryScope by name.

com.fasterxml.jackson.databind.JsonNode getMemorySnapshot()

Gets all memoryscopes suitable for logging.

java.lang.String getStringValue(String pathExpression, String defaultValue)

Get a String value from memory using a path expression.

final boolean isEmpty()
final java.util.Set<java.lang.String> keySet()
java.util.concurrent.CompletableFuture<java.lang.Void> loadAllScopes()

Load all of the scopes.

final java.lang.Object put(String key, Object value)
final void putAll(Map<? extends String,? extends Object> m)
final java.lang.Object remove(Object key)
java.lang.Boolean remove(String key)

Removes the element with the specified key from the dialog state manager.

boolean remove(AbstractMap.SimpleEntry<String,Object> item)

Removes the first occurrence of a specific Object from the dialog state manager.

void removeValue(String path)

Remove property from memory.

MemoryScope resolveMemoryScope(String path, StringBuilder remainingPath)

ResolveMemoryScope will find the MemoryScope for and return the remaining path.

java.util.concurrent.CompletableFuture<java.lang.Void> saveAllChanges()

Save all changes for all scopes.

void setConfiguration(DialogStateManagerConfiguration withDialogStateManagerConfiguration)

Sets the configured path resolvers and memory scopes for the dialog.

void setElement(String key, Object element)

Sets the elements with the specified key.

void setValue(String path, Object value)

Set memory to value.

final int size()
java.util.List<java.lang.String> trackPaths(Iterable<String> paths)

Track when specific paths are changed.

java.lang.String transformPath(String path)

Transform the path using the registered PathTransformers.

ResultPair<java.lang.Object> tryGetValue(String key, Object value)

Gets the value associated with the specified key.

final java.util.Collection<java.lang.Object> values()
java.lang.String version()

Version help caller to identify the updates and decide cache or not.

Methods inherited from java.lang.Object

java.lang.Object.clone java.lang.Object.equals java.lang.Object.finalize java.lang.Object.getClass java.lang.Object.hashCode java.lang.Object.notify java.lang.Object.notifyAll java.lang.Object.toString java.lang.Object.wait java.lang.Object.wait java.lang.Object.wait

Constructor Details

DialogStateManager

public DialogStateManager(DialogContext dc)

Initializes a new instance of the DialogStateManager class.

Parameters:

dc - The dialog context for the current turn of the conversation.

DialogStateManager

public DialogStateManager(DialogContext dc, DialogStateManagerConfiguration configuration)

Initializes a new instance of the DialogStateManager class.

Parameters:

dc - The dialog context for the current turn of the conversation.
configuration - Configuration for the dialog state manager.

Method Details

<T>getValue

public T getValue(String pathExpression, T defaultValue, Class clsType)

Get the value from memory using path expression (NOTE: This always returns clone of value).

Parameters:

pathExpression - Path expression to use.
defaultValue - Default value to return if there is none found.
clsType - Type of value that is being requested as a return.

Returns:

Result or the default value if the path is not valid.

<TypeT>tryGetValue

public ResultPair tryGetValue(String path, Class clsType)

Get the value from memory using path expression (NOTE: This always returns clone of value).

Parameters:

path - path expression to use.
clsType - the Type that is being requested as a result

Returns:

ResultPair with boolean and requested type TypeT as a result

add

public void add(String key, Object value)

Adds an element to the dialog state manager.

Parameters:

key - Key of the element to add.
value - Value of the element to add.

add

public void add(AbstractMap.SimpleEntry item)

Adds an item to the dialog state manager.

Parameters:

item - The SimpleEntry with the key and Object of the item to add.

anyPathChanged

public Boolean anyPathChanged(int counter, Iterable paths)

Check to see if any path has changed since watermark.

Parameters:

counter - Time counter to compare to.
paths - Paths from Trackpaths to check.

Returns:

True if any path has changed since counter.

clear

public void clear()

Removes all items from the dialog state manager.

contains

public Boolean contains(AbstractMap.SimpleEntry item)

Determines whether the dialog state manager contains a specific value.

Parameters:

item - The of the item to locate.

Returns:

True if item is found in the dialog state manager; otherwise,false

containsKey

public final boolean containsKey(Object key)

Parameters:

key

containsKey

public Boolean containsKey(String key)

Determines whether the dialog state manager contains an element with the specified key.

Parameters:

key - The key to locate in the dialog state manager.

Returns:

true if the dialog state manager contains an element with the key; otherwise, false.

containsValue

public final boolean containsValue(Object value)

Parameters:

value

copyTo

public void copyTo(AbstractMap.SimpleEntry[] array, int arrayIndex)

Copies the elements of the dialog state manager to an array starting at a particular index.

Parameters:

array - The one-dimensional array that is the destination of the elements copiedfrom the dialog state manager. The array must have zero-based indexing.
arrayIndex - The zero-based index in array at which copying begins.

deleteScopesMemory

public CompletableFuture deleteScopesMemory(String name)

Delete the memory for a scope.

Parameters:

name - name of the scope

Returns:

Completed CompletableFuture

entrySet

public final Set> entrySet()

get

public final Object get(Object key)

Parameters:

key

getBoolValue

public Boolean getBoolValue(String pathExpression, Boolean defaultValue)

Get a boolean value from memory using a path expression.

Parameters:

pathExpression - Path expression.
defaultValue - Default value if the value doesn't exist.

Returns:

Value or default value if path is not valid.

getConfiguration

public DialogStateManagerConfiguration getConfiguration()

Sets the configured path resolvers and memory scopes for the dialog.

Returns:

The DialogStateManagerConfiguration.

getElement

public Object getElement(String key)

Gets the elements with the specified key.

Parameters:

key - Key to get or set the element.

Returns:

The element with the specified key.

getEnumerator

public Iterable> getEnumerator()

Returns an Iterator that iterates through the collection.

Returns:

An Iterator that can be used to iterate through the collection.

getIntValue

public int getIntValue(String pathExpression, int defaultValue)

Get a int value from memory using a path expression.

Parameters:

pathExpression - Path expression.
defaultValue - Default value if the value doesn't exist.

Returns:

Value or default value if path is not valid.

getIsReadOnly

public Boolean getIsReadOnly()

Gets a value indicating whether the dialog state manager is read-only.

Returns:

true

getMemoryScope

public MemoryScope getMemoryScope(String name)

Get MemoryScope by name.

Parameters:

name - Name of scope.

Returns:

A memory scope.

getMemorySnapshot

public JsonNode getMemorySnapshot()

Gets all memoryscopes suitable for logging.

Returns:

JsonNode that which represents all memory scopes.

getStringValue

public String getStringValue(String pathExpression, String defaultValue)

Get a String value from memory using a path expression.

Parameters:

pathExpression - The path expression.
defaultValue - Default value if the value doesn't exist.

Returns:

String or default value if path is not valid.

isEmpty

public final boolean isEmpty()

keySet

public final Set keySet()

loadAllScopes

public CompletableFuture loadAllScopes()

Load all of the scopes.

Returns:

A Completed Future.

put

public final Object put(String key, Object value)

Parameters:

key
value

putAll

public final void putAll(Map m)

Parameters:

m

remove

public final Object remove(Object key)

Parameters:

key

remove

public Boolean remove(String key)

Removes the element with the specified key from the dialog state manager.

Parameters:

key - The key of the element to remove.

Returns:

true if the element is succesfully removed; otherwise, false.

remove

public boolean remove(AbstractMap.SimpleEntry item)

Removes the first occurrence of a specific Object from the dialog state manager.

Parameters:

item - The Object to remove from the dialog state manager.

Returns:

true if the item was successfully removed from the dialog state manager otherwise false

removeValue

public void removeValue(String path)

Remove property from memory.

Parameters:

path - Path to remove the leaf property.

resolveMemoryScope

public MemoryScope resolveMemoryScope(String path, StringBuilder remainingPath)

ResolveMemoryScope will find the MemoryScope for and return the remaining path.

Parameters:

path - Incoming path to resolve to scope and remaining path.
remainingPath - Remaining subpath in scope.

Returns:

The memory scope.

saveAllChanges

public CompletableFuture saveAllChanges()

Save all changes for all scopes.

Returns:

Completed Future

setConfiguration

public void setConfiguration(DialogStateManagerConfiguration withDialogStateManagerConfiguration)

Sets the configured path resolvers and memory scopes for the dialog.

Parameters:

withDialogStateManagerConfiguration - The configuration to set.

setElement

public void setElement(String key, Object element)

Sets the elements with the specified key.

Parameters:

key - Key to get or set the element.
element - The element to store with the provided key.

setValue

public void setValue(String path, Object value)

Set memory to value.

Parameters:

path - Path to memory.
value - Object to set.

size

public final int size()

trackPaths

public List trackPaths(Iterable paths)

Track when specific paths are changed.

Parameters:

paths - Paths to track.

Returns:

Normalized paths to pass to AnyPathChanged.

transformPath

public String transformPath(String path)

Transform the path using the registered PathTransformers.

Parameters:

path - Path to transform.

Returns:

The transformed path.

tryGetValue

public ResultPair tryGetValue(String key, Object value)

Gets the value associated with the specified key.

Parameters:

key - The key whose value to get.
value - When this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the type of the value parameter.

Returns:

true if the dialog state manager contains an element with the specified key;

values

public final Collection values()

version

public String version()

Version help caller to identify the updates and decide cache or not.

Returns:

Current version

Applies to