View Javadoc
1   /*
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2026, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v2.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package ch.qos.logback.classic.kryo;
15  
16  import ch.qos.logback.classic.spi.LoggerContextVO;
17  import ch.qos.logback.core.kryo.SerializerBase;
18  import com.esotericsoftware.kryo.kryo5.Kryo;
19  import com.esotericsoftware.kryo.kryo5.io.Input;
20  import com.esotericsoftware.kryo.kryo5.io.Output;
21  import com.esotericsoftware.kryo.kryo5.minlog.Log;
22  
23  import java.util.HashMap;
24  
25  public class LoggerContextVOSerializer extends SerializerBase<LoggerContextVO> {
26  
27  
28      public LoggerContextVOSerializer(int capacity) {
29          super(BiMapType.DIRECT_MAP, capacity);
30          setAcceptsNull(false);
31      }
32  
33      @Override
34      protected void writeNewEntry(Kryo kryo, Output output, LoggerContextVO loggerContextVO) {
35          //Log.info("writeNewEntry for LoggerContextVO: " + loggerContextVO);
36          kryo.writeObject(output, loggerContextVO.getName());
37          output.writeLong(loggerContextVO.getBirthTime());
38          kryo.writeObject(output, loggerContextVO.getPropertyMap());
39      }
40  
41      @Override
42      protected LoggerContextVO readNewEntry(Kryo kryo, Input input) {
43          //Log.info("readNewEntry for LoggerContextVO: ");
44          String name = kryo.readObject(input, String.class);
45          long birthTime = input.readLong();
46          HashMap<?, ?> map = kryo.readObject(input, java.util.HashMap.class);
47          LoggerContextVO deserialized = new LoggerContextVO(name, (HashMap<String, String>) map, birthTime);
48          //Log.info("readNewEntry for LoggerContextVO named " + name);
49          return deserialized;
50      }
51  
52  }