001/*
002 * Copyright (c) 2024. The BifroMQ Authors. All Rights Reserved.
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 *    http://www.apache.org/licenses/LICENSE-2.0
008 * Unless required by applicable law or agreed to in writing,
009 * software distributed under the License is distributed on an "AS IS" BASIS,
010 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
011 * See the License for the specific language governing permissions and limitations under the License.
012 */
013
014package com.baidu.bifromq.plugin;
015
016/**
017 * Provides a base context for custom BifroMQ plugins. This abstract class should be subclassed by developers to create
018 * a context for their specific plugin implementation. An instance of this class is created and managed by BifroMQ's
019 * plugin manager during the initialization phase of the plugin lifecycle.
020 *
021 * <p>Subclasses may override the {@link #init()} and {@link #close()} methods to perform initialization and cleanup
022 * tasks.</p>
023 */
024public abstract class BifroMQPluginContext {
025    protected final BifroMQPluginDescriptor descriptor;
026
027    /**
028     * Constructs a new plugin context with the specified descriptor.
029     *
030     * @param descriptor the descriptor that defines this plugin context
031     */
032    public BifroMQPluginContext(BifroMQPluginDescriptor descriptor) {
033        this.descriptor = descriptor;
034    }
035
036    /**
037     * Initializes the plugin context. This method is called during the plugin startup sequence. The default
038     * implementation does nothing and can be overridden by subclasses to provide specific behavior.
039     */
040    protected void init() {
041        // do nothing
042    }
043
044    /**
045     * Cleans up resources used by the plugin context. This method is called during the plugin shutdown sequence. The
046     * default implementation does nothing and can be overridden by subclasses to provide specific cleanup behavior.
047     */
048    protected void close() {
049        // do nothing
050    }
051}