Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Container

Thomas Diesler edited this page May 26, 2014 · 23 revisions

Working with Containers

A Container is an instance of a Gravia Runtime.

The set of supported target containers includes but is not limited to

A Container has the following properties.

Clients can obtain instances of containers from the ContainerManager.

Managing Containers

The ContainerManager is the central entry point for working with containers. It containers operations to

  • Create, start, stop and destroy containers
  • Find containers by given identifiers
  • Associate a container with a given ProfileVersion
  • Associate a container with a list of given Profiles
  • Join/leave the Fabric8 cluster

Container instances returned by the ContainerManager are shallow immutable objects. They represent the state of physical containers at a moment in time.

Creating a Container

When Fabric8 bootstraps it automatically creates the current container. This would be a Tomcat, WildFly, Karaf container depending on the Fabric8 distribution that you bootstrap.

To create another Container from the current Container, you would use a ContainerBuilder and pass the so built CreateOptions to the ContainerManager like this

// Building the create options
KarafContainerBuilder builder = KarafContainerBuilder.create();
CreateOptions options = builder.build();

ContainerManager manager = ContainerManagerLocator.getContainerManager();
Container container = manager.createContainer(options);

The set of supported managed containers is

Creating a container provisions the default Profile

Starting/Stopping a Container

// Starting the container
ContainerManager manager = ContainerManagerLocator.getContainerManager();
container = manager.startContainer(container.getIdentity());

// Stopping the container
container = manager.stopContainer(container.getIdentity());

Destroying a Container

// Destroying the container
ContainerManager manager = ContainerManagerLocator.getContainerManager();
container = manager.destroyContainer(container.getIdentity());

A container that has associated child containers cannot be destroyed.

Concurrency and Locking Strategy

  • Read access to Containers can happen concurrently.
  • Each Container supports the notion of a read-write lock.
  • A client may explicitly acquire a write lock for a Container.
  • Obtaining a write lock for a Container also obtains a write lock on the associated ProfileVersion

Obtaining an exclusive lock on a Container is necessary when consistent access to Container content is required over a number of calls. For example when a Container is provisioned with Profile content it must be guaranteed that the Profile does not change and that no other lifecycle operations can be called on the Container.