@Generated(value="by gapic-generator") public class SchemaServiceClient extends Object implements com.google.api.gax.core.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 (SchemaServiceClient schemaServiceClient = SchemaServiceClient.create()) {
ProjectName parent = ProjectName.of("[PROJECT]");
Schema schema = Schema.newBuilder().build();
String schemaId = "";
Schema response = schemaServiceClient.createSchema(parent, schema, schemaId);
}
Note: close() needs to be called on the schemaServiceClient 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 SchemaServiceSettings to create(). For example:
To customize credentials:
SchemaServiceSettings schemaServiceSettings =
SchemaServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
SchemaServiceClient schemaServiceClient =
SchemaServiceClient.create(schemaServiceSettings);
To customize the endpoint:
SchemaServiceSettings schemaServiceSettings =
SchemaServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
SchemaServiceClient schemaServiceClient =
SchemaServiceClient.create(schemaServiceSettings);
| Modifier and Type | Class and Description |
|---|---|
static class |
SchemaServiceClient.ListSchemasFixedSizeCollection |
static class |
SchemaServiceClient.ListSchemasPage |
static class |
SchemaServiceClient.ListSchemasPagedResponse |
| Modifier | Constructor and Description |
|---|---|
protected |
SchemaServiceClient(SchemaServiceSettings settings)
Constructs an instance of SchemaServiceClient, using the given settings.
|
protected |
SchemaServiceClient(SchemaServiceStub stub) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
awaitTermination(long duration,
TimeUnit unit) |
void |
close() |
static SchemaServiceClient |
create()
Constructs an instance of SchemaServiceClient with default settings.
|
static SchemaServiceClient |
create(SchemaServiceSettings settings)
Constructs an instance of SchemaServiceClient, using the given settings.
|
static SchemaServiceClient |
create(SchemaServiceStub stub)
Constructs an instance of SchemaServiceClient, using the given stub for making calls.
|
Schema |
createSchema(CreateSchemaRequest request)
Creates a schema.
|
Schema |
createSchema(ProjectName parent,
Schema schema,
String schemaId)
Creates a schema.
|
Schema |
createSchema(String parent,
Schema schema,
String schemaId)
Creates a schema.
|
com.google.api.gax.rpc.UnaryCallable<CreateSchemaRequest,Schema> |
createSchemaCallable()
Creates a schema.
|
void |
deleteSchema(DeleteSchemaRequest request)
Deletes a schema.
|
void |
deleteSchema(SchemaName name)
Deletes a schema.
|
void |
deleteSchema(String name)
Deletes a schema.
|
com.google.api.gax.rpc.UnaryCallable<DeleteSchemaRequest,com.google.protobuf.Empty> |
deleteSchemaCallable()
Deletes a schema.
|
Schema |
getSchema(GetSchemaRequest request)
Gets a schema.
|
Schema |
getSchema(SchemaName name)
Gets a schema.
|
Schema |
getSchema(String name)
Gets a schema.
|
com.google.api.gax.rpc.UnaryCallable<GetSchemaRequest,Schema> |
getSchemaCallable()
Gets a schema.
|
SchemaServiceSettings |
getSettings() |
SchemaServiceStub |
getStub() |
boolean |
isShutdown() |
boolean |
isTerminated() |
SchemaServiceClient.ListSchemasPagedResponse |
listSchemas(ListSchemasRequest request)
Lists schemas in a project.
|
SchemaServiceClient.ListSchemasPagedResponse |
listSchemas(ProjectName parent)
Lists schemas in a project.
|
SchemaServiceClient.ListSchemasPagedResponse |
listSchemas(String parent)
Lists schemas in a project.
|
com.google.api.gax.rpc.UnaryCallable<ListSchemasRequest,ListSchemasResponse> |
listSchemasCallable()
Lists schemas in a project.
|
com.google.api.gax.rpc.UnaryCallable<ListSchemasRequest,SchemaServiceClient.ListSchemasPagedResponse> |
listSchemasPagedCallable()
Lists schemas in a project.
|
void |
shutdown() |
void |
shutdownNow() |
ValidateMessageResponse |
validateMessage(ValidateMessageRequest request)
Validates a message against a schema.
|
com.google.api.gax.rpc.UnaryCallable<ValidateMessageRequest,ValidateMessageResponse> |
validateMessageCallable()
Validates a message against a schema.
|
ValidateSchemaResponse |
validateSchema(ProjectName parent,
Schema schema)
Validates a schema.
|
ValidateSchemaResponse |
validateSchema(String parent,
Schema schema)
Validates a schema.
|
ValidateSchemaResponse |
validateSchema(ValidateSchemaRequest request)
Validates a schema.
|
com.google.api.gax.rpc.UnaryCallable<ValidateSchemaRequest,ValidateSchemaResponse> |
validateSchemaCallable()
Validates a schema.
|
protected SchemaServiceClient(SchemaServiceSettings settings) throws IOException
IOException@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") protected SchemaServiceClient(SchemaServiceStub stub)
public static final SchemaServiceClient create() throws IOException
IOExceptionpublic static final SchemaServiceClient create(SchemaServiceSettings settings) throws IOException
IOException@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public static final SchemaServiceClient create(SchemaServiceStub stub)
public final SchemaServiceSettings getSettings()
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public SchemaServiceStub getStub()
public final Schema createSchema(ProjectName parent, Schema schema, String schemaId)
Sample code:
try (SchemaServiceClient schemaServiceClient = SchemaServiceClient.create()) {
ProjectName parent = ProjectName.of("[PROJECT]");
Schema schema = Schema.newBuilder().build();
String schemaId = "";
Schema response = schemaServiceClient.createSchema(parent, schema, schemaId);
}
parent - Required. The name of the project in which to create the schema. Format is
`projects/{project-id}`.schema - Required. The schema object to create.
This schema's `name` parameter is ignored. The schema object returned by CreateSchema will have a `name` made using the given `parent` and `schema_id`.
schemaId - The ID to use for the schema, which will become the final component of the
schema's resource name.
See https://cloud.google.com/pubsub/docs/admin#resource_names for resource name constraints.
com.google.api.gax.rpc.ApiException - if the remote call failspublic final Schema createSchema(String parent, Schema schema, String schemaId)
Sample code:
try (SchemaServiceClient schemaServiceClient = SchemaServiceClient.create()) {
ProjectName parent = ProjectName.of("[PROJECT]");
Schema schema = Schema.newBuilder().build();
String schemaId = "";
Schema response = schemaServiceClient.createSchema(parent.toString(), schema, schemaId);
}
parent - Required. The name of the project in which to create the schema. Format is
`projects/{project-id}`.schema - Required. The schema object to create.
This schema's `name` parameter is ignored. The schema object returned by CreateSchema will have a `name` made using the given `parent` and `schema_id`.
schemaId - The ID to use for the schema, which will become the final component of the
schema's resource name.
See https://cloud.google.com/pubsub/docs/admin#resource_names for resource name constraints.
com.google.api.gax.rpc.ApiException - if the remote call failspublic final Schema createSchema(CreateSchemaRequest request)
Sample code:
try (SchemaServiceClient schemaServiceClient = SchemaServiceClient.create()) {
ProjectName parent = ProjectName.of("[PROJECT]");
Schema schema = Schema.newBuilder().build();
CreateSchemaRequest request = CreateSchemaRequest.newBuilder()
.setParent(parent.toString())
.setSchema(schema)
.build();
Schema response = schemaServiceClient.createSchema(request);
}
request - The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException - if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<CreateSchemaRequest,Schema> createSchemaCallable()
Sample code:
try (SchemaServiceClient schemaServiceClient = SchemaServiceClient.create()) {
ProjectName parent = ProjectName.of("[PROJECT]");
Schema schema = Schema.newBuilder().build();
CreateSchemaRequest request = CreateSchemaRequest.newBuilder()
.setParent(parent.toString())
.setSchema(schema)
.build();
ApiFuture<Schema> future = schemaServiceClient.createSchemaCallable().futureCall(request);
// Do something
Schema response = future.get();
}
public final Schema getSchema(SchemaName name)
Sample code:
try (SchemaServiceClient schemaServiceClient = SchemaServiceClient.create()) {
SchemaName name = SchemaName.of("[PROJECT]", "[SCHEMA]");
Schema response = schemaServiceClient.getSchema(name);
}
name - Required. The name of the schema to get. Format is
`projects/{project}/schemas/{schema}`.com.google.api.gax.rpc.ApiException - if the remote call failspublic final Schema getSchema(String name)
Sample code:
try (SchemaServiceClient schemaServiceClient = SchemaServiceClient.create()) {
SchemaName name = SchemaName.of("[PROJECT]", "[SCHEMA]");
Schema response = schemaServiceClient.getSchema(name.toString());
}
name - Required. The name of the schema to get. Format is
`projects/{project}/schemas/{schema}`.com.google.api.gax.rpc.ApiException - if the remote call failspublic final Schema getSchema(GetSchemaRequest request)
Sample code:
try (SchemaServiceClient schemaServiceClient = SchemaServiceClient.create()) {
SchemaName name = SchemaName.of("[PROJECT]", "[SCHEMA]");
GetSchemaRequest request = GetSchemaRequest.newBuilder()
.setName(name.toString())
.build();
Schema response = schemaServiceClient.getSchema(request);
}
request - The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException - if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<GetSchemaRequest,Schema> getSchemaCallable()
Sample code:
try (SchemaServiceClient schemaServiceClient = SchemaServiceClient.create()) {
SchemaName name = SchemaName.of("[PROJECT]", "[SCHEMA]");
GetSchemaRequest request = GetSchemaRequest.newBuilder()
.setName(name.toString())
.build();
ApiFuture<Schema> future = schemaServiceClient.getSchemaCallable().futureCall(request);
// Do something
Schema response = future.get();
}
public final SchemaServiceClient.ListSchemasPagedResponse listSchemas(ProjectName parent)
Sample code:
try (SchemaServiceClient schemaServiceClient = SchemaServiceClient.create()) {
ProjectName parent = ProjectName.of("[PROJECT]");
for (Schema element : schemaServiceClient.listSchemas(parent).iterateAll()) {
// doThingsWith(element);
}
}
parent - Required. The name of the project in which to list schemas. Format is
`projects/{project-id}`.com.google.api.gax.rpc.ApiException - if the remote call failspublic final SchemaServiceClient.ListSchemasPagedResponse listSchemas(String parent)
Sample code:
try (SchemaServiceClient schemaServiceClient = SchemaServiceClient.create()) {
ProjectName parent = ProjectName.of("[PROJECT]");
for (Schema element : schemaServiceClient.listSchemas(parent.toString()).iterateAll()) {
// doThingsWith(element);
}
}
parent - Required. The name of the project in which to list schemas. Format is
`projects/{project-id}`.com.google.api.gax.rpc.ApiException - if the remote call failspublic final SchemaServiceClient.ListSchemasPagedResponse listSchemas(ListSchemasRequest request)
Sample code:
try (SchemaServiceClient schemaServiceClient = SchemaServiceClient.create()) {
ProjectName parent = ProjectName.of("[PROJECT]");
ListSchemasRequest request = ListSchemasRequest.newBuilder()
.setParent(parent.toString())
.build();
for (Schema element : schemaServiceClient.listSchemas(request).iterateAll()) {
// doThingsWith(element);
}
}
request - The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException - if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<ListSchemasRequest,SchemaServiceClient.ListSchemasPagedResponse> listSchemasPagedCallable()
Sample code:
try (SchemaServiceClient schemaServiceClient = SchemaServiceClient.create()) {
ProjectName parent = ProjectName.of("[PROJECT]");
ListSchemasRequest request = ListSchemasRequest.newBuilder()
.setParent(parent.toString())
.build();
ApiFuture<ListSchemasPagedResponse> future = schemaServiceClient.listSchemasPagedCallable().futureCall(request);
// Do something
for (Schema element : future.get().iterateAll()) {
// doThingsWith(element);
}
}
public final com.google.api.gax.rpc.UnaryCallable<ListSchemasRequest,ListSchemasResponse> listSchemasCallable()
Sample code:
try (SchemaServiceClient schemaServiceClient = SchemaServiceClient.create()) {
ProjectName parent = ProjectName.of("[PROJECT]");
ListSchemasRequest request = ListSchemasRequest.newBuilder()
.setParent(parent.toString())
.build();
while (true) {
ListSchemasResponse response = schemaServiceClient.listSchemasCallable().call(request);
for (Schema element : response.getSchemasList()) {
// doThingsWith(element);
}
String nextPageToken = response.getNextPageToken();
if (!Strings.isNullOrEmpty(nextPageToken)) {
request = request.toBuilder().setPageToken(nextPageToken).build();
} else {
break;
}
}
}
public final void deleteSchema(SchemaName name)
Sample code:
try (SchemaServiceClient schemaServiceClient = SchemaServiceClient.create()) {
SchemaName name = SchemaName.of("[PROJECT]", "[SCHEMA]");
schemaServiceClient.deleteSchema(name);
}
name - Required. Name of the schema to delete. Format is
`projects/{project}/schemas/{schema}`.com.google.api.gax.rpc.ApiException - if the remote call failspublic final void deleteSchema(String name)
Sample code:
try (SchemaServiceClient schemaServiceClient = SchemaServiceClient.create()) {
SchemaName name = SchemaName.of("[PROJECT]", "[SCHEMA]");
schemaServiceClient.deleteSchema(name.toString());
}
name - Required. Name of the schema to delete. Format is
`projects/{project}/schemas/{schema}`.com.google.api.gax.rpc.ApiException - if the remote call failspublic final void deleteSchema(DeleteSchemaRequest request)
Sample code:
try (SchemaServiceClient schemaServiceClient = SchemaServiceClient.create()) {
SchemaName name = SchemaName.of("[PROJECT]", "[SCHEMA]");
DeleteSchemaRequest request = DeleteSchemaRequest.newBuilder()
.setName(name.toString())
.build();
schemaServiceClient.deleteSchema(request);
}
request - The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException - if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<DeleteSchemaRequest,com.google.protobuf.Empty> deleteSchemaCallable()
Sample code:
try (SchemaServiceClient schemaServiceClient = SchemaServiceClient.create()) {
SchemaName name = SchemaName.of("[PROJECT]", "[SCHEMA]");
DeleteSchemaRequest request = DeleteSchemaRequest.newBuilder()
.setName(name.toString())
.build();
ApiFuture<Void> future = schemaServiceClient.deleteSchemaCallable().futureCall(request);
// Do something
future.get();
}
public final ValidateSchemaResponse validateSchema(ProjectName parent, Schema schema)
Sample code:
try (SchemaServiceClient schemaServiceClient = SchemaServiceClient.create()) {
ProjectName parent = ProjectName.of("[PROJECT]");
Schema schema = Schema.newBuilder().build();
ValidateSchemaResponse response = schemaServiceClient.validateSchema(parent, schema);
}
parent - Required. The name of the project in which to validate schemas. Format is
`projects/{project-id}`.schema - Required. The schema object to validate.com.google.api.gax.rpc.ApiException - if the remote call failspublic final ValidateSchemaResponse validateSchema(String parent, Schema schema)
Sample code:
try (SchemaServiceClient schemaServiceClient = SchemaServiceClient.create()) {
ProjectName parent = ProjectName.of("[PROJECT]");
Schema schema = Schema.newBuilder().build();
ValidateSchemaResponse response = schemaServiceClient.validateSchema(parent.toString(), schema);
}
parent - Required. The name of the project in which to validate schemas. Format is
`projects/{project-id}`.schema - Required. The schema object to validate.com.google.api.gax.rpc.ApiException - if the remote call failspublic final ValidateSchemaResponse validateSchema(ValidateSchemaRequest request)
Sample code:
try (SchemaServiceClient schemaServiceClient = SchemaServiceClient.create()) {
ProjectName parent = ProjectName.of("[PROJECT]");
Schema schema = Schema.newBuilder().build();
ValidateSchemaRequest request = ValidateSchemaRequest.newBuilder()
.setParent(parent.toString())
.setSchema(schema)
.build();
ValidateSchemaResponse response = schemaServiceClient.validateSchema(request);
}
request - The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException - if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<ValidateSchemaRequest,ValidateSchemaResponse> validateSchemaCallable()
Sample code:
try (SchemaServiceClient schemaServiceClient = SchemaServiceClient.create()) {
ProjectName parent = ProjectName.of("[PROJECT]");
Schema schema = Schema.newBuilder().build();
ValidateSchemaRequest request = ValidateSchemaRequest.newBuilder()
.setParent(parent.toString())
.setSchema(schema)
.build();
ApiFuture<ValidateSchemaResponse> future = schemaServiceClient.validateSchemaCallable().futureCall(request);
// Do something
ValidateSchemaResponse response = future.get();
}
public final ValidateMessageResponse validateMessage(ValidateMessageRequest request)
Sample code:
try (SchemaServiceClient schemaServiceClient = SchemaServiceClient.create()) {
ProjectName parent = ProjectName.of("[PROJECT]");
ValidateMessageRequest request = ValidateMessageRequest.newBuilder()
.setParent(parent.toString())
.build();
ValidateMessageResponse response = schemaServiceClient.validateMessage(request);
}
request - The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException - if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<ValidateMessageRequest,ValidateMessageResponse> validateMessageCallable()
Sample code:
try (SchemaServiceClient schemaServiceClient = SchemaServiceClient.create()) {
ProjectName parent = ProjectName.of("[PROJECT]");
ValidateMessageRequest request = ValidateMessageRequest.newBuilder()
.setParent(parent.toString())
.build();
ApiFuture<ValidateMessageResponse> future = schemaServiceClient.validateMessageCallable().futureCall(request);
// Do something
ValidateMessageResponse response = future.get();
}
public final void close()
close in interface AutoCloseablepublic void shutdown()
shutdown in interface com.google.api.gax.core.BackgroundResourcepublic boolean isShutdown()
isShutdown in interface com.google.api.gax.core.BackgroundResourcepublic boolean isTerminated()
isTerminated in interface com.google.api.gax.core.BackgroundResourcepublic void shutdownNow()
shutdownNow in interface com.google.api.gax.core.BackgroundResourcepublic boolean awaitTermination(long duration,
TimeUnit unit)
throws InterruptedException
awaitTermination in interface com.google.api.gax.core.BackgroundResourceInterruptedExceptionCopyright © 2021 Google LLC. All rights reserved.