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 */ 017 package org.apache.logging.log4j.core.net; 018 019 import java.util.HashMap; 020 import java.util.Map; 021 import org.apache.logging.log4j.core.appender.OutputStreamManager; 022 023 import java.io.OutputStream; 024 import java.net.InetAddress; 025 026 /** 027 * Abstract base class for managing sockets. 028 */ 029 public abstract class AbstractSocketManager extends OutputStreamManager { 030 031 /** 032 * The internet address of the host. 033 */ 034 protected final InetAddress address; 035 /** 036 * The name of the host. 037 */ 038 protected final String host; 039 /** 040 * The port on the host. 041 */ 042 protected final int port; 043 044 /** 045 * The Constructor. 046 * @param name The unique name of this connection. 047 * @param os The OutputStream to manage. 048 * @param addr The internet address. 049 * @param host The target host name. 050 * @param port The target port number. 051 */ 052 public AbstractSocketManager(final String name, final OutputStream os, final InetAddress addr, final String host, 053 final int port) { 054 super(os, name); 055 this.address = addr; 056 this.host = host; 057 this.port = port; 058 } 059 060 /** 061 * AbstractSocketManager's content format is specified by:<p/> 062 * Key: "port" Value: provided "port" param<p/> 063 * Key: "address" Value: provided "address" param 064 * @return Map of content format keys supporting AbstractSocketManager 065 */ 066 public Map<String, String> getContentFormat() 067 { 068 Map<String, String> result = new HashMap<String, String>(super.getContentFormat()); 069 result.put("port", Integer.toString(port)); 070 result.put("address", address.getHostAddress()); 071 072 return result; 073 } 074 }