The Carbon Java Framework  

The Carbon Core Component Subsytem

Component Service Usage

Author: Doug Voet (dvoet at sapient.com)
Version: $Revision: 1.3 $($Author: araman $ / $Date: 2003/05/05 07:42:45 $)
Created: April 2002

Introduction

This document describes the Component Lookup Service and how to use it to get references to components.

The Component Lookup Service

The Lookup Service is the first point of contact for clients of Components. Lookup is responsible for locating Components and returning their references to clients.

Accessing Components

To access a component, call the fetchComponent method as in the following exmaple:

Cache quoteCache = (Cache) Lookup.getInstance().fetchComponent("/quote/QuoteCache");

Note that the fetchComponent method returns a generic type of Component. This must be casted to the specific type of the component you are requesting. The example assumes that the component is a Cache. This is defined within the component's configuration.

The parameter to the fetchComponent method is the logical name of the component. This name must match the name of a configuration document. The configuration document must contain a ComponentConfiguration or an extension of ComponentConfiguration. If the configuration is not found, the unchecked ComponentNotFoundException is thrown.

Component Instancing

A component is defined by code (functional interface, function implementation, assistants) and configuration. The name/location of the configuration within the Configuration Service defines the logical name of the component. Each component is deployed only once within the Lookup Service. Multiple requests to the Lookup Service using the same logical component name will return the same component instance. This does not preclude multiple deployments of the same type of component. This can be acheived with multiple configuration files. For example, 2 components, one named "/quote/QuoteCache1", the other named "/quote/QuoteCache2". They are both Cache components, but have different configuraitons. Only one instance of each reside within the Lookup Service.

Under the Covers

The Component Keeper

The Lookup singleton is a facade for the ComponentKeeper. In addition to fetching component references, the keeper can be used to destroy components and fetch a Collection of all the components currently deployed. See the org.sape.carbon.core.component.ComponentKeeper javadoc for details.

Component Creation

Each component is created only once. Creation takes place the first time someone tries to fetch it. All successive calls for the same component will return the same instance unless the component is destroyed in the interim. Fetch requests are synchronized such that no 2 threads will create the same component; if one thread is creating the component, the other will wait for the first to complete. Concurrent requests for different components should not effect each other.

Destroying Components

When a component is destroyed, it is removed from the Lookup Service. Subsequent requests for the component will behave as the first request for the component, i.e. it will be created anew.


Copyright © 2001-2003, Sapient Corporation