Class Resource<T extends Resource<T>>

java.lang.Object
com.azure.runtime.host.resources.Resource<T>
Type Parameters:
T - The specific type of the resource, which may or may not be a subtype of this class. This allows for method chaining, even when using a subtype, when used in conjunction with the API on SelfAware.
All Implemented Interfaces:
ResourceWithLifecycle, SelfAware<T>
Direct Known Subclasses:
AzureBicepResource, AzureStorageChildResource, Container, DockerFile, Executable, Value

public abstract class Resource<T extends Resource<T>> extends Object implements ResourceWithLifecycle, SelfAware<T>
Represents a generic resource within the Java Runtime for Azure framework. This abstract class serves as the foundation for all specific types of resources that can be part of a distributed application, such as containers, executables, values, and more. Each resource is characterized by a unique type and name, and can be annotated with additional metadata to provide further context or configuration.

Resources are the building blocks of a Java Runtime for Azure application, allowing developers to define the components that make up their application in a structured and extensible manner. This class provides common functionality that all resources share, including lifecycle management, self-awareness for fluent API design, and annotation support.

Usage example:

// Define a new DockerFile resource
DockerFile dockerFile = new DockerFile("MyDockerFile", "./Dockerfile", ".");
// Add the DockerFile to the application
DistributedApplication app = DistributedApplication.getInstance();
app.addResource(dockerFile);
See Also:
  • Constructor Details

  • Method Details

    • getType

      public final ResourceType getType()
      Gets the type of this resource. The type is used to categorize resources within the Java Runtime for Azure framework, facilitating type-specific handling and configuration.

      Usage example:

      ResourceType type = resource.getType();
      System.out.println("Resource type: " + type);
      
      Returns:
      The ResourceType of this resource.
    • getName

      public final String getName()
      Gets the name of this resource. The name is a unique identifier within the context of the application, allowing for easy reference and management of the resource.

      Usage example:

      String name = resource.getName();
      System.out.println("Resource name: " + name);
      
      Returns:
      The name of this resource.
    • getAnnotations

      public final List<ResourceAnnotation> getAnnotations()
      Returns a modifiable list of annotations associated with this resource. Annotations can be used to attach additional metadata or configuration to a resource, enhancing its functionality or altering its behavior.

      Usage example:

      resource.getAnnotations().add(new ResourceAnnotation("key", "value"));
      
      Returns:
      A list of ResourceAnnotation objects associated with this resource.
    • withAnnotation

      public final T withAnnotation(ResourceAnnotation annotation)
      Adds an annotation to this resource. This method provides a fluent interface for adding annotations, allowing for easy chaining of configuration methods.

      Usage example:

      resource.withAnnotation(new ResourceAnnotation("key", "value"));
      
      Parameters:
      annotation - The annotation to add to this resource.
      Returns:
      This resource, to allow for method chaining.
    • copyInto

      public void copyInto(Resource<?> newResource)
      Copies the characteristics and annotations of this resource into another resource. This method is useful for duplicating or templating resources within an application. Note that this method is currently incomplete and may not copy all aspects of the resource. It is recommended to review the implementation before use.

      Usage example:

      Resource<?> newResource = new SomeResourceType(...);
      existingResource.copyInto(newResource);
      
      Parameters:
      newResource - The resource into which the characteristics and annotations of this resource will be copied.