Github user neykov commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/564#discussion_r103451547
  
    --- Diff: 
core/src/main/java/org/apache/brooklyn/feed/AbstractCommandFeed.java ---
    @@ -0,0 +1,260 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +package org.apache.brooklyn.feed;
    +
    +import static com.google.common.base.Preconditions.checkNotNull;
    +
    +import java.io.IOException;
    +import java.util.List;
    +import java.util.Map;
    +import java.util.Set;
    +import java.util.concurrent.Callable;
    +import java.util.concurrent.TimeUnit;
    +
    +import org.apache.brooklyn.api.entity.Entity;
    +import org.apache.brooklyn.api.entity.EntityLocal;
    +import org.apache.brooklyn.api.location.MachineLocation;
    +import org.apache.brooklyn.config.ConfigKey;
    +import org.apache.brooklyn.core.config.ConfigKeys;
    +import org.apache.brooklyn.core.feed.AbstractFeed;
    +import org.apache.brooklyn.core.feed.AttributePollHandler;
    +import org.apache.brooklyn.core.feed.DelegatingPollHandler;
    +import org.apache.brooklyn.core.feed.Poller;
    +import org.apache.brooklyn.core.location.Locations;
    +import org.apache.brooklyn.feed.ssh.SshPollValue;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +import org.apache.brooklyn.util.time.Duration;
    +
    +import com.google.common.base.Objects;
    +import com.google.common.base.Supplier;
    +import com.google.common.base.Suppliers;
    +import com.google.common.collect.HashMultimap;
    +import com.google.common.collect.SetMultimap;
    +import com.google.common.collect.Sets;
    +import com.google.common.reflect.TypeToken;
    +
    +/**
    + * Provides a feed of attribute values, by polling over ssh.
    + * 
    + * Example usage (e.g. in an entity that extends SoftwareProcessImpl):
    + * <pre>
    + * {@code
    + * private SshFeed feed;
    + * 
    + * //@Override
    + * protected void connectSensors() {
    + *   super.connectSensors();
    + *   
    + *   feed = SshFeed.builder()
    + *       .entity(this)
    + *       .machine(mySshMachineLachine)
    + *       .poll(new CommandPollConfig<Boolean>(SERVICE_UP)
    + *           .command("rabbitmqctl -q status")
    + *           .onSuccess(new Function<SshPollValue, Boolean>() {
    + *               public Boolean apply(SshPollValue input) {
    + *                 return (input.getExitStatus() == 0);
    + *               }}))
    + *       .build();
    + * }
    + * 
    + * {@literal @}Override
    + * protected void disconnectSensors() {
    + *   super.disconnectSensors();
    + *   if (feed != null) feed.stop();
    + * }
    + * }
    + * </pre>
    + * 
    + * @author aled
    + */
    +public abstract class AbstractCommandFeed extends AbstractFeed {
    +
    +    public static final Logger log = 
LoggerFactory.getLogger(AbstractCommandFeed.class);
    +    
    +    @SuppressWarnings("serial")
    +    public static final ConfigKey<Supplier<MachineLocation>> MACHINE = 
ConfigKeys.newConfigKey(
    +            new TypeToken<Supplier<MachineLocation>>() {},
    +            "machine");
    +
    +    public static final ConfigKey<Boolean> EXEC_AS_COMMAND = 
ConfigKeys.newBooleanConfigKey("execAsCommand");
    +    
    +    @SuppressWarnings("serial")
    +    public static final ConfigKey<SetMultimap<SshPollIdentifier, 
CommandPollConfig<?>>> POLLS = ConfigKeys.newConfigKey(
    +            new TypeToken<SetMultimap<SshPollIdentifier, 
CommandPollConfig<?>>>() {},
    +            "polls");
    +    
    +    public static abstract class Builder<T extends AbstractCommandFeed, B 
extends Builder<T, B>> {
    +        private Entity entity;
    +        private boolean onlyIfServiceUp = false;
    +        private Supplier<MachineLocation> machine;
    +        private Duration period = Duration.of(500, TimeUnit.MILLISECONDS);
    +        private boolean execAsCommand = false;
    +        private String uniqueTag;
    +        private volatile boolean built;
    +        
    +        public B entity(Entity val) {
    +            this.entity = val;
    +            return self();
    +        }
    +        public B onlyIfServiceUp() { return onlyIfServiceUp(true); }
    +        public B onlyIfServiceUp(boolean onlyIfServiceUp) {
    +            this.onlyIfServiceUp = onlyIfServiceUp; 
    +            return self();
    +        }
    +        /** optional, to force a machine; otherwise it is inferred from 
the entity */
    +        public B machine(MachineLocation val) { return 
machine(Suppliers.ofInstance(val)); }
    +        /** optional, to force a machine; otherwise it is inferred from 
the entity */
    +        public B machine(Supplier<MachineLocation> val) {
    +            this.machine = val;
    +            return self();
    +        }
    +        public B period(Duration period) {
    +            this.period = period;
    +            return self();
    +        }
    +        public B period(long millis) {
    +            return period(Duration.of(millis, TimeUnit.MILLISECONDS));
    +        }
    +        public B period(long val, TimeUnit units) {
    +            return period(Duration.of(val, units));
    +        }
    +        public abstract B poll(CommandPollConfig<?> config);
    +        public abstract List<CommandPollConfig<?>> getPolls();
    +
    +        public B execAsCommand() {
    +            execAsCommand = true;
    +            return self();
    +        }
    +        public B execAsScript() {
    +            execAsCommand = false;
    +            return self();
    +        }
    +        public B uniqueTag(String uniqueTag) {
    +            this.uniqueTag = uniqueTag;
    +            return self();
    +        }
    +        
    +        protected abstract B self();
    +        
    +        protected abstract T instantiateFeed();
    +
    +        public T build() {
    +            built = true;
    +            T result = instantiateFeed();
    +            result.setEntity(checkNotNull((EntityLocal)entity, "entity"));
    +            result.start();
    +            return result;
    +        }
    +
    +        @Override
    +        protected void finalize() {
    +            if (!built) log.warn("SshFeed.Builder created, but build() 
never called");
    +        }
    +    }
    +    
    +    private static class SshPollIdentifier {
    --- End diff --
    
    Have you kept the name on purpose? It's private so can rename it without 
deprecation cycle.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to