List of usage examples for com.google.common.base Functions constant
public static <E> Function<Object, E> constant(@Nullable E value)
From source file:brooklyn.entity.zookeeper.AbstractZooKeeperImpl.java
@Override protected void connectSensors() { connectServiceUpIsRunning();//from w w w .j a va 2 s. co m if (((JavaSoftwareProcessDriver) getDriver()).isJmxEnabled()) { jmxFeed = JmxFeed.builder().entity(this).period(500, TimeUnit.MILLISECONDS) .pollAttribute(new JmxAttributePollConfig<Long>(OUTSTANDING_REQUESTS) .objectName(ZOOKEEPER_MBEAN).attributeName("OutstandingRequests") .onFailureOrException(Functions.constant(-1l))) .pollAttribute(new JmxAttributePollConfig<Long>(PACKETS_RECEIVED).objectName(ZOOKEEPER_MBEAN) .attributeName("PacketsReceived").onFailureOrException(Functions.constant(-1l))) .pollAttribute(new JmxAttributePollConfig<Long>(PACKETS_SENT).objectName(ZOOKEEPER_MBEAN) .attributeName("PacketsSent").onFailureOrException(Functions.constant(-1l))) .build(); } }
From source file:com.synflow.core.transformations.AbstractExpressionTransformer.java
private void visitExprList(EList<Expression> indexes) { visitExprList(Functions.constant(target), indexes); }
From source file:org.apache.brooklyn.entity.nosql.redis.RedisStoreImpl.java
@Override protected void connectSensors() { super.connectSensors(); connectServiceUpIsRunning();// w w w .j a v a 2 s. co m // Find an SshMachineLocation for the UPTIME feed Optional<Location> location = Iterables.tryFind(getLocations(), Predicates.instanceOf(SshMachineLocation.class)); if (!location.isPresent()) throw new IllegalStateException("Could not find SshMachineLocation in list of locations"); SshMachineLocation machine = (SshMachineLocation) location.get(); String statsCommand = getDriver().getRunDir() + "/bin/redis-cli -p " + getRedisPort() + " info stats"; boolean retrieveUsageMetrics = getConfig(RETRIEVE_USAGE_METRICS); sshFeed = SshFeed.builder().entity(this).machine(machine).period(5, TimeUnit.SECONDS) .poll(new SshPollConfig<Integer>(UPTIME) .command(getDriver().getRunDir() + "/bin/redis-cli -p " + getRedisPort() + " info server") .onFailureOrException(Functions.constant(-1)).onSuccess(infoFunction("uptime_in_seconds")) .enabled(retrieveUsageMetrics)) .poll(new SshPollConfig<Integer>(TOTAL_CONNECTIONS_RECEIVED).command(statsCommand) .onFailureOrException(Functions.constant(-1)) .onSuccess(infoFunction("total_connections_received")).enabled(retrieveUsageMetrics)) .poll(new SshPollConfig<Integer>(TOTAL_COMMANDS_PROCESSED).command(statsCommand) .onFailureOrException(Functions.constant(-1)) .onSuccess(infoFunction("total_commands_processed")).enabled(retrieveUsageMetrics)) .poll(new SshPollConfig<Integer>(EXPIRED_KEYS).command(statsCommand) .onFailureOrException(Functions.constant(-1)).onSuccess(infoFunction("expired_keys")) .enabled(retrieveUsageMetrics)) .poll(new SshPollConfig<Integer>(EVICTED_KEYS).command(statsCommand) .onFailureOrException(Functions.constant(-1)).onSuccess(infoFunction("evicted_keys")) .enabled(retrieveUsageMetrics)) .poll(new SshPollConfig<Integer>(KEYSPACE_HITS).command(statsCommand) .onFailureOrException(Functions.constant(-1)).onSuccess(infoFunction("keyspace_hits")) .enabled(retrieveUsageMetrics)) .poll(new SshPollConfig<Integer>(KEYSPACE_MISSES).command(statsCommand) .onFailureOrException(Functions.constant(-1)).onSuccess(infoFunction("keyspace_misses")) .enabled(retrieveUsageMetrics)) .build(); }
From source file:org.apache.brooklyn.core.sensor.function.FunctionSensor.java
@Override public void apply(final EntityLocal entity) { super.apply(entity); if (LOG.isDebugEnabled()) { LOG.debug("Adding HTTP JSON sensor {} to {}", name, entity); }// ww w . jav a 2 s . c o m final ConfigBag allConfig = ConfigBag.newInstanceCopying(this.params).putAll(params); final Callable<?> function = EntityInitializers.resolve(allConfig, FUNCTION); final Boolean suppressDuplicates = EntityInitializers.resolve(allConfig, SUPPRESS_DUPLICATES); final Duration logWarningGraceTimeOnStartup = EntityInitializers.resolve(allConfig, LOG_WARNING_GRACE_TIME_ON_STARTUP); final Duration logWarningGraceTime = EntityInitializers.resolve(allConfig, LOG_WARNING_GRACE_TIME); FunctionPollConfig<?, T> pollConfig = new FunctionPollConfig<Object, T>(sensor).callable(function) .onFailureOrException(Functions.constant((T) null)) .suppressDuplicates(Boolean.TRUE.equals(suppressDuplicates)) .logWarningGraceTimeOnStartup(logWarningGraceTimeOnStartup).logWarningGraceTime(logWarningGraceTime) .period(period); FunctionFeed feed = FunctionFeed.builder().entity(entity).poll(pollConfig).build(); entity.addFeed(feed); }
From source file:brooklyn.entity.monitoring.zabbix.ZabbixServerImpl.java
@Override public void onManagementStarted() { final byte[] jsonData = ZabbixFeed.JSON_USER_LOGIN .replace("{{username}}", getConfig(ZABBIX_SERVER_USERNAME)) .replace("{{password}}", getConfig(ZABBIX_SERVER_PASSWORD)).getBytes(); login = HttpFeed.builder().entity(this).baseUri(getConfig(ZABBIX_SERVER_API_URL)) .headers(ImmutableMap.of("Content-Type", "application/json")) .poll(new HttpPollConfig<String>(ZABBIX_TOKEN).method("POST").body(jsonData) .onFailure(Functions.constant("")) .onSuccess(HttpValueFunctions.jsonContents("result", String.class))) .build();/*from ww w . j av a2 s . co m*/ policy = addPolicy(PolicySpec.create(AgentTrackingPolicy.class).displayName("Zabbix Agent Tracker") .configure("group", monitoredEntities)); for (Entity each : monitoredEntities.getMembers()) { added(each); } setAttribute(Startable.SERVICE_UP, true); }
From source file:brooklyn.entity.machine.MachineEntityImpl.java
@Override protected void connectSensors() { super.connectSensors(); // Sensors linux-specific if (!getMachine().getMachineDetails().getOsDetails().isLinux()) return;// ww w .ja v a 2 s .c om sensorFeed = SshFeed.builder().entity(this).period(Duration.THIRTY_SECONDS) .poll(new SshPollConfig<Duration>(UPTIME).command("cat /proc/uptime") .onFailureOrException(Functions.<Duration>constant(null)) .onSuccess(new Function<SshPollValue, Duration>() { @Override public Duration apply(SshPollValue input) { return Duration.seconds(Double.valueOf(Strings.getFirstWord(input.getStdout()))); } })) .poll(new SshPollConfig<Double>(LOAD_AVERAGE).command("uptime") .onFailureOrException(Functions.constant(-1d)) .onSuccess(new Function<SshPollValue, Double>() { @Override public Double apply(SshPollValue input) { String loadAverage = Strings.getFirstWordAfter(input.getStdout(), "load average:") .replace(",", ""); return Double.valueOf(loadAverage); } })) .poll(new SshPollConfig<Double>(CPU_USAGE).command("cat /proc/stat") .onFailureOrException(Functions.constant(-1d)) .onSuccess(new Function<SshPollValue, Double>() { @Override public Double apply(SshPollValue input) { List<String> cpuData = Splitter.on(" ").omitEmptyStrings() .splitToList(Strings.getFirstLine(input.getStdout())); Integer system = Integer.parseInt(cpuData.get(1)); Integer user = Integer.parseInt(cpuData.get(3)); Integer idle = Integer.parseInt(cpuData.get(4)); return (double) (system + user) / (double) (system + user + idle); } })) .poll(new SshPollConfig<Long>(USED_MEMORY).command("free | grep Mem:") .onFailureOrException(Functions.constant(-1L)) .onSuccess(new Function<SshPollValue, Long>() { @Override public Long apply(SshPollValue input) { List<String> memoryData = Splitter.on(" ").omitEmptyStrings() .splitToList(Strings.getFirstLine(input.getStdout())); return Long.parseLong(memoryData.get(2)); } })) .poll(new SshPollConfig<Long>(FREE_MEMORY).command("free | grep Mem:") .onFailureOrException(Functions.constant(-1L)) .onSuccess(new Function<SshPollValue, Long>() { @Override public Long apply(SshPollValue input) { List<String> memoryData = Splitter.on(" ").omitEmptyStrings() .splitToList(Strings.getFirstLine(input.getStdout())); return Long.parseLong(memoryData.get(3)); } })) .poll(new SshPollConfig<Long>(TOTAL_MEMORY).command("free | grep Mem:") .onFailureOrException(Functions.constant(-1L)) .onSuccess(new Function<SshPollValue, Long>() { @Override public Long apply(SshPollValue input) { List<String> memoryData = Splitter.on(" ").omitEmptyStrings() .splitToList(Strings.getFirstLine(input.getStdout())); return Long.parseLong(memoryData.get(1)); } })) .build(); }
From source file:brooklyn.entity.container.docker.registry.DockerRegistryImpl.java
@Override public void connectSensors() { super.connectSensors(); connectServiceUpIsRunning();/* www. j a v a 2s.c o m*/ HostAndPort hostAndPort = BrooklynAccessUtils.getBrooklynAccessibleAddress(this, sensors().get(DOCKER_REGISTRY_PORT)); sensors().set(Attributes.MAIN_URI, URI.create("https://" + hostAndPort + "/v2")); httpFeed = HttpFeed.builder().entity(this).period(Duration.seconds(3)) .baseUri(getAttribute(Attributes.MAIN_URI)) .poll(new HttpPollConfig<Boolean>(Attributes.SERVICE_UP).onSuccess(Functions.constant(true)) .onFailureOrException(Functions.constant(false))) .poll(new HttpPollConfig<List<String>>(DOCKER_REGISTRY_CATALOG).suburl("/_catalog") .onSuccess(Functionals.chain(HttpValueFunctions.jsonContents(), JsonFunctions.walk("repositories"), JsonFunctions.forEach(JsonFunctions.cast(String.class)))) .onFailureOrException(Functions.constant(Collections.<String>emptyList()))) .build(); }
From source file:org.apache.brooklyn.entity.monitoring.zabbix.ZabbixServerImpl.java
@Override public void onManagementStarted() { final byte[] jsonData = ZabbixFeed.JSON_USER_LOGIN .replace("{{username}}", getConfig(ZABBIX_SERVER_USERNAME)) .replace("{{password}}", getConfig(ZABBIX_SERVER_PASSWORD)).getBytes(); login = HttpFeed.builder().entity(this).baseUri(getConfig(ZABBIX_SERVER_API_URL)) .headers(ImmutableMap.of("Content-Type", "application/json")) .poll(new HttpPollConfig<String>(ZABBIX_TOKEN).method("POST").body(jsonData) .onFailure(Functions.constant("")) .onSuccess(HttpValueFunctions.jsonContents("result", String.class))) .build();/* ww w.jav a 2s. c o m*/ policy = policies().add(PolicySpec.create(AgentTrackingPolicy.class).displayName("Zabbix Agent Tracker") .configure("group", monitoredEntities)); for (Entity each : monitoredEntities.getMembers()) { added(each); } sensors().set(Startable.SERVICE_UP, true); }
From source file:com.appenginefan.toolkit.common.ServerEndpoint.java
public void close() { checkOpen(); store.mutate(key, Functions.constant((ConnectionState) null)); isModified = false; cachedProperties = null; }
From source file:org.apache.brooklyn.entity.nosql.couchdb.CouchDBNodeImpl.java
@Override protected void connectSensors() { super.connectSensors(); connectServiceUpIsRunning();/*from ww w . jav a 2 s . co m*/ boolean retrieveUsageMetrics = getConfig(RETRIEVE_USAGE_METRICS); httpFeed = HttpFeed.builder().entity(this).period(500, TimeUnit.MILLISECONDS) .baseUri( String.format("http://%s:%d/_stats", getAttribute(HOSTNAME), getHttpPort())) .poll(new HttpPollConfig<Integer>(REQUEST_COUNT) .onSuccess(HttpValueFunctions.jsonContents(new String[] { "httpd", "requests", "count" }, Integer.class)) .onFailureOrException( EntityFunctions.attribute(this, REQUEST_COUNT)) .enabled(retrieveUsageMetrics)) .poll(new HttpPollConfig<Integer>(ERROR_COUNT) .onSuccess(HttpValueFunctions .jsonContents(new String[] { "httpd_status_codes", "404", "count" }, Integer.class)) .onFailureOrException(Functions.constant(-1)).enabled(retrieveUsageMetrics)) .poll(new HttpPollConfig<Integer>(TOTAL_PROCESSING_TIME) .onSuccess( HttpValueFunctions.jsonContents(new String[] { "couchdb", "request_time", "count" }, Integer.class)) .onFailureOrException(Functions.constant(-1)).enabled(retrieveUsageMetrics)) .poll(new HttpPollConfig<Integer>(MAX_PROCESSING_TIME) .onSuccess( Functionals.chain( HttpValueFunctions.jsonContents( new String[] { "couchdb", "request_time", "max" }, Double.class), TypeCoercions.function(Integer.class))) .onFailureOrException(Functions.constant(-1)).enabled(retrieveUsageMetrics)) .build(); WebAppServiceMethods.connectWebAppServerPolicies(this); }