共用方式為


StatefulServiceReplica Interface

public interface StatefulServiceReplica

Defines behavior that governs the lifecycle of a replica, such as startup, initialization, role changes, and shutdown.

Remarks:Stateful service types must implement this interface. The logic of a stateful service type includes behavior that is invoked on Primary replicas and behavior that is invoked on Secondary replicas. If the service author wants to make use of the provided FabricReplicator, then the service must also implement StateProvider to use the implementation of StateReplicator that is provided by FabricReplicator

Method Summary

Modifier and Type Method and Description
void abort()

Ungracefully terminates an instance.

Remarks:Lease loss and, in response to the service, the use of reportFault(FaultType faultType) to report a Permanent fault are examples of ungraceful termination. When this method is invoked, the service instance should immediately release and clean up all references and return.

CompletableFuture<String> changeRoleAsync(ReplicaRole newRole, CancellationToken cancellationToken)

Changes the role of a Primary or Secondary replica.

Remarks:The new role is indicated as a parameter. When the service transitions to the new role, the service has a chance to update its current listening address. The listening address is the address where clients connect to it. This enables the service when it is a Primary replica to only claim some resources such as ports when communication from clients is expected.

CompletableFuture<Void> closeAsync(CancellationToken cancellationToken)

Closes the service replica when it is being shut down. Note that cancellation is advisory and that the operation might still be completed even if it is canceled.

void initialize(StatefulServiceInitializationParameters initializationParameters)

Initializes a newly created service replica.

CompletableFuture<Replicator> openAsync(ReplicaOpenMode openMode, StatefulServicePartition partition, CancellationToken cancellationToken)

Opens an initialized service replica so that additional actions can be taken.

Method Details

abort

public void abort()

Ungracefully terminates an instance.

Remarks:Lease loss and, in response to the service, the use of reportFault(FaultType faultType) to report a Permanent fault are examples of ungraceful termination. When this method is invoked, the service instance should immediately release and clean up all references and return.

changeRoleAsync

public CompletableFuture changeRoleAsync(ReplicaRole newRole, CancellationToken cancellationToken)

Changes the role of a Primary or Secondary replica.

Remarks:The new role is indicated as a parameter. When the service transitions to the new role, the service has a chance to update its current listening address. The listening address is the address where clients connect to it. This enables the service when it is a Primary replica to only claim some resources such as ports when communication from clients is expected.

Parameters:

newRole - The updated ReplicaRole that this replica should transition to.
cancellationToken -

CancellationToken object to indicate the cancellation status of the operation.

Returns:

Returns CompletableFuture of type java.lang.String, the service’s new connection address that is to be associated with the replica via Service Fabric Naming.

closeAsync

public CompletableFuture closeAsync(CancellationToken cancellationToken)

Closes the service replica when it is being shut down. Note that cancellation is advisory and that the operation might still be completed even if it is canceled.

Parameters:

cancellationToken -

CancellationToken object to indicate the cancellation status of the operation.

Returns:

Returns CompletableFuture.

initialize

public void initialize(StatefulServiceInitializationParameters initializationParameters)

Initializes a newly created service replica.

Parameters:

initializationParameters - The StatefulServiceInitializationParameters for this replica.

openAsync

public CompletableFuture openAsync(ReplicaOpenMode openMode, StatefulServicePartition partition, CancellationToken cancellationToken)

Opens an initialized service replica so that additional actions can be taken.

Parameters:

openMode - This supports the Service Fabric infrastructure and is not meant to be used directly from your code.
partition - The StatefulServicePartition information for this replica.
cancellationToken -

CancellationToken object to indicate the cancellation status of the operation.

Returns:

Returns CompletableFuture<Replicator>, the Replicator that is used by the stateful service. To use the Service Fabric implementation, in openAsync(ReplicaOpenMode openMode, StatefulServicePartition partition, CancellationToken cancellationToken) , the replica should return a FabricReplicator that is obtained from createReplicator(StateProvider stateProvider, ReplicatorSettings replicatorSettings)

Applies to