<commit_before>package com.ikasoa.core.nifty;

import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelStateEvent;
import org.jboss.netty.channel.SimpleChannelUpstreamHandler;

public class ConnectionContextHandler extends SimpleChannelUpstreamHandler {
	@Override
	public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
		super.channelConnected(ctx, e);

		NiftyConnectionContext context = new NiftyConnectionContext();
		context.setRemoteAddress(ctx.getChannel().getRemoteAddress());

		ctx.setAttachment(context);
	}
};<commit_msg>Update ConnectionContextHandler.java<commit_after>package com.ikasoa.core.nifty;

import java.net.SocketAddress;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelStateEvent;
import org.jboss.netty.channel.SimpleChannelUpstreamHandler;

public class ConnectionContextHandler extends SimpleChannelUpstreamHandler {

	@Override
	public void channelConnected(ChannelHandlerContext context, ChannelStateEvent e) throws Exception {
		super.channelConnected(context, e);
		IkasoaConnectionContext ikasoaConnectionContext = new IkasoaConnectionContext();
		ikasoaConnectionContext.setRemoteAddress(context.getChannel().getRemoteAddress());
		context.setAttachment(context);
	}

	private class IkasoaConnectionContext implements ConnectionContext {

		private SocketAddress remoteAddress;
		private Map<String, Object> attributes = new ConcurrentHashMap<>();

		@Override
		public SocketAddress getRemoteAddress() {
			return remoteAddress;
		}

		public void setRemoteAddress(SocketAddress remoteAddress) {
			this.remoteAddress = remoteAddress;
		}

		@Override
		public Object getAttribute(String attributeName) {
			if (attributeName == null)
				throw new NullPointerException();
			return attributes.get(attributeName);
		}

		@Override
		public Object setAttribute(String attributeName, Object value) {
			if (attributeName == null)
				throw new NullPointerException();
			if (value == null)
				throw new NullPointerException();
			return attributes.put(attributeName, value);
		}

		@Override
		public Object removeAttribute(String attributeName) {
			if (attributeName == null)
				throw new NullPointerException();
			return attributes.remove(attributeName);
		}

		@Override
		public Iterator<Map.Entry<String, Object>> attributeIterator() {
			return Collections.unmodifiableSet(attributes.entrySet()).iterator();
		}
	}

};
{'fraction_non_alphanumeric': 0.08735632183908046, 'fraction_numerical': 0.0, 'mean_word_length': 6.133879781420765, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6205410', 'n_tokens_mistral': 773, 'n_tokens_neox': 697, 'n_words': 152}