List of usage examples for java.util Set isEmpty
boolean isEmpty();
From source file:MainClass.java
public static void main(String[] a) { String elements[] = { "A", "B", "C", "D", "E" }; Set set = new HashSet(Arrays.asList(elements)); System.out.println(set.isEmpty()); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { CertificateFactory cf = CertificateFactory.getInstance("X.509"); FileInputStream in = new FileInputStream(args[0]); X509CRL crl = (X509CRL) cf.generateCRL(in); Set s = crl.getRevokedCertificates(); if (s != null && s.isEmpty() == false) { Iterator t = s.iterator(); while (t.hasNext()) { X509CRLEntry entry = (X509CRLEntry) t.next(); System.out.println("serial number = " + entry.getSerialNumber().toString(16)); System.out.println("revocation date = " + entry.getRevocationDate()); System.out.println("extensions = " + entry.hasExtensions()); }//from w w w . j a va2 s . c o m } in.close(); }
From source file:Main.java
public static void main(String[] a) { String elements[] = { "A", "B", "C", "D", "E" }; Set<String> set = new HashSet<String>(Arrays.asList(elements)); System.out.println(set.isEmpty()); }
From source file:dhtaccess.benchmark.LatencyMeasure.java
public static void main(String[] args) { boolean details = false; int repeats = DEFAULT_REPEATS; boolean doPut = true; // parse options Options options = new Options(); options.addOption("h", "help", false, "print help"); options.addOption("d", "details", false, "requests secret hash and TTL"); options.addOption("r", "repeats", true, "number of requests"); options.addOption("n", "no-put", false, "does not put"); CommandLineParser parser = new PosixParser(); CommandLine cmd = null;/*from w ww.jav a 2 s . c o m*/ try { cmd = parser.parse(options, args); } catch (ParseException e) { System.out.println("There is an invalid option."); e.printStackTrace(); System.exit(1); } String optVal; if (cmd.hasOption('h')) { usage(COMMAND); System.exit(1); } if (cmd.hasOption('d')) { details = true; } optVal = cmd.getOptionValue('r'); if (optVal != null) { repeats = Integer.parseInt(optVal); } if (cmd.hasOption('n')) { doPut = false; } args = cmd.getArgs(); // parse arguments if (args.length < 1) { usage(COMMAND); System.exit(1); } // prepare for RPC int numAccessor = args.length; DHTAccessor[] accessorArray = new DHTAccessor[numAccessor]; try { for (int i = 0; i < numAccessor; i++) { accessorArray[i] = new DHTAccessor(args[i]); } } catch (MalformedURLException e) { e.printStackTrace(); System.exit(1); } // generate key prefix Random rnd = new Random(System.currentTimeMillis()); StringBuilder sb = new StringBuilder(); for (int i = 0; i < KEY_PREFIX_LENGTH; i++) { sb.append((char) ('a' + rnd.nextInt(26))); } String keyPrefix = sb.toString(); String valuePrefix = VALUE_PREFIX; // benchmarking System.out.println("Repeats " + repeats + " times."); if (doPut) { System.out.println("Putting: " + keyPrefix + "<number>"); for (int i = 0; i < repeats; i++) { byte[] key = null, value = null; try { key = (keyPrefix + i).getBytes(ENCODE); value = (valuePrefix + i).getBytes(ENCODE); } catch (UnsupportedEncodingException e) { e.printStackTrace(); System.exit(1); } int accIndex = rnd.nextInt(numAccessor); DHTAccessor acc = accessorArray[accIndex]; acc.put(key, value, TTL); } } System.out.println("Benchmarking by getting."); int count = 0; long startTime = System.currentTimeMillis(); if (details) { for (int i = 0; i < repeats; i++) { byte[] key = null; try { key = (keyPrefix + i).getBytes(ENCODE); } catch (UnsupportedEncodingException e) { e.printStackTrace(); System.exit(1); } int accIndex = rnd.nextInt(numAccessor); DHTAccessor acc = accessorArray[accIndex]; Set<DetailedGetResult> valueSet = acc.getDetails(key); if (valueSet != null && !valueSet.isEmpty()) { count++; } } } else { for (int i = 0; i < repeats; i++) { byte[] key = null; try { key = (keyPrefix + i).getBytes(ENCODE); } catch (UnsupportedEncodingException e) { e.printStackTrace(); System.exit(1); } int accIndex = rnd.nextInt(numAccessor); DHTAccessor acc = accessorArray[accIndex]; Set<byte[]> valueSet = acc.get(key); if (valueSet != null && !valueSet.isEmpty()) { count++; } } } System.out.println(System.currentTimeMillis() - startTime + " msec."); System.out.println("Rate of successful gets: " + count + " / " + repeats); }
From source file:net.ontopia.topicmaps.cmdlineutils.rdbms.RDBMSIndexTool.java
public static void main(String[] argv) throws Exception { // Initialize logging CmdlineUtils.initializeLogging();/*from www. java 2 s. c om*/ // Register logging options CmdlineOptions options = new CmdlineOptions("RDBMSIndexTool", argv); CmdlineUtils.registerLoggingOptions(options); // Parse command line options try { options.parse(); } catch (CmdlineOptions.OptionsException e) { System.err.println("Error: " + e.getMessage()); System.exit(1); } // Get command line arguments String[] args = options.getArguments(); if (args.length != 1) { usage(); System.exit(3); } // load database schema project ClassLoader cloader = RDBMSIndexTool.class.getClassLoader(); InputStream istream = cloader.getResourceAsStream("net/ontopia/topicmaps/impl/rdbms/config/schema.xml"); Project dbp = DatabaseProjectReader.loadProject(istream); // open database connection String propfile = args[0]; ConnectionFactoryIF cf = new DefaultConnectionFactory(PropertyUtils.loadProperties(new File(propfile)), true); Connection conn = cf.requestConnection(); try { DatabaseMetaData dbm = conn.getMetaData(); boolean downcase = dbm.storesLowerCaseIdentifiers(); Map extra_indexes = new TreeMap(); Map missing_indexes = new TreeMap(); Iterator tables = dbp.getTables().iterator(); while (tables.hasNext()) { Table table = (Table) tables.next(); String table_name = (downcase ? table.getName().toLowerCase() : table.getName()); //! System.out.println("T :" + table_name); // get primary keys from database Map pkeys = getPrimaryKeys(table_name, dbm); // get indexes from database Map indexes = getIndexes(table_name, dbm); Map dindexes = new HashMap(); if (table.getPrimaryKeys() != null) { String pkey = table_name + '(' + StringUtils.join(table.getPrimaryKeys(), ',') + ')'; if (!pkeys.containsKey(pkey)) System.out.println("PKM: " + pkey); } Iterator iter = table.getIndexes().iterator(); while (iter.hasNext()) { Index index = (Index) iter.next(); String i = table_name + '(' + StringUtils.join(index.getColumns(), ',') + ')'; String index_name = (downcase ? index.getName().toLowerCase() : index.getName()); dindexes.put(i, index_name); } Set extra = new HashSet(indexes.keySet()); extra.removeAll(dindexes.keySet()); extra.removeAll(pkeys.keySet()); if (!extra.isEmpty()) { Iterator i = extra.iterator(); while (i.hasNext()) { Object k = i.next(); extra_indexes.put(k, indexes.get(k)); } } Set missing = new HashSet(dindexes.keySet()); missing.addAll(pkeys.keySet()); missing.removeAll(indexes.keySet()); if (!missing.isEmpty()) { Iterator i = missing.iterator(); while (i.hasNext()) { Object k = i.next(); missing_indexes.put(k, dindexes.get(k)); } } } if (!extra_indexes.isEmpty()) System.out.println("/* --- Extra indexes ----------------------------------------- */"); Iterator eiter = extra_indexes.keySet().iterator(); while (eiter.hasNext()) { Object k = eiter.next(); System.out.println("drop index " + extra_indexes.get(k) + "; /* " + k + " */"); } if (!missing_indexes.isEmpty()) System.out.println("/* --- Missing indexes---------------------------------------- */"); Iterator miter = missing_indexes.keySet().iterator(); while (miter.hasNext()) { Object k = miter.next(); System.out.println("create index " + missing_indexes.get(k) + " on " + k + ";"); } } finally { conn.rollback(); conn.close(); } }
From source file:com.github.ansell.shp.SHPDump.java
public static void main(String... args) throws Exception { final OptionParser parser = new OptionParser(); final OptionSpec<Void> help = parser.accepts("help").forHelp(); final OptionSpec<File> input = parser.accepts("input").withRequiredArg().ofType(File.class).required() .describedAs("The input SHP file"); final OptionSpec<File> output = parser.accepts("output").withRequiredArg().ofType(File.class).required() .describedAs("The output directory to use for debugging files"); final OptionSpec<String> outputPrefix = parser.accepts("prefix").withRequiredArg().ofType(String.class) .defaultsTo("shp-debug").describedAs("The output prefix to use for debugging files"); final OptionSpec<File> outputMappingTemplate = parser.accepts("output-mapping").withRequiredArg() .ofType(File.class).describedAs("The output mapping template file if it needs to be generated."); final OptionSpec<Integer> resolution = parser.accepts("resolution").withRequiredArg().ofType(Integer.class) .defaultsTo(2048).describedAs("The output image file resolution"); final OptionSpec<String> format = parser.accepts("format").withRequiredArg().ofType(String.class) .defaultsTo("png").describedAs("The output image format"); final OptionSpec<String> removeIfEmpty = parser.accepts("remove-if-empty").withRequiredArg() .ofType(String.class).describedAs( "The name of an attribute to remove if its value is empty before outputting the resulting shapefile. Use multiple times to specify multiple fields to check"); OptionSet options = null;/*from ww w.jav a 2 s . c o m*/ try { options = parser.parse(args); } catch (final OptionException e) { System.out.println(e.getMessage()); parser.printHelpOn(System.out); throw e; } if (options.has(help)) { parser.printHelpOn(System.out); return; } final Path inputPath = input.value(options).toPath(); if (!Files.exists(inputPath)) { throw new FileNotFoundException("Could not find input SHP file: " + inputPath.toString()); } final Path outputPath = output.value(options).toPath(); if (!Files.exists(outputPath)) { throw new FileNotFoundException("Output directory does not exist: " + outputPath.toString()); } final Path outputMappingPath = options.has(outputMappingTemplate) ? outputMappingTemplate.value(options).toPath() : null; if (options.has(outputMappingTemplate) && Files.exists(outputMappingPath)) { throw new FileNotFoundException( "Output mapping template file already exists: " + outputMappingPath.toString()); } final Set<String> filterFields = ConcurrentHashMap.newKeySet(); if (options.has(removeIfEmpty)) { for (String nextFilterField : removeIfEmpty.values(options)) { System.out.println("Will filter field if empty value found: " + nextFilterField); filterFields.add(nextFilterField); } } if (!filterFields.isEmpty()) { System.out.println("Full set of filter fields: " + filterFields); } final String prefix = outputPrefix.value(options); FileDataStore store = FileDataStoreFinder.getDataStore(inputPath.toFile()); if (store == null) { throw new RuntimeException("Could not read the given input as an ESRI Shapefile: " + inputPath.toAbsolutePath().toString()); } for (String typeName : new LinkedHashSet<>(Arrays.asList(store.getTypeNames()))) { System.out.println(""); System.out.println("Type: " + typeName); SimpleFeatureSource featureSource = store.getFeatureSource(typeName); SimpleFeatureType schema = featureSource.getSchema(); Name outputSchemaName = new NameImpl(schema.getName().getNamespaceURI(), schema.getName().getLocalPart().replace(" ", "").replace("%20", "")); System.out.println("Replacing name on schema: " + schema.getName() + " with " + outputSchemaName); SimpleFeatureType outputSchema = SHPUtils.changeSchemaName(schema, outputSchemaName); List<String> attributeList = new ArrayList<>(); for (AttributeDescriptor attribute : schema.getAttributeDescriptors()) { System.out.println("Attribute: " + attribute.getName().toString()); attributeList.add(attribute.getName().toString()); } CsvSchema csvSchema = CSVUtil.buildSchema(attributeList); SimpleFeatureCollection collection = featureSource.getFeatures(); int featureCount = 0; Path nextCSVFile = outputPath.resolve(prefix + ".csv"); Path nextSummaryCSVFile = outputPath .resolve(prefix + "-" + outputSchema.getTypeName() + "-Summary.csv"); List<SimpleFeature> outputFeatureList = new CopyOnWriteArrayList<>(); try (SimpleFeatureIterator iterator = collection.features(); Writer bufferedWriter = Files.newBufferedWriter(nextCSVFile, StandardCharsets.UTF_8, StandardOpenOption.CREATE_NEW); SequenceWriter csv = CSVUtil.newCSVWriter(bufferedWriter, csvSchema);) { List<String> nextLine = new ArrayList<>(); while (iterator.hasNext()) { SimpleFeature feature = iterator.next(); featureCount++; if (featureCount <= 2) { System.out.println(""); System.out.println(feature.getIdentifier()); } else if (featureCount % 100 == 0) { System.out.print("."); } boolean filterThisFeature = false; for (AttributeDescriptor attribute : schema.getAttributeDescriptors()) { String featureString = Optional.ofNullable(feature.getAttribute(attribute.getName())) .orElse("").toString(); nextLine.add(featureString); if (filterFields.contains(attribute.getName().toString()) && featureString.trim().isEmpty()) { filterThisFeature = true; } if (featureString.length() > 100) { featureString = featureString.substring(0, 100) + "..."; } if (featureCount <= 2) { System.out.print(attribute.getName() + "="); System.out.println(featureString); } } if (!filterThisFeature) { outputFeatureList.add(SHPUtils.changeSchemaName(feature, outputSchema)); csv.write(nextLine); } nextLine.clear(); } } try (Reader csvReader = Files.newBufferedReader(nextCSVFile, StandardCharsets.UTF_8); Writer summaryOutput = Files.newBufferedWriter(nextSummaryCSVFile, StandardCharsets.UTF_8, StandardOpenOption.CREATE_NEW); final Writer mappingWriter = options.has(outputMappingTemplate) ? Files.newBufferedWriter(outputMappingPath) : NullWriter.NULL_WRITER) { CSVSummariser.runSummarise(csvReader, summaryOutput, mappingWriter, CSVSummariser.DEFAULT_SAMPLE_COUNT, false); } if (featureCount > 100) { System.out.println(""); } System.out.println(""); System.out.println("Feature count: " + featureCount); SimpleFeatureCollection outputCollection = new ListFeatureCollection(outputSchema, outputFeatureList); Path outputShapefilePath = outputPath.resolve(prefix + "-" + outputSchema.getTypeName() + "-dump"); if (!Files.exists(outputShapefilePath)) { Files.createDirectory(outputShapefilePath); } SHPUtils.writeShapefile(outputCollection, outputShapefilePath); // Create ZIP file from the contents to keep the subfiles together Path outputShapefileZipPath = outputPath .resolve(prefix + "-" + outputSchema.getTypeName() + "-dump.zip"); try (final OutputStream out = Files.newOutputStream(outputShapefileZipPath, StandardOpenOption.CREATE_NEW); final ZipOutputStream zip = new ZipOutputStream(out, StandardCharsets.UTF_8);) { Files.list(outputShapefilePath).forEachOrdered(Unchecked.consumer(e -> { zip.putNextEntry(new ZipEntry(e.getFileName().toString())); Files.copy(e, zip); zip.closeEntry(); })); } try (final OutputStream outputStream = Files.newOutputStream( outputPath.resolve(prefix + "." + format.value(options)), StandardOpenOption.CREATE_NEW);) { MapContent map = new MapContent(); map.setTitle(prefix + "-" + outputSchema.getTypeName()); Style style = SLD.createSimpleStyle(featureSource.getSchema()); Layer layer = new FeatureLayer(new CollectionFeatureSource(outputCollection), style); map.addLayer(layer); SHPUtils.renderImage(map, outputStream, resolution.value(options), format.value(options)); } } }
From source file:Inmemantlr.java
public static void main(String[] args) { LOGGER.info("Inmemantlr tool"); HelpFormatter hformatter = new HelpFormatter(); Options options = new Options(); // Binary arguments options.addOption("h", "print this message"); Option grmr = Option.builder().longOpt("grmrfiles").hasArgs().desc("comma-separated list of ANTLR files") .required(true).argName("grmrfiles").type(String.class).valueSeparator(',').build(); Option infiles = Option.builder().longOpt("infiles").hasArgs() .desc("comma-separated list of files to parse").required(true).argName("infiles").type(String.class) .valueSeparator(',').build(); Option utilfiles = Option.builder().longOpt("utilfiles").hasArgs() .desc("comma-separated list of utility files to be added for " + "compilation").required(false) .argName("utilfiles").type(String.class).valueSeparator(',').build(); Option odir = Option.builder().longOpt("outdir") .desc("output directory in which the dot files will be " + "created").required(false).hasArg(true) .argName("outdir").type(String.class).build(); options.addOption(infiles);/*from w ww . j a v a 2s. com*/ options.addOption(grmr); options.addOption(utilfiles); options.addOption(odir); CommandLineParser parser = new DefaultParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); if (cmd.hasOption('h')) { hformatter.printHelp("java -jar inmemantlr.jar", options); System.exit(0); } } catch (ParseException e) { hformatter.printHelp("java -jar inmemantlr.jar", options); LOGGER.error(e.getMessage()); System.exit(-1); } // input files Set<File> ins = getFilesForOption(cmd, "infiles"); // grammar files Set<File> gs = getFilesForOption(cmd, "grmrfiles"); // utility files Set<File> uf = getFilesForOption(cmd, "utilfiles"); // output dir Set<File> od = getFilesForOption(cmd, "outdir"); if (od.size() > 1) { LOGGER.error("output directories must be less than or equal to 1"); System.exit(-1); } if (ins.size() <= 0) { LOGGER.error("no input files were specified"); System.exit(-1); } if (gs.size() <= 0) { LOGGER.error("no grammar files were specified"); System.exit(-1); } LOGGER.info("create generic parser"); GenericParser gp = null; try { gp = new GenericParser(gs.toArray(new File[gs.size()])); } catch (FileNotFoundException e) { LOGGER.error(e.getMessage()); System.exit(-1); } if (!uf.isEmpty()) { try { gp.addUtilityJavaFiles(uf.toArray(new String[uf.size()])); } catch (FileNotFoundException e) { LOGGER.error(e.getMessage()); System.exit(-1); } } LOGGER.info("create and add parse tree listener"); DefaultTreeListener dt = new DefaultTreeListener(); gp.setListener(dt); LOGGER.info("compile generic parser"); try { gp.compile(); } catch (CompilationException e) { LOGGER.error("cannot compile generic parser: {}", e.getMessage()); System.exit(-1); } String fpfx = ""; for (File of : od) { if (!of.exists() || !of.isDirectory()) { LOGGER.error("output directory does not exist or is not a " + "directory"); System.exit(-1); } fpfx = of.getAbsolutePath(); } Ast ast; for (File f : ins) { try { gp.parse(f); } catch (IllegalWorkflowException | FileNotFoundException e) { LOGGER.error(e.getMessage()); System.exit(-1); } ast = dt.getAst(); if (!fpfx.isEmpty()) { String of = fpfx + "/" + FilenameUtils.removeExtension(f.getName()) + ".dot"; LOGGER.info("write file {}", of); try { FileUtils.writeStringToFile(new File(of), ast.toDot(), "UTF-8"); } catch (IOException e) { LOGGER.error(e.getMessage()); System.exit(-1); } } else { LOGGER.info("Tree for {} \n {}", f.getName(), ast.toDot()); } } System.exit(0); }
From source file:edu.usc.goffish.gofs.tools.GoFSDeployGraph.java
@SuppressWarnings("deprecation") public static void main(String[] args) throws IOException { if (args.length < REQUIRED_ARGS) { PrintUsageAndQuit(null);/*ww w . j a v a 2 s.c o m*/ } if (args.length == 1 && args[0].equals("-help")) { PrintUsageAndQuit(null); } // optional arguments boolean overwriteGraph = false; PartitionerMode partitionerMode = PartitionerMode.METIS; ComponentizerMode componentizerMode = ComponentizerMode.WCC; MapperMode mapperMode = MapperMode.ROUNDROBIN; PartitionedFileMode partitionedFileMode = PartitionedFileMode.DEFAULT; DistributerMode distributerMode = DistributerMode.SCP; int instancesGroupingSize = 1; int numSubgraphBins = -1; // optional sub arguments Path metisBinaryPath = null; String[] extraMetisOptions = null; Path partitioningPath = null; Path partitionedGMLFilePath = null; // parse optional arguments int i = 0; OptArgLoop: for (i = 0; i < args.length - REQUIRED_ARGS; i++) { switch (args[i]) { case "-overwriteGraph": overwriteGraph = true; break; case "-partitioner": i++; if (args[i].equals("stream")) { partitionerMode = PartitionerMode.STREAM; } else if (args[i].startsWith("metis")) { String[] subargs = parseSubArgs('=', args[i]); if (subargs[0].equals("metis")) { partitionerMode = PartitionerMode.METIS; if (subargs.length > 1) { try { metisBinaryPath = Paths.get(subargs[1]); if (!metisBinaryPath.isAbsolute()) { throw new InvalidPathException(metisBinaryPath.toString(), "metis binary path must be absolute"); } } catch (InvalidPathException e) { PrintUsageAndQuit("metis binary - " + e.getMessage()); } if (subargs.length > 2) { extraMetisOptions = parseSubArgs(' ', subargs[2]); } } } else { PrintUsageAndQuit(null); } } else if (args[i].startsWith("predefined")) { String[] subargs = parseSubArgs('=', args[i]); if (subargs[0].equals("predefined")) { partitionerMode = PartitionerMode.PREDEFINED; if (subargs.length < 2) { PrintUsageAndQuit(null); } try { partitioningPath = Paths.get(subargs[1]); } catch (InvalidPathException e) { PrintUsageAndQuit("partitioning file - " + e.getMessage()); } } else { PrintUsageAndQuit(null); } } else { PrintUsageAndQuit(null); } break; case "-intermediategml": if (args[i + 1].startsWith("save")) { i++; String[] subargs = parseSubArgs('=', args[i]); if (subargs[0].equals("save")) { if (subargs.length < 2) { PrintUsageAndQuit(null); } partitionedFileMode = PartitionedFileMode.SAVE; try { partitionedGMLFilePath = Paths.get(subargs[1]); } catch (InvalidPathException e) { PrintUsageAndQuit("partitioned gml file - " + e.getMessage()); } } } else { partitionedFileMode = PartitionedFileMode.READ; } break; case "-componentizer": i++; switch (args[i]) { case "single": componentizerMode = ComponentizerMode.SINGLE; break; case "wcc": componentizerMode = ComponentizerMode.WCC; break; default: PrintUsageAndQuit(null); } break; case "-distributer": i++; switch (args[i]) { case "scp": distributerMode = DistributerMode.SCP; break; case "write": distributerMode = DistributerMode.WRITE; break; default: PrintUsageAndQuit(null); } break; case "-mapper": i++; if (args[i].equalsIgnoreCase("roundrobin")) { mapperMode = MapperMode.ROUNDROBIN; } else { PrintUsageAndQuit(null); } break; case "-serializer:instancegroupingsize": i++; try { if (args[i].equalsIgnoreCase("ALL")) { instancesGroupingSize = Integer.MAX_VALUE; } else { instancesGroupingSize = Integer.parseInt(args[i]); if (instancesGroupingSize < 1) { PrintUsageAndQuit("Serialization instance grouping size must be greater than zero"); } } } catch (NumberFormatException e) { PrintUsageAndQuit("Serialization instance grouping size - " + e.getMessage()); } break; case "-serializer:numsubgraphbins": i++; try { numSubgraphBins = Integer.parseInt(args[i]); if (instancesGroupingSize < 1) { PrintUsageAndQuit("Serialization number of subgraph bins must be greater than zero"); } } catch (NumberFormatException e) { PrintUsageAndQuit("Serialization number of subgraph bins - " + e.getMessage()); } break; default: break OptArgLoop; } } if (args.length - i < REQUIRED_ARGS) { PrintUsageAndQuit(null); } // required arguments IInternalNameNode nameNode = null; Class<? extends IInternalNameNode> nameNodeType = null; URI nameNodeLocation = null; String graphId = null; int numPartitions = 0; Path gmlTemplatePath = null; List<Path> gmlInstancePaths = new LinkedList<>(); // parse required arguments try { nameNodeType = NameNodeProvider.loadNameNodeType(args[i]); i++; } catch (ReflectiveOperationException e) { PrintUsageAndQuit("name node type - " + e.getMessage()); } try { nameNodeLocation = new URI(args[i]); i++; } catch (URISyntaxException e) { PrintUsageAndQuit("name node location - " + e.getMessage()); } try { nameNode = NameNodeProvider.loadNameNode(nameNodeType, nameNodeLocation); } catch (ReflectiveOperationException e) { PrintUsageAndQuit("error loading name node - " + e.getMessage()); } graphId = args[i++]; try { numPartitions = Integer.parseInt(args[i]); i++; } catch (NumberFormatException e) { PrintUsageAndQuit("number of partitions - " + e.getMessage()); } Path gmlInputFile = null; try { gmlInputFile = Paths.get(args[i]); i++; } catch (InvalidPathException e) { PrintUsageAndQuit(e.getMessage()); } // finished parsing args if (i < args.length) { PrintUsageAndQuit("Unrecognized argument \"" + args[i] + "\""); } // ensure name node is available if (!nameNode.isAvailable()) { throw new IOException("Name node at " + nameNode.getURI() + " is not available"); } // ensure there are data nodes available Set<URI> dataNodes = nameNode.getDataNodes(); if (dataNodes == null || dataNodes.isEmpty()) { throw new IllegalArgumentException("name node does not have any data nodes available for deployment"); } // ensure graph id does not exist (unless to be overwritten) IntCollection partitions = nameNode.getPartitionDirectory().getPartitions(graphId); if (partitions != null) { if (!overwriteGraph) { throw new IllegalArgumentException( "graph id \"" + graphId + "\" already exists in name node partition directory"); } else { for (int partitionId : partitions) { nameNode.getPartitionDirectory().removePartitionMapping(graphId, partitionId); } } } IGraphLoader loader = null; IPartitioner partitioner = null; if (partitionedFileMode != PartitionedFileMode.READ) { XMLConfiguration configuration; try { configuration = new XMLConfiguration(gmlInputFile.toFile()); configuration.setDelimiterParsingDisabled(true); //read the template property gmlTemplatePath = Paths.get(configuration.getString("template")); //read the instance property for (Object instance : configuration.getList("instances.instance")) { gmlInstancePaths.add(Paths.get(instance.toString())); } } catch (ConfigurationException | InvalidPathException e) { PrintUsageAndQuit("gml input file - " + e.getMessage()); } // create loader loader = new GMLGraphLoader(gmlTemplatePath); // create partitioner switch (partitionerMode) { case METIS: if (metisBinaryPath == null) { partitioner = new MetisPartitioner(); } else { partitioner = new MetisPartitioner(metisBinaryPath, extraMetisOptions); } break; case STREAM: partitioner = new StreamPartitioner(new LDGObjectiveFunction()); break; case PREDEFINED: partitioner = new PredefinedPartitioner( MetisPartitioning.read(Files.newInputStream(partitioningPath))); break; default: PrintUsageAndQuit(null); } } // create componentizer IGraphComponentizer graphComponentizer = null; switch (componentizerMode) { case SINGLE: graphComponentizer = new SingleComponentizer(); break; case WCC: graphComponentizer = new WCCComponentizer(); break; default: PrintUsageAndQuit(null); } // create mapper IPartitionMapper partitionMapper = null; switch (mapperMode) { case ROUNDROBIN: partitionMapper = new RoundRobinPartitionMapper(nameNode.getDataNodes()); break; default: PrintUsageAndQuit(null); } // create serializer ISliceSerializer serializer = nameNode.getSerializer(); if (serializer == null) { throw new IOException("name node at " + nameNode.getURI() + " returned null serializer"); } // create distributer IPartitionDistributer partitionDistributer = null; switch (distributerMode) { case SCP: partitionDistributer = new SCPPartitionDistributer(serializer, instancesGroupingSize, numSubgraphBins); break; case WRITE: partitionDistributer = new DirectWritePartitionDistributer(serializer, instancesGroupingSize, numSubgraphBins); break; } GMLPartitionBuilder partitionBuilder = null; try { System.out.print("Executing command: DeployGraph"); for (String arg : args) { System.out.print(" " + arg); } System.out.println(); // perform deployment long time = System.currentTimeMillis(); switch (partitionedFileMode) { case DEFAULT: partitionBuilder = new GMLPartitionBuilder(graphComponentizer, gmlTemplatePath, gmlInstancePaths); deploy(nameNode.getPartitionDirectory(), graphId, numPartitions, loader, partitioner, partitionBuilder, null, partitionMapper, partitionDistributer); break; case SAVE: //save partitioned gml files partitionBuilder = new GMLPartitionBuilder(partitionedGMLFilePath, graphComponentizer, gmlTemplatePath, gmlInstancePaths); //partitioned gml input file name format as graphid_numpartitions_paritioningtype_serializer String intermediateGMLInputFile = new StringBuffer().append(graphId).append("_") .append(numPartitions).append("_").append(partitionerMode.name().toLowerCase()).append("_") .append(serializer.getClass().getSimpleName().toLowerCase()).toString(); deploy(nameNode.getPartitionDirectory(), graphId, numPartitions, loader, partitioner, partitionBuilder, intermediateGMLInputFile, partitionMapper, partitionDistributer); break; case READ: //read partitioned gml files partitionBuilder = new GMLPartitionBuilder(graphComponentizer); partitionBuilder.new XMLConfigurationBuilder(gmlInputFile.toFile().getAbsolutePath()) .readIntermediateGMLFile(); deploy(nameNode.getPartitionDirectory(), graphId, numPartitions, partitionBuilder, partitionMapper, partitionDistributer); break; } System.out.println("finished [total " + (System.currentTimeMillis() - time) + "ms]"); } finally { if (partitionBuilder != null) partitionBuilder.close(); } }
From source file:br.bireme.ngrams.NGrams.java
/** * @param args the command line arguments * @throws java.io.IOException//from ww w. j a va2s .co m * @throws org.apache.lucene.queryparser.classic.ParseException * @throws javax.xml.parsers.ParserConfigurationException * @throws org.xml.sax.SAXException */ public static void main(String[] args) throws IOException, ParseException, ParserConfigurationException, SAXException { final long startTime = new GregorianCalendar().getTimeInMillis(); if (args.length < 5) { usage(); } final NGSchema schema = new NGSchema("dummy", args[2], args[3]); if (args[0].equals("index")) { if (args.length != 6) { usage(); } final NGIndex index = new NGIndex("dummy", args[1], false); index(index, schema, args[4], args[5]); System.out.println("Indexing has finished."); } else if (args[0].equals("search1")) { if (args.length < 7) { usage(); } final NGIndex index = new NGIndex("dummy", args[1], true); if (args.length == 7) { search(index, schema, args[4], args[5], args[6], "utf-8"); } else { search(index, schema, args[4], args[5], args[6], args[7]); } System.out.println("Searching has finished."); } else if (args[0].equals("search2")) { if (args.length < 4 + 1) { usage(); } final NGIndex index = new NGIndex("dummy", args[1], true); Set<String> set = null; if (args.length == 5) { set = search(index, schema, args[4], false); } else if (args[5].equals("--original")) { set = search(index, schema, args[4], true); } else usage(); if ((set == null) || (set.isEmpty())) { System.out.println("No result was found."); } else { int pos = 0; for (String res : set) { System.out.println((++pos) + ") " + res); } } } else if (args[0].equals("search3")) { if (args.length < 5) { usage(); } final NGIndex index = new NGIndex("dummy", args[1], true); Set<String> set = null; if (args.length == 5) { set = srcWithoutSimil(index, schema, args[4], false); } else if (args[5].equals("--original")) { set = srcWithoutSimil(index, schema, args[4], true); } else usage(); if ((set == null) || (set.isEmpty())) { System.out.println("No result was found."); } else { int pos = 0; for (String res : set) { System.out.println((++pos) + ") " + res); } } } else if (args[0].equals("export")) { if (args.length != 6) { usage(); } final NGIndex index = new NGIndex("dummy", args[1], true); export(index, schema, args[4], args[5]); } else { usage(); } final long endTime = new GregorianCalendar().getTimeInMillis(); final long difTime = (endTime - startTime) / 1000; System.out.println("\nElapsed time: " + difTime + "s"); }
From source file:com.linkedin.databus2.client.util.DatabusClusterUtil.java
/** * @param args//from www . j a v a2 s .c om * DbusClusterUtil -z <zookeper-server> -c <cluster-name> [-p * <partitionNumber] partitions readSCN writeSCN SCN remove * clients */ public static void main(String[] args) { try { GnuParser cmdLineParser = new GnuParser(); Options options = new Options(); options.addOption("z", true, "zk-server").addOption("c", true, "cluster-name ") .addOption("p", true, "partition").addOption("l", false, "legacy") .addOption("h", false, "help"); CommandLine cmdLineArgs = cmdLineParser.parse(options, args, false); if (cmdLineArgs.hasOption('h')) { usage(); System.exit(0); } if (!cmdLineArgs.hasOption('c')) { usage(); System.exit(1); } String clusterName = cmdLineArgs.getOptionValue('c'); String zkServer = cmdLineArgs.getOptionValue('z'); boolean isLegacyChkptLocation = cmdLineArgs.hasOption('l'); if (zkServer == null || zkServer.isEmpty()) { zkServer = "localhost:2181"; } String partitionStr = cmdLineArgs.getOptionValue('p'); String partition = partitionStr; if ((partition != null) && partition.equals("all")) { partition = ""; } String[] fns = cmdLineArgs.getArgs(); if (fns.length < 1) { usage(); System.exit(1); } DatabusClusterUtilHelper clusterState = new DatabusClusterUtilHelper(zkServer, clusterName); String function = fns[0]; String arg1 = (fns.length > 1) ? fns[1] : null; String arg2 = (fns.length > 2) ? fns[2] : null; boolean clusterExists = clusterState.existsCluster(); if (function.equals("create")) { if (!clusterExists) { if (arg1 == null) { throw new DatabusClusterUtilException("create: please provide the number of partitions"); } int part = Integer.parseInt(arg1); clusterState.createCluster(part); return; } else { throw new DatabusClusterUtilException("Cluster " + clusterName + " already exists"); } } if (!clusterExists) { throw new DatabusClusterUtilException("Cluster doesn't exist! "); } if (function.equals("delete")) { clusterState.removeCluster(); } else if (function.equals("partitions")) { int numParts = clusterState.getNumPartitions(); System.out.println(numParts); } else { // all these functions require the notion of partition; Set<Integer> partitions = getPartitions(partition, clusterState.getNumPartitions()); if (function.equals("sources")) { DatabusClusterCkptManager ckptMgr = new DatabusClusterCkptManager(zkServer, clusterName, null, partitions, isLegacyChkptLocation); Set<String> sources = ckptMgr.getSourcesFromCheckpoint(); if (sources != null) { for (String s : sources) { System.out.println(s); } } else { throw new DatabusClusterUtilException( "sources: Sources not found for cluster " + clusterName); } } else if (function.equals("clients")) { clusterState.getClusterInfo(); for (Integer p : partitions) { String client = clusterState.getInstanceForPartition(p); System.out.println(p + "\t" + client); } } else if (function.equals("readSCN")) { List<String> sources = getSources(arg1); if ((sources != null) && !sources.isEmpty()) { DatabusClusterCkptManager ckptMgr = new DatabusClusterCkptManager(zkServer, clusterName, sources, partitions, isLegacyChkptLocation); Map<Integer, Checkpoint> ckpts = ckptMgr.readCheckpoint(); char delim = '\t'; for (Map.Entry<Integer, Checkpoint> mkPair : ckpts.entrySet()) { StringBuilder output = new StringBuilder(64); output.append(mkPair.getKey()); output.append(delim); Checkpoint cp = mkPair.getValue(); if (cp == null) { output.append(-1); output.append(delim); output.append(-1); } else { if (cp.getConsumptionMode() == DbusClientMode.ONLINE_CONSUMPTION) { output.append(cp.getWindowScn()); output.append(delim); output.append(cp.getWindowOffset()); } else if (cp.getConsumptionMode() == DbusClientMode.BOOTSTRAP_CATCHUP) { output.append(cp.getWindowScn()); output.append(delim); output.append(cp.getWindowOffset()); } else if (cp.getConsumptionMode() == DbusClientMode.BOOTSTRAP_SNAPSHOT) { output.append(cp.getBootstrapSinceScn()); output.append(delim); output.append(-1); } } System.out.println(output.toString()); } } else { throw new DatabusClusterUtilException("readSCN: please specify non-empty sources"); } } else if (function.equals("checkpoint")) { List<String> sources = getSources(arg1); if ((sources != null) && !sources.isEmpty()) { DatabusClusterCkptManager ckptMgr = new DatabusClusterCkptManager(zkServer, clusterName, sources, partitions, isLegacyChkptLocation); Map<Integer, Checkpoint> ckpts = ckptMgr.readCheckpoint(); char delim = '\t'; for (Map.Entry<Integer, Checkpoint> mkPair : ckpts.entrySet()) { StringBuilder output = new StringBuilder(64); output.append(mkPair.getKey()); output.append(delim); Checkpoint cp = mkPair.getValue(); if (cp == null) { output.append("null"); } else { output.append(cp.toString()); } System.out.println(output.toString()); } } else { throw new DatabusClusterUtilException("readSCN: please specify non-empty sources"); } } else if (function.equals("writeSCN")) { String scnStr = arg1; Long scn = Long.parseLong(scnStr); if (partitionStr != null) { List<String> sources = getSources(arg2); if ((sources != null) && !sources.isEmpty()) { DatabusClusterCkptManager ckptMgr = new DatabusClusterCkptManager(zkServer, clusterName, sources, partitions, isLegacyChkptLocation); ckptMgr.writeCheckpoint(scn); } else { throw new DatabusClusterUtilException("writeSCN: please specify non-empty sources"); } } else { throw new DatabusClusterUtilException( "writeSCN: to write the SCN to all partitions please use '-p all'"); } } else if (function.equals("removeSCN")) { if (partitionStr != null) { List<String> sources = getSources(arg1); if ((sources != null) && !sources.isEmpty()) { DatabusClusterCkptManager ckptMgr = new DatabusClusterCkptManager(zkServer, clusterName, sources, partitions, isLegacyChkptLocation); ckptMgr.remove(); } else { throw new DatabusClusterUtilException("remove: please specify non-empty sources"); } } else { throw new DatabusClusterUtilException( "remove: to remove SCN from all partitions please use '-p all'"); } } else { usage(); System.exit(1); } } } catch (ParseException e) { usage(); System.exit(1); } catch (DatabusClusterUtilException e) { System.err.println("Error! " + e.toString()); System.exit(1); } }