<commit_before>/*
 * Copyright (c) 2010, Regents of the University of California
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * 
 *  * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 *  * Neither the name of the University of California, Berkeley
 * nor the names of its contributors may be used to endorse or promote
 * products derived from this software without specific prior written
 * permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * Author: <NAME> (<EMAIL>), 2013.
 */

package radlab.rain.workload.rubbos;


import java.util.Arrays;
//import java.util.Calendar;
//import java.util.concurrent.atomic.AtomicInteger;
//import java.util.concurrent.Semaphore;
import java.util.logging.Logger;
import java.util.Random;
import org.apache.http.HttpStatus;
import org.json.JSONObject;
import org.json.JSONException;
import radlab.rain.Generator;
import radlab.rain.LoadProfile;
import radlab.rain.Operation;
import radlab.rain.ScenarioTrack;
import radlab.rain.util.HttpTransport;
import radlab.rain.util.NegativeExponential;


/**
 * Operation generator for the RUBBoS workload.
 *
 * @author <NAME> (<EMAIL>)
 */
public class RubbosGenerator extends Generator
{
	// Operation indices used in the mix matrix.
	// Use the same order of the native RUBBoS mix matrix
	public static final int STORIES_OF_THE_DAY_OP = 0;
	public static final int REGISTER_OP = 1;
	public static final int REGISTER_USER_OP = 2;
	public static final int BROWSE_OP = 3;
	public static final int BROWSE_CATEGORIES_OP = 4;
	public static final int BROWSE_STORIES_BY_CATEGORY_OP = 5;
	public static final int OLDER_STORIES_OP = 6;
	public static final int VIEW_STORY_OP = 7;
	public static final int POST_COMMENT_OP = 8;
	public static final int STORE_COMMENT_OP = 9;
	public static final int VIEW_COMMENT_OP = 10;
	public static final int MODERATE_COMMENT_OP = 11;
	public static final int STORE_MODERATE_LOG_OP = 12;
	public static final int SUBMIT_STORY_OP = 13;
	public static final int STORE_STORY_OP = 14;
	public static final int SEARCH_OP = 15;
	public static final int SEARCH_IN_STORIES_OP = 16;
	public static final int SEARCH_IN_COMMENTS_OP = 17;
	public static final int SEARCH_IN_USERS_OP = 18;
	public static final int AUTHOR_LOGIN_OP = 20;
	public static final int AUTHOR_TASKS_OP = 21;
	public static final int REVIEW_STORIES_OP = 22;
	public static final int ACCEPT_STORY_OP = 23;
	public static final int REJECT_STORY_OP = 24;
	public static final int BACK_SPECIAL_OP = 25; ///< Emulate a click on the "Back" button of the browser
	public static final int EOS_SPECIAL_OP = 26; ///< Terminate the current user session

	// Static members shared among all instances
	private static Random _rng; ///< The Random Number Generator
	private static RubbosConfiguration _conf; ///< The RUBBoS-related configuration found in the JSON profile file


	private HttpTransport _http;
	private Logger _logger;
	private RubbosSessionState _sessionState; ///< Holds user session data
	private RubbosUtility _utility;
	private double _thinkTime = -1; ///< The mean think time; a value <= 0 means that no think time is used.
	private NegativeExponential _thinkTimeRng;
	private double _cycleTime = -1; ///< The mean cycle time; a value <= 0 means that no cycle time is used.
	private NegativeExponential _cycleTimeRng;
	private String _baseURL;
	private String _storiesOfTheDayURL; 
	private String _registerURL;<commit_msg>[rubbos] (bug-fix:minor) Bad operation numbering<commit_after>/*
 * Copyright (c) 2010, Regents of the University of California
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * 
 *  * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 *  * Neither the name of the University of California, Berkeley
 * nor the names of its contributors may be used to endorse or promote
 * products derived from this software without specific prior written
 * permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * Author: <NAME> (<EMAIL>), 2013.
 */

package radlab.rain.workload.rubbos;


import java.util.Arrays;
import java.util.logging.Logger;
import java.util.Random;
import org.apache.http.HttpStatus;
import org.json.JSONObject;
import org.json.JSONException;
import radlab.rain.Generator;
import radlab.rain.LoadProfile;
import radlab.rain.Operation;
import radlab.rain.ScenarioTrack;
import radlab.rain.util.HttpTransport;
import radlab.rain.util.NegativeExponential;


/**
 * Operation generator for the RUBBoS workload.
 *
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
public class RubbosGenerator extends Generator
{
	// Operation indices used in the mix matrix.
	// Use the same order of the native RUBBoS mix matrix
	public static final int STORIES_OF_THE_DAY_OP = 0;
	public static final int REGISTER_OP = 1;
	public static final int REGISTER_USER_OP = 2;
	public static final int BROWSE_OP = 3;
	public static final int BROWSE_CATEGORIES_OP = 4;
	public static final int BROWSE_STORIES_BY_CATEGORY_OP = 5;
	public static final int OLDER_STORIES_OP = 6;
	public static final int VIEW_STORY_OP = 7;
	public static final int POST_COMMENT_OP = 8;
	public static final int STORE_COMMENT_OP = 9;
	public static final int VIEW_COMMENT_OP = 10;
	public static final int MODERATE_COMMENT_OP = 11;
	public static final int STORE_MODERATE_LOG_OP = 12;
	public static final int SUBMIT_STORY_OP = 13;
	public static final int STORE_STORY_OP = 14;
	public static final int SEARCH_OP = 15;
	public static final int SEARCH_IN_STORIES_OP = 16;
	public static final int SEARCH_IN_COMMENTS_OP = 17;
	public static final int SEARCH_IN_USERS_OP = 18;
	public static final int AUTHOR_LOGIN_OP = 19;
	public static final int AUTHOR_TASKS_OP = 20;
	public static final int REVIEW_STORIES_OP = 21;
	public static final int ACCEPT_STORY_OP = 22;
	public static final int REJECT_STORY_OP = 23;
	public static final int BACK_SPECIAL_OP = 24; ///< Emulate a click on the "Back" button of the browser
	public static final int EOS_SPECIAL_OP = 25; ///< Terminate the current user session

	// Static members shared among all instances
	private static Random _rng; ///< The Random Number Generator
	private static RubbosConfiguration _conf; ///< The RUBBoS-related configuration found in the JSON profile file


	private HttpTransport _http;
	private Logger _logger;
	private RubbosSessionState _sessionState; ///< Holds user session data
	private RubbosUtility _utility;
	private double _thinkTime = -1; ///< The mean think time; a value <= 0 means that no think time is used.
	private NegativeExponential _thinkTimeRng;
	private double _cycleTime = -1; ///< The mean cycle time; a value <= 0 means that no cycle time is used.
	private NegativeExponential _cycleTimeRng;
	private String _baseURL;
	private String _storiesOfTheDayURL; 
	private String _registerURL;
{'fraction_non_alphanumeric': 0.06159420289855073, 'fraction_numerical': 0.011857707509881422, 'mean_word_length': 4.581495098039215, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '7145621', 'n_tokens_mistral': 2812, 'n_tokens_neox': 2520, 'n_words': 1117}