public void writeChecksums() throws IOException { String checksumName = CHECKSUMS_PREFIX + System.currentTimeMillis(); ImmutableMap<String, StoreFileMetaData> files = list(); synchronized (mutex) { Map<String, String> checksums = new HashMap<String, String>(); for (StoreFileMetaData metaData : files.values()) { if (metaData.checksum() != null) { checksums.put(metaData.name(), metaData.checksum()); } } IndexOutput output = directory.createOutput(checksumName, IOContext.DEFAULT, true); output.writeInt(0); // version output.writeStringStringMap(checksums); output.close(); } for (StoreFileMetaData metaData : files.values()) { if (metaData.name().startsWith(CHECKSUMS_PREFIX) && !checksumName.equals(metaData.name())) { try { directory.deleteFileChecksum(metaData.name()); } catch (Exception e) { // ignore } } } }
private int findLatestIndex() throws IOException { ImmutableMap<String, BlobMetaData> blobs = metaDataBlobContainer.listBlobsByPrefix("metadata-"); int index = -1; for (BlobMetaData md : blobs.values()) { if (logger.isTraceEnabled()) { logger.trace("[findLatestMetadata]: Processing [" + md.name() + "]"); } String name = md.name(); int fileIndex = Integer.parseInt(name.substring(name.indexOf('-') + 1)); if (fileIndex >= index) { // try and read the meta data byte[] data = null; try { data = metaDataBlobContainer.readBlobFully(name); readMetaData(data); index = fileIndex; } catch (IOException e) { logger.warn( "[findLatestMetadata]: failed to read metadata from [{}], data_length [{}] ignoring...", e, name, data == null ? "na" : data.length); } } } return index; }
public Collection<Class<? extends CloseableIndexComponent>> indexServices() { List<Class<? extends CloseableIndexComponent>> services = Lists.newArrayList(); for (Plugin plugin : plugins.values()) { services.addAll(plugin.indexServices()); } return services; }
@Override public void traverse(ObjectMapperListener objectMapperListener) { objectMapperListener.objectMapper(this); for (Mapper mapper : mappers.values()) { mapper.traverse(objectMapperListener); } }
public Collection<Class<? extends LifecycleComponent>> services() { List<Class<? extends LifecycleComponent>> services = Lists.newArrayList(); for (Plugin plugin : plugins.values()) { services.addAll(plugin.services()); } return services; }
public ThreadPoolStats stats() { List<ThreadPoolStats.Stats> stats = new ArrayList<ThreadPoolStats.Stats>(); for (ExecutorHolder holder : executors.values()) { String name = holder.info.getName(); // no need to have info on "same" thread pool if ("same".equals(name)) { continue; } int threads = -1; int queue = -1; int active = -1; long rejected = -1; int largest = -1; long completed = -1; if (holder.executor instanceof ThreadPoolExecutor) { ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) holder.executor; threads = threadPoolExecutor.getPoolSize(); queue = threadPoolExecutor.getQueue().size(); active = threadPoolExecutor.getActiveCount(); largest = threadPoolExecutor.getLargestPoolSize(); completed = threadPoolExecutor.getCompletedTaskCount(); RejectedExecutionHandler rejectedExecutionHandler = threadPoolExecutor.getRejectedExecutionHandler(); if (rejectedExecutionHandler instanceof XRejectedExecutionHandler) { rejected = ((XRejectedExecutionHandler) rejectedExecutionHandler).rejected(); } } stats.add( new ThreadPoolStats.Stats(name, threads, queue, active, rejected, largest, completed)); } return new ThreadPoolStats(stats); }
public Collection<Class<? extends Module>> indexModules() { List<Class<? extends Module>> modules = Lists.newArrayList(); for (Plugin plugin : plugins.values()) { modules.addAll(plugin.indexModules()); } return modules; }
public DiscoveryNode findByAddress(TransportAddress address) { for (DiscoveryNode node : nodes.values()) { if (node.address().equals(address)) { return node; } } return null; }
@Override public void deleteBlobsByFilter(BlobNameFilter filter) throws IOException { ImmutableMap<String, BlobMetaData> blobs = listBlobs(); for (BlobMetaData blob : blobs.values()) { if (filter.accept(blob.name())) { deleteBlob(blob.name()); } } }
@BeforeClass public void makeTestData() throws IOException { for (final FileContentPair fileContentPair : testFileContentPairs.values()) { try (Writer fos = new OutputStreamWriter(new FileOutputStream(fileContentPair.file), Charsets.UTF_8)) { fos.write(fileContentPair.content); } } }
public void shutdown() { estimatedTimeThread.running = false; estimatedTimeThread.interrupt(); scheduler.shutdown(); for (ExecutorHolder executor : executors.values()) { if (executor.executor instanceof ThreadPoolExecutor) { ((ThreadPoolExecutor) executor.executor).shutdown(); } } }
// ------------------------------------------------------------------------- public void test_cashFlowEquivalentAndSensitivity() { Swap swap = Swap.builder().legs(IBOR_LEG, FIXED_LEG).build(); ImmutableMap<NotionalExchange, PointSensitivityBuilder> computedFull = CashFlowEquivalentCalculator.cashFlowEquivalentAndSensitivitySwap(swap.expand(), PROVIDER); ImmutableList<NotionalExchange> keyComputedFull = computedFull.keySet().asList(); ImmutableList<PointSensitivityBuilder> valueComputedFull = computedFull.values().asList(); ImmutableMap<NotionalExchange, PointSensitivityBuilder> computedIborLeg = CashFlowEquivalentCalculator.cashFlowEquivalentAndSensitivityIborLeg( IBOR_LEG.expand(), PROVIDER); ImmutableMap<NotionalExchange, PointSensitivityBuilder> computedFixedLeg = CashFlowEquivalentCalculator.cashFlowEquivalentAndSensitivityFixedLeg( FIXED_LEG.expand(), PROVIDER); assertEquals(computedFixedLeg.keySet().asList(), keyComputedFull.subList(0, 2)); assertEquals(computedIborLeg.keySet().asList(), keyComputedFull.subList(2, 6)); assertEquals(computedFixedLeg.values().asList(), valueComputedFull.subList(0, 2)); assertEquals(computedIborLeg.values().asList(), valueComputedFull.subList(2, 6)); double eps = 1.0e-7; RatesFiniteDifferenceSensitivityCalculator calc = new RatesFiniteDifferenceSensitivityCalculator(eps); int size = keyComputedFull.size(); for (int i = 0; i < size; ++i) { final int index = i; CurveCurrencyParameterSensitivities expected = calc.sensitivity( PROVIDER, p -> ((NotionalExchange) CashFlowEquivalentCalculator.cashFlowEquivalentSwap(swap.expand(), p) .getPaymentEvents() .get(index)) .getPaymentAmount()); PointSensitivityBuilder point = computedFull.get( CashFlowEquivalentCalculator.cashFlowEquivalentSwap(swap.expand(), PROVIDER) .getPaymentEvents() .get(index)); CurveCurrencyParameterSensitivities computed = PROVIDER.curveParameterSensitivity(point.build()); assertTrue(computed.equalWithTolerance(expected, eps * NOTIONAL)); } }
@Override public void includeInAllIfNotSet(Boolean includeInAll) { if (this.includeInAll == null) { this.includeInAll = includeInAll; } // when called from outside, apply this on all the inner mappers for (Mapper mapper : mappers.values()) { if (mapper instanceof AllFieldMapper.IncludeInAll) { ((AllFieldMapper.IncludeInAll) mapper).includeInAllIfNotSet(includeInAll); } } }
public ThreadPoolInfo info() { List<Info> infos = new ArrayList<Info>(); for (ExecutorHolder holder : executors.values()) { String name = holder.info.getName(); // no need to have info on "same" thread pool if ("same".equals(name)) { continue; } infos.add(holder.info); } return new ThreadPoolInfo(infos); }
@Override public ImmutableMap<String, BlobMetaData> listBlobsByPrefix(String blobNamePrefix) throws IOException { ImmutableMap<String, BlobMetaData> allBlobs = listBlobs(); ImmutableMap.Builder<String, BlobMetaData> blobs = ImmutableMap.builder(); for (BlobMetaData blob : allBlobs.values()) { if (blob.name().startsWith(blobNamePrefix)) { blobs.put(blob.name(), blob); } } return blobs.build(); }
@Override public List<BakedQuad> getGeneralQuads() { if (general == null) { // Create list of general quads. ImmutableList.Builder<BakedQuad> genQuads = ImmutableList.builder(); if (base != null) genQuads.addAll(base.getGeneralQuads()); for (IFlexibleBakedModel bakedPart : parts.values()) genQuads.addAll(bakedPart.getGeneralQuads()); general = genQuads.build(); } return general; }
@Override public void run(ImmutableMap<Integer, Long> cache) { // We know there's a 1:1 mapping between partitions and HSIds in this map. // let's flip it Map<Long, Integer> hsIdToPart = new HashMap<Long, Integer>(); for (Entry<Integer, Long> e : cache.entrySet()) { hsIdToPart.put(e.getValue(), e.getKey()); } Set<Long> newMasters = new HashSet<Long>(); newMasters.addAll(cache.values()); // we want to see items which are present in the new map but not in the old, // these are newly promoted SPIs newMasters.removeAll(m_currentSPMasters); // send the messages indicating promotion from here for each new master for (long newMaster : newMasters) { sendLeaderChangeNotify(newMaster, hsIdToPart.get(newMaster)); } m_currentSPMasters.clear(); m_currentSPMasters.addAll(cache.values()); }
@Override public void run(ImmutableMap<Integer, Long> cache) { for (Long HSId : cache.values()) { if (HSId == getInitiatorHSId()) { if (!m_promoted) { acceptPromotion(); m_promoted = true; } break; } } }
public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { boolean result = scheduler.awaitTermination(timeout, unit); for (ExecutorHolder executor : executors.values()) { if (executor.executor instanceof ThreadPoolExecutor) { result &= ((ThreadPoolExecutor) executor.executor).awaitTermination(timeout, unit); } } while (!retiredExecutors.isEmpty()) { result &= ((ThreadPoolExecutor) retiredExecutors.remove().executor).awaitTermination(timeout, unit); } return result; }
public void shutdownNow() { estimatedTimeThread.running = false; estimatedTimeThread.interrupt(); scheduler.shutdownNow(); for (ExecutorHolder executor : executors.values()) { if (executor.executor instanceof ThreadPoolExecutor) { ((ThreadPoolExecutor) executor.executor).shutdownNow(); } } while (!retiredExecutors.isEmpty()) { ((ThreadPoolExecutor) retiredExecutors.remove().executor).shutdownNow(); } }
@Override public void run(ImmutableMap<Integer, Long> cache) { Set<Long> currentLeaders = new HashSet<Long>(cache.values()); tmLog.debug("Updated leaders: " + currentLeaders); if (m_state.get() == AppointerState.CLUSTER_START) { if (currentLeaders.size() == m_partitionCount) { tmLog.debug("Leader appointment complete, promoting MPI and unblocking."); m_state.set(AppointerState.DONE); m_MPI.acceptPromotion(); m_startupLatch.countDown(); } } }
Property getProp(String pname) { if (this.rawType.isBuiltinWithName("Array") && NUMERIC_PATTERN.matcher(pname).matches()) { if (typeMap.isEmpty()) { return Property.make(getCommonTypes().UNKNOWN, null); } Preconditions.checkState(typeMap.size() == 1); JSType elmType = Iterables.getOnlyElement(typeMap.values()); return Property.make(elmType, null); } Property p = this.rawType.getProp(pname); // TODO(aravindpg): Also look for getters and setters specially (in RawNominalType::protoProps), // but avoid putting them in the hot path of getProp. return p == null ? null : p.substituteGenerics(typeMap); }
@Override public List<BakedQuad> getFaceQuads(EnumFacing side) { if (faces == null) { // Create map of each face's quads. EnumMap<EnumFacing, ImmutableList<BakedQuad>> faces = Maps.newEnumMap(EnumFacing.class); for (EnumFacing face : EnumFacing.values()) { ImmutableList.Builder<BakedQuad> faceQuads = ImmutableList.builder(); if (base != null) faceQuads.addAll(base.getFaceQuads(face)); for (IFlexibleBakedModel bakedPart : parts.values()) faceQuads.addAll(bakedPart.getFaceQuads(face)); faces.put(face, faceQuads.build()); } this.faces = Maps.immutableEnumMap(faces); } return faces.get(side); }
private void go() { while (true) { madeProgress = false; for (ClassNode klass : allClasses.values()) { analyzeClass(klass); } if (!madeProgress) { break; } } immutableClasses = ImmutableSet.copyOf( Sets.difference( allClasses.keySet(), Sets.union(trulyMutableClasses, classesWithMutableDescendents))); }
@Test public void testComposition() { final Processor<File, File, String> compose = makeComposedProcessorFileStringProcessor(); final List<Result<File, File>> testFiles = testFileContentPairs .values() .stream() .map(fileContentPair -> fileContentPair.file) .map(file -> Result.success(file, file)) .collect(Collectors.toList()); final Iterable<Result<File, String>> processed = compose.process(testFiles); for (final Result r : processed) { Assert.assertFalse(r.isFailed(), "Failed result did not fail!"); final FileContentPair fileContentPair = testFileContentPairs.get(r.getOutput()); Assert.assertNotNull(fileContentPair); } }
public CommitPoint findCommitPoint(String index, int shardId) throws IOException { BlobPath path = BlobStoreIndexGateway.shardPath(basePath, index, shardId); ImmutableBlobContainer container = blobStore.immutableBlobContainer(path); ImmutableMap<String, BlobMetaData> blobs = container.listBlobs(); List<CommitPoint> commitPointsList = Lists.newArrayList(); for (BlobMetaData md : blobs.values()) { if (md.length() == 0) { // a commit point that was not flushed yet... continue; } if (md.name().startsWith("commit-")) { try { commitPointsList.add(CommitPoints.fromXContent(container.readBlobFully(md.name()))); } catch (Exception e) { logger.warn("failed to read commit point at path {} with name [{}]", e, path, md.name()); } } } CommitPoints commitPoints = new CommitPoints(commitPointsList); if (commitPoints.commits().isEmpty()) { return null; } return commitPoints.commits().get(0); }
public Baked( ResourceLocation location, boolean perspective, IFlexibleBakedModel base, ImmutableMap<String, IFlexibleBakedModel> parts) { this.base = base; this.parts = parts; if (base != null) internalBase = base; else { Iterator<IFlexibleBakedModel> iter = parts.values().iterator(); if (iter.hasNext()) internalBase = iter.next(); else throw new IllegalArgumentException( "No base model or submodel provided for MultiModel.Baked " + location + "."); } // Only changes the base model based on perspective, may recurse for parts in the future. if (perspective && base instanceof IPerspectiveAwareModel) { IPerspectiveAwareModel perBase = (IPerspectiveAwareModel) base; ImmutableMap.Builder<TransformType, Pair<Baked, TRSRTransformation>> builder = ImmutableMap.builder(); for (TransformType type : TransformType.values()) { Pair<? extends IFlexibleBakedModel, Matrix4f> p = perBase.handlePerspective(type); IFlexibleBakedModel newBase = p.getLeft(); builder.put( type, Pair.of( new Baked(location, false, newBase, parts), new TRSRTransformation(p.getRight()))); } transforms = builder.build(); } else { transforms = ImmutableMap.of(); } }
public GameAILoader() { _finder = new ClassAIFinder(); _classes = _finder.getAIClasses(AI.class, "ch.hesso"); ImmutableMap.Builder<String, AI> builder = ImmutableMap.builder(); for (Class<? extends AI> ai : _classes) { try { AI instance = ai.newInstance(); instance.initialize(GameController.this); if (instance.kind().equals(PLAYER)) { _default = instance; _defaultAIName = instance.name(); } builder.put(instance.name(), instance); initClassFields(ai, instance); } catch (InstantiationException | IllegalAccessException e) { LOG.log(Level.SEVERE, "[GameController.GameAILoader.GameAILoader]: " + e.getMessage()); } } _ais = builder.build(); if (_default == null && _ais.size() > 0) { _default = _ais.values().asList().get(0); _defaultAIName = _ais.keySet().asList().get(0); } }
public Collection<LongSet> longs() { return longPositions.values(); }
private <A extends Arg> BuildRule createExtensionBuildRule( TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver ruleResolver, CxxPlatform cxxPlatform, A args) { SourcePathResolver pathResolver = new SourcePathResolver(ruleResolver); // Extract all C/C++ sources from the constructor arg. ImmutableMap<String, CxxSource> srcs = CxxDescriptionEnhancer.parseCxxSources(params, ruleResolver, cxxPlatform, args); ImmutableMap<Path, SourcePath> headers = CxxDescriptionEnhancer.parseHeaders(params, ruleResolver, cxxPlatform, args); ImmutableMap<String, SourcePath> lexSrcs = CxxDescriptionEnhancer.parseLexSources(params, ruleResolver, args); ImmutableMap<String, SourcePath> yaccSrcs = CxxDescriptionEnhancer.parseYaccSources(params, ruleResolver, args); CxxHeaderSourceSpec lexYaccSources = CxxDescriptionEnhancer.createLexYaccBuildRules( params, ruleResolver, cxxPlatform, ImmutableList.<String>of(), lexSrcs, ImmutableList.<String>of(), yaccSrcs); // Setup the header symlink tree and combine all the preprocessor input from this rule // and all dependencies. HeaderSymlinkTree headerSymlinkTree = CxxDescriptionEnhancer.requireHeaderSymlinkTree( params, ruleResolver, new SourcePathResolver(ruleResolver), cxxPlatform, /* includeLexYaccHeaders */ true, lexSrcs, yaccSrcs, headers, HeaderVisibility.PRIVATE); ImmutableList<CxxPreprocessorInput> cxxPreprocessorInput = CxxDescriptionEnhancer.collectCxxPreprocessorInput( targetGraph, params, cxxPlatform, CxxFlags.getLanguageFlags( args.preprocessorFlags, args.platformPreprocessorFlags, args.langPreprocessorFlags, cxxPlatform), args.prefixHeaders.get(), ImmutableList.of(headerSymlinkTree), ImmutableSet.<Path>of(), CxxPreprocessables.getTransitiveCxxPreprocessorInput( targetGraph, cxxPlatform, params.getDeps())); ImmutableMap<String, CxxSource> allSources = ImmutableMap.<String, CxxSource>builder() .putAll(srcs) .putAll(lexYaccSources.getCxxSources()) .build(); // Generate rule to build the object files. ImmutableMap<CxxPreprocessAndCompile, SourcePath> picObjects = CxxSourceRuleFactory.requirePreprocessAndCompileRules( params, ruleResolver, pathResolver, cxxPlatform, cxxPreprocessorInput, CxxFlags.getFlags(args.compilerFlags, args.platformCompilerFlags, cxxPlatform), cxxBuckConfig.getPreprocessMode(), allSources, CxxSourceRuleFactory.PicType.PIC); // Setup the rules to link the shared library. String extensionName = getExtensionName(params.getBuildTarget()); Path extensionPath = getExtensionPath(params.getBuildTarget(), cxxPlatform.getFlavor()); return CxxLinkableEnhancer.createCxxLinkableBuildRule( targetGraph, cxxPlatform, params, pathResolver, /* extraLdFlags */ CxxFlags.getFlags( args.linkerFlags, args.platformLinkerFlags, cxxPlatform), getExtensionTarget(params.getBuildTarget(), cxxPlatform.getFlavor()), Linker.LinkType.SHARED, Optional.of(extensionName), extensionPath, picObjects.values(), Linker.LinkableDepType.SHARED, params.getDeps(), args.cxxRuntimeType, Optional.<SourcePath>absent()); }