<commit_before>/**
 * Copyright (C) 2012 Ness Computing, Inc.
 *
 * 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 com.nesscomputing.jms;

import java.io.IOException;
import java.io.InterruptedIOException;
import java.io.Serializable;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import javax.jms.BytesMessage;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.ObjectMessage;
import javax.jms.Session;
import javax.jms.StreamMessage;
import javax.jms.TextMessage;

import com.google.common.base.Preconditions;

import com.nesscomputing.logging.Log;

/**
 * Base code for the topic and queue runnables.
 */
public abstract class AbstractJmsRunnable implements Runnable
{
    protected final Log LOG = Log.forClass(this.getClass());

    private AtomicReference<Connection> connectionHolder = new AtomicReference<Connection>();
    private AtomicReference<Session> sessionHolder = new AtomicReference<Session>();
    private AtomicBoolean running = new AtomicBoolean(true);
    private AtomicBoolean connected = new AtomicBoolean(false);

    private int backoff = 1;

    private final ConnectionFactory connectionFactory;
    private final JmsConfig jmsConfig;
    private final String name;

    protected AbstractJmsRunnable(@Nonnull final ConnectionFactory connectionFactory,
                                  @Nonnull final JmsConfig jmsConfig,
                                  @Nonnull final String name)
    {
        Preconditions.checkState(name != null, "The name can not be null!");
        this.connectionFactory = connectionFactory;
        this.jmsConfig = jmsConfig;
        this.name = name;
    }

    public void shutdown()
    {
        running.set(false);
    }

    public boolean isRunning()
    {
        return running.get();
    }

    public boolean isConnected()<commit_msg>Make final some fields that can be final.<commit_after>/**
 * Copyright (C) 2012 Ness Computing, Inc.
 *
 * 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 com.nesscomputing.jms;

import java.io.IOException;
import java.io.InterruptedIOException;
import java.io.Serializable;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import javax.jms.BytesMessage;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.ObjectMessage;
import javax.jms.Session;
import javax.jms.StreamMessage;
import javax.jms.TextMessage;

import com.google.common.base.Preconditions;

import com.nesscomputing.logging.Log;

/**
 * Base code for the topic and queue runnables.
 */
public abstract class AbstractJmsRunnable implements Runnable
{
    protected final Log LOG = Log.forClass(this.getClass());

    private final AtomicReference<Connection> connectionHolder = new AtomicReference<Connection>();
    private final AtomicReference<Session> sessionHolder = new AtomicReference<Session>();
    private final AtomicBoolean running = new AtomicBoolean(true);
    private final AtomicBoolean connected = new AtomicBoolean(false);

    private int backoff = 1;

    private final ConnectionFactory connectionFactory;
    private final JmsConfig jmsConfig;
    private final String name;

    protected AbstractJmsRunnable(@Nonnull final ConnectionFactory connectionFactory,
                                  @Nonnull final JmsConfig jmsConfig,
                                  @Nonnull final String name)
    {
        Preconditions.checkState(name != null, "The name can not be null!");
        this.connectionFactory = connectionFactory;
        this.jmsConfig = jmsConfig;
        this.name = name;
    }

    public void shutdown()
    {
        running.set(false);
    }

    public boolean isRunning()
    {
        return running.get();
    }

    public boolean isConnected()
{'fraction_non_alphanumeric': 0.08020873598763047, 'fraction_numerical': 0.003478933127174333, 'mean_word_length': 3.6917497733454216, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '13525', 'n_tokens_mistral': 1378, 'n_tokens_neox': 1325, 'n_words': 448}