Vision AI v1 API - Class StreamingServiceClient (1.0.0-beta01)

public abstract class StreamingServiceClient

Reference documentation and code samples for the Vision AI v1 API class StreamingServiceClient.

StreamingService client wrapper, for convenient use.

Inheritance

object > StreamingServiceClient

Namespace

Google.Cloud.VisionAI.V1

Assembly

Google.Cloud.VisionAI.V1.dll

Remarks

Streaming service for receiving and sending packets.

Properties

DefaultEndpoint

public static string DefaultEndpoint { get; }

The default endpoint for the StreamingService service, which is a host of "visionai.googleapis.com" and a port of 443.

Property Value
Type Description
string

DefaultScopes

public static IReadOnlyList<string> DefaultScopes { get; }

The default StreamingService scopes.

Property Value
Type Description
IReadOnlyListstring
Remarks

The default StreamingService scopes are:

GrpcClient

public virtual StreamingService.StreamingServiceClient GrpcClient { get; }

The underlying gRPC StreamingService client

Property Value
Type Description
StreamingServiceStreamingServiceClient

IAMPolicyClient

public virtual IAMPolicyClient IAMPolicyClient { get; }

The IAMPolicyClient associated with this client.

Property Value
Type Description
IAMPolicyClient

LocationsClient

public virtual LocationsClient LocationsClient { get; }

The LocationsClient associated with this client.

Property Value
Type Description
LocationsClient

ServiceMetadata

public static ServiceMetadata ServiceMetadata { get; }

The service metadata associated with this client type.

Property Value
Type Description
ServiceMetadata

Methods

AcquireLease(AcquireLeaseRequest, CallSettings)

public virtual Lease AcquireLease(AcquireLeaseRequest request, CallSettings callSettings = null)

AcquireLease acquires a lease.

Parameters
Name Description
request AcquireLeaseRequest

The request object containing all of the parameters for the API call.

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
Lease

The RPC response.

Example
// Create client
StreamingServiceClient streamingServiceClient = StreamingServiceClient.Create();
// Initialize request argument(s)
AcquireLeaseRequest request = new AcquireLeaseRequest
{
    Series = "",
    Owner = "",
    Term = new Duration(),
    LeaseType = LeaseType.Unspecified,
};
// Make the request
Lease response = streamingServiceClient.AcquireLease(request);

AcquireLeaseAsync(AcquireLeaseRequest, CallSettings)

public virtual Task<Lease> AcquireLeaseAsync(AcquireLeaseRequest request, CallSettings callSettings = null)

AcquireLease acquires a lease.

Parameters
Name Description
request AcquireLeaseRequest

The request object containing all of the parameters for the API call.

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
TaskLease

A Task containing the RPC response.

Example
// Create client
StreamingServiceClient streamingServiceClient = await StreamingServiceClient.CreateAsync();
// Initialize request argument(s)
AcquireLeaseRequest request = new AcquireLeaseRequest
{
    Series = "",
    Owner = "",
    Term = new Duration(),
    LeaseType = LeaseType.Unspecified,
};
// Make the request
Lease response = await streamingServiceClient.AcquireLeaseAsync(request);

AcquireLeaseAsync(AcquireLeaseRequest, CancellationToken)

public virtual Task<Lease> AcquireLeaseAsync(AcquireLeaseRequest request, CancellationToken cancellationToken)

AcquireLease acquires a lease.

Parameters
Name Description
request AcquireLeaseRequest

The request object containing all of the parameters for the API call.

cancellationToken CancellationToken

A CancellationToken to use for this RPC.

Returns
Type Description
TaskLease

A Task containing the RPC response.

Example
// Create client
StreamingServiceClient streamingServiceClient = await StreamingServiceClient.CreateAsync();
// Initialize request argument(s)
AcquireLeaseRequest request = new AcquireLeaseRequest
{
    Series = "",
    Owner = "",
    Term = new Duration(),
    LeaseType = LeaseType.Unspecified,
};
// Make the request
Lease response = await streamingServiceClient.AcquireLeaseAsync(request);

