All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.predic8.membrane.core.util.DNSCache Maven / Gradle / Ivy

There is a newer version: 5.6.0
Show newest version
/* Copyright 2012 predic8 GmbH, www.predic8.com

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License. */

package com.predic8.membrane.core.util;

import java.net.InetAddress;
import java.util.Collection;
import java.util.Hashtable;
import java.util.Map;

/**
 * See InetAddress Caching of InetAddress class
 *
 * Java 1.5 implementation of InetAddress Caching differs from Java 1.6 one.
 */
public class DNSCache {

	private Map hostNames = new Hashtable();
	private Map canonicalHostNames = new Hashtable();
	private Map hostAddresses = new Hashtable();

	public String getHostName(InetAddress address) {
		if (hostNames.containsKey(address))
			return hostNames.get(address);

		String hostName = address.getHostName();
		hostNames.put(address, hostName);
		return hostName;
	}

	public String getCanonicalHostName(InetAddress address) {
		if (canonicalHostNames.containsKey(address))
			return canonicalHostNames.get(address);

		String canonicalHostName = address.getCanonicalHostName();
		canonicalHostNames.put(address, canonicalHostName);
		return canonicalHostName;
	}

	public String getHostAddress(InetAddress address) {
		if (hostAddresses.containsKey(address))
			return hostAddresses.get(address);

		String hostAddress = address.getHostAddress();
		hostAddresses.put(address, hostAddress);
		return hostAddress;
	}

	public Collection getCachedHostNames() {
		return hostNames.values();
	}

	public Collection getCachedCanonicalHostNames() {
		return canonicalHostNames.values();
	}

	public Collection getCachedHostAddresses() {
		return hostAddresses.values();
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy