CAMEL-7999: More components include documentation
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/83f048d9 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/83f048d9 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/83f048d9 Branch: refs/heads/master Commit: 83f048d9ff00899b226fd7583dd33d6bcdc234a2 Parents: 6467b0f Author: Claus Ibsen <davscl...@apache.org> Authored: Fri Jan 2 11:00:26 2015 +0100 Committer: Claus Ibsen <davscl...@apache.org> Committed: Fri Jan 2 11:00:26 2015 +0100 ---------------------------------------------------------------------- .../camel/component/snmp/SnmpComponent.java | 9 ++- .../camel/component/snmp/SnmpEndpoint.java | 66 ++++++++++++++------ 2 files changed, 52 insertions(+), 23 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/83f048d9/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpComponent.java ---------------------------------------------------------------------- diff --git a/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpComponent.java b/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpComponent.java index 8579656..fbbe4aa 100644 --- a/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpComponent.java +++ b/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpComponent.java @@ -19,19 +19,22 @@ package org.apache.camel.component.snmp; import java.util.Map; import org.apache.camel.Endpoint; -import org.apache.camel.impl.DefaultComponent; +import org.apache.camel.impl.UriEndpointComponent; /** * Represents the component that manages {@link SnmpEndpoint}. It holds the list * of named direct endpoints. */ -public class SnmpComponent extends DefaultComponent { +public class SnmpComponent extends UriEndpointComponent { + + public SnmpComponent() { + super(SnmpEndpoint.class); + } @Override protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { SnmpEndpoint endpoint = new SnmpEndpoint(uri, this); setProperties(endpoint, parameters); - endpoint.initiate(); return endpoint; } } http://git-wip-us.apache.org/repos/asf/camel/blob/83f048d9/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpEndpoint.java b/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpEndpoint.java index 53e8ffe..2315156 100644 --- a/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpEndpoint.java +++ b/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpEndpoint.java @@ -25,12 +25,16 @@ import org.apache.camel.Processor; import org.apache.camel.Producer; import org.apache.camel.impl.DefaultExchange; import org.apache.camel.impl.DefaultPollingEndpoint; +import org.apache.camel.spi.UriEndpoint; +import org.apache.camel.spi.UriParam; +import org.apache.camel.spi.UriPath; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.snmp4j.CommandResponderEvent; import org.snmp4j.PDU; import org.snmp4j.mp.SnmpConstants; +@UriEndpoint(scheme = "snmp", label = "monitoring") public class SnmpEndpoint extends DefaultPollingEndpoint { public static final String DEFAULT_COMMUNITY = "public"; @@ -41,13 +45,26 @@ public class SnmpEndpoint extends DefaultPollingEndpoint { private static final Logger LOG = LoggerFactory.getLogger(SnmpEndpoint.class); private OIDList oids = new OIDList(); - private String address; + + private transient String address; + + @UriPath private String protocol = "udp"; + @UriPath + private String host; + @UriPath + private Integer port; + @UriParam(defaultValue = "" + DEFAULT_SNMP_RETRIES) private int retries = DEFAULT_SNMP_RETRIES; + @UriParam(defaultValue = "" + DEFAULT_SNMP_TIMEOUT) private int timeout = DEFAULT_SNMP_TIMEOUT; + @UriParam(defaultValue = "" + DEFAULT_SNMP_VERSION) private int snmpVersion = DEFAULT_SNMP_VERSION; + @UriParam(defaultValue = DEFAULT_COMMUNITY) private String snmpCommunity = DEFAULT_COMMUNITY; + @UriParam private SnmpActionType type; + @UriParam(defaultValue = "60") private int delay = 60; /** @@ -134,27 +151,11 @@ public class SnmpEndpoint extends DefaultPollingEndpoint { * creates and configures the endpoint * * @throws Exception if unable to setup connection + * @deprecated use {@link #start()} instead */ + @Deprecated public void initiate() throws Exception { - URI uri = URI.create(getEndpointUri()); - String host = uri.getHost(); - int port = uri.getPort(); - if (host == null || host.trim().length() < 1) { - host = "127.0.0.1"; - } - if (port == -1) { - if (getType() == SnmpActionType.POLL) { - port = 161; // default snmp poll port - } else { - port = 162; // default trap port - } - } - - - // set the address - String address = String.format("%s:%s/%d", getProtocol(), host, port); - LOG.debug("Using snmp address {}", address); - setAddress(address); + // noop } public int getDelay() { @@ -235,6 +236,31 @@ public class SnmpEndpoint extends DefaultPollingEndpoint { } @Override + protected void doStart() throws Exception { + super.doStart(); + + URI uri = URI.create(getEndpointUri()); + String host = uri.getHost(); + int port = uri.getPort(); + if (host == null || host.trim().length() < 1) { + host = "127.0.0.1"; + } + if (port == -1) { + if (getType() == SnmpActionType.POLL) { + port = 161; // default snmp poll port + } else { + port = 162; // default trap port + } + } + + + // set the address + String address = String.format("%s:%s/%d", getProtocol(), host, port); + LOG.debug("Using snmp address {}", address); + setAddress(address); + } + + @Override public String toString() { // only show address to avoid user and password details to be shown return "SnmpEndpoint[" + address + "]";