@Generated(value="by gapic-generator") @BetaApi public class RouteClient extends Object implements BackgroundResource
This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:
try (RouteClient routeClient = RouteClient.create()) {
ProjectGlobalRouteName route = ProjectGlobalRouteName.of("[PROJECT]", "[ROUTE]");
Operation response = routeClient.deleteRoute(route);
}
Note: close() needs to be called on the routeClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().
The surface of this class includes several types of Java methods for each of the API's methods:
See the individual methods for example code.
Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.
This class can be customized by passing in a custom instance of RouteSettings to create(). For example:
To customize credentials:
RouteSettings routeSettings =
RouteSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
RouteClient routeClient =
RouteClient.create(routeSettings);
To customize the endpoint:
RouteSettings routeSettings =
RouteSettings.newBuilder().setEndpoint(myEndpoint).build();
RouteClient routeClient =
RouteClient.create(routeSettings);
Modifier and Type | Class and Description |
---|---|
static class |
RouteClient.ListRoutesFixedSizeCollection |
static class |
RouteClient.ListRoutesPage |
static class |
RouteClient.ListRoutesPagedResponse |
Modifier | Constructor and Description |
---|---|
protected |
RouteClient(RouteSettings settings)
Constructs an instance of RouteClient, using the given settings.
|
protected |
RouteClient(RouteStub stub) |
Modifier and Type | Method and Description |
---|---|
boolean |
awaitTermination(long duration,
TimeUnit unit) |
void |
close() |
static RouteClient |
create()
Constructs an instance of RouteClient with default settings.
|
static RouteClient |
create(RouteSettings settings)
Constructs an instance of RouteClient, using the given settings.
|
static RouteClient |
create(RouteStub stub)
Constructs an instance of RouteClient, using the given stub for making calls.
|
Operation |
deleteRoute(DeleteRouteHttpRequest request)
Deletes the specified Route resource.
|
Operation |
deleteRoute(ProjectGlobalRouteName route)
Deletes the specified Route resource.
|
Operation |
deleteRoute(String route)
Deletes the specified Route resource.
|
UnaryCallable<DeleteRouteHttpRequest,Operation> |
deleteRouteCallable()
Deletes the specified Route resource.
|
Route |
getRoute(GetRouteHttpRequest request)
Returns the specified Route resource.
|
Route |
getRoute(ProjectGlobalRouteName route)
Returns the specified Route resource.
|
Route |
getRoute(String route)
Returns the specified Route resource.
|
UnaryCallable<GetRouteHttpRequest,Route> |
getRouteCallable()
Returns the specified Route resource.
|
RouteSettings |
getSettings() |
RouteStub |
getStub() |
Operation |
insertRoute(InsertRouteHttpRequest request)
Creates a Route resource in the specified project using the data included in the request.
|
Operation |
insertRoute(ProjectName project,
Route routeResource)
Creates a Route resource in the specified project using the data included in the request.
|
Operation |
insertRoute(String project,
Route routeResource)
Creates a Route resource in the specified project using the data included in the request.
|
UnaryCallable<InsertRouteHttpRequest,Operation> |
insertRouteCallable()
Creates a Route resource in the specified project using the data included in the request.
|
boolean |
isShutdown() |
boolean |
isTerminated() |
RouteClient.ListRoutesPagedResponse |
listRoutes(ListRoutesHttpRequest request)
Retrieves the list of Route resources available to the specified project.
|
RouteClient.ListRoutesPagedResponse |
listRoutes(ProjectName project)
Retrieves the list of Route resources available to the specified project.
|
RouteClient.ListRoutesPagedResponse |
listRoutes(String project)
Retrieves the list of Route resources available to the specified project.
|
UnaryCallable<ListRoutesHttpRequest,RouteList> |
listRoutesCallable()
Retrieves the list of Route resources available to the specified project.
|
UnaryCallable<ListRoutesHttpRequest,RouteClient.ListRoutesPagedResponse> |
listRoutesPagedCallable()
Retrieves the list of Route resources available to the specified project.
|
void |
shutdown() |
void |
shutdownNow() |
protected RouteClient(RouteSettings settings) throws IOException
IOException
public static final RouteClient create() throws IOException
IOException
public static final RouteClient create(RouteSettings settings) throws IOException
IOException
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public static final RouteClient create(RouteStub stub)
public final RouteSettings getSettings()
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public RouteStub getStub()
@BetaApi public final Operation deleteRoute(ProjectGlobalRouteName route)
Sample code:
try (RouteClient routeClient = RouteClient.create()) {
ProjectGlobalRouteName route = ProjectGlobalRouteName.of("[PROJECT]", "[ROUTE]");
Operation response = routeClient.deleteRoute(route);
}
route
- Name of the Route resource to delete.ApiException
- if the remote call fails@BetaApi public final Operation deleteRoute(String route)
Sample code:
try (RouteClient routeClient = RouteClient.create()) {
ProjectGlobalRouteName route = ProjectGlobalRouteName.of("[PROJECT]", "[ROUTE]");
Operation response = routeClient.deleteRoute(route.toString());
}
route
- Name of the Route resource to delete.ApiException
- if the remote call fails@BetaApi public final Operation deleteRoute(DeleteRouteHttpRequest request)
Sample code:
try (RouteClient routeClient = RouteClient.create()) {
String formattedRoute = ProjectGlobalRouteName.format("[PROJECT]", "[ROUTE]");
DeleteRouteHttpRequest request = DeleteRouteHttpRequest.newBuilder()
.setRoute(formattedRoute)
.build();
Operation response = routeClient.deleteRoute(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call fails@BetaApi public final UnaryCallable<DeleteRouteHttpRequest,Operation> deleteRouteCallable()
Sample code:
try (RouteClient routeClient = RouteClient.create()) {
String formattedRoute = ProjectGlobalRouteName.format("[PROJECT]", "[ROUTE]");
DeleteRouteHttpRequest request = DeleteRouteHttpRequest.newBuilder()
.setRoute(formattedRoute)
.build();
ApiFuture<Operation> future = routeClient.deleteRouteCallable().futureCall(request);
// Do something
Operation response = future.get();
}
@BetaApi public final Route getRoute(ProjectGlobalRouteName route)
Sample code:
try (RouteClient routeClient = RouteClient.create()) {
ProjectGlobalRouteName route = ProjectGlobalRouteName.of("[PROJECT]", "[ROUTE]");
Route response = routeClient.getRoute(route);
}
route
- Name of the Route resource to return.ApiException
- if the remote call fails@BetaApi public final Route getRoute(String route)
Sample code:
try (RouteClient routeClient = RouteClient.create()) {
ProjectGlobalRouteName route = ProjectGlobalRouteName.of("[PROJECT]", "[ROUTE]");
Route response = routeClient.getRoute(route.toString());
}
route
- Name of the Route resource to return.ApiException
- if the remote call fails@BetaApi public final Route getRoute(GetRouteHttpRequest request)
Sample code:
try (RouteClient routeClient = RouteClient.create()) {
String formattedRoute = ProjectGlobalRouteName.format("[PROJECT]", "[ROUTE]");
GetRouteHttpRequest request = GetRouteHttpRequest.newBuilder()
.setRoute(formattedRoute)
.build();
Route response = routeClient.getRoute(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call fails@BetaApi public final UnaryCallable<GetRouteHttpRequest,Route> getRouteCallable()
Sample code:
try (RouteClient routeClient = RouteClient.create()) {
String formattedRoute = ProjectGlobalRouteName.format("[PROJECT]", "[ROUTE]");
GetRouteHttpRequest request = GetRouteHttpRequest.newBuilder()
.setRoute(formattedRoute)
.build();
ApiFuture<Route> future = routeClient.getRouteCallable().futureCall(request);
// Do something
Route response = future.get();
}
@BetaApi public final Operation insertRoute(ProjectName project, Route routeResource)
Sample code:
try (RouteClient routeClient = RouteClient.create()) {
ProjectName project = ProjectName.of("[PROJECT]");
Route routeResource = Route.newBuilder().build();
Operation response = routeClient.insertRoute(project, routeResource);
}
project
- Project ID for this request.routeResource
- Represents a Route resource. A route specifies how certain packets should
be handled by the network. Routes are associated with instances by tags and the set of
routes for a particular instance is called its routing table.
For each packet leaving an instance, the system searches that instance's routing table for a single best matching route. Routes match packets by destination IP address, preferring smaller or more specific ranges over larger ones. If there is a tie, the system selects the route with the smallest priority value. If there is still a tie, it uses the layer three and four packet headers to select just one of the remaining matching routes. The packet is then forwarded as specified by the nextHop field of the winning route - either to another instance destination, an instance gateway, or a Google Compute Engine-operated gateway.
Packets that do not match any route in the sending instance's routing table are dropped. (== resource_for beta.routes ==) (== resource_for v1.routes ==)
ApiException
- if the remote call fails@BetaApi public final Operation insertRoute(String project, Route routeResource)
Sample code:
try (RouteClient routeClient = RouteClient.create()) {
ProjectName project = ProjectName.of("[PROJECT]");
Route routeResource = Route.newBuilder().build();
Operation response = routeClient.insertRoute(project.toString(), routeResource);
}
project
- Project ID for this request.routeResource
- Represents a Route resource. A route specifies how certain packets should
be handled by the network. Routes are associated with instances by tags and the set of
routes for a particular instance is called its routing table.
For each packet leaving an instance, the system searches that instance's routing table for a single best matching route. Routes match packets by destination IP address, preferring smaller or more specific ranges over larger ones. If there is a tie, the system selects the route with the smallest priority value. If there is still a tie, it uses the layer three and four packet headers to select just one of the remaining matching routes. The packet is then forwarded as specified by the nextHop field of the winning route - either to another instance destination, an instance gateway, or a Google Compute Engine-operated gateway.
Packets that do not match any route in the sending instance's routing table are dropped. (== resource_for beta.routes ==) (== resource_for v1.routes ==)
ApiException
- if the remote call fails@BetaApi public final Operation insertRoute(InsertRouteHttpRequest request)
Sample code:
try (RouteClient routeClient = RouteClient.create()) {
String formattedProject = ProjectName.format("[PROJECT]");
Route routeResource = Route.newBuilder().build();
InsertRouteHttpRequest request = InsertRouteHttpRequest.newBuilder()
.setProject(formattedProject)
.setRouteResource(routeResource)
.build();
Operation response = routeClient.insertRoute(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call fails@BetaApi public final UnaryCallable<InsertRouteHttpRequest,Operation> insertRouteCallable()
Sample code:
try (RouteClient routeClient = RouteClient.create()) {
String formattedProject = ProjectName.format("[PROJECT]");
Route routeResource = Route.newBuilder().build();
InsertRouteHttpRequest request = InsertRouteHttpRequest.newBuilder()
.setProject(formattedProject)
.setRouteResource(routeResource)
.build();
ApiFuture<Operation> future = routeClient.insertRouteCallable().futureCall(request);
// Do something
Operation response = future.get();
}
@BetaApi public final RouteClient.ListRoutesPagedResponse listRoutes(ProjectName project)
Sample code:
try (RouteClient routeClient = RouteClient.create()) {
ProjectName project = ProjectName.of("[PROJECT]");
for (Route element : routeClient.listRoutes(project).iterateAll()) {
// doThingsWith(element);
}
}
project
- Project ID for this request.ApiException
- if the remote call fails@BetaApi public final RouteClient.ListRoutesPagedResponse listRoutes(String project)
Sample code:
try (RouteClient routeClient = RouteClient.create()) {
ProjectName project = ProjectName.of("[PROJECT]");
for (Route element : routeClient.listRoutes(project.toString()).iterateAll()) {
// doThingsWith(element);
}
}
project
- Project ID for this request.ApiException
- if the remote call fails@BetaApi public final RouteClient.ListRoutesPagedResponse listRoutes(ListRoutesHttpRequest request)
Sample code:
try (RouteClient routeClient = RouteClient.create()) {
String formattedProject = ProjectName.format("[PROJECT]");
ListRoutesHttpRequest request = ListRoutesHttpRequest.newBuilder()
.setProject(formattedProject)
.build();
for (Route element : routeClient.listRoutes(request).iterateAll()) {
// doThingsWith(element);
}
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call fails@BetaApi public final UnaryCallable<ListRoutesHttpRequest,RouteClient.ListRoutesPagedResponse> listRoutesPagedCallable()
Sample code:
try (RouteClient routeClient = RouteClient.create()) {
String formattedProject = ProjectName.format("[PROJECT]");
ListRoutesHttpRequest request = ListRoutesHttpRequest.newBuilder()
.setProject(formattedProject)
.build();
ApiFuture<ListRoutesPagedResponse> future = routeClient.listRoutesPagedCallable().futureCall(request);
// Do something
for (Route element : future.get().iterateAll()) {
// doThingsWith(element);
}
}
@BetaApi public final UnaryCallable<ListRoutesHttpRequest,RouteList> listRoutesCallable()
Sample code:
try (RouteClient routeClient = RouteClient.create()) {
String formattedProject = ProjectName.format("[PROJECT]");
ListRoutesHttpRequest request = ListRoutesHttpRequest.newBuilder()
.setProject(formattedProject)
.build();
while (true) {
RouteList response = routeClient.listRoutesCallable().call(request);
for (Route element : response.getItemsList()) {
// doThingsWith(element);
}
String nextPageToken = response.getNextPageToken();
if (!Strings.isNullOrEmpty(nextPageToken)) {
request = request.toBuilder().setPageToken(nextPageToken).build();
} else {
break;
}
}
}
public final void close()
close
in interface AutoCloseable
public void shutdown()
shutdown
in interface BackgroundResource
public boolean isShutdown()
isShutdown
in interface BackgroundResource
public boolean isTerminated()
isTerminated
in interface BackgroundResource
public void shutdownNow()
shutdownNow
in interface BackgroundResource
public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException
awaitTermination
in interface BackgroundResource
InterruptedException
Copyright © 2019 Google LLC. All rights reserved.