-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mahina Kaholokula
authored
Jun 30, 2020
1 parent
dabb4ce
commit 50cb81d
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
...icedirectory/snippets/snippets/src/main/java/com/example/servicedirectory/Quickstart.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright 2020 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.example.servicedirectory; | ||
|
||
// [START servicedirectory_quickstart] | ||
|
||
import com.google.cloud.servicedirectory.v1beta1.LocationName; | ||
import com.google.cloud.servicedirectory.v1beta1.Namespace; | ||
import com.google.cloud.servicedirectory.v1beta1.RegistrationServiceClient; | ||
import com.google.cloud.servicedirectory.v1beta1.RegistrationServiceClient.ListNamespacesPagedResponse; | ||
import java.io.IOException; | ||
|
||
public class Quickstart { | ||
|
||
public static void quickstart() throws IOException { | ||
// TODO(developer): Replace these variables before running the sample. | ||
String projectId = "your-project-id"; | ||
String locationId = "your-region"; | ||
quickstart(projectId, locationId); | ||
} | ||
|
||
public static void quickstart(String projectId, String locationId) throws IOException { | ||
// 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 (RegistrationServiceClient client = RegistrationServiceClient.create()) { | ||
|
||
// The project and location that hold the namespace to list. | ||
LocationName parent = LocationName.of(projectId, locationId); | ||
|
||
// Call the API. | ||
ListNamespacesPagedResponse response = client.listNamespaces(parent); | ||
|
||
// Iterate over each namespace and print its name. | ||
System.out.println("Namespaces:"); | ||
for (Namespace namespace : response.iterateAll()) { | ||
System.out.println(namespace.getName()); | ||
} | ||
} | ||
} | ||
} | ||
// [END servicedirectory_quickstart] |