更新大区

更新游戏服务器大区详细信息。

代码示例

Java

如需了解如何安装和使用 Game Servers 客户端库,请参阅 Game Servers 客户端库


import com.google.api.gax.longrunning.OperationFuture;
import com.google.cloud.gaming.v1.OperationMetadata;
import com.google.cloud.gaming.v1.Realm;
import com.google.cloud.gaming.v1.RealmsServiceClient;
import com.google.protobuf.FieldMask;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class UpdateRealm {
  public static void updateRealm(String projectId, String regionId, String realmId)
      throws IOException, InterruptedException, ExecutionException, TimeoutException {
    // String projectId = "your-project-id";
    // String regionId = "us-central1-f";
    // String realmId = "your-realm-id";
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (RealmsServiceClient client = RealmsServiceClient.create()) {
      String parent = String.format("projects/%s/locations/%s", projectId, regionId);
      String realmName = String.format("%s/realms/%s", parent, realmId);

      Realm realm = Realm.newBuilder().setName(realmName).setTimeZone("America/New_York").build();

      FieldMask fieldMask = FieldMask.newBuilder().addPaths("time_zone").build();

      OperationFuture<Realm, OperationMetadata> call = client.updateRealmAsync(realm, fieldMask);

      Realm updated = call.get(1, TimeUnit.MINUTES);
      System.out.println("Realm updated: " + updated.getName());
    }
  }
}

Python

如需了解如何安装和使用 Game Servers 客户端库,请参阅 Game Servers 客户端库

def update_realm(project_id, location, realm_id):
    """Updates a realm."""

    client = gaming.RealmsServiceClient()

    request = realms.UpdateRealmRequest(
        realm=realms.Realm(
            name=f"projects/{project_id}/locations/{location}/realms/{realm_id}",
            labels={"label-key-1": "label-value-1", "label-key-2": "label-value-2"},
        ),
        update_mask=field_mask.FieldMask(paths=["labels"]),
    )

    operation = client.update_realm(request)
    print(f"Update realm operation: {operation.operation.name}")
    operation.result(timeout=120)

后续步骤

如需搜索和过滤其他 Google Cloud 产品的代码示例,请参阅 Google Cloud 示例浏览器