001/*
002 * (C) Copyright 2006-2017 Nuxeo (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Nuxeo - initial API and implementation
018 */
019package org.nuxeo.runtime.model;
020
021import org.nuxeo.runtime.service.TimestampedService;
022
023/**
024 * A Nuxeo Runtime component.
025 * <p>
026 * Components are extensible and adaptable objects and they provide methods to respond to component life cycle events.
027 *
028 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
029 */
030public interface Component extends Extensible, TimestampedService {
031
032    /**
033     * Activates the component.
034     * <p>
035     * This method is called by the runtime when a component is activated.
036     *
037     * @param context the runtime context
038     */
039    void activate(ComponentContext context);
040
041    /**
042     * Deactivates the component.
043     * <p>
044     * This method is called by the runtime when a component is deactivated.
045     *
046     * @param context the runtime context
047     */
048    void deactivate(ComponentContext context);
049
050    /**
051     * The component notification order for {@link #applicationStarted}.
052     * <p>
053     * Components are notified in increasing order. Order 1000 is the default order for components that don't care.
054     * Order 100 is the repository initialization.
055     *
056     * @return the order, 1000 by default
057     * @since 5.6
058     */
059    default int getApplicationStartedOrder() {
060        return ComponentStartOrders.DEFAULT;
061    }
062
063    /**
064     * Notify the component that Nuxeo Framework finished starting all Nuxeo bundles. Implementors must migrate the code
065     * of the applicationStarted and move it to {@link Component#start(ComponentContext)} and
066     * {@link #stop(ComponentContext)} methods
067     *
068     * @deprecated since 9.2, since the introduction of {@link Component#start(ComponentContext)} and
069     *             {@link #stop(ComponentContext)} methods
070     */
071    @Deprecated
072    default void applicationStarted(ComponentContext context) {
073        // do nothing by default
074    }
075
076    /**
077     * Start the component. This method is called after all the components were resolved and activated
078     *
079     * @since 9.2
080     */
081    void start(ComponentContext context);
082
083    /**
084     * Stop the component.
085     *
086     * @since 9.2
087     */
088    void stop(ComponentContext context) throws InterruptedException;
089
090}