<commit_before>package cl.yaykuy.loader;

/*
* Copyright 2011-2012 the original author or authors.
*
* Licensed 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.
*/


import java.util.Map;

import org.vertx.java.core.AsyncResult;
import org.vertx.java.core.Future;
import org.vertx.java.core.Handler;
import org.vertx.java.core.json.JsonObject;
import org.vertx.java.core.logging.Logger;
import org.vertx.java.platform.Verticle;

public class ServerLoaderVerticle extends Verticle {
	Logger logger;
	int totalModules,loadedModules=0;
	int totalVerticles,loadedVerticles=0;
	
	public void start(final Future<Void> startedResult) {
		JsonObject config = container.config();
		if(config==null){
			startedResult.setFailure(new Exception("Config Null"));
			return;
		}
		JsonObject appConfig = config.getObject("appConfig");
		if(appConfig==null){
			startedResult.setFailure(new Exception("appConfig Null"));
			return;
		}
		
		deployAllModules(startedResult);
		
	}
	
	private void deployAllModules(final Future<Void> startedResult){
		JsonObject appConfig = container.config().getObject("appConfig");
		JsonObject modulesConfig=null;
		try{
			modulesConfig = appConfig.getObject("modules");
		}catch(Exception e){
			startedResult.setFailure(new Exception("modules malformed"));
			return;
		}
		
		if(modulesConfig != null && modulesConfig.size()>0){
			totalModules=modulesConfig.size();
			for (Map.Entry<String,Object > e : modulesConfig.toMap().entrySet()) {
			    String name = e.getKey();
			    String moduleName = modulesConfig.getObject(name).getString("module");
			    container.deployModule(moduleName,deployedModule(name,startedResult));
			}
		}else{
			deployAllVerticles(startedResult);
		}
	}
	
	
	private Handler<AsyncResult<String>> deployedModule(final String name,final Future<Void> startedResult){
		return new Handler<AsyncResult<String>>(){
			@Override
			public void handle(AsyncResult<String> asyncResult) {
				if (asyncResult.succeeded()) {
					loadedModules++;
				    container.logger().info("Module "+name+ " deployed "+loadedModules+"/"+totalModules);
					if(loadedModules==totalModules){
						deployAllVerticles(startedResult);
				    }
		        } else {
		        	container.logger().error("Deployment of module "+name+ " failed.",
		        			asyncResult.cause());
		        	startedResult.setFailure(asyncResult.cause());
		        }
			}
		};
	}
	
