<commit_before>package net.rubyeye.xmemcached;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import net.rubyeye.xmemcached.command.Command;
import net.spy.memcached.transcoders.CachedData;
import net.spy.memcached.transcoders.Transcoder;

import com.google.code.yanf4j.nio.Session;
import com.google.code.yanf4j.nio.impl.HandlerAdapter;
import com.google.code.yanf4j.util.Queue;
import com.google.code.yanf4j.util.SimpleQueue;

public class MemcachedHandler extends HandlerAdapter<Command> {
	@SuppressWarnings("unchecked")
	private Transcoder transcoder;

	protected Queue<Command> executingCmds = new SimpleQueue<Command>();

	protected XMemcachedClient client;

	private static final int MAX_TRIES = 5;

	protected static final Log log = LogFactory.getLog(MemcachedHandler.class);

	private int connectTries = 0;

	@Override
	public void onMessageSent(Session session, Command t) {
		try {
			if (t.getMergeCommands() == null) {
				executingCmds.push(t);
			} else {
				List<Command> mergeCmds = t.getMergeCommands();
				for (Command cmd : mergeCmds) {
					executingCmds.push(cmd);
				}

			}
		} catch (InterruptedException e) {

		}
	}

	@Override
	public void onReceive(Session session, final Command recvCmd) {
		try {
			final Command executingCmd = executingCmds.pop();
			if (executingCmd == null)
				return;
			if (recvCmd.getException() != null) {
				executingCmd.setException(recvCmd.getException());
				executingCmd.getLatch().countDown();
			} else {

				switch (executingCmd.getCommandType()) {
				case EXCEPTION:
				case GET_MANY:
					processGetManyCommand(recvCmd, executingCmd);
					break;
				case GET_ONE:
					processGetOneCommand(session, recvCmd, executingCmd);
					break;
				case SET:
				case ADD:
				case REPLACE:
				case DELETE:
				case INCR:
				case DECR:
				case VERSION:
					processCommand(recvCmd, executingCmd);
					break;
				}
			}
		} catch (InterruptedException e) {
			Thread.currentThread().interrupt();
		}

	}

	private void processCommand(Command recvCmd, Command executingCmd) {
		executingCmd.setResult(recvCmd.getResult());
		executingCmd.getLatch().countDown();
	}<commit_msg>减小try catch范围<commit_after>package net.rubyeye.xmemcached;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import net.rubyeye.xmemcached.command.Command;
import net.spy.memcached.transcoders.CachedData;
import net.spy.memcached.transcoders.Transcoder;

import com.google.code.yanf4j.nio.Session;
import com.google.code.yanf4j.nio.impl.HandlerAdapter;
import com.google.code.yanf4j.util.Queue;
import com.google.code.yanf4j.util.SimpleQueue;

public class MemcachedHandler extends HandlerAdapter<Command> {
	@SuppressWarnings("unchecked")
	private Transcoder transcoder;

	protected Queue<Command> executingCmds = new SimpleQueue<Command>();

	protected XMemcachedClient client;

	private static final int MAX_TRIES = 5;

	protected static final Log log = LogFactory.getLog(MemcachedHandler.class);

	private int connectTries = 0;
	ExecutorService executors = Executors.newCachedThreadPool();

	@Override
	public void onMessageSent(Session session, Command t) {
		try {
			if (t.getMergeCommands() == null) {
				executingCmds.push(t);
			} else {
				List<Command> mergeCmds = t.getMergeCommands();
				for (Command cmd : mergeCmds) {
					executingCmds.push(cmd);
				}

			}
		} catch (InterruptedException e) {

		}
	}

	@Override
	public void onReceive(Session session, final Command recvCmd) {
		Command executingCmd = null;
		try {
			executingCmd = executingCmds.pop();
		} catch (InterruptedException e) {
			Thread.currentThread().interrupt();
		}
		if (executingCmd == null)
			return;
		if (recvCmd.getException() != null) {
			executingCmd.setException(recvCmd.getException());
			executingCmd.getLatch().countDown();
		} else {

			switch (executingCmd.getCommandType()) {
			case EXCEPTION:
			case GET_MANY:
				processGetManyCommand(recvCmd, executingCmd);
				break;
			case GET_ONE:
				processGetOneCommand(session, recvCmd, executingCmd);
				break;
			case SET:
			case ADD:
			case REPLACE:
			case DELETE:
			case INCR:
			case DECR:
			case VERSION:
				processCommand(recvCmd, executingCmd);
				break;
			}
		}

	}

	private void processCommand(Command recvCmd, Command executingCmd) {
		executingCmd.setResult(recvCmd.getResult());
		executingCmd.getLatch().countDown();
	}
{'fraction_non_alphanumeric': 0.1072642310960068, 'fraction_numerical': 0.002548853016142736, 'mean_word_length': 4.32090395480226, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '7384542', 'n_tokens_mistral': 1755, 'n_tokens_neox': 1533, 'n_words': 313}