001/**
002 * Logback: the reliable, generic, fast and flexible logging framework.
003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
004 *
005 * This program and the accompanying materials are dual-licensed under
006 * either the terms of the Eclipse Public License v1.0 as published by
007 * the Eclipse Foundation
008 *
009 *   or (per the licensee's choosing)
010 *
011 * under the terms of the GNU Lesser General Public License version 2.1
012 * as published by the Free Software Foundation.
013 */
014package ch.qos.logback.classic.spi;
015
016import java.io.Serializable;
017import java.util.Map;
018
019import ch.qos.logback.classic.LoggerContext;
020
021/**
022 * LoggerContextVO offers a restricted view of LoggerContext intended to be
023 * exposed by LoggingEvent to remote systems. This restricted view is optimized
024 * for serialization.
025 * 
026 * <p>
027 * Some of the LoggerContext or Logger attributes MUST not survive
028 * serialization, e.g appenders, level values etc, as these attributes may have
029 * other values on the remote platform. LoggerContextVO class exposes the
030 * minimal and relevant attributes to the remote host, instead of having to deal
031 * with an incomplete LoggerContext with many null references.
032 * 
033 * @author Ceki G&uuml;lc&uuml;
034 * @author S&eacute;bastien Pennec
035 */
036public class LoggerContextVO implements Serializable {
037
038    private static final long serialVersionUID = 5488023392483144387L;
039
040    final String name;
041    final Map<String, String> propertyMap;
042    final long birthTime;
043
044    public LoggerContextVO(LoggerContext lc) {
045        this.name = lc.getName();
046        this.propertyMap = lc.getCopyOfPropertyMap();
047        this.birthTime = lc.getBirthTime();
048    }
049
050    public LoggerContextVO(String name, Map<String, String> propertyMap, long birthTime) {
051        this.name = name;
052        this.propertyMap = propertyMap;
053        this.birthTime = birthTime;
054    }
055
056    public String getName() {
057        return name;
058    }
059
060    public Map<String, String> getPropertyMap() {
061        return propertyMap;
062    }
063
064    public long getBirthTime() {
065        return birthTime;
066    }
067
068    @Override
069    public String toString() {
070        return "LoggerContextVO{" + "name='" + name + '\'' + ", propertyMap=" + propertyMap + ", birthTime=" + birthTime + '}';
071    }
072
073    @Override
074    public boolean equals(Object o) {
075        if (this == o)
076            return true;
077        if (!(o instanceof LoggerContextVO))
078            return false;
079
080        LoggerContextVO that = (LoggerContextVO) o;
081
082        if (birthTime != that.birthTime)
083            return false;
084        if (name != null ? !name.equals(that.name) : that.name != null)
085            return false;
086        if (propertyMap != null ? !propertyMap.equals(that.propertyMap) : that.propertyMap != null)
087            return false;
088
089        return true;
090    }
091
092    @Override
093    public int hashCode() {
094        int result = name != null ? name.hashCode() : 0;
095        result = 31 * result + (propertyMap != null ? propertyMap.hashCode() : 0);
096        result = 31 * result + (int) (birthTime ^ (birthTime >>> 32));
097
098        return result;
099    }
100}