	private void deployAllVerticles(final Future<Void> startedResult){
		JsonObject appConfig = container.config().getObject("appConfig");
		JsonObject verticlesConfig=null;
		try{
			verticlesConfig = appConfig.getObject("verticles");
		}catch(Exception e){
			startedResult.setFailure(new Exception("verticles malformed"));
			return;
		}
		
		if(verticlesConfig != null && verticlesConfig.size()>0){
			totalVerticles=verticlesConfig.size();
			for (Map.Entry<String,Object > e : verticlesConfig.toMap().entrySet()) {
				try{
				    String name = e.getKey();
				    String verticleFile = verticlesConfig.getObject(name).getString("file");
				    if(verticleFile==null){
				    	verticleFile="verticles/"+name+"_verticle.js";
				    }else{
				    	verticleFile="verticles/"+verticleFile;
				    }
				    container.deployVerticle(verticleFile,deployedVerticle(name,startedResult));
				}catch (Exception e2){
					startedResult.setFailure(new Exception("verticle definition malformed"));
					return;
				}
			}
		}else{
			deployServerVerticle(startedResult);
		}
	}
	
	
	private Handler<AsyncResult<String>> deployedVerticle(final String name,final Future<Void> startedResult){
		return new Handler<AsyncResult<String>>(){
			@Override
			public void handle(AsyncResult<String> asyncResult) {
				if (asyncResult.succeeded()) {
					loadedVerticles++;
				    container.logger().info("Verticle "+name+ " deployed "+loadedVerticles+"/"+totalVerticles);
					if(loadedVerticles==totalVerticles){
						deployServerVerticle(startedResult);
				    }
		        } else {
		        	container.logger().error("Deployment of verticle "+name+ " failed.",
		        			asyncResult.cause());
		        	startedResult.setFailure(asyncResult.cause());
		        }
			}
		};
	}

	
	private void deployServerVerticle(final Future<Void> startedResult){
		JsonObject appConfig = container.config().getObject("appConfig");
		String serverVerticleConfig=null;
		try{
			serverVerticleConfig = appConfig.getString("serverVerticle");
		}catch(Exception e){
			startedResult.setFailure(new Exception("serverVerticle malformed"));
			return;
		}
		
		if(serverVerticleConfig != null && !serverVerticleConfig.trim().equals("")){
			String verticleFile = null;
			if(container.config().getObject("server")!= null){
				verticleFile=container.config().getObject("server").getString("file");
			}
		    if(verticleFile==null){
		    	verticleFile="verticles/"+serverVerticleConfig+"_verticle.js";
		    }
		    container.deployVerticle(verticleFile,deployedServerVerticle(verticleFile,startedResult));
		}else{
			done(startedResult);
		}
	}
	
	
	private Handler<AsyncResult<String>> deployedServerVerticle(final String filename,final Future<Void> startedResult){
		return new Handler<AsyncResult<String>>(){
			@Override
			public void handle(AsyncResult<String> asyncResult) {
				if (asyncResult.succeeded()) {
					container.logger().info("Server Verticle file:"+filename+ " deployed ");
					done(startedResult);
		        } else {
		        	container.logger().error("Deployment of Server verticle "+filename+ " failed.",
		        			asyncResult.cause());
		        	startedResult.setFailure(asyncResult.cause());
		        }
			}
		};
	}
	
	private void done(final Future<Void> startedResult){
		container.logger().info("App Ready to Rock!");
		startedResult.setResult(null);
	}
}
<commit_msg>Soporte para config de verticles y modules<commit_after>package cl.yaykuy.loader;

/*
* Copyright 2011-2012 the original author or authors.
*
* Licensed 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.
*/


import java.util.Map;

import org.vertx.java.core.AsyncResult;
import org.vertx.java.core.Future;
import org.vertx.java.core.Handler;
import org.vertx.java.core.json.JsonObject;
import org.vertx.java.core.logging.Logger;
import org.vertx.java.platform.Verticle;

public class ServerLoaderVerticle extends Verticle {
	Logger logger;
	int totalModules,loadedModules=0;
	int totalVerticles,loadedVerticles=0;
	
	public void start(final Future<Void> startedResult) {
		JsonObject config = container.config();
		if(config==null){
			startedResult.setFailure(new Exception("Config Null"));
			return;
		}
		JsonObject appConfig = config.getObject("appConfig");
		if(appConfig==null){
			startedResult.setFailure(new Exception("appConfig Null"));
			return;
		}
		
		deployAllModules(startedResult);
		
	}
	
	private void deployAllModules(final Future<Void> startedResult){
		JsonObject appConfig = container.config().getObject("appConfig");
		JsonObject modulesConfig=null;
		try{
			modulesConfig = appConfig.getObject("modules");
		}catch(Exception e){
			startedResult.setFailure(new Exception("modules malformed"));
			return;
		}
		
		if(modulesConfig != null && modulesConfig.size()>0){
			totalModules=modulesConfig.size();
			for (Map.Entry<String,Object > e : modulesConfig.toMap().entrySet()) {
			    String name = e.getKey();
			    String moduleName = modulesConfig.getObject(name).getString("module");
			    JsonObject moduleConfig = container.config().getObject(moduleName);
			    container.deployModule(moduleName,moduleConfig,deployedModule(name,startedResult));
			}
		}else{
			deployAllVerticles(startedResult);
		}
	}
	
	
	private Handler<AsyncResult<String>> deployedModule(final String name,final Future<Void> startedResult){
		return new Handler<AsyncResult<String>>(){
			@Override
			public void handle(AsyncResult<String> asyncResult) {
				if (asyncResult.succeeded()) {
					loadedModules++;
				    container.logger().info("Module "+name+ " deployed "+loadedModules+"/"+totalModules);
					if(loadedModules==totalModules){
						deployAllVerticles(startedResult);
				    }
		        } else {
		        	container.logger().error("Deployment of module "+name+ " failed.",
		        			asyncResult.cause());
		        	startedResult.setFailure(asyncResult.cause());
		        }
			}
		};
	}
	
