StatelessServiceBase Class

  • java.lang.Object
    • microsoft.servicefabric.services.runtime.StatelessServiceBase

public class StatelessServiceBase

Represents base class for Microsoft Service Fabric based stateless reliable service.

Constructor Summary

Constructor Description
StatelessServiceBase()

Method Summary

Modifier and Type Method and Description
List<ServiceInstanceListener> createServiceInstanceListeners()

Override this method to supply the communication listeners for the service instance. The endpoints returned by the communication listener's are stored as a JSON string of ListenerName, Endpoint string pairs like {"Endpoints":{"Listener1":"Endpoint1","Listener2":"Endpoint2" ...}}

Map<String, String> getAddresses()

Gets list of all the addresses for this service instances as (ListenerName, Endpoint) key-value pair.

StatelessServicePartition getPartition()

Gets the service partition to which current service instance belongs.

StatelessServiceContext getServiceContext()

Gets the service context that this stateless service is operating under. It provides information like InstanceId, PartitionId, ServiceName etc.

void onAbort()

Notification that the service is being aborted. RunAsync MAY be running concurrently with the execution of this method, as cancellation is not awaited on the abort path.

CompletableFuture<?> onCloseAsync(CancellationToken cancellationToken)

This method is called as the final step of closing the service. Override this method to be notified that Close has completed for this instance's internal components.

CompletableFuture<?> onOpenAsync(CancellationToken cancellationToken)

This method is called as the final step of opening the service. Override this method to be notified that Open has completed for this instance's internal components.

CompletableFuture<?> runAsync(CancellationToken cancellationToken)

Services that want to implement a background task which runs when it is opened, just override this method with their logic.

void setAddresses(Map<String, String> addresses)

Sets list of all the addresses for this service instance as (ListenerName, Endpoint) key-value pair.

Constructor Details

StatelessServiceBase

protected StatelessServiceBase()

Method Details

createServiceInstanceListeners

protected List createServiceInstanceListeners()

Override this method to supply the communication listeners for the service instance. The endpoints returned by the communication listener's are stored as a JSON string of ListenerName, Endpoint string pairs like {"Endpoints":{"Listener1":"Endpoint1","Listener2":"Endpoint2" ...}}

Returns:

List of ServiceInstanceListeners

getAddresses

protected Map getAddresses()

Gets list of all the addresses for this service instances as (ListenerName, Endpoint) key-value pair.

Returns:

An Map containing list of addresses as (ListenerName, Endpoint) key-value pair.

getPartition

protected StatelessServicePartition getPartition()

Gets the service partition to which current service instance belongs.

Returns:

An StatelessServicePartition that represents the partition to which this service replica belongs.

getServiceContext

public StatelessServiceContext getServiceContext()

Gets the service context that this stateless service is operating under. It provides information like InstanceId, PartitionId, ServiceName etc.

Returns:

A StatelessServiceContext that describes the service context.

onAbort

protected void onAbort()

Notification that the service is being aborted. RunAsync MAY be running concurrently with the execution of this method, as cancellation is not awaited on the abort path.

onCloseAsync

protected CompletableFuture onCloseAsync(CancellationToken cancellationToken)

This method is called as the final step of closing the service. Override this method to be notified that Close has completed for this instance's internal components.

Parameters:

cancellationToken -

CancellationToken object to indicate the cancellation status of the operation.

Returns:

A CompletableFuture that represents outstanding operation.

onOpenAsync

protected CompletableFuture onOpenAsync(CancellationToken cancellationToken)

This method is called as the final step of opening the service. Override this method to be notified that Open has completed for this instance's internal components.

Parameters:

cancellationToken -

CancellationToken object to indicate the cancellation status of the operation.

Returns:

A CompletableFuture that represents outstanding operation.

runAsync

protected CompletableFuture runAsync(CancellationToken cancellationToken)

Services that want to implement a background task which runs when it is opened, just override this method with their logic.

Parameters:

cancellationToken -

CancellationToken object to indicate the cancellation status of the operation.

Returns:

A CompletableFuture that represents outstanding operation.

setAddresses

protected void setAddresses(Map addresses)

Sets list of all the addresses for this service instance as (ListenerName, Endpoint) key-value pair.

Parameters:

addresses - An Map containing list of addresses as (ListenerName, Endpoint) key-value pair.

Applies to