<commit_before>/*
 * #%L
 * Bitrepository Protocol
 * 
 * $Id$
 * $HeadURL$
 * %%
 * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as 
 * published by the Free Software Foundation, either version 2.1 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 Lesser Public License for more details.
 * 
 * You should have received a copy of the GNU General Lesser Public 
 * License along with this program.  If not, see
 * <http://www.gnu.org/licenses/lgpl-2.1.html>.
 * #L%
 */
package org.bitrepository.client.conversation;

import org.bitrepository.bitrepositorymessages.Message;
import org.bitrepository.bitrepositorymessages.MessageRequest;
import org.bitrepository.bitrepositorymessages.MessageResponse;
import org.bitrepository.common.exceptions.UnableToFinishException;
import org.bitrepository.protocol.ProtocolConstants;
import org.bitrepository.client.exceptions.UnexpectedResponseException;

import java.math.BigInteger;
import java.util.Timer;
import java.util.TimerTask;

/**
 * Implements the generic conversation state functionality, 
 * like timeouts and the definition of the common state attributes.
 *
 * ToDo Implement ConversationState and consider moving selected method here when this class is in general usage.
 */
public abstract class GeneralConversationState {
    /** The timer used for timeout checks. */
    private final Timer timer = new Timer("GeneralConversationStateTimer");
    /** The timer task for timeout of identify in this conversation. */
    private final TimerTask stateTimeoutTask = new StateTimerTask();

    /**
     * Startes the state by: <ol>
     *     <li>Starting the timeout timer.</li>
     *     <li>Sends the request which triggers the responses for this state.</li>
     * </ol>
     */
    public synchronized final void start() {
        timer.schedule(stateTimeoutTask, getTimeout());
        sendRequest();
    }

    /**
     * The general message handler for this state. Will only accept <code>MessageResponses</code>.
     * Takes care of the general message bookkepping and delegates the specifics of the message handling to the
     * concrete states {@link #processMessage(MessageResponse)}.
     * @param message The message to handle.
     */
    public synchronized final void handleMessage(Message message) {
        if (!(message instanceof MessageResponse)) {
            getContext().getMonitor().outOfSequenceMessage(
                    "Can only handle responses, but received " + message.getClass().getSimpleName());
        }<commit_msg>Make GeneralConversationStateTimer static<commit_after>/*
 * #%L
 * Bitrepository Protocol
 * 
 * $Id$
 * $HeadURL$
 * %%
 * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as 
 * published by the Free Software Foundation, either version 2.1 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 Lesser Public License for more details.
 * 
 * You should have received a copy of the GNU General Lesser Public 
 * License along with this program.  If not, see
 * <http://www.gnu.org/licenses/lgpl-2.1.html>.
 * #L%
 */
package org.bitrepository.client.conversation;

import org.bitrepository.bitrepositorymessages.Message;
import org.bitrepository.bitrepositorymessages.MessageRequest;
import org.bitrepository.bitrepositorymessages.MessageResponse;
import org.bitrepository.common.exceptions.UnableToFinishException;
import org.bitrepository.protocol.ProtocolConstants;
import org.bitrepository.client.exceptions.UnexpectedResponseException;

import java.math.BigInteger;
import java.util.Timer;
import java.util.TimerTask;

/**
 * Implements the generic conversation state functionality, 
 * like timeouts and the definition of the common state attributes.
 *
 * ToDo Implement ConversationState and consider moving selected method here when this class is in general usage.
 */
public abstract class GeneralConversationState {
    /** The timer used for timeout checks. */
    private final static Timer timer = new Timer("GeneralConversationStateTimer");
    /** The timer task for timeout of identify in this conversation. */
    private final TimerTask stateTimeoutTask = new StateTimerTask();

    /**
     * Startes the state by: <ol>
     *     <li>Starting the timeout timer.</li>
     *     <li>Sends the request which triggers the responses for this state.</li>
     * </ol>
     */
    public synchronized final void start() {
        timer.schedule(stateTimeoutTask, getTimeout());
        sendRequest();
    }

    /**
     * The general message handler for this state. Will only accept <code>MessageResponses</code>.
     * Takes care of the general message bookkepping and delegates the specifics of the message handling to the
     * concrete states {@link #processMessage(MessageResponse)}.
     * @param message The message to handle.
     */
    public synchronized final void handleMessage(Message message) {
        if (!(message instanceof MessageResponse)) {
            getContext().getMonitor().outOfSequenceMessage(
                    "Can only handle responses, but received " + message.getClass().getSimpleName());
        }
{'fraction_non_alphanumeric': 0.08177056935293124, 'fraction_numerical': 0.0040547389761784085, 'mean_word_length': 3.6984126984126986, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '685334', 'n_tokens_mistral': 1478, 'n_tokens_neox': 1422, 'n_words': 591}