List of usage examples for java.lang Iterable Iterable
Iterable
From source file:jetbrains.exodus.entitystore.PersistentEntityStoreImpl.java
public void deleteEntityType(@NotNull final String entityTypeName) { final PersistentStoreTransaction txn = getAndCheckCurrentTransaction(); final int entityTypeId = entityTypes.delete(txn, entityTypeName); if (entityTypeId < 0) { return;/*from www .j a v a 2 s . c om*/ } entitiesTables.remove(entityTypeId); entitiesHistoryTables.remove(entityTypeId); propertiesTables.remove(entityTypeId); propertiesHistoryTables.remove(entityTypeId); linksTables.remove(entityTypeId); linksHistoryTables.remove(entityTypeId); blobsTables.remove(entityTypeId); blobsHistoryTables.remove(entityTypeId); final String entityTableName = namingRulez.getEntitiesTableName(entityTypeId); final String propertiesTableName = namingRulez.getPropertiesTableName(entityTypeId); final String linksTableName = namingRulez.getLinksTableName(entityTypeId); final String secondLinksTableName = TwoColumnTable.secondColumnDatabaseName(linksTableName); final String blobsTableName = namingRulez.getBlobsTableName(entityTypeId); truncateStores(txn, Arrays.<String>asList(entityTableName, linksTableName, secondLinksTableName, propertiesTableName, blobsTableName), new Iterable<String>() { @Override public Iterator<String> iterator() { return new Iterator<String>() { // enumerate all property value indexes private int propertyId = 0; @Override public boolean hasNext() { return propertyId < 10000; // this was taken from } @Override public String next() { return propertiesTableName + "#value_idx" + propertyId++; } @Override public void remove() { // don't give a damn } }; } }); }
From source file:com.servoy.j2db.util.Utils.java
/** * Iterate over iterator./*from w w w .java2s. c o m*/ * <pre> * for (T o: Utils.iterate(iterator)) * { * o. .... * } * </pre> * @param iterator when null, iterate over empty list */ public static <T> Iterable<T> iterate(final Iterator<T> iterator) { return iterator == null ? Collections.<T>emptyList() : new Iterable<T>() { public Iterator<T> iterator() { return iterator; } }; }
From source file:org.apache.nifi.controller.repository.StandardProcessSession.java
private void removeExpired(final Set<FlowFileRecord> flowFiles, final Connection connection) { if (flowFiles.isEmpty()) { return;/*from ww w . j a v a 2 s . c o m*/ } LOG.info("{} {} FlowFiles have expired and will be removed", new Object[] { this, flowFiles.size() }); final List<RepositoryRecord> expiredRecords = new ArrayList<>(flowFiles.size()); final Connectable connectable = context.getConnectable(); final String processorType = connectable.getComponentType(); final StandardProvenanceReporter expiredReporter = new StandardProvenanceReporter(this, connectable.getIdentifier(), processorType, context.getProvenanceRepository(), this); final Map<String, FlowFileRecord> recordIdMap = new HashMap<>(); for (final FlowFileRecord flowFile : flowFiles) { recordIdMap.put(flowFile.getAttribute(CoreAttributes.UUID.key()), flowFile); final StandardRepositoryRecord record = new StandardRepositoryRecord(connection.getFlowFileQueue(), flowFile); record.markForDelete(); expiredRecords.add(record); expiredReporter.expire(flowFile, "Expiration Threshold = " + connection.getFlowFileQueue().getFlowFileExpiration()); decrementClaimCount(flowFile.getContentClaim()); final long flowFileLife = System.currentTimeMillis() - flowFile.getEntryDate(); final Object terminator = connectable instanceof ProcessorNode ? ((ProcessorNode) connectable).getProcessor() : connectable; LOG.info("{} terminated by {} due to FlowFile expiration; life of FlowFile = {} ms", new Object[] { flowFile, terminator, flowFileLife }); } try { final Iterable<ProvenanceEventRecord> iterable = new Iterable<ProvenanceEventRecord>() { @Override public Iterator<ProvenanceEventRecord> iterator() { final Iterator<ProvenanceEventRecord> expiredEventIterator = expiredReporter.getEvents() .iterator(); final Iterator<ProvenanceEventRecord> enrichingIterator = new Iterator<ProvenanceEventRecord>() { @Override public boolean hasNext() { return expiredEventIterator.hasNext(); } @Override public ProvenanceEventRecord next() { final ProvenanceEventRecord event = expiredEventIterator.next(); final StandardProvenanceEventRecord.Builder enriched = new StandardProvenanceEventRecord.Builder() .fromEvent(event); final FlowFileRecord record = recordIdMap.get(event.getFlowFileUuid()); if (record == null) { return null; } final ContentClaim claim = record.getContentClaim(); if (claim != null) { final ResourceClaim resourceClaim = claim.getResourceClaim(); enriched.setCurrentContentClaim(resourceClaim.getContainer(), resourceClaim.getSection(), resourceClaim.getId(), record.getContentClaimOffset() + claim.getOffset(), record.getSize()); enriched.setPreviousContentClaim(resourceClaim.getContainer(), resourceClaim.getSection(), resourceClaim.getId(), record.getContentClaimOffset() + claim.getOffset(), record.getSize()); } enriched.setAttributes(record.getAttributes(), Collections.<String, String>emptyMap()); return enriched.build(); } @Override public void remove() { throw new UnsupportedOperationException(); } }; return enrichingIterator; } }; context.getProvenanceRepository().registerEvents(iterable); context.getFlowFileRepository().updateRepository(expiredRecords); } catch (final IOException e) { LOG.error("Failed to update FlowFile Repository to record expired records due to {}", e); } }
From source file:io.minio.MinioClient.java
/** * Returns {@code Iterable<Result<Upload>>} of given bucket name, prefix and recursive flag. * All parts size are aggregated when aggregatePartSize is true. *//*w ww . java 2 s . c o m*/ private Iterable<Result<Upload>> listIncompleteUploads(final String bucketName, final String prefix, final boolean recursive, final boolean aggregatePartSize) { return new Iterable<Result<Upload>>() { @Override public Iterator<Result<Upload>> iterator() { return new Iterator<Result<Upload>>() { private String nextKeyMarker; private String nextUploadIdMarker; private ListMultipartUploadsResult listMultipartUploadsResult; private Result<Upload> error; private Iterator<Upload> uploadIterator; private boolean completed = false; private synchronized void populate() { String delimiter = "/"; if (recursive) { delimiter = null; } this.listMultipartUploadsResult = null; this.uploadIterator = null; try { this.listMultipartUploadsResult = listIncompleteUploads(bucketName, nextKeyMarker, nextUploadIdMarker, prefix, delimiter, 1000); } catch (InvalidBucketNameException | NoSuchAlgorithmException | InsufficientDataException | IOException | InvalidKeyException | NoResponseException | XmlPullParserException | ErrorResponseException | InternalException e) { this.error = new Result<>(null, e); } finally { if (this.listMultipartUploadsResult != null) { this.uploadIterator = this.listMultipartUploadsResult.uploads().iterator(); } else { this.uploadIterator = new LinkedList<Upload>().iterator(); } } } private synchronized long getAggregatedPartSize(String objectName, String uploadId) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException, InternalException { long aggregatedPartSize = 0; for (Result<Part> result : listObjectParts(bucketName, objectName, uploadId)) { aggregatedPartSize += result.get().partSize(); } return aggregatedPartSize; } @Override public boolean hasNext() { if (this.completed) { return false; } if (this.error == null && this.uploadIterator == null) { populate(); } if (this.error == null && !this.uploadIterator.hasNext() && this.listMultipartUploadsResult.isTruncated()) { this.nextKeyMarker = this.listMultipartUploadsResult.nextKeyMarker(); this.nextUploadIdMarker = this.listMultipartUploadsResult.nextUploadIdMarker(); populate(); } if (this.error != null) { return true; } if (this.uploadIterator.hasNext()) { return true; } this.completed = true; return false; } @Override public Result<Upload> next() { if (this.completed) { throw new NoSuchElementException(); } if (this.error == null && this.uploadIterator == null) { populate(); } if (this.error == null && !this.uploadIterator.hasNext() && this.listMultipartUploadsResult.isTruncated()) { this.nextKeyMarker = this.listMultipartUploadsResult.nextKeyMarker(); this.nextUploadIdMarker = this.listMultipartUploadsResult.nextUploadIdMarker(); populate(); } if (this.error != null) { this.completed = true; return this.error; } if (this.uploadIterator.hasNext()) { Upload upload = this.uploadIterator.next(); if (aggregatePartSize) { long aggregatedPartSize; try { aggregatedPartSize = getAggregatedPartSize(upload.objectName(), upload.uploadId()); } catch (InvalidBucketNameException | NoSuchAlgorithmException | InsufficientDataException | IOException | InvalidKeyException | NoResponseException | XmlPullParserException | ErrorResponseException | InternalException e) { // special case: ignore the error as we can't propagate the exception in next() aggregatedPartSize = -1; } upload.setAggregatedPartSize(aggregatedPartSize); } return new Result<>(upload, null); } this.completed = true; throw new NoSuchElementException(); } @Override public void remove() { throw new UnsupportedOperationException(); } }; } }; }
From source file:io.minio.MinioClient.java
/** * Executes List object parts of multipart upload for given bucket name, object name and upload ID and * returns {@code Iterable<Result<Part>>}. *//*from ww w.j av a2 s . c o m*/ private Iterable<Result<Part>> listObjectParts(final String bucketName, final String objectName, final String uploadId) { return new Iterable<Result<Part>>() { @Override public Iterator<Result<Part>> iterator() { return new Iterator<Result<Part>>() { private int nextPartNumberMarker; private ListPartsResult listPartsResult; private Result<Part> error; private Iterator<Part> partIterator; private boolean completed = false; private synchronized void populate() { this.listPartsResult = null; this.partIterator = null; try { this.listPartsResult = listObjectParts(bucketName, objectName, uploadId, nextPartNumberMarker); } catch (InvalidBucketNameException | NoSuchAlgorithmException | InsufficientDataException | IOException | InvalidKeyException | NoResponseException | XmlPullParserException | ErrorResponseException | InternalException e) { this.error = new Result<>(null, e); } finally { if (this.listPartsResult != null) { this.partIterator = this.listPartsResult.partList().iterator(); } else { this.partIterator = new LinkedList<Part>().iterator(); } } } @Override public boolean hasNext() { if (this.completed) { return false; } if (this.error == null && this.partIterator == null) { populate(); } if (this.error == null && !this.partIterator.hasNext() && this.listPartsResult.isTruncated()) { this.nextPartNumberMarker = this.listPartsResult.nextPartNumberMarker(); populate(); } if (this.error != null) { return true; } if (this.partIterator.hasNext()) { return true; } this.completed = true; return false; } @Override public Result<Part> next() { if (this.completed) { throw new NoSuchElementException(); } if (this.error == null && this.partIterator == null) { populate(); } if (this.error == null && !this.partIterator.hasNext() && this.listPartsResult.isTruncated()) { this.nextPartNumberMarker = this.listPartsResult.nextPartNumberMarker(); populate(); } if (this.error != null) { this.completed = true; return this.error; } if (this.partIterator.hasNext()) { return new Result<>(this.partIterator.next(), null); } this.completed = true; throw new NoSuchElementException(); } @Override public void remove() { throw new UnsupportedOperationException(); } }; } }; }
From source file:mondrian.olap.Util.java
/** * Casts a collection to iterable.//from ww w . j a v a2 s . c o m * * Under JDK 1.4, {@link Collection} objects do not implement * {@link Iterable}, so this method inserts a casting wrapper. (Since * Iterable does not exist under JDK 1.4, they will have been compiled * under JDK 1.5 or later, then retrowoven to 1.4 class format. References * to Iterable will have been replaced with references to * <code>com.rc.retroweaver.runtime.Retroweaver_</code>. * * <p>Under later JDKs this method is trivial. This method can be deleted * when we discontinue support for JDK 1.4. * * @param iterable Object which ought to be iterable * @param <T> Element type * @return Object cast to Iterable */ public static <T> Iterable<T> castToIterable(final Object iterable) { if (Util.Retrowoven && !(iterable instanceof Iterable)) { return new Iterable<T>() { public Iterator<T> iterator() { return ((Collection<T>) iterable).iterator(); } }; } return (Iterable<T>) iterable; }
From source file:org.apache.accumulo.tserver.TabletServer.java
public void config(String hostname) { log.info("Tablet server starting on " + hostname); majorCompactorThread = new Daemon(new LoggingRunnable(log, new MajorCompactor(getConfiguration()))); majorCompactorThread.setName("Split/MajC initiator"); majorCompactorThread.start();//from w w w. j a v a2s. com clientAddress = HostAndPort.fromParts(hostname, 0); try { AccumuloVFSClassLoader.getContextManager().setContextConfig( new ContextManager.DefaultContextsConfig(new Iterable<Entry<String, String>>() { @Override public Iterator<Entry<String, String>> iterator() { return getConfiguration().iterator(); } })); } catch (IOException e) { throw new RuntimeException(e); } // A task that cleans up unused classloader contexts Runnable contextCleaner = new Runnable() { @Override public void run() { Set<String> contextProperties = getServerConfigurationFactory().getConfiguration() .getAllPropertiesWithPrefix(Property.VFS_CONTEXT_CLASSPATH_PROPERTY).keySet(); Set<String> configuredContexts = new HashSet<String>(); for (String prop : contextProperties) { configuredContexts.add(prop.substring(Property.VFS_CONTEXT_CLASSPATH_PROPERTY.name().length())); } try { AccumuloVFSClassLoader.getContextManager().removeUnusedContexts(configuredContexts); } catch (IOException e) { log.warn("{}", e.getMessage(), e); } } }; AccumuloConfiguration aconf = getConfiguration(); SimpleTimer.getInstance(aconf).schedule(contextCleaner, 60000, 60000); FileSystemMonitor.start(aconf, Property.TSERV_MONITOR_FS); Runnable gcDebugTask = new Runnable() { @Override public void run() { gcLogger.logGCInfo(getConfiguration()); } }; SimpleTimer.getInstance(aconf).schedule(gcDebugTask, 0, TIME_BETWEEN_GC_CHECKS); Runnable constraintTask = new Runnable() { @Override public void run() { ArrayList<Tablet> tablets; synchronized (onlineTablets) { tablets = new ArrayList<Tablet>(onlineTablets.values()); } for (Tablet tablet : tablets) { tablet.checkConstraints(); } } }; SimpleTimer.getInstance(aconf).schedule(constraintTask, 0, 1000); }
From source file:org.apache.accumulo.server.tabletserver.ScanRunState.java
public void config(String hostname) { log.info("Tablet server starting on " + hostname); security = AuditedSecurityOperation.getInstance(); clientAddress = HostAndPort.fromParts(hostname, 0); logger = new TabletServerLogger(this, getSystemConfiguration().getMemoryInBytes(Property.TSERV_WALOG_MAX_SIZE)); try {/*from w w w . j a v a 2 s . c om*/ AccumuloVFSClassLoader.getContextManager().setContextConfig( new ContextManager.DefaultContextsConfig(new Iterable<Entry<String, String>>() { @Override public Iterator<Entry<String, String>> iterator() { return getSystemConfiguration().iterator(); } })); } catch (IOException e) { throw new RuntimeException(e); } // A task that cleans up unused classloader contexts Runnable contextCleaner = new Runnable() { @Override public void run() { ArrayList<KeyExtent> extents; synchronized (onlineTablets) { extents = new ArrayList<KeyExtent>(onlineTablets.keySet()); } Set<Text> tables = new HashSet<Text>(); for (KeyExtent keyExtent : extents) { tables.add(keyExtent.getTableId()); } HashSet<String> contexts = new HashSet<String>(); for (Text tableid : tables) { String context = getTableConfiguration(new KeyExtent(tableid, null, null)) .get(Property.TABLE_CLASSPATH); if (!context.equals("")) { contexts.add(context); } } try { AccumuloVFSClassLoader.getContextManager().removeUnusedContexts(contexts); } catch (IOException e) { log.warn(e.getMessage(), e); } } }; SimpleTimer.getInstance().schedule(contextCleaner, 60000, 60000); FileSystemMonitor.start(getSystemConfiguration(), Property.TSERV_MONITOR_FS); Runnable gcDebugTask = new Runnable() { @Override public void run() { logGCInfo(getSystemConfiguration()); } }; SimpleTimer.getInstance().schedule(gcDebugTask, 0, 1000); Runnable constraintTask = new Runnable() { @Override public void run() { ArrayList<Tablet> tablets; synchronized (onlineTablets) { tablets = new ArrayList<Tablet>(onlineTablets.values()); } for (Tablet tablet : tablets) { tablet.checkConstraints(); } } }; SimpleTimer.getInstance().schedule(constraintTask, 0, 1000); this.resourceManager = new TabletServerResourceManager(instance, fs); lastPingTime = System.currentTimeMillis(); currentMaster = null; statsKeeper = new TabletStatsKeeper(); // start major compactor majorCompactorThread = new Daemon(new LoggingRunnable(log, new MajorCompactor(getSystemConfiguration()))); majorCompactorThread.setName("Split/MajC initiator"); majorCompactorThread.start(); }