Udostępnij za pośrednictwem


IReliableStateManager.GetOrAddAsync Method

Definition

Overloads

GetOrAddAsync<T>(String)

Gets an IReliableState of the given type T and with the given name if it exists, or creates one and returns it if it doesn't already exist.

GetOrAddAsync<T>(Uri)

Gets an IReliableState of the given type T and with the given name if it exists, or creates one and returns it if it doesn't already exist.

GetOrAddAsync<T>(ITransaction, String)

Gets an IReliableState of the given type T and with the given name if it exists, or creates one and returns it if it doesn't already exist.

GetOrAddAsync<T>(ITransaction, Uri)

Gets an IReliableState of the given type T and with the given name if it exists, or creates one and returns it if it doesn't already exist.

GetOrAddAsync<T>(String, TimeSpan)

Gets an IReliableState of the given type T and with the given name if it exists, or creates one and returns it if it doesn't already exist.

GetOrAddAsync<T>(Uri, TimeSpan)

Gets an IReliableState of the given type T and with the given name if it exists, or creates one and returns it if it doesn't already exist.

GetOrAddAsync<T>(ITransaction, String, TimeSpan)

Gets an IReliableState of the given type T and with the given name if it exists, or creates one and returns it if it doesn't already exist.

GetOrAddAsync<T>(ITransaction, Uri, TimeSpan)

Gets an IReliableState of the given type T and with the given name if it exists, or creates one and returns it if it doesn't already exist.

GetOrAddAsync<T>(String)

Gets an IReliableState of the given type T and with the given name if it exists, or creates one and returns it if it doesn't already exist.

