List of usage examples for org.apache.commons.collections4 IteratorUtils singletonIterator
public static <E> ResettableIterator<E> singletonIterator(final E object)
From source file:org.apache.metron.profiler.spark.function.HBaseWriterFunction.java
/** * Writes a set of measurements to HBase. * * @param iterator The measurements to write. * @return The number of measurements written to HBase. *//* w w w. j a v a 2s .co m*/ @Override public Iterator<Integer> call(Iterator<ProfileMeasurementAdapter> iterator) throws Exception { int count = 0; LOG.debug("About to write profile measurement(s) to HBase"); // do not open hbase connection, if nothing to write List<ProfileMeasurementAdapter> measurements = IteratorUtils.toList(iterator); if (measurements.size() > 0) { // open an HBase connection Configuration config = HBaseConfiguration.create(); try (HBaseClient client = new HBaseClient(tableProvider, config, tableName)) { for (ProfileMeasurementAdapter adapter : measurements) { ProfileMeasurement m = adapter.toProfileMeasurement(); client.addMutation(rowKeyBuilder.rowKey(m), columnBuilder.columns(m), durability); } count = client.mutate(); } catch (IOException e) { LOG.error("Unable to open connection to HBase", e); throw new RuntimeException(e); } } LOG.debug("{} profile measurement(s) written to HBase", count); return IteratorUtils.singletonIterator(count); }
From source file:org.jamocha.filter.PathNodeFilterSet.java
@Override public Iterator<PathNodeFilterSet> iterator() { return IteratorUtils.singletonIterator(this); }