1 /* 2 * (C)opyright 2010, Nikolaos Georgosopoulos 3 * 4 * This file is part of URLChecker. 5 6 URLChecker is free software: you can redistribute it and/or modify 7 it under the terms of the Lesser General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 URLChecker is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the Lesser General Public License 17 along with URLChecker. If not, see <http://www.gnu.org/licenses/>. 18 19 */ 20 package net.sf.urlchecker.v2.communication; 21 22 import org.apache.commons.configuration.ConfigurationException; 23 import org.apache.http.client.HttpClient; 24 25 /** 26 * The new CommunicationBuilder Class. This and the CheckUrlsCommand in the v2 27 * are mandatory to use the new HttpClient. 28 * 29 * <p> 30 * <b> $Id: CommunicationBuilder.java 183 2010-12-17 19:10:21Z georgosn $</b> 31 * </p> 32 * 33 * @author $LastChangedBy: georgosn $ 34 * @version $LastChangedRevision: 183 $ 35 */ 36 public class CommunicationBuilder { 37 38 /** 39 * Returns the multithreaded client configured by the default 40 * httpconfigurations file in the class-path. 41 * 42 * @return the multithreaded client 43 * @throws org.apache.commons.configuration.ConfigurationException 44 * the configuration exception 45 */ 46 public HttpClient getMultithreadedClient() throws ConfigurationException { 47 return CommunicationFactory.getInstance().configureClient(true); 48 } 49 50 /** 51 * Returns the multithreaded client configured by the given file if it 52 * exists in the class path. If the file cannot be found the 53 * httpconfigurations.xml will be tried and if nothing found the internal 54 * default configuration will be used. 55 * 56 * @param fileName 57 * the file name 58 * @return the multithreaded client 59 * @throws org.apache.commons.configuration.ConfigurationException 60 * the configuration exception 61 */ 62 public HttpClient getMultithreadedClient(String fileName) 63 throws ConfigurationException { 64 return CommunicationFactory.getInstance().configureClient(true, 65 fileName); 66 } 67 68 /** 69 * Return the singlethreaded client configured by the default 70 * httpconfigurations file in the class-path. 71 * 72 * @return the singlethreaded client 73 * @throws org.apache.commons.configuration.ConfigurationException 74 * the configuration exception 75 */ 76 public HttpClient getSinglethreadedClient() throws ConfigurationException { 77 return CommunicationFactory.getInstance().configureClient(false); 78 } 79 80 /** 81 * Gets the singlethreaded client configured by the given file if it exists 82 * in the class path. If the file cannot be found the httpconfigurations.xml 83 * will be tried and if nothing found the internal default configuration 84 * will be used. 85 * 86 * @param fileName 87 * the file name 88 * @return the singlethreaded client 89 * @throws org.apache.commons.configuration.ConfigurationException 90 * the configuration exception 91 */ 92 public HttpClient getSinglethreadedClient(String fileName) 93 throws ConfigurationException { 94 return CommunicationFactory.getInstance().configureClient(false, 95 fileName); 96 } 97 98 /** 99 * Shutdown communication. Releases any connections opened and forgotten. If 100 * used, the client is lost and needs to be reconfigured for another use. 101 */ 102 public void shutdownCommunication() { 103 CommunicationFactory.getInstance().shutdown(); 104 } 105 }