public System.Threading.Tasks.Task<T> GetOrAddAsync<T> (string name) where T : Microsoft.ServiceFabric.Data.IReliableState;
abstract member GetOrAddAsync : string -> System.Threading.Tasks.Task<'T (requires 'T :> Microsoft.ServiceFabric.Data.IReliableState)> (requires 'T :> Microsoft.ServiceFabric.Data.IReliableState)
Public Function GetOrAddAsync(Of T As IReliableState) (name As String) As Task(Of T)

Type Parameters

T

When specifying the IReliableState type, you may ask for either a class type or an interface type.

If specifying a class type, the system will attempt to return an instance of that type. If an instance of that type cannot be instantiated (e.g., abstract class, no suitable constructor), an ArgumentException is thrown.

If specifying an interface type, the manager will attempt to resolve the interface to a concrete type. If type mapping is specified by the user, this method will use the user-specified mapping to resolve the type (not yet supported). If type mapping is not specified by the user this method will select the default implementation for the interface given. If the given interface type does not have a default implementation, or a user-specified mapping for the type is not provided or the type is invalid, this method will throw ArgumentException.

Parameters

name
String

The name of the IReliableState. This name must be unique in this IReliableStateManager across IReliableState types, including unrelated types.

Returns

Task<T>

Task that represents the asynchronous operation. The task result is the reliable state instance.

Exceptions

name is null.

An instance of the type T cannot be created, or the existing IReliableState instance is not of type T.

The operation failed to complete within the default timeout.

Indicates that the Reliable State Manager is closed.

The operation has been internally faulted by the system. Retry the operation

Remarks

This is an atomic operation. When an IReliableState needs to be created, it will either complete and return successfully or it will not be created.

Applies to

GetOrAddAsync<T>(Uri)

Gets an IReliableState of the given type T and with the given name if it exists, or creates one and returns it if it doesn't already exist.

public System.Threading.Tasks.Task<T> GetOrAddAsync<T> (Uri name) where T : Microsoft.ServiceFabric.Data.IReliableState;
abstract member GetOrAddAsync : Uri -> System.Threading.Tasks.Task<'T (requires 'T :> Microsoft.ServiceFabric.Data.IReliableState)> (requires 'T :> Microsoft.ServiceFabric.Data.IReliableState)
Public Function GetOrAddAsync(Of T As IReliableState) (name As Uri) As Task(Of T)

Type Parameters

T

When specifying the IReliableState type, you may ask for either a class type or an interface type.

If specifying a class type, the system will attempt to return an instance of that type. If an instance of that type cannot be instantiated (e.g., abstract class, no suitable constructor), an ArgumentException is thrown.

If specifying an interface type, the manager will attempt to resolve the interface to a concrete type. If type mapping is specified by the user, this method will use the user-specified mapping to resolve the type (not yet supported). If type mapping is not specified by the user this method will select the default implementation for the interface given. If the given interface type does not have a default implementation, or a user-specified mapping for the type is not provided or the type is invalid, this method will throw ArgumentException.

Parameters

name
Uri

The name of the IReliableState. This name must be unique in this IReliableStateManager across IReliableState types, including unrelated types.

Returns

Task<T>

Task that represents the asynchronous operation. The task result is the reliable state instance.

Exceptions

name is null.

An instance of the type T cannot be created, or the existing IReliableState instance is not of type T.

The operation failed to complete within the default timeout.

Indicates that the Reliable State Manager is closed.

The operation has been internally faulted by the system. Retry the operation

Remarks

This is an atomic operation. When an IReliableState needs to be created, it will either complete and return successfully or it will not be created.

Applies to

GetOrAddAsync<T>(ITransaction, String)

Gets an IReliableState of the given type T and with the given name if it exists, or creates one and returns it if it doesn't already exist.

public System.Threading.Tasks.Task<T> GetOrAddAsync<T> (Microsoft.ServiceFabric.Data.ITransaction tx, string name) where T : Microsoft.ServiceFabric.Data.IReliableState;
abstract member GetOrAddAsync : Microsoft.ServiceFabric.Data.ITransaction * string -> System.Threading.Tasks.Task<'T (requires 'T :> Microsoft.ServiceFabric.Data.IReliableState)> (requires 'T :> Microsoft.ServiceFabric.Data.IReliableState)
Public Function GetOrAddAsync(Of T As IReliableState) (tx As ITransaction, name As String) As Task(Of T)

Type Parameters

T

When specifying the IReliableState type, you may ask for either a class type or an interface type.

If specifying a class type, the system will attempt to return an instance of that type. If an instance of that type cannot be instantiated (e.g., abstract class, no suitable constructor), an ArgumentException is thrown.

If specifying an interface type, the manager will attempt to resolve the interface to a concrete type. If type mapping is specified by the user, this method will use the user-specified mapping to resolve the type (not yet supported). If type mapping is not specified by the user this method will select the default implementation for the interface given. If the given interface type does not have a default implementation, or a user-specified mapping for the type is not provided or the type is invalid, this method will throw ArgumentException.

Parameters

tx
ITransaction

Transaction to associate this operation with.

name
String

The name of the IReliableState. This name must be unique in this IReliableStateManager across IReliableState types, including unrelated types.

Returns

Task<T>

Task that represents the asynchronous operation. The task result is the reliable state instance.

Exceptions

tx is null, or name is null.

An instance of the type T cannot be created, or the existing IReliableState instance is not of type T.

The operation failed to complete within the default timeout.

The transaction has been internally faulted by the system. Retry the operation on a new transaction

Thrown when a method call is invalid for the object's current state. Example, transaction used is already terminated: committed or aborted by the user. If this exception is thrown, it is highly likely that there is a bug in the service code of the use of transactions.

Indicates that the Reliable State Manager is closed.

Remarks

This is an atomic operation. When an IReliableState needs to be created, it will either complete and return successfully or it will not be created. If this method throws an exception, the transaction must be aborted.

Applies to

GetOrAddAsync<T>(ITransaction, Uri)

Gets an IReliableState of the given type T and with the given name if it exists, or creates one and returns it if it doesn't already exist.

public System.Threading.Tasks.Task<T> GetOrAddAsync<T> (Microsoft.ServiceFabric.Data.ITransaction tx, Uri name) where T : Microsoft.ServiceFabric.Data.IReliableState;
abstract member GetOrAddAsync : Microsoft.ServiceFabric.Data.ITransaction * Uri -> System.Threading.Tasks.Task<'T (requires 'T :> Microsoft.ServiceFabric.Data.IReliableState)> (requires 'T :> Microsoft.ServiceFabric.Data.IReliableState)
Public Function GetOrAddAsync(Of T As IReliableState) (tx As ITransaction, name As Uri) As Task(Of T)

Type Parameters

T

When specifying the IReliableState type, you may ask for either a class type or an interface type.

If specifying a class type, the system will attempt to return an instance of that type. If an instance of that type cannot be instantiated (e.g., abstract class, no suitable constructor), an ArgumentException is thrown.

If specifying an interface type, the manager will attempt to resolve the interface to a concrete type. If type mapping is specified by the user, this method will use the user-specified mapping to resolve the type (not yet supported). If type mapping is not specified by the user this method will select the default implementation for the interface given. If the given interface type does not have a default implementation, or a user-specified mapping for the type is not provided or the type is invalid, this method will throw ArgumentException.

Parameters

tx
ITransaction

Transaction to associate this operation with.

name
Uri

The name of the IReliableState. This name must be unique in this IReliableStateManager across IReliableState types, including unrelated types.

Returns

Task<T>

Task that represents the asynchronous operation. The task result is the reliable state instance.

Exceptions

tx is null, or name is null.

An instance of the type T cannot be created, or the existing IReliableState instance is not of type T.

The operation failed to complete within the default timeout.

The transaction has been internally faulted by the system. Retry the operation on a new transaction

Thrown when a method call is invalid for the object's current state. Example, transaction used is already terminated: committed or aborted by the user. If this exception is thrown, it is highly likely that there is a bug in the service code of the use of transactions.

Indicates that the Reliable State Manager is closed.

Remarks

This is an atomic operation. When an IReliableState needs to be created, it will either complete and return successfully or it will not be created. If this method throws an exception, the transaction must be aborted.

Applies to

GetOrAddAsync<T>(String, TimeSpan)

Gets an IReliableState of the given type T and with the given name if it exists, or creates one and returns it if it doesn't already exist.

public System.Threading.Tasks.Task<T> GetOrAddAsync<T> (string name, TimeSpan timeout) where T : Microsoft.ServiceFabric.Data.IReliableState;
abstract member GetOrAddAsync : string * TimeSpan -> System.Threading.Tasks.Task<'T (requires 'T :> Microsoft.ServiceFabric.Data.IReliableState)> (requires 'T :> Microsoft.ServiceFabric.Data.IReliableState)
Public Function GetOrAddAsync(Of T As IReliableState) (name As String, timeout As TimeSpan) As Task(Of T)

Type Parameters

T

When specifying the IReliableState type, you may ask for either a class type or an interface type.

If specifying a class type, the system will attempt to return an instance of that type. If an instance of that type cannot be instantiated (e.g., abstract class, no suitable constructor), an ArgumentException is thrown.

If specifying an interface type, the manager will attempt to resolve the interface to a concrete type. If type mapping is specified by the user, this method will use the user-specified mapping to resolve the type (not yet supported). If type mapping is not specified by the user this method will select the default implementation for the interface given. If the given interface type does not have a default implementation, or a user-specified mapping for the type is not provided or the type is invalid, this method will throw ArgumentException.

Parameters

name
String

The name of the IReliableState. This name must be unique in this IReliableStateManager across IReliableState types, including unrelated types.

timeout
TimeSpan

The amount of time to wait for the operation to complete before throwing a TimeoutException. Primarily used to prevent deadlocks. The default is 4 seconds.

Returns

Task<T>

Task that represents the asynchronous operation. The task result is the reliable state instance.

Exceptions

name is null.

An instance of the type T cannot be created, or the existing IReliableState instance is not of type T, or timeout is negative.

The operation failed to complete within the given timeout.

Indicates that the Reliable State Manager is closed.

The operation has been internally faulted by the system. Retry the operation

Remarks

This is an atomic operation. When an IReliableState needs to be created, it will either complete and return successfully or it will not be created.

Applies to

GetOrAddAsync<T>(Uri, TimeSpan)

Gets an IReliableState of the given type T and with the given name if it exists, or creates one and returns it if it doesn't already exist.

public System.Threading.Tasks.Task<T> GetOrAddAsync<T> (Uri name, TimeSpan timeout) where T : Microsoft.ServiceFabric.Data.IReliableState;
abstract member GetOrAddAsync : Uri * TimeSpan -> System.Threading.Tasks.Task<'T (requires 'T :> Microsoft.ServiceFabric.Data.IReliableState)> (requires 'T :> Microsoft.ServiceFabric.Data.IReliableState)
Public Function GetOrAddAsync(Of T As IReliableState) (name As Uri, timeout As TimeSpan) As Task(Of T)

Type Parameters

T

When specifying the IReliableState type, you may ask for either a class type or an interface type.

If specifying a class type, the system will attempt to return an instance of that type. If an instance of that type cannot be instantiated (e.g., abstract class, no suitable constructor), an ArgumentException is thrown.

If specifying an interface type, the manager will attempt to resolve the interface to a concrete type. If type mapping is specified by the user, this method will use the user-specified mapping to resolve the type (not yet supported). If type mapping is not specified by the user this method will select the default implementation for the interface given. If the given interface type does not have a default implementation, or a user-specified mapping for the type is not provided or the type is invalid, this method will throw ArgumentException.

Parameters

name
Uri

The name of the IReliableState. This name must be unique in this IReliableStateManager across IReliableState types, including unrelated types.

timeout
TimeSpan

The amount of time to wait for the operation to complete before throwing a TimeoutException. Primarily used to prevent deadlocks. The default is 4 seconds.

Returns

Task<T>

Task that represents the asynchronous operation. The task result is the reliable state instance.

Exceptions

name is null.

An instance of the type T cannot be created, or the existing IReliableState instance is not of type T, or timeout is negative.

The operation failed to complete within the given timeout.

Indicates that the Reliable State Manager is closed.

The operation has been internally faulted by the system. Retry the operation

Remarks

This is an atomic operation. When an IReliableState needs to be created, it will either complete and return successfully or it will not be created.

Applies to

GetOrAddAsync<T>(ITransaction, String, TimeSpan)

Gets an IReliableState of the given type T and with the given name if it exists, or creates one and returns it if it doesn't already exist.

public System.Threading.Tasks.Task<T> GetOrAddAsync<T> (Microsoft.ServiceFabric.Data.ITransaction tx, string name, TimeSpan timeout) where T : Microsoft.ServiceFabric.Data.IReliableState;
abstract member GetOrAddAsync : Microsoft.ServiceFabric.Data.ITransaction * string * TimeSpan -> System.Threading.Tasks.Task<'T (requires 'T :> Microsoft.ServiceFabric.Data.IReliableState)> (requires 'T :> Microsoft.ServiceFabric.Data.IReliableState)
Public Function GetOrAddAsync(Of T As IReliableState) (tx As ITransaction, name As String, timeout As TimeSpan) As Task(Of T)

Type Parameters

T

When specifying the IReliableState type, you may ask for either a class type or an interface type.

If specifying a class type, the system will attempt to return an instance of that type. If an instance of that type cannot be instantiated (e.g., abstract class, no suitable constructor), an ArgumentException is thrown.

If specifying an interface type, the manager will attempt to resolve the interface to a concrete type. If type mapping is specified by the user, this method will use the user-specified mapping to resolve the type (not yet supported). If type mapping is not specified by the user this method will select the default implementation for the interface given. If the given interface type does not have a default implementation, or a user-specified mapping for the type is not provided or the type is invalid, this method will throw ArgumentException.

Parameters

tx
ITransaction

Transaction to associate this operation with.

name
String

The name of the IReliableState. This name must be unique in this IReliableStateManager across IReliableState types, including unrelated types.

timeout
TimeSpan

The amount of time to wait for the operation to complete before throwing a TimeoutException. Primarily used to prevent deadlocks. The default is 4 seconds.

Returns

Task<T>

Task that represents the asynchronous operation. The task result is the reliable state instance.

Exceptions

tx is null, or name is null.

An instance of the type T cannot be created, or the existing IReliableState instance is not of type T, or timeout is negative.

The operation failed to complete within the given timeout.

The transaction has been internally faulted by the system. Retry the operation on a new transaction

Thrown when a method call is invalid for the object's current state. Example, transaction used is already terminated: committed or aborted by the user. If this exception is thrown, it is highly likely that there is a bug in the service code of the use of transactions.

Indicates that the Reliable State Manager is closed.

Remarks

This is an atomic operation. When an IReliableState needs to be created, it will either complete and return successfully or it will not be created. If this method throws an exception, the transaction must be aborted.

Applies to

GetOrAddAsync<T>(ITransaction, Uri, TimeSpan)

Gets an IReliableState of the given type T and with the given name if it exists, or creates one and returns it if it doesn't already exist.

public System.Threading.Tasks.Task<T> GetOrAddAsync<T> (Microsoft.ServiceFabric.Data.ITransaction tx, Uri name, TimeSpan timeout) where T : Microsoft.ServiceFabric.Data.IReliableState;
abstract member GetOrAddAsync : Microsoft.ServiceFabric.Data.ITransaction * Uri * TimeSpan -> System.Threading.Tasks.Task<'T (requires 'T :> Microsoft.ServiceFabric.Data.IReliableState)> (requires 'T :> Microsoft.ServiceFabric.Data.IReliableState)
Public Function GetOrAddAsync(Of T As IReliableState) (tx As ITransaction, name As Uri, timeout As TimeSpan) As Task(Of T)

Type Parameters

T

When specifying the IReliableState type, you may ask for either a class type or an interface type.

If specifying a class type, the system will attempt to return an instance of that type. If an instance of that type cannot be instantiated (e.g., abstract class, no suitable constructor), an ArgumentException is thrown.

If specifying an interface type, the manager will attempt to resolve the interface to a concrete type. If type mapping is specified by the user, this method will use the user-specified mapping to resolve the type (not yet supported). If type mapping is not specified by the user this method will select the default implementation for the interface given. If the given interface type does not have a default implementation, or a user-specified mapping for the type is not provided or the type is invalid, this method will throw ArgumentException.

Parameters

tx
ITransaction

Transaction to associate this operation with.

name
Uri

The name of the IReliableState. This name must be unique in this IReliableStateManager across IReliableState types, including unrelated types.

timeout
TimeSpan

The amount of time to wait for the operation to complete before throwing a TimeoutException. Primarily used to prevent deadlocks. The default is 4 seconds.

Returns

Task<T>

Task that represents the asynchronous operation. The task result is the reliable state instance.

Exceptions

tx is null, or name is null.

An instance of the type T cannot be created, or the existing IReliableState instance is not of type T, or timeout is negative.

The operation failed to complete within the given timeout.

The transaction has been internally faulted by the system. Retry the operation on a new transaction

Thrown when a method call is invalid for the object's current state. Example, transaction used is already terminated: committed or aborted by the user. If this exception is thrown, it is highly likely that there is a bug in the service code of the use of transactions.

Indicates that the Reliable State Manager is closed.

Remarks

This is an atomic operation. When an IReliableState needs to be created, it will either complete and return successfully or it will not be created. If this method throws an exception, the transaction must be aborted.

Applies to