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.logging.log4j;
018
019import java.io.Serializable;
020
021/**
022 *  Markers are objects that are used to add easily filterable information to log messages.
023 *
024 *  Markers can be hierarchical - each Marker may have a parent. This allows for broad categories
025 *  being subdivided into more specific categories. An example might be a Marker named "Error" with
026 *  children named "SystemError" and "ApplicationError".
027 */
028public interface Marker extends Serializable {
029
030        /**
031     * Adds a Marker as a parent to this Marker.
032     * @param markers The parent markers to add.
033     * @return The current Marker object, thus allowing multiple adds to be concatenated.
034     * @throws IllegalArgumentException if the argument is {@code null}
035     */
036    Marker addParents(Marker... markers);
037
038    /**
039         * Returns true if the given marker has the same name as this marker.
040         *
041         * @param obj the reference object with which to compare. 
042         * @return true if the given marker has the same name as this marker.
043         * @since 2.4
044         */
045    @Override
046        public boolean equals(Object obj);
047
048    /**
049     * Returns the name of this Marker.
050     * @return The name of the Marker.
051     */
052    String getName();
053
054    /**
055     * Returns a list of parents of this Marker.
056     * @return The parent Markers or {@code null} if this Marker has no parents.
057     */
058    Marker[] getParents();
059
060    /**
061     * Returns a hash code value based on the name of this marker.
062     * Markers are equal if they have the same name.
063     * @return the computed hash code
064         * @since 2.4
065     */
066    @Override
067        public int hashCode();
068
069    /**
070     * Indicates whether this Marker has references to any other Markers.
071     * @return {@code true} if the Marker has parent Markers
072     */
073    boolean hasParents();
074
075    /**
076     * Checks whether this Marker is an instance of the specified Marker.
077     * @param m The Marker to check.
078     * @return {@code true} if this Marker or one of its ancestors is the specified Marker, {@code false} otherwise.
079     * @throws IllegalArgumentException if the argument is {@code null}
080     */
081    boolean isInstanceOf(Marker m);
082
083    /**
084     * Checks whether this Marker is an instance of the specified Marker.
085     * @param name The name of the Marker.
086     * @return {@code true} if this Marker or one of its ancestors matches the specified name, {@code false} otherwise.
087     * @throws IllegalArgumentException if the argument is {@code null}
088     */
089    boolean isInstanceOf(String name);
090
091    /**
092     * Removes the specified Marker as a parent of this Marker.
093     * @param marker The marker to remove.
094     * @return {@code true} if the marker was removed.
095     * @throws IllegalArgumentException if the argument is {@code null}
096     */
097    boolean remove(Marker marker);
098
099    /**
100     * Replaces the set of parent Markers with the provided Markers.
101     * @param markers The new set of parent Markers or {@code null} to clear the parents.
102     * @return The current Marker object.
103     */
104    Marker setParents(Marker... markers);
105}