<commit_before>package com.relayrides.pushy;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;

import java.util.List;
import java.util.Vector;

public class MockApnsServer {
	
	private EventLoopGroup bossGroup;
	private EventLoopGroup workerGroup;
	
	private final int port;
	private final int maxPayloadSize;
	
	private final Vector<SimpleApnsPushNotification> receivedNotifications;
	
	private int failWithErrorCount = -1;
	private ApnsErrorCode errorCode;
	
	private int silentlyCloseCount = -1;
	
	public MockApnsServer(final int port, final int maxPayloadSize) {
		this.port = port;
		this.maxPayloadSize = maxPayloadSize;
		
		this.receivedNotifications = new Vector<SimpleApnsPushNotification>();
	}
	
	public void start() {
		this.bossGroup = new NioEventLoopGroup();
		this.workerGroup = new NioEventLoopGroup();
		
		final ServerBootstrap bootstrap = new ServerBootstrap();
		
		bootstrap.group(bossGroup, workerGroup);
		bootstrap.channel(NioServerSocketChannel.class);
		
		final MockApnsServer server = this;
		
		bootstrap.childHandler(new ChannelInitializer<SocketChannel>() {

			@Override
			protected void initChannel(final SocketChannel channel) throws Exception {
				channel.pipeline().addLast("decoder", new ApnsPushNotificationDecoder(maxPayloadSize));
				channel.pipeline().addLast("encoder", new ApnsErrorEncoder());
				channel.pipeline().addLast("handler", new MockApnsServerHandler(server));
			}
			
		});
		
		bootstrap.childOption(ChannelOption.SO_KEEPALIVE, true);
		
		bootstrap.bind(this.port);
	}
	
	public void shutdown() {
		this.workerGroup.shutdownGracefully();
		this.bossGroup.shutdownGracefully();
	}
	
	public void failWithErrorAfterNotifications(final ApnsErrorCode errorCode, final int notificationCount) {
		this.failWithErrorCount = notificationCount;
		this.errorCode = errorCode;
	}
	
	protected ApnsErrorCode getErrorCodeForReceivedNotificationCount(final int notificationCount) {
		if (notificationCount == this.failWithErrorCount) {
			return this.errorCode;
		} else {
			return null;
		}
	}
	
	public void silentlyCloseConnectionAfterNotifications(final int notificationCount) {
		this.silentlyCloseCount = notificationCount;
	}
	
	protected boolean shouldCloseSilentlyForNotificationCount(final int notificationCount) {
		return notificationCount == this.silentlyCloseCount;
	}
	
	protected void addReceivedNotification(final SimpleApnsPushNotification notification) {
		this.receivedNotifications.add(notification);
	}
	
	public List<SimpleApnsPushNotification> getReceivedNotifications() {
		return java.util.Collections.unmodifiableList(this.receivedNotifications);
	}
}<commit_msg>Fixed another potential sticky reference bug in the mock APNS server.<commit_after>package com.relayrides.pushy;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;

import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

public class MockApnsServer {
	
	private EventLoopGroup bossGroup;
	private EventLoopGroup workerGroup;
	
	private final int port;
	private final int maxPayloadSize;
	
	private final Vector<SimpleApnsPushNotification> receivedNotifications;
	
	private int failWithErrorCount = -1;
	private ApnsErrorCode errorCode;
	
	private int silentlyCloseCount = -1;
	
	public MockApnsServer(final int port, final int maxPayloadSize) {
		this.port = port;
		this.maxPayloadSize = maxPayloadSize;
		
		this.receivedNotifications = new Vector<SimpleApnsPushNotification>();
	}
	
	public void start() {
		this.bossGroup = new NioEventLoopGroup();
		this.workerGroup = new NioEventLoopGroup();
		
		final ServerBootstrap bootstrap = new ServerBootstrap();
		
		bootstrap.group(bossGroup, workerGroup);
		bootstrap.channel(NioServerSocketChannel.class);
		
		final MockApnsServer server = this;
		
		bootstrap.childHandler(new ChannelInitializer<SocketChannel>() {

			@Override
			protected void initChannel(final SocketChannel channel) throws Exception {
				channel.pipeline().addLast("decoder", new ApnsPushNotificationDecoder(maxPayloadSize));
				channel.pipeline().addLast("encoder", new ApnsErrorEncoder());
				channel.pipeline().addLast("handler", new MockApnsServerHandler(server));
			}
			
		});
		
		bootstrap.childOption(ChannelOption.SO_KEEPALIVE, true);
		
		bootstrap.bind(this.port);
	}
	
	public void shutdown() {
		this.workerGroup.shutdownGracefully();
		this.bossGroup.shutdownGracefully();
	}
	
	public void failWithErrorAfterNotifications(final ApnsErrorCode errorCode, final int notificationCount) {
		this.failWithErrorCount = notificationCount;
		this.errorCode = errorCode;
	}
	
	protected ApnsErrorCode getErrorCodeForReceivedNotificationCount(final int notificationCount) {
		if (notificationCount == this.failWithErrorCount) {
			return this.errorCode;
		} else {
			return null;
		}
	}
	
	public void silentlyCloseConnectionAfterNotifications(final int notificationCount) {
		this.silentlyCloseCount = notificationCount;
	}
	
	protected boolean shouldCloseSilentlyForNotificationCount(final int notificationCount) {
		return notificationCount == this.silentlyCloseCount;
	}
	
	protected void addReceivedNotification(final SimpleApnsPushNotification notification) {
		this.receivedNotifications.add(notification);
	}
	
	public List<SimpleApnsPushNotification> getReceivedNotifications() {
		return new ArrayList<SimpleApnsPushNotification>(this.receivedNotifications);
	}
}
{'fraction_non_alphanumeric': 0.08444745303773904, 'fraction_numerical': 0.0006769334912844813, 'mean_word_length': 5.73120728929385, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, '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': '3745839', 'n_tokens_mistral': 1807, 'n_tokens_neox': 1618, 'n_words': 343}