001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions Copyright [year] [name of copyright owner]".
013 *
014 * Copyright 2010-2011 ApexIdentity Inc.
015 * Portions Copyright 2011-2015 ForgeRock AS.
016 */
017
018package org.forgerock.openig.heap;
019
020import org.forgerock.json.JsonValue;
021
022/**
023 * Creates and initializes an object that is stored in a {@link Heap}. A heaplet can retrieve
024 * object(s) it depends on from the heap.
025 */
026public interface Heaplet {
027
028    /**
029     * Called to request the heaplet to create an object.
030     *
031     * @param name
032     *            the name of the object to be created.
033     * @param config
034     *            the heaplet's configuration object.
035     * @param heap
036     *            the heap where object dependencies can be retrieved.
037     * @return the object created by the heaplet.
038     * @throws HeapException
039     *             if an exception occurred during creation of the object or any of its dependencies.
040     * @throws org.forgerock.json.JsonValueException
041     *             if the heaplet (or one of its dependencies) has a malformed configuration object.
042     */
043    Object create(Name name, JsonValue config, Heap heap) throws HeapException;
044
045    /**
046     * Called to indicate that the object created by the heaplet is going to be dereferenced.
047     * This gives the heaplet an opportunity to free any resources that are being held prior
048     * to its dereference.
049     */
050    void destroy();
051}