You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by is...@apache.org on 2013/07/05 12:32:55 UTC

[18/34] committing refactoered adc components and top level pom in components

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ca25b1f7/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/commands/SubscribeCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/commands/SubscribeCommand.java b/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/commands/SubscribeCommand.java
new file mode 100644
index 0000000..90908e9
--- /dev/null
+++ b/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/commands/SubscribeCommand.java
@@ -0,0 +1,208 @@
+/**
+ *  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.stratos.adc.mgt.cli.commands;
+
+import org.apache.stratos.adc.mgt.cli.Command;
+import org.apache.stratos.adc.mgt.cli.CommandLineService;
+import org.apache.stratos.adc.mgt.cli.StratosCommandContext;
+import org.apache.stratos.adc.mgt.cli.exception.CommandException;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.GnuParser;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.stratos.adc.mgt.cli.utils.CliConstants;
+
+public class SubscribeCommand implements Command<StratosCommandContext> {
+
+	private static final Logger logger = LoggerFactory.getLogger(ListCommand.class);
+
+	private final Options options;;
+
+	public SubscribeCommand() {
+		options = constructOptions();
+	}
+
+	/**
+	 * Construct Options.
+	 * 
+	 * @return Options expected from command-line.
+	 */
+	private Options constructOptions() {
+		final Options options = new Options();
+		Option policyOption = new Option(CliConstants.POLICY_OPTION, CliConstants.POLICY_LONG_OPTION, true,
+				"Auto-scaling policy.\nPlease use \"" + CliConstants.POLICIES_ACTION
+						+ "\" command to view the available policies.");
+		policyOption.setArgName("policy name");
+		options.addOption(policyOption);
+
+		Option connectOption = new Option(CliConstants.CONNECT_OPTION, CliConstants.CONNECT_LONG_OPTION, true,
+				"Data cartridge type");
+		connectOption.setArgName("data cartridge type");
+		options.addOption(connectOption);
+
+		Option aliasOption = new Option(CliConstants.DATA_ALIAS_OPTION, CliConstants.DATA_ALIAS_LONG_OPTION, true,
+				"Data cartridge alias");
+		aliasOption.setArgName("alias");
+		options.addOption(aliasOption);
+
+		Option urlOption = new Option(CliConstants.REPO_URL_OPTION, CliConstants.REPO_URL_LONG_OPTION, true,
+				"GIT repository URL");
+		urlOption.setArgName("url");
+		options.addOption(urlOption);
+
+		options.addOption(CliConstants.PRIVATE_REPO_OPTION, CliConstants.PRIVATE_REPO_LONG_OPTION, false,
+				"Private repository");
+
+		Option usernameOption = new Option(CliConstants.USERNAME_OPTION, CliConstants.USERNAME_LONG_OPTION, true,
+				"GIT repository username");
+		usernameOption.setArgName("username");
+		options.addOption(usernameOption);
+
+		Option passwordOption = new Option(CliConstants.PASSWORD_OPTION, CliConstants.PASSWORD_LONG_OPTION, true,
+				"GIT repository password");
+		passwordOption.setArgName("password");
+		passwordOption.setOptionalArg(true);
+		options.addOption(passwordOption);
+		return options;
+	}
+
+	@Override
+	public String getName() {
+		return CliConstants.SUBSCRIBE_ACTION;
+	}
+
+	@Override
+	public String getDescription() {
+		return "Subscribe to a cartridge";
+	}
+
+	@Override
+	public String getArgumentSyntax() {
+		return "[Cartridge type] [Cartridge alias]";
+	}
+
+	@Override
+	public int execute(StratosCommandContext context, String[] args) throws CommandException {
+		if (logger.isDebugEnabled()) {
+			logger.debug("Executing {} command...", getName());
+		}
+		if (args != null && args.length > 0) {
+			String[] remainingArgs = null;
+			String type = null;
+			String alias = null;
+			String policy = null;
+			String repoURL = null, dataCartridgeType = null, dataCartridgeAlias = null, username = "", password = "";
+			boolean privateRepo = false;
+			final CommandLineParser parser = new GnuParser();
+			CommandLine commandLine;
+			try {
+				commandLine = parser.parse(options, args);
+				remainingArgs = commandLine.getArgs();
+				if (remainingArgs != null && remainingArgs.length == 2) {
+					// Get type
+					type = remainingArgs[0];
+					alias = remainingArgs[1];
+				} else {
+					context.getStratosApplication().printUsage(getName());
+					return CliConstants.BAD_ARGS_CODE;
+				}
+
+				if (logger.isDebugEnabled()) {
+					logger.debug("Subscribing to {} cartridge with alias {}", type, alias);
+				}
+
+				if (commandLine.hasOption(CliConstants.POLICY_OPTION)) {
+					if (logger.isTraceEnabled()) {
+						logger.trace("Policy option is passed");
+					}
+					policy = commandLine.getOptionValue(CliConstants.POLICY_OPTION);
+				}
+				if (commandLine.hasOption(CliConstants.REPO_URL_OPTION)) {
+					if (logger.isTraceEnabled()) {
+						logger.trace("RepoURL option is passed");
+					}
+					repoURL = commandLine.getOptionValue(CliConstants.REPO_URL_OPTION);
+				}
+				if (commandLine.hasOption(CliConstants.PRIVATE_REPO_OPTION)) {
+					if (logger.isTraceEnabled()) {
+						logger.trace("privateRepo option is passed");
+					}
+					privateRepo = true;
+				}
+				if (commandLine.hasOption(CliConstants.USERNAME_OPTION)) {
+					if (logger.isTraceEnabled()) {
+						logger.trace("Username option is passed");
+					}
+					username = commandLine.getOptionValue(CliConstants.USERNAME_OPTION);
+				}
+				if (commandLine.hasOption(CliConstants.PASSWORD_OPTION)) {
+					if (logger.isTraceEnabled()) {
+						logger.trace("Password option is passed");
+					}
+					password = commandLine.getOptionValue(CliConstants.PASSWORD_OPTION);
+				}
+				if (commandLine.hasOption(CliConstants.CONNECT_OPTION)) {
+					if (logger.isTraceEnabled()) {
+						logger.trace("Connect option is passed");
+					}
+					dataCartridgeType = commandLine.getOptionValue(CliConstants.CONNECT_OPTION);
+				}
+				if (commandLine.hasOption(CliConstants.DATA_ALIAS_OPTION)) {
+					if (logger.isTraceEnabled()) {
+						logger.trace("Data alias option is passed");
+					}
+					dataCartridgeAlias = commandLine.getOptionValue(CliConstants.DATA_ALIAS_OPTION);
+				}
+				
+				if (StringUtils.isNotBlank(username) && StringUtils.isBlank(password)) {
+					password = context.getApplication().getInput("GIT Repository Password", '*');
+				}
+
+				if (StringUtils.isNotBlank(dataCartridgeType) && !StringUtils.isNotBlank(dataCartridgeAlias)) {
+					System.out.println("Data cartridge alias is required.");
+					context.getStratosApplication().printUsage(getName());
+					return CliConstants.BAD_ARGS_CODE;
+				}
+				CommandLineService.getInstance().subscribe(type, alias, policy, repoURL, privateRepo, username,
+						password, dataCartridgeType, dataCartridgeAlias);
+				return CliConstants.SUCCESSFUL_CODE;
+			} catch (ParseException e) {
+				if (logger.isErrorEnabled()) {
+					logger.error("Error parsing arguments", e);
+				}
+				System.out.println(e.getMessage());
+				return CliConstants.BAD_ARGS_CODE;
+			}
+		} else {
+			context.getStratosApplication().printUsage(getName());
+			return CliConstants.BAD_ARGS_CODE;
+		}
+	}
+
+	@Override
+	public Options getOptions() {
+		return options;
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ca25b1f7/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/commands/SyncCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/commands/SyncCommand.java b/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/commands/SyncCommand.java
new file mode 100644
index 0000000..6e21a4d
--- /dev/null
+++ b/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/commands/SyncCommand.java
@@ -0,0 +1,76 @@
+/**
+ *  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.stratos.adc.mgt.cli.commands;
+
+import org.apache.stratos.adc.mgt.cli.exception.CommandException;
+import org.apache.commons.cli.Options;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.stratos.adc.mgt.cli.Command;
+import org.apache.stratos.adc.mgt.cli.CommandLineService;
+import org.apache.stratos.adc.mgt.cli.StratosCommandContext;
+import org.apache.stratos.adc.mgt.cli.utils.CliConstants;
+
+public class SyncCommand implements Command<StratosCommandContext> {
+
+	private static final Logger logger = LoggerFactory.getLogger(SyncCommand.class);
+
+	public SyncCommand() {
+	}
+
+	@Override
+	public String getName() {
+		return CliConstants.SYNC_ACTION;
+	}
+
+	@Override
+	public String getDescription() {
+		return "Synchronize GIT repository for the subscribed cartridge";
+	}
+
+	@Override
+	public String getArgumentSyntax() {
+		return "[Cartridge alias]";
+	}
+
+	@Override
+	public int execute(StratosCommandContext context, String[] args) throws CommandException {
+		if (logger.isDebugEnabled()) {
+			logger.debug("Executing {} command...", getName());
+		}
+		if (args != null && args.length == 1) {
+			String alias = args[0];
+			if (logger.isDebugEnabled()) {
+				logger.debug("Synchronizing repository for alias {}", alias);
+			}
+
+			CommandLineService.getInstance().sync(alias);
+			return CliConstants.SUCCESSFUL_CODE;
+		} else {
+			context.getStratosApplication().printUsage(getName());
+			return CliConstants.BAD_ARGS_CODE;
+		}
+	}
+
+	@Override
+	public Options getOptions() {
+		return null;
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ca25b1f7/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/commands/UnsubscribeCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/commands/UnsubscribeCommand.java b/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/commands/UnsubscribeCommand.java
new file mode 100644
index 0000000..9b178e4
--- /dev/null
+++ b/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/commands/UnsubscribeCommand.java
@@ -0,0 +1,130 @@
+/**
+ *  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.stratos.adc.mgt.cli.commands;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.GnuParser;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.stratos.adc.mgt.cli.Command;
+import org.apache.stratos.adc.mgt.cli.CommandLineService;
+import org.apache.stratos.adc.mgt.cli.StratosCommandContext;
+import org.apache.stratos.adc.mgt.cli.exception.CommandException;
+import org.apache.stratos.adc.mgt.cli.utils.CliConstants;
+
+public class UnsubscribeCommand implements Command<StratosCommandContext> {
+
+	private static final Logger logger = LoggerFactory.getLogger(UnsubscribeCommand.class);
+	
+	private final Options options;;
+
+	public UnsubscribeCommand() {
+		options = constructOptions();
+	}
+	
+	/**
+	 * Construct Options.
+	 * 
+	 * @return Options expected from command-line.
+	 */
+	private Options constructOptions() {
+		final Options options = new Options();
+		Option forceOption = new Option(CliConstants.FORCE_OPTION, CliConstants.FORCE_LONG_OPTION, false,
+				"Never prompt for confirmation");
+		options.addOption(forceOption);
+		return options;
+	}
+
+	@Override
+	public String getName() {
+		return CliConstants.UNSUBSCRIBE_ACTION;
+	}
+
+	@Override
+	public String getDescription() {
+		return "Unsubscribe from a subscribed cartridge";
+	}
+
+	@Override
+	public String getArgumentSyntax() {
+		return "[Cartridge alias]";
+	}
+
+	@Override
+	public int execute(StratosCommandContext context, String[] args) throws CommandException {
+		if (logger.isDebugEnabled()) {
+			logger.debug("Executing {} command...", getName());
+		}
+		if (args != null && args.length > 0) {
+			String[] remainingArgs = null;
+			String alias = null;
+			boolean force = false;
+			final CommandLineParser parser = new GnuParser();
+			CommandLine commandLine;
+			try {
+				commandLine = parser.parse(options, args);
+				remainingArgs = commandLine.getArgs();
+				if (remainingArgs != null && remainingArgs.length == 1) {
+					// Get alias
+					alias = remainingArgs[0];
+				} else {
+					if (logger.isDebugEnabled()) {
+						logger.debug("Unsubscribe: not enough arguments");
+					}
+					context.getStratosApplication().printUsage(getName());
+					return CliConstants.BAD_ARGS_CODE;
+				}
+
+				if (commandLine.hasOption(CliConstants.FORCE_OPTION)) {
+					if (logger.isTraceEnabled()) {
+						logger.trace("Force option is passed");
+					}
+					force = true;
+				}
+				if (logger.isDebugEnabled()) {
+					logger.debug("Unsubscribing {}, Force Option: {}", alias, force);
+				}
+				if (force || context.getApplication().getConfirmation("Are you sure you want to unsubscribe?")) {
+					System.out.format("Unsubscribing the cartridge %s%n", alias);
+					CommandLineService.getInstance().unsubscribe(alias);
+				}
+				return CliConstants.SUCCESSFUL_CODE;
+			} catch (ParseException e) {
+				if (logger.isErrorEnabled()) {
+					logger.error("Error parsing arguments", e);
+				}
+				System.out.println(e.getMessage());
+				return CliConstants.BAD_ARGS_CODE;
+			}
+		} else {
+			context.getStratosApplication().printUsage(getName());
+			return CliConstants.BAD_ARGS_CODE;
+		}
+	}
+
+	@Override
+	public Options getOptions() {
+		return options;
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ca25b1f7/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/completer/CommandCompleter.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/completer/CommandCompleter.java b/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/completer/CommandCompleter.java
new file mode 100644
index 0000000..3405762
--- /dev/null
+++ b/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/completer/CommandCompleter.java
@@ -0,0 +1,133 @@
+/**
+ *  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.stratos.adc.mgt.cli.completer;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import jline.console.completer.ArgumentCompleter;
+import jline.console.completer.Completer;
+import jline.console.completer.StringsCompleter;
+
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.text.StrTokenizer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.stratos.adc.mgt.cli.Command;
+import org.apache.stratos.adc.mgt.cli.StratosApplication;
+import org.apache.stratos.adc.mgt.cli.StratosCommandContext;
+import org.apache.stratos.adc.mgt.cli.utils.CliConstants;
+
+public class CommandCompleter implements Completer {
+
+	private static final Logger logger = LoggerFactory.getLogger(StratosApplication.class);
+
+	/**
+	 * Keep arguments for each command
+	 */
+	private final Map<String, Collection<String>> argumentMap;
+	
+	private final Completer helpCommandCompleter;
+
+	private final Completer defaultCommandCompleter;
+
+	public CommandCompleter(Map<String, Command<StratosCommandContext>> commands) {
+		if (logger.isDebugEnabled()) {
+			logger.debug("Creating auto complete for {} commands", commands.size());
+		}
+		argumentMap = new HashMap<String, Collection<String>>();
+		defaultCommandCompleter = new StringsCompleter(commands.keySet());
+		helpCommandCompleter = new ArgumentCompleter(new StringsCompleter(CliConstants.HELP_ACTION),
+				defaultCommandCompleter);
+		for (String action : commands.keySet()) {
+			Command<StratosCommandContext> command = commands.get(action);
+			Options commandOptions = command.getOptions();
+			if (commandOptions != null) {
+				if (logger.isDebugEnabled()) {
+					logger.debug("Creating argument completer for command: {}", action);
+				}
+				List<String> arguments = new ArrayList<String>();
+				Collection<?> allOptions = commandOptions.getOptions();
+				for (Object o : allOptions) {
+					Option option = (Option) o;
+					String longOpt = option.getLongOpt();
+					String opt = option.getOpt();
+					if (StringUtils.isNotBlank(longOpt)) {
+						arguments.add("--" + longOpt);
+					} else if (StringUtils.isNotBlank(opt)) {
+						arguments.add("-" + opt);
+					}
+				}
+
+				argumentMap.put(action, arguments);
+			}
+		}
+	}
+
+	@Override
+	public int complete(String buffer, int cursor, List<CharSequence> candidates) {
+		if (logger.isTraceEnabled()) {
+			logger.trace("Buffer: {}, cursor: {}", buffer, cursor);
+			logger.trace("Candidates {}", candidates);
+		}
+		if (StringUtils.isNotBlank(buffer)) {
+			// User is typing a command
+			StrTokenizer strTokenizer = new StrTokenizer(buffer);
+			String action = strTokenizer.next();
+			Collection<String> arguments = argumentMap.get(action);
+			if (arguments != null) {
+				if (logger.isTraceEnabled()) {
+					logger.trace("Arguments found for {}, Tokens: {}", action, strTokenizer.getTokenList());
+					logger.trace("Arguments for {}: {}", action, arguments);
+				}
+				List<String> args = new ArrayList<String>(arguments);
+				List<Completer> completers = new ArrayList<Completer>();
+				for (String token : strTokenizer.getTokenList()) {
+					boolean argContains = arguments.contains(token);
+					if (token.startsWith("-") && !argContains) {
+						continue;
+					}
+					if (argContains) {
+						if (logger.isTraceEnabled()) {
+							logger.trace("Removing argument {}", token);
+						}
+						args.remove(token);
+					}
+					completers.add(new StringsCompleter(token));
+				}
+				completers.add(new StringsCompleter(args));
+				Completer completer = new ArgumentCompleter(completers);
+				return completer.complete(buffer, cursor, candidates);
+			} else if (CliConstants.HELP_ACTION.equals(action)) {
+				// For help action, we need to display available commands as arguments
+				return helpCommandCompleter.complete(buffer, cursor, candidates);
+			}
+		}
+		if (logger.isTraceEnabled()) {
+			logger.trace("Using Default Completer...");
+		}
+		return defaultCommandCompleter.complete(buffer, cursor, candidates);
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ca25b1f7/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/exception/CommandException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/exception/CommandException.java b/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/exception/CommandException.java
new file mode 100644
index 0000000..a462500
--- /dev/null
+++ b/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/exception/CommandException.java
@@ -0,0 +1,39 @@
+/**
+ *  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.stratos.adc.mgt.cli.exception;
+
+public class CommandException extends Exception {
+
+	private static final long serialVersionUID = 1L;
+
+	public CommandException() {
+	}
+
+	public CommandException(String message) {
+		super(message);
+	}
+
+	public CommandException(Throwable cause) {
+		super(cause);
+	}
+
+	public CommandException(String message, Throwable cause) {
+		super(message, cause);
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ca25b1f7/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/utils/CliConstants.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/utils/CliConstants.java b/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/utils/CliConstants.java
new file mode 100644
index 0000000..986bb72
--- /dev/null
+++ b/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/utils/CliConstants.java
@@ -0,0 +1,130 @@
+/**
+ *  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.stratos.adc.mgt.cli.utils;
+
+/**
+ * Constants for CLI Tool
+ */
+public class CliConstants {
+
+	public static final String STRATOS_APPLICATION_NAME = "stratos";
+
+	public static final String STRATOS_URL_ENV_PROPERTY = "STRATOS_URL";
+
+	public static final String STRATOS_USERNAME_ENV_PROPERTY = "STRATOS_USERNAME";
+
+	public static final String STRATOS_PASSWORD_ENV_PROPERTY = "STRATOS_PASSWORD";
+
+	public static final String STRATOS_SHELL_PROMPT = "stratos> ";
+	
+	public static final int SUCCESSFUL_CODE = 0;
+	public static final int BAD_ARGS_CODE = 1;
+	public static final int ERROR_CODE = 2;
+
+
+	/**
+	 * The Directory for storing configuration
+	 */
+	public static final String STRATOS_DIR = ".stratos";
+	public static final String STRATOS_HISTORY_DIR = ".history";
+
+	public static final String HELP_ACTION = "help";
+
+	/**
+	 * Subscribe to a cartridge.
+	 */
+	public static final String SUBSCRIBE_ACTION = "subscribe";
+
+	public static final String UNSUBSCRIBE_ACTION = "unsubscribe";
+
+	/**
+	 * List the subscribed cartridges
+	 */
+	public static final String LIST_ACTION = "list";
+
+	/**
+	 * List the available cartridges
+	 */
+	public static final String CARTRIDGES_ACTION = "cartridges";
+
+	/**
+	 * Give information of a cartridge.
+	 */
+	public static final String INFO_ACTION = "info";
+
+	/**
+	 * Synchronize repository
+	 */
+	public static final String SYNC_ACTION = "sync";
+
+	/**
+	 * Domain mapping
+	 */
+	public static final String ADD_DOMAIN_MAPPING_ACTION = "add-domain-mapping";
+	/**
+	 * Remove Domain mapping
+	 */
+	public static final String REMOVE_DOMAIN_MAPPING_ACTION = "remove-domain-mapping";
+	
+	/**
+	 * List the available policies
+	 */
+	public static final String POLICIES_ACTION = "policies";
+
+	/**
+	 * Exit action
+	 */
+	public static final String EXIT_ACTION = "exit";
+
+	public static final String REPO_URL_OPTION = "r";
+	public static final String REPO_URL_LONG_OPTION = "repoURL";
+	
+	public static final String PRIVATE_REPO_OPTION = "i";
+	public static final String PRIVATE_REPO_LONG_OPTION = "privateRepo";
+
+	public static final String USERNAME_OPTION = "u";
+	public static final String USERNAME_LONG_OPTION = "username";
+
+	public static final String PASSWORD_OPTION = "p";
+	public static final String PASSWORD_LONG_OPTION = "password";
+
+	public static final String HELP_OPTION = "h";
+	public static final String HELP_LONG_OPTION = "help";
+	
+	public static final String POLICY_OPTION = "o";
+	public static final String POLICY_LONG_OPTION = "policy";
+	
+	public static final String CONNECT_OPTION = "c";
+	public static final String CONNECT_LONG_OPTION = "connect";
+	
+	public static final String DATA_ALIAS_OPTION = "d";
+	public static final String DATA_ALIAS_LONG_OPTION = "data-alias";
+	
+	public static final String FULL_OPTION = "f";
+	public static final String FULL_LONG_OPTION = "full";
+	
+	public static final String FORCE_OPTION = "f";
+	public static final String FORCE_LONG_OPTION = "force";
+	
+	public static final String TRACE_OPTION = "trace";
+	
+	public static final String DEBUG_OPTION = "debug";
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ca25b1f7/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/utils/CommandLineUtils.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/utils/CommandLineUtils.java b/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/utils/CommandLineUtils.java
new file mode 100644
index 0000000..c6167f2
--- /dev/null
+++ b/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/utils/CommandLineUtils.java
@@ -0,0 +1,94 @@
+/**
+ *  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.stratos.adc.mgt.cli.utils;
+
+import java.text.MessageFormat;
+import java.util.ResourceBundle;
+
+public class CommandLineUtils {
+	
+	private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("Resources");
+
+	public static <T> void printTable(T[] data, RowMapper<T> mapper, String... headers) {
+		if (data == null) {
+			return;
+		}
+		// The maximum number of columns
+		// All data String[] length must be equal to this
+		int columns = headers.length;
+		int rows = data.length + 1;
+
+		String[][] table = new String[rows][columns];
+		table[0] = headers;
+
+		for (int i = 0; i < data.length; i++) {
+			T t = data[i];
+			table[i + 1] = mapper.getData(t);
+		}
+
+		// Find the maximum length of a string in each column
+		int[] lengths = new int[columns];
+		for (int i = 0; i < table.length; i++) {
+			for (int j = 0; j < table[i].length; j++) {
+				lengths[j] = Math.max(table[i][j].length(), lengths[j]);
+			}
+		}
+
+		// The border rows
+		String borders[] = new String[lengths.length];
+		// Generate a format string for each column
+		String[] formats = new String[lengths.length];
+		for (int i = 0; i < lengths.length; i++) {
+			StringBuilder stringBuilder = new StringBuilder();
+			stringBuilder.append("+");
+			for (int j = 0; j < lengths[i] + 2; j++) {
+				stringBuilder.append("-");
+			}
+			boolean finalColumn = (i + 1 == lengths.length);
+			if (finalColumn) {
+				stringBuilder.append("+\n");
+			}
+			borders[i] = stringBuilder.toString();
+			formats[i] = "| %1$-" + lengths[i] + "s " + (finalColumn ? "|\n" : "");
+		}
+
+		// Print the table
+		for (int i = 0; i < table.length; i++) {
+			for (int j = 0; j < table[i].length; j++) {
+				System.out.print(borders[j]);
+			}
+			for (int j = 0; j < table[i].length; j++) {
+				System.out.format(formats[j], table[i][j]);
+			}
+			if (i + 1 == table.length) {
+				for (int j = 0; j < table[i].length; j++) {
+					System.out.print(borders[j]);
+				}
+			}
+		}
+	}
+	
+	public static String getMessage(String key, Object... args) {
+		String message = BUNDLE.getString(key);
+		if (args != null && args.length > 0) {
+			message = MessageFormat.format(message, args);
+		}
+		return message;
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ca25b1f7/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/utils/RowMapper.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/utils/RowMapper.java b/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/utils/RowMapper.java
new file mode 100644
index 0000000..0a61ad7
--- /dev/null
+++ b/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/utils/RowMapper.java
@@ -0,0 +1,23 @@
+/**
+ *  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.stratos.adc.mgt.cli.utils;
+
+public interface RowMapper<T> {
+	String[] getData(T t);
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ca25b1f7/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/resources/Resources.properties
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/resources/Resources.properties b/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/resources/Resources.properties
new file mode 100644
index 0000000..fcec66f
--- /dev/null
+++ b/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/resources/Resources.properties
@@ -0,0 +1,25 @@
+
+
+cannot.list.available.cartridges=An error occurred when getting available cartridges.
+cannot.list.subscribed.cartridges=An error occurred when getting subscribed cartridges.
+cannot.get.cartridge.info=An error occurred when getting cartridge information.
+cannot.syncrepo=Synchronization failed
+cannot.subscribe=Subscribe failed
+cannot.unsubscribe=Unsubscribe failed
+cannot.mapdomain=Map Domain failed
+cannot.removedomain=Mapped Domain removal failed
+
+notsubscribed.error=You have not subscribed to {0}
+domainmapping.exists.error=The domain mapping {0} already exists for {1}
+
+cartridge.notregistered=Cartridge {0} is not registered
+cartridge.invalid.alias=The provided cartridge alias is not valid. The alias can contain only lowercase characters and numbers.
+cartridge.already.subscribed=You have already subscribed for cartridge type {0}
+cartridge.alias.duplicate=Duplicate cartridge alias {0}
+
+policy.error=Could not load policy.
+repository.required=An external repository required
+repository.credentials.required=Username and Password are required for the repository: {0}
+repository.transport.error=Error connecting to the repository: {0}
+repository.invalid.error=Invalid repository: {0}
+remote.error=Error connecting to back-end service.
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ca25b1f7/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/resources/log4j.properties b/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/resources/log4j.properties
new file mode 100755
index 0000000..958eb9c
--- /dev/null
+++ b/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/resources/log4j.properties
@@ -0,0 +1,15 @@
+log4j.appender.console=org.apache.log4j.ConsoleAppender
+log4j.appender.console.Target=System.out
+log4j.appender.console.layout=org.apache.log4j.PatternLayout
+log4j.appender.console.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p %c{1} [%t] %n%m%n
+
+log4j.appender.file=org.apache.log4j.RollingFileAppender
+log4j.appender.file.File=${user.home}/.stratos/.stratos-cli.log
+log4j.appender.file.MaxFileSize=10MB
+log4j.appender.file.MaxBackupIndex=100
+log4j.appender.file.layout=org.apache.log4j.PatternLayout
+log4j.appender.file.layout.conversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p %c{1} [%t] %n%m%n
+
+#Loggers
+log4j.rootLogger=info, file
+log4j.logger.org.wso2.carbon.adc.mgt.cli=info
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ca25b1f7/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/resources/wso2carbon.jks
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/resources/wso2carbon.jks b/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/resources/wso2carbon.jks
new file mode 100644
index 0000000..7942c53
Binary files /dev/null and b/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/resources/wso2carbon.jks differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ca25b1f7/components/org.apache.stratos.adc.mgt.repository.synchronizer/2.1.1/pom.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.mgt.repository.synchronizer/2.1.1/pom.xml b/components/org.apache.stratos.adc.mgt.repository.synchronizer/2.1.1/pom.xml
index 10d8467..32b2a28 100644
--- a/components/org.apache.stratos.adc.mgt.repository.synchronizer/2.1.1/pom.xml
+++ b/components/org.apache.stratos.adc.mgt.repository.synchronizer/2.1.1/pom.xml
@@ -28,7 +28,7 @@
     <modelVersion>4.0.0</modelVersion>
     <artifactId>org.apache.stratos.adc.mgt.repository.synchronizer</artifactId>
     <version>2.1.1</version>
-    <name>Repository Synchronizer</name>
+    <name>Apache Stratos - Repository Synchronizer</name>
     <description>Repository Synchronizer</description>
     <packaging>war</packaging>
 

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ca25b1f7/components/org.apache.stratos.lb.common/4.1.3/pom.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.lb.common/4.1.3/pom.xml b/components/org.apache.stratos.lb.common/4.1.3/pom.xml
new file mode 100644
index 0000000..6e95752
--- /dev/null
+++ b/components/org.apache.stratos.lb.common/4.1.3/pom.xml
@@ -0,0 +1,120 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+       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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <parent>
+        <groupId>org.apache.stratos</groupId>
+        <artifactId>stratos-components-parent</artifactId>
+        <version>2.0.0</version>
+        <relativePath>../../pom.xml</relativePath>
+    </parent>
+
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>org.apache.stratos</groupId>
+    <artifactId>org.apache.stratos.lb.common</artifactId>
+    <packaging>bundle</packaging>
+    <version>4.1.3</version>
+    <name>Apache Stratos Loadbalancer - Common</name>
+    <url>http://apache.org</url>
+    
+    <dependencies>
+    	<dependency>
+            <groupId>org.wso2.carbon</groupId>
+            <artifactId>org.wso2.carbon.core</artifactId>
+            <version>${wso2carbon.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>com.google.guava.wso2</groupId>
+	        <artifactId>guava</artifactId>
+            <version>${google.guava.wso2.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.synapse</groupId>
+            <artifactId>synapse-core</artifactId>
+            <version>${synapse.core.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>${junit.version}</version>
+        </dependency>
+        <!--dependency>
+          <groupId>org.testng</groupId>
+          <artifactId>testng</artifactId>
+          <version>6.3.1</version>
+          <scope>test</scope>
+        </dependency-->
+        <dependency>
+            <groupId>org.wso2.carbon</groupId>
+            <artifactId>org.wso2.carbon.logging</artifactId>
+            <version>4.1.0</version>
+        </dependency>
+        <!--dependency>
+        	<groupId>mysql</groupId>
+        	<artifactId>mysql-connector-java</artifactId>
+        	<version>5.1.6</version>
+        </dependency-->
+        <!-- This mysql dependency is required for tests-->
+    </dependencies>
+
+    <build>
+        <plugins>
+            <!--plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <version>2.12</version>
+                <configuration>
+                  <suiteXmlFiles>
+                    <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
+                  </suiteXmlFiles>
+                </configuration>
+              </plugin-->
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-scr-plugin</artifactId>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+                        <Bundle-Name>${project.artifactId}</Bundle-Name>
+                        <Export-Package>
+                            org.apache.stratos.lb.common.*,
+                        </Export-Package>
+                        <Private-Package>
+                        	org.apache.stratos.lb.common.conf.internal;
+                        </Private-Package>
+                        <Import-Package>
+                            !org.apache.commons.logging,
+                            org.apache.commons.logging; version=0.0.0,
+                            *;resolution:=optional
+                        </Import-Package>
+                        <DynamicImport-Package>*</DynamicImport-Package>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ca25b1f7/components/org.apache.stratos.lb.common/4.1.3/src/main/java/org/apache/stratos/lb/common/cache/LRUCache.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.lb.common/4.1.3/src/main/java/org/apache/stratos/lb/common/cache/LRUCache.java b/components/org.apache.stratos.lb.common/4.1.3/src/main/java/org/apache/stratos/lb/common/cache/LRUCache.java
new file mode 100644
index 0000000..342430c
--- /dev/null
+++ b/components/org.apache.stratos.lb.common/4.1.3/src/main/java/org/apache/stratos/lb/common/cache/LRUCache.java
@@ -0,0 +1,103 @@
+/**
+ *  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.stratos.lb.common.cache;
+
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+/**
+ * A simple, thread-safe LRU cache implementation. This cache allows concurrent reads.
+ * Concurrent write attempts are synchronized using an exclusive lock.
+ */
+public class LRUCache<K,V> extends LinkedHashMap<K,V> {
+
+    private static final long serialVersionUID = 5901026458782787628L;
+    private int maxEntries;
+    private ReadWriteLock lock;
+
+    public LRUCache(int maxEntries) {
+        super(maxEntries + 1, 1, false);
+        this.maxEntries = maxEntries;
+        this.lock = new ReentrantReadWriteLock();
+    }
+
+    @Override
+    public V get(Object key) {
+        lock.readLock().lock();
+        try {
+            return super.get(key);
+        } finally {
+            lock.readLock().unlock();
+        }
+    }
+
+    @Override
+    public V put(K key, V value) {
+        lock.writeLock().lock();
+        try {
+            return super.put(key, value);
+        } finally {
+            lock.writeLock().unlock();
+        }
+    }
+
+    @Override
+    public V remove(Object key) {
+        lock.writeLock().lock();
+        try {
+            return super.remove(key);
+        } finally {
+            lock.writeLock().unlock();
+        }
+    }
+
+    @Override
+    public void clear() {
+        lock.writeLock().lock();
+        try {
+            super.clear();
+        } finally {
+            lock.writeLock().unlock();
+        }
+    }
+
+    @Override
+    protected boolean removeEldestEntry(Map.Entry<K,V> eldest) {
+        boolean remove = size() > maxEntries;
+        if (remove) {
+            handleRemovableEntry(eldest);
+        }
+        return remove;
+    }
+
+    protected void handleRemovableEntry(Map.Entry<K,V> entry) {
+
+    }
+
+    public void exclusiveLock() {
+        lock.writeLock().lock();
+    }
+
+    public void release() {
+        lock.writeLock().unlock();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ca25b1f7/components/org.apache.stratos.lb.common/4.1.3/src/main/java/org/apache/stratos/lb/common/cache/URLMappingCache.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.lb.common/4.1.3/src/main/java/org/apache/stratos/lb/common/cache/URLMappingCache.java b/components/org.apache.stratos.lb.common/4.1.3/src/main/java/org/apache/stratos/lb/common/cache/URLMappingCache.java
new file mode 100644
index 0000000..3c23efc
--- /dev/null
+++ b/components/org.apache.stratos.lb.common/4.1.3/src/main/java/org/apache/stratos/lb/common/cache/URLMappingCache.java
@@ -0,0 +1,47 @@
+/**
+ *  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.stratos.lb.common.cache;
+
+import org.apache.stratos.lb.common.util.DomainMapping;
+import java.util.Map;
+
+public class URLMappingCache {
+    private Map<String,DomainMapping> validMappings;
+
+    private static URLMappingCache instance = null;
+    protected URLMappingCache(int maxValidKeys) {
+        validMappings = new LRUCache<String, DomainMapping>(maxValidKeys);
+    }
+
+    public void addValidMapping(String hostName, DomainMapping mapping) {
+        validMappings.put(hostName, mapping);
+    }
+
+    public DomainMapping getMapping(String hostName) {
+        return validMappings.get(hostName);
+    }
+
+    public static URLMappingCache getInstance(int maxValidKeys) {
+      if(instance == null) {
+
+         instance = new URLMappingCache(maxValidKeys);
+      }
+      return instance;
+   }
+}