List of usage examples for com.google.common.base Functions identity
@SuppressWarnings("unchecked") public static <E> Function<E, E> identity()
From source file:com.romeikat.datamessie.core.base.ui.page.StatisticsPage.java
private Function<LocalDate, LocalDate> getTransformDateFunction() { final StatisticsInterval statisticsInterval = statisticsIntervalSelector.getModelObject(); switch (statisticsInterval) { case DAY:/*from www . ja v a 2 s . c om*/ return Functions.identity(); case WEEK: return new GetFirstDayOfWeekFunction(); case MONTH: return new GetFirstDayOfMonthFunction(); case YEAR: return new GetFirstDayOfYearFunction(); default: return new Function<LocalDate, LocalDate>() { @Override public LocalDate apply(final LocalDate from) { return null; } }; } }
From source file:io.datakernel.aggregation_db.Aggregation.java
private <T> StreamProducer<T> getOrderedStream(StreamProducer<T> rawStream, Class<T> resultClass, List<String> keys, List<String> fields, DefiningClassLoader classLoader) { Comparator keyComparator = createKeyComparator(resultClass, keys, classLoader); Path path = Paths.get("sorterStorage", "%d.part"); BufferSerializer bufferSerializer = structure.createBufferSerializer(resultClass, getKeys(), fields, classLoader);/*from w w w . j a v a 2 s. co m*/ StreamMergeSorterStorage sorterStorage = new StreamMergeSorterStorageImpl(eventloop, executorService, bufferSerializer, path, sorterBlockSize); StreamSorter sorter = new StreamSorter(eventloop, sorterStorage, Functions.identity(), keyComparator, false, sorterItemsInMemory); rawStream.streamTo(sorter.getInput()); return sorter.getOutput(); }
From source file:com.facebook.buck.cxx.CxxDescriptionEnhancer.java
/** * @return a function that transforms the {@link FrameworkPath} to search paths with any embedded * macros expanded./*www .j a v a 2 s.com*/ */ public static RuleKeyAppendableFunction<FrameworkPath, Path> frameworkPathToSearchPath( final CxxPlatform cxxPlatform, final SourcePathResolver resolver) { return new RuleKeyAppendableFunction<FrameworkPath, Path>() { private RuleKeyAppendableFunction<String, String> translateMacrosFn = CxxFlags .getTranslateMacrosFn(cxxPlatform); @Override public void appendToRuleKey(RuleKeyObjectSink sink) { sink.setReflectively("translateMacrosFn", translateMacrosFn); } @Override public Path apply(FrameworkPath input) { Function<FrameworkPath, Path> convertToPath = FrameworkPath .getUnexpandedSearchPathFunction(resolver::getAbsolutePath, Functions.identity()); String pathAsString = convertToPath.apply(input).toString(); return Paths.get(translateMacrosFn.apply(pathAsString)); } }; }
From source file:org.apache.brooklyn.entity.brooklynnode.BrooklynNodeImpl.java
@Override protected void connectSensors() { super.connectSensors(); // TODO what sensors should we poll? ConfigToAttributes.apply(this); URI webConsoleUri;/*from w ww. j ava2 s .co m*/ if (isHttpProtocolEnabled("http")) { int port = getConfig(PORT_MAPPER).apply(getAttribute(HTTP_PORT)); HostAndPort accessible = BrooklynAccessUtils.getBrooklynAccessibleAddress(this, port); webConsoleUri = URI .create(String.format("http://%s:%s", accessible.getHostText(), accessible.getPort())); } else if (isHttpProtocolEnabled("https")) { int port = getConfig(PORT_MAPPER).apply(getAttribute(HTTPS_PORT)); HostAndPort accessible = BrooklynAccessUtils.getBrooklynAccessibleAddress(this, port); webConsoleUri = URI .create(String.format("https://%s:%s", accessible.getHostText(), accessible.getPort())); } else { // web-console is not enabled webConsoleUri = null; } sensors().set(WEB_CONSOLE_URI, webConsoleUri); if (webConsoleUri != null) { httpFeed = HttpFeed.builder().entity(this).period(getConfig(POLL_PERIOD)).baseUri(webConsoleUri) .credentialsIfNotNull(getConfig(MANAGEMENT_USER), getConfig(MANAGEMENT_PASSWORD)) .poll(new HttpPollConfig<Boolean>(WEB_CONSOLE_ACCESSIBLE).suburl("/v1/server/healthy") .onSuccess(Functionals.chain(HttpValueFunctions.jsonContents(), JsonFunctions.cast(Boolean.class))) //if using an old distribution the path doesn't exist, but at least the instance is responding .onFailure(HttpValueFunctions.responseCodeEquals(404)).setOnException(false)) .poll(new HttpPollConfig<ManagementNodeState>(MANAGEMENT_NODE_STATE) .suburl("/v1/server/ha/state") .onSuccess(Functionals.chain( Functionals.chain(HttpValueFunctions.jsonContents(), JsonFunctions.cast(String.class)), Enums.fromStringFunction(ManagementNodeState.class))) .setOnFailureOrException(null)) // TODO sensors for load, size, etc .build(); if (!Lifecycle.RUNNING.equals(getAttribute(SERVICE_STATE_ACTUAL))) { // TODO when updating the map, if it would change from empty to empty on a successful run (see in nginx) ServiceNotUpLogic.updateNotUpIndicator(this, WEB_CONSOLE_ACCESSIBLE, "No response from the web console yet"); } enrichers().add(Enrichers.builder().updatingMap(Attributes.SERVICE_NOT_UP_INDICATORS) .from(WEB_CONSOLE_ACCESSIBLE).computing(Functionals.ifNotEquals(true) .value("URL where Brooklyn listens is not answering correctly")) .build()); addEnricher(Enrichers.builder().transforming(WEB_CONSOLE_ACCESSIBLE).computing(Functions.identity()) .publishing(SERVICE_PROCESS_IS_RUNNING).build()); } else { connectServiceUpIsRunning(); } }
From source file:io.datakernel.cube.Cube.java
private <T> StreamProducer<T> getOrderedResultStream(CubeQuery query, Class<T> resultClass, StreamProducer<T> rawResultStream, List<String> dimensions, List<String> measures, DefiningClassLoader classLoader) { if (queryRequiresSorting(query)) { Comparator fieldComparator = createFieldComparator(query, resultClass, classLoader); Path path = Paths.get("sorterStorage", "%d.part"); BufferSerializer bufferSerializer = structure.createBufferSerializer(resultClass, dimensions, measures, classLoader);// ww w. j a v a2 s. c o m StreamMergeSorterStorage sorterStorage = new StreamMergeSorterStorageImpl(eventloop, executorService, bufferSerializer, path, sorterBlockSize); StreamSorter sorter = new StreamSorter(eventloop, sorterStorage, Functions.identity(), fieldComparator, false, sorterItemsInMemory); rawResultStream.streamTo(sorter.getInput()); return sorter.getOutput(); } else { return rawResultStream; } }
From source file:com.eucalyptus.simpleworkflow.SimpleWorkflowService.java
public Run startWorkflowExecution(final StartWorkflowExecutionRequest request) throws SimpleWorkflowException { final Context ctx = Contexts.lookup(); final UserFullName userFullName = ctx.getUserFullName(); final AccountFullName accountFullName = userFullName.asAccountFullName(); final Predicate<? super WorkflowType> accessible = SimpleWorkflowMetadatas.filteringFor(WorkflowType.class) .byPrivileges().buildPredicate(); final WorkflowExecution workflowExecution = allocate(new Supplier<WorkflowExecution>() { @Override/*from ww w.ja v a 2 s . c o m*/ public WorkflowExecution get() { try { if (!workflowExecutions.listByExample(WorkflowExecution.exampleForOpenWorkflow(accountFullName, request.getDomain(), request.getWorkflowId()), Predicates.alwaysTrue(), Functions.identity()).isEmpty()) { throw new SimpleWorkflowClientException("WorkflowExecutionAlreadyStartedFault", "Workflow open with ID " + request.getWorkflowId()); } final Domain domain; try { domain = domains.lookupByName(accountFullName, request.getDomain(), Registered, Functions.<Domain>identity()); } catch (SwfMetadataNotFoundException e) { throw upClient("UnknownResourceFault", "Unknown domain: " + request.getDomain()); } if (workflowExecutions.countOpenByDomain(accountFullName, domain.getDisplayName()) >= SimpleWorkflowProperties .getOpenWorkflowExecutionsPerDomain()) { throw upClient("LimitExceededFault", "Request would exceed limit for open workflow executions"); } final WorkflowType workflowType; try { workflowType = workflowTypes.lookupByExample( WorkflowType.exampleWithUniqueName(accountFullName, request.getDomain(), request.getWorkflowType().getName(), request.getWorkflowType().getVersion()), accountFullName, request.getWorkflowType().getName(), Predicates.and(accessible, WorkflowType.Status.Registered), Functions.<WorkflowType>identity()); } catch (SwfMetadataNotFoundException e) { throw upClient("UnknownResourceFault", "Unknown workflow type: " + request.getWorkflowType().getName()); } if (request.getChildPolicy() == null && workflowType.getDefaultChildPolicy() == null) { throw upClient("DefaultUndefinedFault", "Default child policy undefined"); } if (request.getTaskList() == null && workflowType.getDefaultTaskList() == null) { throw upClient("DefaultUndefinedFault", "Default task list undefined"); } final String childPolicy = Objects.firstNonNull(request.getChildPolicy(), workflowType.getDefaultChildPolicy()); final String taskList = request.getTaskList() == null ? workflowType.getDefaultTaskList() : request.getTaskList().getName(); final Integer executionStartToCloseTimeout = requireDefault( parsePeriod(request.getExecutionStartToCloseTimeout(), -1), workflowType.getDefaultExecutionStartToCloseTimeout(), "ExecutionStartToCloseTimeout"); final Integer taskStartToCloseTimeout = requireDefault( parsePeriod(request.getTaskStartToCloseTimeout(), -1), workflowType.getDefaultTaskStartToCloseTimeout(), "TaskStartToCloseTimeout"); final String taskStartToCloseTimeoutStr = taskStartToCloseTimeout < 0 ? "NONE" : String.valueOf(taskStartToCloseTimeout); final WorkflowExecution workflowExecution = WorkflowExecution.create(userFullName, UUID.randomUUID().toString(), domain, workflowType, request.getWorkflowId(), childPolicy, taskList, executionStartToCloseTimeout, taskStartToCloseTimeout < 0 ? null : taskStartToCloseTimeout, request.getTagList(), Lists.newArrayList( new WorkflowExecutionStartedEventAttributes().withChildPolicy(childPolicy) .withExecutionStartToCloseTimeout( String.valueOf(executionStartToCloseTimeout)) .withInput(request.getInput()).withParentInitiatedEventId(0L) .withTaskList(new TaskList().withName(taskList)) .withTagList(request.getTagList()) .withTaskStartToCloseTimeout(taskStartToCloseTimeoutStr) .withWorkflowType(request.getWorkflowType()), new DecisionTaskScheduledEventAttributes() .withStartToCloseTimeout(taskStartToCloseTimeoutStr) .withTaskList(request.getTaskList()))); return workflowExecutions.save(workflowExecution); } catch (Exception ex) { throw new RuntimeException(ex); } } }, WorkflowExecution.class, request.getWorkflowId()); notifyTaskList(accountFullName, workflowExecution.getDomainName(), "decision", workflowExecution.getTaskList()); final Run run = new Run(); run.setRunId(workflowExecution.getDisplayName()); return request.reply(run); }
From source file:com.google.devtools.build.lib.rules.android.AndroidBinary.java
private static Artifact getStubDex(RuleContext ruleContext, JavaSemantics javaSemantics, boolean split) throws InterruptedException { String attribute = split ? "$incremental_split_stub_application" : "$incremental_stub_application"; TransitiveInfoCollection dep = ruleContext.getPrerequisite(attribute, Mode.TARGET); if (dep == null) { ruleContext.attributeError(attribute, "Stub application cannot be found"); return null; }//from w ww . j a v a 2 s. c om JavaCompilationArgsProvider provider = dep.getProvider(JavaCompilationArgsProvider.class); if (provider == null) { ruleContext.attributeError(attribute, "'" + dep.getLabel() + "' should be a Java target"); return null; } JavaTargetAttributes attributes = new JavaTargetAttributes.Builder(javaSemantics) .addRuntimeClassPathEntries(provider.getJavaCompilationArgs().getRuntimeJars()).build(); Function<Artifact, Artifact> desugaredJars = Functions.identity(); if (AndroidCommon.getAndroidConfig(ruleContext).desugarJava8()) { desugaredJars = collectDesugaredJarsFromAttributes(ruleContext, ImmutableList.of(attribute)).build() .collapseToFunction(); } Artifact stubDeployJar = getDxArtifact(ruleContext, split ? "split_stub_deploy.jar" : "stub_deploy.jar"); new DeployArchiveBuilder(javaSemantics, ruleContext).setOutputJar(stubDeployJar).setAttributes(attributes) .setDerivedJarFunction(desugaredJars).build(); Artifact stubDex = getDxArtifact(ruleContext, split ? "split_stub_application.dex" : "stub_application.dex"); AndroidCommon.createDexAction(ruleContext, stubDeployJar, stubDex, ImmutableList.<String>of(), false, null); return stubDex; }
From source file:com.google.devtools.build.lib.rules.android.AndroidBinary.java
/** * Returns a {@link DexArchiveProvider} of all transitively generated dex archives as well as dex * archives for the Jars produced by the binary target itself. *//*from w ww . ja v a 2s . c o m*/ public static Function<Artifact, Artifact> collectDesugaredJars(RuleContext ruleContext, AndroidCommon common, AndroidSemantics semantics, JavaTargetAttributes attributes) { if (!AndroidCommon.getAndroidConfig(ruleContext).desugarJava8()) { return Functions.identity(); } AndroidRuntimeJarProvider.Builder result = collectDesugaredJarsFromAttributes(ruleContext, semantics.getAttributesWithJavaRuntimeDeps(ruleContext)); for (Artifact jar : common.getJarsProducedForRuntime()) { // Create dex archives next to all Jars produced by AndroidCommon for this rule. We need to // do this (instead of placing dex archives into the _dx subdirectory like DexArchiveAspect) // because for "legacy" ResourceApks, AndroidCommon produces Jars per resource dependency that // can theoretically have duplicate basenames, so they go into special directories, and we // piggyback on that naming scheme here by placing dex archives into the same directories. PathFragment jarPath = jar.getRootRelativePath(); Artifact desugared = DexArchiveAspect.desugar(ruleContext, jar, attributes.getBootClassPath(), attributes.getCompileTimeClassPath(), ruleContext.getDerivedArtifact( jarPath.replaceName(jarPath.getBaseName() + "_desugared.jar"), jar.getRoot())); result.addDesugaredJar(jar, desugared); } return result.build().collapseToFunction(); }