<commit_before>/* Copyright 2009 - 2010 The Stajistics Project
 *
 * 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.
 */
package org.stajistics.session;

import java.util.Date;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.stajistics.StatsKey;
import org.stajistics.data.DataSet;
import org.stajistics.event.StatsEventManager;
import org.stajistics.event.StatsEventType;
import org.stajistics.session.recorder.DataRecorder;
import org.stajistics.task.TaskService;
import org.stajistics.tracker.StatsTracker;

/**
 * An implementation of {@link StatsSession} that can potentially pad the
 * tracker, and thus the client of the tracker, from blocking on calls to
 * {@link #track(StatsTracker, long)}, and {@link #update(StatsTracker, long)}.
 * When either of these calls are made, they are queued for execution by the
 * associated {@link TaskService}, which will typically invoke them in a
 * background thread. This queuing behaviour does impose the overhead of queue
 * entry object creation on the client of a tracker, but this is necessary to
 * fulfil the main purpose of this implementation. {@link #collectData()} may be
 * called on an instance of this class and the resulting {@link DataSet} is
 * guaranteed to contain data fields that are related to one another for a given
 * update. For example, if {@link #collectData()} is called at the same time as
 * a update #2, the resulting {@link DataSet} will contain data related only to
 * update #1 or update #2. It will not contain the data from a partially
 * recorded update. Furthermore, it allows this data integrity without having to
 * block the client of the {@link StatsTracker}, which could sacrifice
 * performance. If better performance is preferred at the cost of potentially
 * inconsistent data, see {@link org.stajistics.session.ConcurrentStatsSession}.
 * 
 * @see org.stajistics.session.ConcurrentStatsSession
 * 
 * @author The Stajistics Project
 */
public class AsynchronousStatsSession extends AbstractStatsSession {

    private static final Logger logger = LoggerFactory.getLogger(AsynchronousStatsSession.class);

    private volatile long hits = 0;
    private volatile long firstHitStamp = -1;
    private volatile long lastHitStamp = -1;
    private volatile long commits = 0;
<commit_msg>Updated Javadoc for AsynchronousStatsSession.<commit_after>/* Copyright 2009 - 2010 The Stajistics Project
 *
 * 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.
 */
package org.stajistics.session;

import java.util.Date;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.stajistics.StatsKey;
import org.stajistics.data.DataSet;
import org.stajistics.event.StatsEventManager;
import org.stajistics.event.StatsEventType;
import org.stajistics.session.recorder.DataRecorder;
import org.stajistics.task.TaskService;
import org.stajistics.tracker.StatsTracker;

/**
 * An implementation of {@link StatsSession} that can potentially pad the
 * tracker, and thus the client of the tracker, from blocking on
 * {@link #update(StatsTracker, long)} calls.
 * 
 * <p>
 * Calls to {@link #update(StatsTracker, long)} are queued for execution by the
 * associated {@link TaskService}, which will typically invoke them in a
 * background thread. This queuing behaviour does impose the overhead of queue
 * entry object creation on the client of a tracker, but this is necessary to
 * fulfill the main purpose of this implementation.
 * 
 * <p>
 * {@link #collectData()} may be called on an instance of this class and the
 * resulting {@link DataSet} is guaranteed to contain data fields that are
 * related to one another for a given update. For example, if
 * {@link #collectData()} is called at the same time as a update #2, the
 * resulting {@link DataSet} will contain data related only to update #1 or
 * update #2. It will not contain the data from a partially recorded update.
 * Furthermore, it allows this data integrity without having to block the client
 * of the {@link StatsTracker}, which could sacrifice performance.
 * 
 * <p>
 * If better performance is preferred at the cost of potentially inconsistent
 * data, see {@link org.stajistics.session.ConcurrentStatsSession}.
 * 
 * @see org.stajistics.session.ConcurrentStatsSession
 * 
 * @author The Stajistics Project
 */
public class AsynchronousStatsSession extends AbstractStatsSession {

    private static final Logger logger = LoggerFactory.getLogger(AsynchronousStatsSession.class);

    private volatile long hits = 0;
    private volatile long firstHitStamp = -1;
    private volatile long lastHitStamp = -1;
    private volatile long commits = 0;

{'fraction_non_alphanumeric': 0.0750375187593797, 'fraction_numerical': 0.007003501750875438, 'mean_word_length': 4.548566142460684, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, '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': '5220920', 'n_tokens_mistral': 1586, 'n_tokens_neox': 1536, 'n_words': 690}