
org.apacheextras.camel.component.rcode.RCodeConfiguration Maven / Gradle / Ivy
/**************************************************************************************
http://code.google.com/a/apache-extras.org/p/camel-extra
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
http://www.gnu.org/licenses/gpl-2.0-standalone.html
***************************************************************************************/
package org.apacheextras.camel.component.rcode;
import java.net.URI;
import org.apache.camel.RuntimeCamelException;
/**
* The RCodeConfiguration object contains all elements that can be configured
* on an endpoint or component.
*/
public final class RCodeConfiguration implements Cloneable {
/**
* The default rServe host set to
* 127.0.0.1
.
*/
public static final String DEFAULT_RSERVE_HOST = "127.0.0.1";
/**
* The default rServe port set to
* 6311
.
*/
public static final int DEFAULT_RSERVE_PORT = 6311;
/**
* Default buffer size set to
* 2MB
in bytes.
*/
public static final long DEFAULT_BUFFER_SIZE = 1024 * 1024 * 2;
/**
* Lowest buffer size is 32KB.
*/
public static final long LOWEST_BUFFER_SIZE = 32768;
/**
* Largest buffer size is 1GB.
*/
public static final long LARGEST_BUFFER_SIZE = 1073741824;
// Initialize the default host
private String host = DEFAULT_RSERVE_HOST;
// Initialize the default port
private int port = DEFAULT_RSERVE_PORT;
// Field for user
private String user;
// Field for password
private String password;
// Field defining the buffer size
private long bufferSize = DEFAULT_BUFFER_SIZE;
/**
* Creates a new RCodeConfiguration object with default values.
* The default values are:
*
* - host = 127.0.0.1
* - port = 6311
* - bufferSize = 2MB
*
*/
public RCodeConfiguration() {
}
/**
* Creates ab RCodeConfiguration based on an URI parameter.
*
* @param uri URI
*/
public RCodeConfiguration(URI uri) {
// Configure the host based on the endpoint URI
final String uriHost = uri.getHost();
if (null != uriHost && !uriHost.trim().isEmpty()) {
setHost(uriHost);
}
// Configure port based on endpoint URI
final int uriPort = uri.getPort();
if (-1 != uriPort) {
setPort(uriPort);
}
}
/**
* Copies the existing RCodeConfiguration into a new object.
* The new object is an actual clone of the original.
*
* @return RCodeConfiguration
*/
public RCodeConfiguration copy() {
try {
return (RCodeConfiguration) clone();
} catch (CloneNotSupportedException ex) {
throw new RuntimeCamelException(ex);
}
}
/**
* @return the host
*/
public String getHost() {
return host;
}
/**
* @param host the host to set
*/
public void setHost(String host) {
this.host = host;
}
/**
* @return the port
*/
public int getPort() {
return port;
}
/**
* @param port the port to set
*/
public void setPort(int port) {
this.port = port;
}
/**
* @return the user
*/
public String getUser() {
return user;
}
/**
* @param user the user to set
*/
public void setUser(String user) {
this.user = user;
}
/**
* @return the password
*/
public String getPassword() {
return password;
}
/**
* @param password the password to set
*/
public void setPassword(String password) {
this.password = password;
}
/**
* @return the bufferSize
*/
public long getBufferSize() {
return bufferSize;
}
/**
* @param bufferSize the bufferSize to set
*/
public void setBufferSize(long bufferSize) {
// Set the buffer size to it's limits in bytes
// Note: The boundaries that can be processed are 32K and 1GB
if (bufferSize < LOWEST_BUFFER_SIZE) {
this.bufferSize = LOWEST_BUFFER_SIZE;
} else if (bufferSize > LARGEST_BUFFER_SIZE) {
this.bufferSize = LARGEST_BUFFER_SIZE;
}
this.bufferSize = bufferSize;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy