All Downloads are FREE. Search and download functionalities are using the official Maven repository.

orbit.client.mesh.AddressableLeaser.kt Maven / Gradle / Ivy

There is a newer version: 2.0.0a19
Show newest version
/*
 Copyright (C) 2015 - 2019 Electronic Arts Inc.  All rights reserved.
 This file is part of the Orbit Project .
 See license in LICENSE.
 */

package orbit.client.mesh

import kotlinx.coroutines.guava.await
import orbit.client.net.GrpcClient
import orbit.shared.addressable.AddressableReference
import orbit.shared.proto.AddressableManagementGrpc
import orbit.shared.proto.AddressableManagementOuterClass
import orbit.shared.proto.toAddressableLease
import orbit.shared.proto.toAddressableReferenceProto

internal class AddressableLeaser(grpcClient: GrpcClient) {
    private val addressableManagementStub = AddressableManagementGrpc.newFutureStub(grpcClient.channel)

    suspend fun renewLease(reference: AddressableReference) =
        addressableManagementStub.renewLease(
            AddressableManagementOuterClass.RenewAddressableLeaseRequestProto.newBuilder()
                .setReference(reference.toAddressableReferenceProto())
                .build()
        ).await()?.lease?.toAddressableLease()

    suspend fun abandonLease(reference: AddressableReference) =
        addressableManagementStub.abandonLease(
            AddressableManagementOuterClass.AbandonAddressableLeaseRequestProto.newBuilder()
                .setReference(reference.toAddressableReferenceProto())
                .build()
        ).await()?.abandoned ?: false
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy