List of usage examples for java.lang Iterable iterator
Iterator<T> iterator();
From source file:net.solarnetwork.node.control.demandbalancer.DemandBalancer.java
private Integer collectDemandWatts() { log.debug("Collecting current consumption data to inform demand balancer..."); Iterable<EnergyDatum> demand = null; try {/*w ww.j a v a 2 s .c o m*/ demand = getCurrentDatum(consumptionDataSource); if (demand.iterator().hasNext()) { stats.put(STAT_LAST_CONSUMPTION_COLLECTION_DATE, System.currentTimeMillis()); stats.remove(STAT_LAST_CONSUMPTION_COLLECTION_ERROR); } else { stats.put(STAT_LAST_CONSUMPTION_COLLECTION_ERROR, ERROR_NO_DATA_RETURNED); } } catch (RuntimeException e) { log.error("Error collecting consumption data: {}", e.getMessage()); stats.put(STAT_LAST_CONSUMPTION_COLLECTION_ERROR, messageForException(e)); } return wattsForEnergyDatum(demand); }
From source file:org.ihtsdo.otf.refset.graph.gao.HistoryGao.java
/** * @param memberId/*from w w w .j a v a 2s . co m*/ * @return {@link ChangeRecord} */ public ChangeRecord<Member> getMemberStateHistory(String memberId, String refsetId) throws RefsetGraphAccessException, EntityNotFoundException { Object[] criteria = { memberId, refsetId }; LOGGER.debug("Getting member history for criteria {}", criteria); ChangeRecord<Member> history = new ChangeRecord<Member>(); TitanGraph g = null; try { g = f.getReadOnlyGraph(); Iterable<Vertex> vRs = g.query().has(TYPE, VertexType.refset.toString()).has(ID, refsetId).limit(1) .vertices(); if (!vRs.iterator().hasNext()) { throw new EntityNotFoundException("Refset does not exist for given refset id " + refsetId); } Vertex vR = vRs.iterator().next(); GremlinPipeline<Vertex, Vertex> pipe = new GremlinPipeline<Vertex, Vertex>(g); pipe.start(vR).inE(EdgeLabel.members.toString()).outV().has(ID, memberId).has(TYPE, VertexType.member.toString()); List<Vertex> vMs = pipe.toList(); for (Vertex vM : vMs) { Member currentMember = RefsetConvertor.getMember(vM); Iterable<Edge> edges = vM.getEdges(Direction.OUT, EdgeLabel.members.toString()); for (Edge edge : edges) { Set<String> eKeys = edge.getPropertyKeys(); if (eKeys.contains(REFERENCE_COMPONENT_ID)) { String referenceComponentId = edge.getProperty(REFERENCE_COMPONENT_ID); currentMember.setReferencedComponentId(referenceComponentId); } } GremlinPipeline<Vertex, Vertex> fPipe = new GremlinPipeline<Vertex, Vertex>(); fPipe.start(vM).outE(EdgeLabel.hasState.toString()).inV().has(ACTIVE).has(TYPE, VertexType.hMember.toString()); List<Vertex> fls = fPipe.toList(); List<Member> ms = RefsetConvertor.getStateMembers(fls); //we need to get missing data from existing member detail. TODO create full details during state creation for (Member m : ms) { if (StringUtils.isEmpty(m.getModuleId())) { m.setModuleId(currentMember.getModuleId()); } if (StringUtils.isEmpty(m.getReferencedComponentId())) { m.setReferencedComponentId(currentMember.getReferencedComponentId()); } } history.setRecords(ms); } } catch (EntityNotFoundException e) { RefsetGraphFactory.rollback(g); LOGGER.error("Error getting member state history", e); throw e; } catch (Exception e) { RefsetGraphFactory.rollback(g); LOGGER.error("Error getting member state history", e); throw new RefsetGraphAccessException(e.getMessage(), e); } finally { RefsetGraphFactory.shutdown(g); } LOGGER.debug("Returning {} ", history); return history; }
From source file:me.cybermaxke.merchants.v17r4.SMerchant.java
protected Collection<EntityPlayer>[] split(Iterable<Player> players) { Collection<EntityPlayer> list0 = null; Collection<EntityPlayer> list1 = null; Collection<EntityPlayer> list2 = null; Collection<EntityPlayer> list3 = null; Iterator<Player> it = players.iterator(); while (it.hasNext()) { EntityPlayer player0 = ((CraftPlayer) it.next()).getHandle(); int version = player0.playerConnection.networkManager.getVersion(); if (version < 28) { if (list0 == null) { list0 = Lists.newArrayList(); }//from w ww . j a v a 2 s . com list0.add(player0); } else if (version < 29) { if (list1 == null) { list1 = Lists.newArrayList(); } list1.add(player0); } else if (version < 47) { if (list2 == null) { list2 = Lists.newArrayList(); } list2.add(player0); } else { if (list3 == null) { list3 = Lists.newArrayList(); } list3.add(player0); } } // list0 < 28; list1 < 29; list3 < 47; list4 >= 47 return new Collection[] { list0, list1, list2, list3 }; }
From source file:com.infinira.aerospike.dataaccess.repository.AerospikeRepository.java
/** * Find all entities that match a given filter and qualifiers. * @param filter Filter on fields//w ww.j a v a2 s. co m * @param qualifiers Qualifiers * @return ArrayList of entities */ @Override public ArrayList<T> findAll(Filter filter, Qualifier... qualifiers) { final ArrayList<T> scanList = new ArrayList<T>(); Iterable<T> results = findAllUsingQuery(filter, qualifiers); Iterator<T> iterator = results.iterator(); try { while (iterator.hasNext()) { scanList.add(iterator.next()); //System.out.println(iterator.next()); } } finally { ((EntityIterator<T>) iterator).close(); } return scanList; }
From source file:io.brooklyn.ambari.server.AmbariServerImpl.java
@Override public void addHostsToHostGroup(final String blueprintName, final String hostgroupName, final List<String> hosts, final String cluster) { Iterable<Map> hostGroupMapping = Iterables.transform(hosts, fqdnsToMaps(blueprintName, hostgroupName)); LOG.info("hosts " + hostGroupMapping.iterator().hasNext()); HostEndpoint hostEndpoint = restAdapter.create(HostEndpoint.class); Request request = hostEndpoint.addHosts(cluster, Lists.newArrayList(hostGroupMapping)); RequestCheckRunnable.check(request)/*from w w w. j ava 2 s .c o m*/ .headers(ImmutableMap.of(HttpHeaders.AUTHORIZATION, HttpTool.toBasicAuthorizationValue(usernamePasswordCredentials))) .timeout(Duration.ONE_HOUR) .errorMessage(String.format("Error during adding %s to %s", hosts, hostgroupName)).build().run(); }
From source file:com.fluidops.iwb.api.WikiStorageBulkServiceImpl.java
private WikiRevision max(Iterable<WikiRevision> bootstrapRevisions) { WikiRevision latesBootstrapRevision = bootstrapRevisions.iterator().next(); for (WikiRevision wikiRevision : bootstrapRevisions) { if (latesBootstrapRevision.date.getTime() < wikiRevision.date.getTime()) latesBootstrapRevision = wikiRevision; }//from w w w . j a v a2 s. co m return latesBootstrapRevision; }
From source file:org.dasein.cloud.qingcloud.compute.QingCloudImage.java
@Override public void removeAllImageShares(@Nonnull String providerImageId) throws CloudException, InternalException { APITrace.begin(getProvider(), "Image.removeAllImageShares"); try {// w w w. j a va 2 s . c om Iterable<String> shares = listShares(providerImageId); QingCloudRequestBuilder requestBuilder = QingCloudRequestBuilder.post(getProvider()) .action("RevokeImageFromUsers").parameter("image", providerImageId) .parameter("zone", getProvider().getZoneId()); Iterator<String> sharesIterator = shares.iterator(); int index = 1; while (sharesIterator.hasNext()) { requestBuilder.parameter("users." + (index++), sharesIterator.next()); } Requester<ResponseModel> requester = new QingCloudRequester<ResponseModel, ResponseModel>(getProvider(), requestBuilder.build(), ResponseModel.class); requester.execute(); } finally { APITrace.end(); } }
From source file:com.github.rvesse.airline.model.OptionMetadata.java
public OptionMetadata(OptionType optionType, Iterable<String> options, String title, String description, int arity, boolean hidden, boolean overrides, boolean sealed, Iterable<OptionRestriction> restrictions, Iterable<Field> path) { //@formatter:on if (optionType == null) throw new NullPointerException("optionType cannot be null"); if (options == null) throw new NullPointerException("options cannot be null"); if (!options.iterator().hasNext()) throw new NullPointerException("options cannot be empty"); if (title == null) throw new NullPointerException("title cannot be null"); this.optionType = optionType; this.options = AirlineUtils.unmodifiableSetCopy(options); this.title = title; this.description = description; this.arity = arity; this.hidden = hidden; this.overrides = overrides; this.sealed = sealed; this.restrictions = restrictions != null ? AirlineUtils.unmodifiableListCopy(restrictions) : Collections.<OptionRestriction>emptyList(); if (path != null) { this.accessors = SetUtils.unmodifiableSet(AirlineUtils.singletonSet(new Accessor(path))); }// w w w. ja va 2 s. c om }
From source file:org.openbaton.vnfm.MediaServerManager.java
@Override public VirtualNetworkFunctionRecord terminate(VirtualNetworkFunctionRecord virtualNetworkFunctionRecord) { log.info("Terminating vnfr with id " + virtualNetworkFunctionRecord.getId()); ManagedVNFR managedVnfr = null;// w w w . j a va2 s. com Iterable<ManagedVNFR> managedVnfrs = managedVnfrRepository .findByVnfrId(virtualNetworkFunctionRecord.getId()); if (managedVnfrs.iterator().hasNext()) { managedVnfr = managedVnfrs.iterator().next(); } else { managedVnfr = new ManagedVNFR(); managedVnfr.setNsrId(virtualNetworkFunctionRecord.getParent_ns_id()); managedVnfr.setVnfrId(virtualNetworkFunctionRecord.getId()); } managedVnfr.setTask(Action.RELEASE_RESOURCES); managedVnfrRepository.save(managedVnfr); try { elasticityManagement.deactivate(virtualNetworkFunctionRecord.getParent_ns_id(), virtualNetworkFunctionRecord.getId()).get(60, TimeUnit.SECONDS); } catch (InterruptedException e) { log.error(e.getMessage(), e); } catch (ExecutionException e) { log.error(e.getMessage(), e); } catch (TimeoutException e) { log.error(e.getMessage(), e); } try { virtualNetworkFunctionRecord = nfvoRequestor.getNetworkServiceRecordAgent() .getVirtualNetworkFunctionRecord(virtualNetworkFunctionRecord.getParent_ns_id(), virtualNetworkFunctionRecord.getId()); } catch (SDKException e) { log.error(e.getMessage(), e); } for (VirtualDeploymentUnit vdu : virtualNetworkFunctionRecord.getVdu()) { Set<VNFCInstance> vnfciToRem = new HashSet<>(); VimInstance vimInstance = null; try { vimInstance = Utils.getVimInstance(vdu.getVimInstanceName(), nfvoRequestor); } catch (NotFoundException e) { log.error(e.getMessage(), e); } for (VNFCInstance vnfcInstance : vdu.getVnfc_instance()) { log.debug("Releasing resources for vdu with id " + vdu.getId()); try { mediaServerResourceManagement.release(vnfcInstance, vimInstance); log.debug("Removed VNFCinstance: " + vnfcInstance); } catch (VimException e) { log.error(e.getMessage(), e); throw new RuntimeException(e.getMessage(), e); } vnfciToRem.add(vnfcInstance); log.debug("Released resources for vdu with id " + vdu.getId()); } vdu.getVnfc_instance().removeAll(vnfciToRem); } log.info("Terminated vnfr with id " + virtualNetworkFunctionRecord.getId()); try { applicationManagement.deleteByVnfrId(virtualNetworkFunctionRecord.getId()); mediaServerManagement.deleteByVnfrId(virtualNetworkFunctionRecord.getId()); } catch (NotFoundException e) { log.warn(e.getMessage()); } try { managedVnfrRepository.deleteByVnfrId(virtualNetworkFunctionRecord.getId()); } catch (NotFoundException e) { log.warn("ManagedVNFR were not existing and therefore not deletable"); } return virtualNetworkFunctionRecord; }