001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.reef.wake.remote.address; 020 021import org.apache.reef.tang.Tang; 022import org.apache.reef.tang.exceptions.InjectionException; 023 024import java.util.logging.Level; 025import java.util.logging.Logger; 026 027/** 028 * Uses Tang to create the default LocalAddressProvider. 029 * 030 * @deprecated Have an instance of LocalAddressProvider injected instead. 031 */ 032@Deprecated 033public final class LocalAddressProviderFactory { 034 private static final Logger LOGGER = Logger.getLogger(LocalAddressProviderFactory.class.getName()); 035 private static LocalAddressProvider instance = null; 036 037 /** 038 * This class shall never be instantiated. 039 */ 040 private LocalAddressProviderFactory() { 041 // Intentionally left blank. 042 } 043 044 /** 045 * @return the default LocalAddressProvider 046 * @deprecated Have an instance of LocalAddressProvider injected instead. 047 */ 048 public static LocalAddressProvider getInstance() { 049 if (null == instance) { 050 makeInstance(); 051 } 052 return instance; 053 } 054 055 /** 056 * Makes the instance. 057 */ 058 private static void makeInstance() { 059 assert (null == instance); 060 try { 061 LOGGER.log(Level.FINER, "Instantiating default LocalAddressProvider for legacy users."); 062 instance = Tang.Factory.getTang().newInjector().getInstance(LocalAddressProvider.class); 063 LOGGER.log(Level.FINER, "Instantiated default LocalAddressProvider for legacy users."); 064 } catch (final InjectionException e) { 065 throw new RuntimeException("Unable to instantiate default LocalAddressProvider for legacy users.", e); 066 } 067 assert (null != instance); 068 } 069}