1 2 3 4 package net.nutch.clustering; 5 6 import net.nutch.plugin.*; 7 import net.nutch.util.NutchConf; 8 import java.util.logging.Logger ; 9 import net.nutch.util.LogFormatter; 10 11 17 public class OnlineClustererFactory { 18 public static final Logger LOG = LogFormatter 19 .getLogger(OnlineClustererFactory.class.getName()); 20 21 private final static ExtensionPoint X_POINT = PluginRepository.getInstance() 22 .getExtensionPoint(OnlineClusterer.X_POINT_ID); 23 24 private OnlineClustererFactory() {} 25 26 33 public static OnlineClusterer getOnlineClusterer() 34 throws PluginRuntimeException { 35 36 if (X_POINT == null) { 37 return null; 39 } 40 41 String extensionName = NutchConf.get("extension.clustering.extension-name"); 42 if (extensionName != null) { 43 Extension extension = findExtension(extensionName); 44 if (extension != null) { 45 LOG.info("Using clustering extension: " + extensionName); 46 return (OnlineClusterer) extension.getExtensionInstance(); 47 } 48 LOG.warning("Clustering extension not found: '" + extensionName 49 + "', trying the default"); 50 } 52 53 Extension[] extensions = X_POINT.getExtentens(); 54 if (extensions.length > 0) { 55 LOG.info("Using the first clustering extension found: " 56 + extensions[0].getId()); 57 return (OnlineClusterer) extensions[0].getExtensionInstance(); 58 } else { 59 return null; 60 } 61 } 62 63 private static Extension findExtension(String name) 64 throws PluginRuntimeException { 65 66 Extension[] extensions = X_POINT.getExtentens(); 67 68 for (int i = 0; i < extensions.length; i++) { 69 Extension extension = extensions[i]; 70 71 if (name.equals(extension.getId())) 72 return extension; 73 } 74 return null; 75 } 76 77 } 78 | Popular Tags |