	private void deployAllVerticles(final Future<Void> startedResult){
		JsonObject appConfig = container.config().getObject("appConfig");
		JsonObject verticlesConfig=null;
		try{
			verticlesConfig = appConfig.getObject("verticles");
		}catch(Exception e){
			startedResult.setFailure(new Exception("verticles malformed"));
			return;
		}
		
		if(verticlesConfig != null && verticlesConfig.size()>0){
			totalVerticles=verticlesConfig.size();
			for (Map.Entry<String,Object > e : verticlesConfig.toMap().entrySet()) {
				try{
				    String verticleName = e.getKey();
				    String verticleFile = verticlesConfig.getObject(verticleName).getString("file");
				    if(verticleFile==null){
				    	verticleFile="verticles/"+verticleName+"_verticle.js";
				    }
				    JsonObject verticleConfig = container.config().getObject(verticleName);
				    
				    container.deployVerticle(verticleFile,verticleConfig,deployedVerticle(verticleName,startedResult));
				}catch (Exception e2){
					startedResult.setFailure(new Exception("verticle definition malformed"));
					return;
				}
			}
		}else{
			deployServerVerticle(startedResult);
		}
	}
	
	
	private Handler<AsyncResult<String>> deployedVerticle(final String name,final Future<Void> startedResult){
		return new Handler<AsyncResult<String>>(){
			@Override
			public void handle(AsyncResult<String> asyncResult) {
				if (asyncResult.succeeded()) {
					loadedVerticles++;
				    container.logger().info("Verticle "+name+ " deployed "+loadedVerticles+"/"+totalVerticles);
					if(loadedVerticles==totalVerticles){
						deployServerVerticle(startedResult);
				    }
		        } else {
		        	container.logger().error("Deployment of verticle "+name+ " failed.",
		        			asyncResult.cause());
		        	startedResult.setFailure(asyncResult.cause());
		        }
			}
		};
	}

	
	private void deployServerVerticle(final Future<Void> startedResult){
		JsonObject appConfig = container.config().getObject("appConfig");
		String serverVerticleName=null;
		try{
			serverVerticleName = appConfig.getString("serverVerticle");
		}catch(Exception e){
			startedResult.setFailure(new Exception("serverVerticle malformed"));
			return;
		}
		
		if(serverVerticleName != null && !serverVerticleName.trim().equals("")){
			String verticleFile = null;
			JsonObject verticleConfig = container.config().getObject("server");
			if(verticleConfig!= null){
				verticleFile=container.config().getObject("server").getString("file");
			}
		    if(verticleFile==null){
		    	verticleFile="verticles/"+serverVerticleName+"_verticle.js";
		    }
		    container.deployVerticle(verticleFile,verticleConfig,deployedServerVerticle(verticleFile,startedResult));
		}else{
			done(startedResult);
		}
	}
	
	
	private Handler<AsyncResult<String>> deployedServerVerticle(final String filename,final Future<Void> startedResult){
		return new Handler<AsyncResult<String>>(){
			@Override
			public void handle(AsyncResult<String> asyncResult) {
				if (asyncResult.succeeded()) {
					container.logger().info("Server Verticle file:"+filename+ " deployed ");
					done(startedResult);
		        } else {
		        	container.logger().error("Deployment of Server verticle "+filename+ " failed.",
		        			asyncResult.cause());
		        	startedResult.setFailure(asyncResult.cause());
		        }
			}
		};
	}
	
	private void done(final Future<Void> startedResult){
		container.logger().info("App Ready to Rock!");
		startedResult.setResult(null);
	}
}

{'fraction_non_alphanumeric': 0.12361840558124951, 'fraction_numerical': 0.0026652034177314416, 'mean_word_length': 4.211601307189542, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5997371', 'n_tokens_mistral': 4271, 'n_tokens_neox': 3591, 'n_words': 727}