Create()

public static StreamingServiceClient Create()

Synchronously creates a StreamingServiceClient using the default credentials, endpoint and settings. To specify custom credentials or other settings, use StreamingServiceClientBuilder.

Returns
Type Description
StreamingServiceClient

The created StreamingServiceClient.

CreateAsync(CancellationToken)

public static Task<StreamingServiceClient> CreateAsync(CancellationToken cancellationToken = default)

Asynchronously creates a StreamingServiceClient using the default credentials, endpoint and settings. To specify custom credentials or other settings, use StreamingServiceClientBuilder.

Parameter
Name Description
cancellationToken CancellationToken

The CancellationToken to use while creating the client.

Returns
Type Description
TaskStreamingServiceClient

The task representing the created StreamingServiceClient.

ReceiveEvents(CallSettings, BidirectionalStreamingSettings)

public virtual StreamingServiceClient.ReceiveEventsStream ReceiveEvents(CallSettings callSettings = null, BidirectionalStreamingSettings streamingSettings = null)

Receive events given the stream name.

Parameters
Name Description
callSettings CallSettings

If not null, applies overrides to this RPC call.

streamingSettings BidirectionalStreamingSettings

If not null, applies streaming overrides to this RPC call.

Returns
Type Description
StreamingServiceClientReceiveEventsStream

The client-server stream.

Example
// Create client
StreamingServiceClient streamingServiceClient = StreamingServiceClient.Create();
// Initialize streaming call, retrieving the stream object
using StreamingServiceClient.ReceiveEventsStream response = streamingServiceClient.ReceiveEvents();

// Sending requests and retrieving responses can be arbitrarily interleaved
// Exact sequence will depend on client/server behavior

// Create task to do something with responses from server
Task responseHandlerTask = Task.Run(async () =>
{
    // Note that C# 8 code can use await foreach
    AsyncResponseStream<ReceiveEventsResponse> responseStream = response.GetResponseStream();
    while (await responseStream.MoveNextAsync())
    {
        ReceiveEventsResponse responseItem = responseStream.Current;
        // Do something with streamed response
    }
    // The response stream has completed
});

// Send requests to the server
bool done = false;
while (!done)
{
    // Initialize a request
    ReceiveEventsRequest request = new ReceiveEventsRequest
    {
        SetupRequest = new ReceiveEventsRequest.Types.SetupRequest(),
    };
    // Stream a request to the server
    await response.WriteAsync(request);
    // Set "done" to true when sending requests is complete
}

// Complete writing requests to the stream
await response.WriteCompleteAsync();
// Await the response handler
// This will complete once all server responses have been processed
await responseHandlerTask;

ReceivePackets(CallSettings, BidirectionalStreamingSettings)

public virtual StreamingServiceClient.ReceivePacketsStream ReceivePackets(CallSettings callSettings = null, BidirectionalStreamingSettings streamingSettings = null)

Receive packets from the series.

Parameters
Name Description
callSettings CallSettings

If not null, applies overrides to this RPC call.

streamingSettings BidirectionalStreamingSettings

If not null, applies streaming overrides to this RPC call.

Returns
Type Description
StreamingServiceClientReceivePacketsStream

The client-server stream.

Example
// Create client
StreamingServiceClient streamingServiceClient = StreamingServiceClient.Create();
// Initialize streaming call, retrieving the stream object
using StreamingServiceClient.ReceivePacketsStream response = streamingServiceClient.ReceivePackets();

// Sending requests and retrieving responses can be arbitrarily interleaved
// Exact sequence will depend on client/server behavior

