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