List of usage examples for com.google.common.base Functions forPredicate
public static <T> Function<T, Boolean> forPredicate(Predicate<T> predicate)
From source file:org.hobsoft.entangle.guava.GuavaConverters.java
public static <S> Converter<S, Boolean> forPredicate(Predicate<? super S> predicate) { return forFunction(Functions.forPredicate(predicate)); }
From source file:brooklyn.event.feed.http.HttpValueFunctions.java
public static Function<HttpToolResponse, Boolean> responseCodeEquals(final int expected) { return Functionals.chain(HttpValueFunctions.responseCode(), Functions.forPredicate(Predicates.equalTo(expected))); }
From source file:brooklyn.event.feed.ssh.SshValueFunctions.java
public static Function<SshPollValue, Boolean> exitStatusEquals(final int expected) { return chain(SshValueFunctions.exitStatus(), Functions.forPredicate(Predicates.equalTo(expected))); }
From source file:brooklyn.event.feed.http.HttpValueFunctions.java
public static Function<HttpToolResponse, Boolean> responseCodeEquals(final int... expected) { List<Integer> expectedList = Lists.newArrayList(); for (int e : expected) { expectedList.add((Integer) e); }/*from w w w . ja va2 s. c o m*/ return Functionals.chain(HttpValueFunctions.responseCode(), Functions.forPredicate(Predicates.in(expectedList))); }
From source file:com.vilt.minium.impl.Waits.java
public static void waitForPredicate(CoreWebElements<?> webElements, Duration timeout, Duration interval, Predicate<? super CoreWebElements<?>> predicate) { Configuration configuration = ((WebElementsDriverProvider<?>) webElements).configure(); if (timeout == null) { timeout = configuration.defaultTimeout(); }/*from w ww.ja va 2 s . c om*/ if (interval == null) { interval = configuration.defaultInterval(); } WebElementsWait wait = getWait(webElements, timeout, interval); Function<? super CoreWebElements<?>, Boolean> function = Functions.forPredicate(predicate); wait.until(function); }
From source file:com.eucalyptus.util.CollectionUtils.java
/** * Apply the given predicate for each item in the iterable. * * <p>This method is an anti-pattern as the predicate is really an effect (it * can only be useful for its side effect)</p> * * @param iterable The iterable/*from w w w . j a va 2 s .co m*/ * @param predicate The predicate to apply * @param <T> The iterable type */ public static <T> void each(final Iterable<T> iterable, final Predicate<? super T> predicate) { each(iterable, Functions.forPredicate(predicate)); }
From source file:brooklyn.entity.webapp.jetty.Jetty6ServerImpl.java
@Override public void connectSensors() { super.connectSensors(); if (getDriver().isJmxEnabled()) { String serverMbeanName = "org.mortbay.jetty:type=server,id=0"; String statsMbeanName = "org.mortbay.jetty.handler:type=atomicstatisticshandler,id=0"; jmxFeedJetty = JmxFeed.builder().entity(this).period(500, TimeUnit.MILLISECONDS) .pollAttribute(new JmxAttributePollConfig<Boolean>(SERVICE_UP).objectName(serverMbeanName) .attributeName("running") .onSuccess(Functions.forPredicate(Predicates.<Object>equalTo(true))) .setOnFailureOrException(false)) .pollAttribute(new JmxAttributePollConfig<Integer>(REQUEST_COUNT).objectName(statsMbeanName) .attributeName("requests")) .pollAttribute(new JmxAttributePollConfig<Integer>(RESPONSES_4XX_COUNT) .objectName(statsMbeanName).attributeName("responses4xx")) .pollAttribute(new JmxAttributePollConfig<Integer>(RESPONSES_5XX_COUNT) .objectName(statsMbeanName).attributeName("responses5xx")) .pollAttribute(new JmxAttributePollConfig<Integer>(TOTAL_PROCESSING_TIME) .objectName(statsMbeanName).attributeName("requestTimeTotal")) .pollAttribute(new JmxAttributePollConfig<Integer>(MAX_PROCESSING_TIME) .objectName(statsMbeanName).attributeName("requestTimeMax")) // NB: requestsActive may be useful .build();//from ww w .j a va2 s. com addEnricher(Enrichers.builder().combining(RESPONSES_4XX_COUNT, RESPONSES_5XX_COUNT) .publishing(ERROR_COUNT).computingSum().build()); jmxFeedMx = JavaAppUtils.connectMXBeanSensors(this); } else { // if not using JMX log.warn("Jetty running without JMX monitoring; limited visibility of service available"); // TODO we could do simple things, like check that web server is accepting connections } }
From source file:org.apache.brooklyn.entity.webapp.jetty.Jetty6ServerImpl.java
@Override public void connectSensors() { super.connectSensors(); if (getDriver().isJmxEnabled()) { String serverMbeanName = "org.mortbay.jetty:type=server,id=0"; String statsMbeanName = "org.mortbay.jetty.handler:type=atomicstatisticshandler,id=0"; jmxFeedJetty = JmxFeed.builder().entity(this).period(500, TimeUnit.MILLISECONDS) .pollAttribute(new JmxAttributePollConfig<Boolean>(SERVICE_UP).objectName(serverMbeanName) .attributeName("running") .onSuccess(Functions.forPredicate(Predicates.<Object>equalTo(true))) .setOnFailureOrException(false)) .pollAttribute(new JmxAttributePollConfig<Integer>(REQUEST_COUNT).objectName(statsMbeanName) .attributeName("requests") .onFailureOrException(EntityFunctions.attribute(this, REQUEST_COUNT))) .pollAttribute(new JmxAttributePollConfig<Integer>(RESPONSES_4XX_COUNT) .objectName(statsMbeanName).attributeName("responses4xx")) .pollAttribute(new JmxAttributePollConfig<Integer>(RESPONSES_5XX_COUNT) .objectName(statsMbeanName).attributeName("responses5xx")) .pollAttribute(new JmxAttributePollConfig<Integer>(TOTAL_PROCESSING_TIME) .objectName(statsMbeanName).attributeName("requestTimeTotal")) .pollAttribute(new JmxAttributePollConfig<Integer>(MAX_PROCESSING_TIME) .objectName(statsMbeanName).attributeName("requestTimeMax")) // NB: requestsActive may be useful .build();//from w w w .jav a2s. c o m enrichers().add(Enrichers.builder().combining(RESPONSES_4XX_COUNT, RESPONSES_5XX_COUNT) .publishing(ERROR_COUNT).computingSum().build()); jmxFeedMx = JavaAppUtils.connectMXBeanSensors(this); } else { // if not using JMX log.warn("Jetty running without JMX monitoring; limited visibility of service available"); // TODO we could do simple things, like check that web server is accepting connections } }
From source file:com.vilt.minium.impl.Waits.java
/** * * @param webElements WebElement to test * @param timeout timeout duration/*from w ww .j a v a2s .c o m*/ * @param interval interval duration * @param predicate predicate to check * @return true if wait for predicate was successful, false if timeout occured */ public static boolean waitForPredicateOrTimeout(CoreWebElements<?> webElements, Duration timeout, Duration interval, Predicate<? super CoreWebElements<?>> predicate) { Configuration configuration = ((WebElementsDriverProvider<?>) webElements).configure(); if (timeout == null) { timeout = configuration.defaultTimeout(); } if (interval == null) { interval = configuration.defaultInterval(); } WebElementsWait wait = getWait(webElements, timeout, interval); Function<? super CoreWebElements<?>, Boolean> function = Functions.forPredicate(predicate); try { wait.until(function); return true; } catch (TimeoutException e) { return false; } }
From source file:org.apache.brooklyn.entity.webapp.tomcat.TomcatServerImpl.java
@Override public void connectSensors() { super.connectSensors(); if (getDriver().isJmxEnabled()) { String requestProcessorMbeanName = "Catalina:type=GlobalRequestProcessor,name=\"http-*\""; Integer port = isHttpsEnabled() ? getAttribute(HTTPS_PORT) : getAttribute(HTTP_PORT); String connectorMbeanName = format("Catalina:type=Connector,port=%s", port); boolean retrieveUsageMetrics = getConfig(RETRIEVE_USAGE_METRICS); jmxWebFeed = JmxFeed.builder().entity(this).period(3000, TimeUnit.MILLISECONDS) .pollAttribute(new JmxAttributePollConfig<Boolean>(SERVICE_PROCESS_IS_RUNNING) // TODO Want to use something different from SERVICE_PROCESS_IS_RUNNING, // to indicate this is jmx MBean's reported state (or failure to connect) .objectName(connectorMbeanName).attributeName("stateName") .onSuccess(Functions.forPredicate(Predicates.<Object>equalTo("STARTED"))) .setOnFailureOrException(false).suppressDuplicates(true)) .pollAttribute(new JmxAttributePollConfig<String>(CONNECTOR_STATUS) .objectName(connectorMbeanName).attributeName("stateName").suppressDuplicates(true)) .pollAttribute(/*from ww w .j ava 2 s .c om*/ new JmxAttributePollConfig<Integer>(ERROR_COUNT).objectName(requestProcessorMbeanName) .attributeName("errorCount").enabled(retrieveUsageMetrics)) .pollAttribute( new JmxAttributePollConfig<Integer>(REQUEST_COUNT).objectName(requestProcessorMbeanName) .attributeName("requestCount").enabled(retrieveUsageMetrics) .onFailureOrException(EntityFunctions.attribute(this, REQUEST_COUNT))) .pollAttribute(new JmxAttributePollConfig<Integer>(TOTAL_PROCESSING_TIME) .objectName(requestProcessorMbeanName).attributeName("processingTime") .enabled(retrieveUsageMetrics)) .build(); jmxAppFeed = JavaAppUtils.connectMXBeanSensors(this); } else { // if not using JMX LOG.warn("Tomcat running without JMX monitoring; limited visibility of service available"); connectServiceUpIsRunning(); } }