List of usage examples for com.google.common.base Functions constant
public static <E> Function<Object, E> constant(@Nullable E value)
From source file:com.facebook.buck.artifact_cache.SQLiteArtifactCache.java
@Override public ListenableFuture<Void> store(ArtifactInfo info, BorrowablePath content) { if (!getCacheReadMode().isWritable()) { return Futures.immediateFuture(null); }/* w w w .ja v a 2s.c o m*/ ListenableFuture<Void> metadataResult = Futures.immediateFuture(null); if (!info.getMetadata().isEmpty()) { metadataResult = storeMetadata(info); } ListenableFuture<Void> contentResult = Futures.immediateFuture(null); if (!info.getMetadata().containsKey(TwoLevelArtifactCacheDecorator.METADATA_KEY)) { contentResult = storeContent(info.getRuleKeys(), content); } return Futures.transform(Futures.allAsList(metadataResult, contentResult), Functions.constant(null), MoreExecutors.directExecutor()); }
From source file:org.apache.brooklyn.entity.group.DynamicClusterImpl.java
private void connectAllMembersUp() { clusterOneAndAllMembersUp = FunctionFeed.builder().entity(this).period(Duration.FIVE_SECONDS) .poll(new FunctionPollConfig<Boolean, Boolean>(CLUSTER_ONE_AND_ALL_MEMBERS_UP) .onException(Functions.constant(Boolean.FALSE)) .callable(new ClusterOneAndAllMembersUpCallable(this))) .build();/*from w w w . j a v a 2 s. com*/ }
From source file:org.pentaho.di.trans.dataservice.serialization.DataServiceMetaStoreUtil.java
public DataServiceMeta getDataServiceByStepName(TransMeta transMeta, String stepName) { Set<Integer> cacheKeys = createCacheKeys(transMeta, stepName); for (Map.Entry<Integer, String> entry : stepCache.getAll(cacheKeys).entrySet()) { String serviceName = entry.getValue(); if (serviceName.isEmpty()) { // Step is marked as not having a Data Service return null; }//w ww . j av a 2 s. c o m // Check if Data Service is still valid DataServiceMeta dataServiceMeta; try { dataServiceMeta = getDataService(serviceName, transMeta); } catch (MetaStoreException e) { dataServiceMeta = null; } if (dataServiceMeta != null && dataServiceMeta.getStepname().equals(stepName)) { return dataServiceMeta; } else { stepCache.remove(entry.getKey(), serviceName); } } // Look up from embedded metastore for (DataServiceMeta dataServiceMeta : getDataServices(transMeta)) { if (dataServiceMeta.getStepname().equalsIgnoreCase(stepName)) { return dataServiceMeta; } } // Data service not found on step, store negative result in the cache stepCache.putAll(Maps.asMap(cacheKeys, Functions.constant(""))); return null; }
From source file:brooklyn.entity.nosql.couchbase.CouchbaseNodeImpl.java
public void connectSensors() { super.connectSensors(); connectServiceUpIsRunning();/*from ww w.j a v a 2s . c om*/ HostAndPort hostAndPort = BrooklynAccessUtils.getBrooklynAccessibleAddress(this, this.getAttribute(CouchbaseNode.COUCHBASE_WEB_ADMIN_PORT)); httpFeed = HttpFeed.builder().entity(this).period(Duration.seconds(3)) .baseUri("http://" + hostAndPort + "/pools/nodes/") .credentialsIfNotNull(getConfig(CouchbaseNode.COUCHBASE_ADMIN_USERNAME), getConfig(CouchbaseNode.COUCHBASE_ADMIN_PASSWORD)) .poll(getSensorFromNodeStat(CouchbaseNode.OPS, "ops")) .poll(getSensorFromNodeStat(CouchbaseNode.COUCH_DOCS_DATA_SIZE, "couch_docs_data_size")) .poll(getSensorFromNodeStat(CouchbaseNode.COUCH_DOCS_ACTUAL_DISK_SIZE, "couch_docs_actual_disk_size")) .poll(getSensorFromNodeStat(CouchbaseNode.EP_BG_FETCHED, "ep_bg_fetched")) .poll(getSensorFromNodeStat(CouchbaseNode.MEM_USED, "mem_used")) .poll(getSensorFromNodeStat(CouchbaseNode.COUCH_VIEWS_ACTUAL_DISK_SIZE, "couch_views_actual_disk_size")) .poll(getSensorFromNodeStat(CouchbaseNode.CURR_ITEMS, "curr_items")) .poll(getSensorFromNodeStat(CouchbaseNode.VB_REPLICA_CURR_ITEMS, "vb_replica_curr_items")) .poll(getSensorFromNodeStat(CouchbaseNode.COUCH_VIEWS_DATA_SIZE, "couch_views_data_size")) .poll(getSensorFromNodeStat(CouchbaseNode.GET_HITS, "get_hits")) .poll(getSensorFromNodeStat(CouchbaseNode.CMD_GET, "cmd_get")) .poll(getSensorFromNodeStat(CouchbaseNode.CURR_ITEMS_TOT, "curr_items_tot")) .poll(new HttpPollConfig<String>(CouchbaseNode.REBALANCE_STATUS) .onSuccess(HttpValueFunctions.jsonContents("rebalanceStatus", String.class)) .onFailureOrException(Functions.constant("Could not retrieve"))) .build(); }
From source file:brooklyn.config.render.RendererHints.java
/** * Forces the given sensor or config key's value to be censored. It will be * presented as <code>********</code>. *//*from w w w . java 2s . c om*/ @Beta public static <T> DisplayValue<T> censoredValue() { return new DisplayValue<T>(Functions.constant("********")); }
From source file:com.netflix.metacat.main.services.search.ElasticSearchRefresh.java
@SuppressWarnings("checkstyle:methodname") private ListenableFuture<Void> _processPartitions(final List<QualifiedName> qNames) { final List<QualifiedName> excludeQualifiedNames = config.getElasticSearchRefreshExcludeQualifiedNames(); final List<String> tables = elasticSearchUtil.getTableIdsByCatalogs(ElasticSearchDoc.Type.table.name(), qNames, excludeQualifiedNames); final List<ListenableFuture<ListenableFuture<Void>>> futures = tables.stream() .map(s -> service.submit(() -> { final QualifiedName tableName = QualifiedName.fromString(s, false); final List<ListenableFuture<Void>> indexFutures = Lists.newArrayList(); int offset = 0; int count; final Sort sort; if ("s3".equals(tableName.getCatalogName()) || "aegisthus".equals(tableName.getCatalogName())) { sort = new Sort("id", SortOrder.ASC); } else { sort = new Sort("part_id", SortOrder.ASC); }// w w w. j av a 2 s.c o m final Pageable pageable = new Pageable(10000, offset); do { final List<PartitionDto> partitionDtos = partitionService.list(tableName, sort, pageable, true, true, new GetPartitionsRequestDto(null, null, true, true)); count = partitionDtos.size(); if (!partitionDtos.isEmpty()) { final List<List<PartitionDto>> partitionedPartitionDtos = Lists.partition(partitionDtos, 1000); partitionedPartitionDtos.forEach(subPartitionsDtos -> indexFutures .add(indexPartitionDtos(tableName, subPartitionsDtos))); offset = offset + count; pageable.setOffset(offset); } } while (count == 10000); return Futures.transform(Futures.successfulAsList(indexFutures), Functions.constant((Void) null)); })).collect(Collectors.toList()); final ListenableFuture<Void> processPartitionsFuture = Futures .transformAsync(Futures.successfulAsList(futures), input -> { final List<ListenableFuture<Void>> inputFuturesWithoutNulls = input.stream().filter(NOT_NULL) .collect(Collectors.toList()); return Futures.transform(Futures.successfulAsList(inputFuturesWithoutNulls), Functions.constant(null)); }); return Futures.transformAsync(processPartitionsFuture, input -> { elasticSearchUtil.refresh(); final List<ListenableFuture<Void>> cleanUpFutures = tables.stream() .map(s -> service.submit( () -> partitionsCleanUp(QualifiedName.fromString(s, false), excludeQualifiedNames))) .collect(Collectors.toList()); return Futures.transform(Futures.successfulAsList(cleanUpFutures), Functions.constant(null)); }); }
From source file:test.demo.KnnQuery.java
private static List<FilteredIndexRange<Object, LongRange>> queryto(List<LongRange> region, SpaceFillingCurve sfc, int maxRanges, Map<Pow2LengthBitSetRange, NodeValue<BigIntegerContent>> rolledupMap) { List<? extends List<LongRange>> x = ImmutableList.of(region); LongContent zero = new LongContent(0L); LongContent one = new LongContent(1L); Object filter = ""; RegionInspector<Object, LongContent> simpleRegionInspector = SimpleRegionInspector.create(x, one, Functions.constant(filter), LongRangeHome.INSTANCE, zero); // Not using using sub-ranges here. PlainFilterCombiner<Object, Long, LongContent, LongRange> combiner = new PlainFilterCombiner<>(filter); QueryBuilder<Object, LongRange> queryBuilder = BacktrackingQueryBuilder.create(simpleRegionInspector, combiner, maxRanges, true, LongRangeHome.INSTANCE, zero); sfc.accept(new ZoomingSpaceVisitorAdapter(sfc, queryBuilder)); Query<Object, LongRange> query = queryBuilder.get(); return query.getFilteredIndexRanges(); }
From source file:edu.uci.ics.jung.samples.PluggableRendererDemo.java
public JPanel startFunction() { this.graph = buildGraph(); Layout<Integer, Number> layout = new FRLayout<Integer, Number>(graph); vv = new VisualizationViewer<Integer, Number>(layout); vv.getRenderer().setVertexRenderer(new CachingVertexRenderer<Integer, Number>(vv)); vv.getRenderer().setEdgeRenderer(new CachingEdgeRenderer<Integer, Number>(vv)); PickedState<Integer> picked_state = vv.getPickedVertexState(); self_loop = new SelfLoopEdgePredicate<Integer, Number>(); // create decorators seedFillColor = new SeedFillColor<Integer>(picked_state); seedDrawColor = new SeedDrawColor<Integer>(); ewcs = new EdgeWeightStrokeFunction<Number>(edge_weight); vsh = new VertexStrokeHighlight<Integer, Number>(graph, picked_state); vff = new VertexFontTransformer<Integer>(); eff = new EdgeFontTransformer<Number>(); vs_none = Functions.constant(null); es_none = Functions.constant(null);/*from ww w.ja v a 2 s .c o m*/ vssa = new VertexShapeSizeAspect<Integer, Number>(graph, voltages); show_edge = new DirectionDisplayPredicate<Integer, Number>(true, true); show_arrow = new DirectionDisplayPredicate<Integer, Number>(true, false); show_vertex = new VertexDisplayPredicate<Integer, Number>(false); // uses a gradient edge if unpicked, otherwise uses picked selection edgeDrawPaint = new GradientPickedEdgePaintFunction<Integer, Number>( new PickableEdgePaintTransformer<Number>(vv.getPickedEdgeState(), Color.black, Color.cyan), vv); edgeFillPaint = new GradientPickedEdgePaintFunction<Integer, Number>( new PickableEdgePaintTransformer<Number>(vv.getPickedEdgeState(), Color.black, Color.cyan), vv); vv.getRenderContext().setVertexFillPaintTransformer(seedFillColor); vv.getRenderContext().setVertexDrawPaintTransformer(seedDrawColor); vv.getRenderContext().setVertexStrokeTransformer(vsh); vv.getRenderContext().setVertexLabelTransformer(vs_none); vv.getRenderContext().setVertexFontTransformer(vff); vv.getRenderContext().setVertexShapeTransformer(vssa); vv.getRenderContext().setVertexIncludePredicate(show_vertex); vv.getRenderContext().setEdgeDrawPaintTransformer(edgeDrawPaint); vv.getRenderContext().setEdgeLabelTransformer(es_none); vv.getRenderContext().setEdgeFontTransformer(eff); vv.getRenderContext().setEdgeStrokeTransformer(ewcs); vv.getRenderContext().setEdgeIncludePredicate(show_edge); vv.getRenderContext().setEdgeShapeTransformer(EdgeShape.line(graph)); vv.getRenderContext().setEdgeArrowPredicate(show_arrow); vv.getRenderContext().setArrowFillPaintTransformer(Functions.<Paint>constant(Color.lightGray)); vv.getRenderContext().setArrowDrawPaintTransformer(Functions.<Paint>constant(Color.black)); JPanel jp = new JPanel(); jp.setLayout(new BorderLayout()); vv.setBackground(Color.white); GraphZoomScrollPane scrollPane = new GraphZoomScrollPane(vv); jp.add(scrollPane); gm = new DefaultModalGraphMouse<Integer, Number>(); vv.setGraphMouse(gm); gm.add(new PopupGraphMousePlugin()); addBottomControls(jp); vssa.setScaling(true); vv.setVertexToolTipTransformer(new VoltageTips<Number>()); vv.setToolTipText( "<html><center>Use the mouse wheel to zoom<p>Click and Drag the mouse to pan<p>Shift-click and Drag to Rotate</center></html>"); return jp; }
From source file:org.apache.aurora.scheduler.updater.JobUpdateControllerImpl.java
@Override public void abort(IJobUpdateKey key, AuditData auditData) throws UpdateStateException { unscopedChangeUpdateStatus(key,//from w w w . j a v a 2 s. co m Functions.compose(createAuditedEvent(auditData), Functions.constant(ABORTED))); }
From source file:org.apache.aurora.scheduler.updater.JobUpdateControllerImpl.java
@Override public void rollback(IJobUpdateKey key, AuditData auditData) throws UpdateStateException { unscopedChangeUpdateStatus(key,//from ww w . j ava2 s . co m Functions.compose(createAuditedEvent(auditData), Functions.constant(ROLLING_BACK))); }