001/**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.camel.spi;
018
019/**
020 * Strategy for assigning the name part of the {@link javax.management.ObjectName}
021 * for a managed {@link org.apache.camel.CamelContext}.
022 * <p/>
023 * A strategy is needed as you can run multiple CamelContext in the same JVM, and want them
024 * to be enlisted in the JVM wide JMXMBeanServer. And this requires a strategy to be able
025 * to calculate unique names, in case of clashes. Or to enforce an explicit fixed name,
026 * to ensure the JMX name is not using dynamic counters etc.
027 * <p/>
028 * This strategy supports a naming pattern which supports at least the following tokens
029 * <ul>
030 *   <li>#camelId# - the camel id (eg the camel name)</li>
031 *   <li>#name# - same as #camelId#</li>
032 *   <li>#counter# - an incrementing counter</li>
033 * </ul>
034 *
035 * @see CamelContextNameStrategy
036 * @see org.apache.camel.impl.DefaultManagementNameStrategy
037 */
038public interface ManagementNameStrategy {
039
040    /**
041     * Gets the custom name pattern.
042     *
043     * @return the custom name pattern, or <tt>null</tt> if using the default pattern strategy.
044     */
045    String getNamePattern();
046
047    /**
048     * Sets a custom name pattern, which will be used instead of any default patterns.
049     *
050     * @param pattern a custom name pattern.
051     */
052    void setNamePattern(String pattern);
053
054    /**
055     * Gets the name
056     * <p/>
057     * The {@link #isFixedName()} determines if the name can be re-calculated such as when using a counter,
058     * or the name is always fixed.
059     *
060     * @return the name.
061     */
062    String getName();
063
064    /**
065     * Gets the next calculated name, if this strategy is not using fixed names.
066     * <p/>
067     * The {@link #isFixedName()} determines if the name can be re-calculated such as when using a counter,
068     * or the name is always fixed.
069     *
070     * @return the next name
071     */
072    String getNextName();
073
074    /**
075     * Whether the name will be fixed, or allow re-calculation such as by using an unique counter.
076     *
077     * @return <tt>true</tt> for fixed names, <tt>false</tt> for names which can re-calculated
078     */
079    boolean isFixedName();
080
081    /**
082     * Creates a new management name with the given pattern.
083     *
084     * @param pattern the pattern
085     * @param name    the name
086     * @param invalidCheck whether to check for invalid pattern
087     * @return the management name
088     * @throws IllegalArgumentException if the pattern or name is invalid or empty
089     */
090    String resolveManagementName(String pattern, String name, boolean invalidCheck);
091}