// Create task to do something with responses from server
Task responseHandlerTask = Task.Run(async () =>
{
    // Note that C# 8 code can use await foreach
    AsyncResponseStream<ReceivePacketsResponse> responseStream = response.GetResponseStream();
    while (await responseStream.MoveNextAsync())
    {
        ReceivePacketsResponse responseItem = responseStream.Current;
        // Do something with streamed response
    }
    // The response stream has completed
});

// Send requests to the server
bool done = false;
while (!done)
{
    // Initialize a request
    ReceivePacketsRequest request = new ReceivePacketsRequest
    {
        SetupRequest = new ReceivePacketsRequest.Types.SetupRequest(),
    };
    // Stream a request to the server
    await response.WriteAsync(request);
    // Set "done" to true when sending requests is complete
}

// Complete writing requests to the stream
await response.WriteCompleteAsync();
// Await the response handler
// This will complete once all server responses have been processed
await responseHandlerTask;

ReleaseLease(ReleaseLeaseRequest, CallSettings)

public virtual ReleaseLeaseResponse ReleaseLease(ReleaseLeaseRequest request, CallSettings callSettings = null)

RleaseLease releases a lease.

Parameters
Name Description
request ReleaseLeaseRequest

The request object containing all of the parameters for the API call.

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
ReleaseLeaseResponse

The RPC response.

Example
// Create client
StreamingServiceClient streamingServiceClient = StreamingServiceClient.Create();
// Initialize request argument(s)
ReleaseLeaseRequest request = new ReleaseLeaseRequest
{
    Id = "",
    Series = "",
    Owner = "",
};
// Make the request
ReleaseLeaseResponse response = streamingServiceClient.ReleaseLease(request);

ReleaseLeaseAsync(ReleaseLeaseRequest, CallSettings)

public virtual Task<ReleaseLeaseResponse> ReleaseLeaseAsync(ReleaseLeaseRequest request, CallSettings callSettings = null)

RleaseLease releases a lease.

Parameters
Name Description
request ReleaseLeaseRequest

The request object containing all of the parameters for the API call.

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
TaskReleaseLeaseResponse

A Task containing the RPC response.

Example
// Create client
StreamingServiceClient streamingServiceClient = await StreamingServiceClient.CreateAsync();
// Initialize request argument(s)
ReleaseLeaseRequest request = new ReleaseLeaseRequest
{
    Id = "",
    Series = "",
    Owner = "",
};
// Make the request
ReleaseLeaseResponse response = await streamingServiceClient.ReleaseLeaseAsync(request);

ReleaseLeaseAsync(ReleaseLeaseRequest, CancellationToken)

public virtual Task<ReleaseLeaseResponse> ReleaseLeaseAsync(ReleaseLeaseRequest request, CancellationToken cancellationToken)

RleaseLease releases a lease.

Parameters
Name Description
request ReleaseLeaseRequest

The request object containing all of the parameters for the API call.

cancellationToken CancellationToken

A CancellationToken to use for this RPC.

Returns
Type Description
TaskReleaseLeaseResponse

A Task containing the RPC response.

Example
// Create client
StreamingServiceClient streamingServiceClient = await StreamingServiceClient.CreateAsync();
// Initialize request argument(s)
ReleaseLeaseRequest request = new ReleaseLeaseRequest
{
    Id = "",
    Series = "",
    Owner = "",
};
// Make the request
ReleaseLeaseResponse response = await streamingServiceClient.ReleaseLeaseAsync(request);

RenewLease(RenewLeaseRequest, CallSettings)

public virtual Lease RenewLease(RenewLeaseRequest request, CallSettings callSettings = null)

RenewLease renews a lease.

Parameters
Name Description
request RenewLeaseRequest

The request object containing all of the parameters for the API call.

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
Lease

The RPC response.

Example
// Create client
StreamingServiceClient streamingServiceClient = StreamingServiceClient.Create();
// Initialize request argument(s)
RenewLeaseRequest request = new RenewLeaseRequest
{
    Id = "",
    Series = "",
    Owner = "",
    Term = new Duration(),
};
// Make the request
Lease response = streamingServiceClient.RenewLease(request);

