<commit_before>/*
 * Tigase Jabber/XMPP Server
 * Copyright (C) 2004-2007 "<NAME>" <<EMAIL>>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License.
 *
 * 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 Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. Look for COPYING file in the top folder.
 * If not, see http://www.gnu.org/licenses/.
 *
 * $Rev$
 * Last modified by $Author$
 * $Date$
 */

package tigase.server.bosh;

//~--- non-JDK imports --------------------------------------------------------

import tigase.server.Command;
import tigase.server.Packet;
import tigase.server.ReceiverTimeoutHandler;
import tigase.server.xmppclient.ClientConnectionManager;

import tigase.xmpp.Authorization;
import tigase.xmpp.JID;
import tigase.xmpp.PacketErrorTypeException;
import tigase.xmpp.StanzaType;
import tigase.xmpp.XMPPIOService;

import static tigase.server.bosh.Constants.*;

//~--- JDK imports ------------------------------------------------------------

import java.util.ArrayDeque;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Queue;
import java.util.TimerTask;
import java.util.UUID;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;

//~--- classes ----------------------------------------------------------------

/**
 * Describe class BoshConnectionManager here.
 * 
 * 
 * Created: Sat Jun 2 12:24:29 2007
 * 
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @version $Rev$
 */
public class BoshConnectionManager extends ClientConnectionManager implements
		BoshSessionTaskHandler {

	/**
	 * Variable <code>log</code> is a class logger.
	 */
	private static final Logger log = Logger
			.getLogger("tigase.server.bosh.BoshConnectionManager");
	private static final String ROUTINGS_PROP_KEY = "routings";
	private static final String ROUTING_MODE_PROP_KEY = "multi-mode";
	private static final boolean ROUTING_MODE_PROP_VAL = true;
	private static final String ROUTING_ENTRY_PROP_KEY = ".+";
	private static final String ROUTING_ENTRY_PROP_VAL = DEF_SM_NAME + "@localhost";
	private static final int DEF_PORT_NO = 5280;

	// ~--- fields ---------------------------------------------------------------

	private int[] PORTS = { DEF_PORT_NO };

	// private static final String HOSTNAMES_PROP_KEY = "hostnames";
	// private String[] HOSTNAMES_PROP_VAL = {"localhost", "hostname"};
	// private RoutingsContainer routings = null;
	// private Set<String> hostnames = new TreeSet<String>();
	private long max_wait = MAX_WAIT_DEF_PROP_VAL;
	private long min_polling = MIN_POLLING_PROP_VAL;
	private long max_pause = MAX_PAUSE_PROP_VAL;
	private long max_inactivity = MAX_INACTIVITY_PROP_VAL;
	private int hold_requests = HOLD_REQUESTS_PROP_VAL;
	private int concurrent_requests = CONCURRENT_REQUESTS_PROP_VAL;
	private ReceiverTimeoutHandler stoppedHandler = newStoppedHandler();
	private ReceiverTimeoutHandler startedHandler = newStartedHandler();
	// This should be actually a multi-thread save variable.
	// Changing it to 
	private final Map<UUID, BoshSession> sessions = new ConcurrentSkipListMap<UUID, BoshSession>();

	// ~--- methods --------------------------------------------------------------

	/**
	 * Method description
	 * 
	 * 
	 * @param packet
	 * @param bs
	 * 
	 * @return
	 */
	@Override
	public boolean addOutStreamClosed(Packet packet, BoshSession bs) {
		packet.setPacketFrom(getFromAddress(bs.getSid().toString()));
		packet.setPacketTo(bs.getDataReceiver());

		return addOutPacketWithTimeout(packet, stoppedHandler, 15l, TimeUnit.SECONDS);
	}

	/**
	 * 
	 * @param packet
	 * @param bs
	 * @return
	 */
	@Override
	public boolean addOutStreamOpen(Packet packet, BoshSession bs) {
		packet.initVars(getFromAddress(bs.getSid().toString()), bs.getDataReceiver());

		return addOutPacketWithTimeout(packet, startedHandler, 15l, TimeUnit.SECONDS);
	}

	/**
	 * Method description
	 * 
	 * 
	 * @param tt
	 */
	@Override
	public void cancelTask(TimerTask tt) {
		tt.cancel();
	}

	// ~--- get methods ----------------------------------------------------------<commit_msg>Added logging for all packets received by the BoshConnectionManager to make it possible to debug bosh without switching debugging on for other components.<commit_after>/*
 * Tigase Jabber/XMPP Server
 * Copyright (C) 2004-2007 "<NAME>" <<EMAIL>>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License.
 *
 * 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 Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. Look for COPYING file in the top folder.
 * If not, see http://www.gnu.org/licenses/.
 *
 * $Rev$
 * Last modified by $Author$
 * $Date$
 */

package tigase.server.bosh;

//~--- non-JDK imports --------------------------------------------------------

import tigase.server.Command;
import tigase.server.Packet;
import tigase.server.ReceiverTimeoutHandler;
import tigase.server.xmppclient.ClientConnectionManager;

import tigase.xmpp.Authorization;
import tigase.xmpp.JID;
import tigase.xmpp.PacketErrorTypeException;
import tigase.xmpp.StanzaType;
import tigase.xmpp.XMPPIOService;

import static tigase.server.bosh.Constants.*;

//~--- JDK imports ------------------------------------------------------------

import java.util.ArrayDeque;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Queue;
import java.util.TimerTask;
import java.util.UUID;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;

//~--- classes ----------------------------------------------------------------

/**
 * Describe class BoshConnectionManager here.
 * 
 * 
 * Created: Sat Jun 2 12:24:29 2007
 * 
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @version $Rev$
 */
public class BoshConnectionManager extends ClientConnectionManager implements
		BoshSessionTaskHandler {

	/**
	 * Variable <code>log</code> is a class logger.
	 */
	private static final Logger log = Logger
			.getLogger("tigase.server.bosh.BoshConnectionManager");
	private static final String ROUTINGS_PROP_KEY = "routings";
	private static final String ROUTING_MODE_PROP_KEY = "multi-mode";
	private static final boolean ROUTING_MODE_PROP_VAL = true;
	private static final String ROUTING_ENTRY_PROP_KEY = ".+";
	private static final String ROUTING_ENTRY_PROP_VAL = DEF_SM_NAME + "@localhost";
	private static final int DEF_PORT_NO = 5280;

	private int[] PORTS = { DEF_PORT_NO };

	// private static final String HOSTNAMES_PROP_KEY = "hostnames";
	// private String[] HOSTNAMES_PROP_VAL = {"localhost", "hostname"};
	// private RoutingsContainer routings = null;
	// private Set<String> hostnames = new TreeSet<String>();
	private long max_wait = MAX_WAIT_DEF_PROP_VAL;
	private long min_polling = MIN_POLLING_PROP_VAL;
	private long max_pause = MAX_PAUSE_PROP_VAL;
	private long max_inactivity = MAX_INACTIVITY_PROP_VAL;
	private int hold_requests = HOLD_REQUESTS_PROP_VAL;
	private int concurrent_requests = CONCURRENT_REQUESTS_PROP_VAL;
	private ReceiverTimeoutHandler stoppedHandler = newStoppedHandler();
	private ReceiverTimeoutHandler startedHandler = newStartedHandler();
	// This should be actually a multi-thread save variable.
	// Changing it to 
	private final Map<UUID, BoshSession> sessions = new ConcurrentSkipListMap<UUID, BoshSession>();

	@Override
	public void processPacket(final Packet packet) {
		if (log.isLoggable(Level.FINEST)) {
			log.log(Level.FINEST, "Processing packet: {0}", packet.toString());
		}
		super.processPacket(packet);
	}
	/**
	 * Method description
	 * 
	 * 
	 * @param packet
	 * @param bs
	 * 
	 * @return
	 */
	@Override
	public boolean addOutStreamClosed(Packet packet, BoshSession bs) {
		packet.setPacketFrom(getFromAddress(bs.getSid().toString()));
		packet.setPacketTo(bs.getDataReceiver());

		return addOutPacketWithTimeout(packet, stoppedHandler, 15l, TimeUnit.SECONDS);
	}

	/**
	 * 
	 * @param packet
	 * @param bs
	 * @return
	 */
	@Override
	public boolean addOutStreamOpen(Packet packet, BoshSession bs) {
		packet.initVars(getFromAddress(bs.getSid().toString()), bs.getDataReceiver());

		return addOutPacketWithTimeout(packet, startedHandler, 15l, TimeUnit.SECONDS);
	}

	/**
	 * Method description
	 * 
	 * 
	 * @param tt
	 */
	@Override
	public void cancelTask(TimerTask tt) {
		tt.cancel();
	}
{'fraction_non_alphanumeric': 0.15543928493568782, 'fraction_numerical': 0.006213211249182472, 'mean_word_length': 3.366968110423608, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, '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': '1691270', 'n_tokens_mistral': 2795, 'n_tokens_neox': 2632, 'n_words': 758}