RenewLeaseAsync(RenewLeaseRequest, CallSettings)

public virtual Task<Lease> RenewLeaseAsync(RenewLeaseRequest request, CallSettings callSettings = null)

RenewLease renews a lease.

Parameters
Name Description
request RenewLeaseRequest

The request object containing all of the parameters for the API call.

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
TaskLease

A Task containing the RPC response.

Example
// Create client
StreamingServiceClient streamingServiceClient = await StreamingServiceClient.CreateAsync();
// Initialize request argument(s)
RenewLeaseRequest request = new RenewLeaseRequest
{
    Id = "",
    Series = "",
    Owner = "",
    Term = new Duration(),
};
// Make the request
Lease response = await streamingServiceClient.RenewLeaseAsync(request);

RenewLeaseAsync(RenewLeaseRequest, CancellationToken)

public virtual Task<Lease> RenewLeaseAsync(RenewLeaseRequest request, CancellationToken cancellationToken)

RenewLease renews a lease.

Parameters
Name Description
request RenewLeaseRequest

The request object containing all of the parameters for the API call.

cancellationToken CancellationToken

A CancellationToken to use for this RPC.

Returns
Type Description
TaskLease

A Task containing the RPC response.

Example
// Create client
StreamingServiceClient streamingServiceClient = await StreamingServiceClient.CreateAsync();
// Initialize request argument(s)
RenewLeaseRequest request = new RenewLeaseRequest
{
    Id = "",
    Series = "",
    Owner = "",
    Term = new Duration(),
};
// Make the request
Lease response = await streamingServiceClient.RenewLeaseAsync(request);

SendPackets(CallSettings, BidirectionalStreamingSettings)

public virtual StreamingServiceClient.SendPacketsStream SendPackets(CallSettings callSettings = null, BidirectionalStreamingSettings streamingSettings = null)

Send packets to the series.

Parameters
Name Description
callSettings CallSettings

If not null, applies overrides to this RPC call.

streamingSettings BidirectionalStreamingSettings

If not null, applies streaming overrides to this RPC call.

Returns
Type Description
StreamingServiceClientSendPacketsStream

The client-server stream.

Example
// Create client
StreamingServiceClient streamingServiceClient = StreamingServiceClient.Create();
// Initialize streaming call, retrieving the stream object
using StreamingServiceClient.SendPacketsStream response = streamingServiceClient.SendPackets();

// Sending requests and retrieving responses can be arbitrarily interleaved
// Exact sequence will depend on client/server behavior

// Create task to do something with responses from server
Task responseHandlerTask = Task.Run(async () =>
{
    // Note that C# 8 code can use await foreach
    AsyncResponseStream<SendPacketsResponse> responseStream = response.GetResponseStream();
    while (await responseStream.MoveNextAsync())
    {
        SendPacketsResponse responseItem = responseStream.Current;
        // Do something with streamed response
    }
    // The response stream has completed
});

// Send requests to the server
bool done = false;
while (!done)
{
    // Initialize a request
    SendPacketsRequest request = new SendPacketsRequest
    {
        Packet = new Packet(),
    };
    // Stream a request to the server
    await response.WriteAsync(request);
    // Set "done" to true when sending requests is complete
}

// Complete writing requests to the stream
await response.WriteCompleteAsync();
// Await the response handler
// This will complete once all server responses have been processed
await responseHandlerTask;

ShutdownDefaultChannelsAsync()

public static Task ShutdownDefaultChannelsAsync()

Shuts down any channels automatically created by Create() and CreateAsync(CancellationToken). Channels which weren't automatically created are not affected.

Returns
Type Description
Task

A task representing the asynchronous shutdown operation.

Remarks

After calling this method, further calls to Create() and CreateAsync(CancellationToken) will create new channels, which could in turn be shut down by another call to this method.