<commit_before>//
// BatchConnectionRequest.java
// xal
//
// Created by <NAME> on 6/14/12
// Copyright 2012 Oak Ridge National Lab. All rights reserved.
//

package xal.ca;

import xal.tools.messaging.*;
import xal.tools.dispatch.*;

import java.util.*;
import java.util.concurrent.Callable;


/** BatchConnectionRequest */
public class BatchConnectionRequest extends java.lang.Object {
	/** time (msec) to periodically watch for status when waiting for connections */
	static final private long WATCH_TIME = 100;
	
	/** message center for dispatching events */
	final private MessageCenter MESSAGE_CENTER;
	
	/** proxy which forwards events to registered listeners */
	final private BatchConnectionRequestListener EVENT_PROXY;
	
	/** set of channels for which to request batch operations */
	final private Set<Channel> CHANNELS;
	
	/** table of get request exceptions keyed by channel */
	final private Map<Channel,Exception> EXCEPTIONS;
	
	/** channels pending completion */
	final private Set<Channel> PENDING_CHANNELS;
	
	/** channels that have been connected */
	final private Set<Channel> CONNECTED_CHANNELS;
	
	/** channels that have been connected */
	final private Set<Channel> DISCONNECTED_CHANNELS;
	
	/** object used for waiting and notification */
	final private Object COMPLETION_LOCK;
	
	/** queue to synchronize access to resources */
	final private DispatchQueue RESOURCE_SYNC_QUEUE;
	
	/** request handler */
	final private RequestHandler REQUEST_HANDLER;
	
	/** indicates whether this request has been canceled */
	private volatile boolean _isCanceled;

	
	/** Constructor */
    public BatchConnectionRequest( final Collection<Channel> channels ) {
		MESSAGE_CENTER = new MessageCenter( "BatchConnectionRequest" );
		EVENT_PROXY = MESSAGE_CENTER.registerSource( this, BatchConnectionRequestListener.class );
		
		COMPLETION_LOCK = new Object();
		RESOURCE_SYNC_QUEUE = DispatchQueue.createConcurrentQueue( "Resource Synchronization" );
		
		CONNECTED_CHANNELS = new HashSet<Channel>();
		DISCONNECTED_CHANNELS = new HashSet<Channel>();
		EXCEPTIONS = new HashMap<Channel,Exception>();
		PENDING_CHANNELS = new HashSet<Channel>();
		
		CHANNELS = new HashSet<Channel>( channels.size() );
		CHANNELS.addAll( channels );
		
		REQUEST_HANDLER = new RequestHandler();
    }
	
	<commit_msg>-n  Dispose of the resource sync queue when no longer needed.<commit_after>//
// BatchConnectionRequest.java
// xal
//
// Created by <NAME> on 6/14/12
// Copyright 2012 Oak Ridge National Lab. All rights reserved.
//

package xal.ca;

import xal.tools.messaging.*;
import xal.tools.dispatch.*;

import java.util.*;
import java.util.concurrent.Callable;


/** BatchConnectionRequest */
public class BatchConnectionRequest extends java.lang.Object {
	/** time (msec) to periodically watch for status when waiting for connections */
	static final private long WATCH_TIME = 100;
	
	/** message center for dispatching events */
	final private MessageCenter MESSAGE_CENTER;
	
	/** proxy which forwards events to registered listeners */
	final private BatchConnectionRequestListener EVENT_PROXY;
	
	/** set of channels for which to request batch operations */
	final private Set<Channel> CHANNELS;
	
	/** table of get request exceptions keyed by channel */
	final private Map<Channel,Exception> EXCEPTIONS;
	
	/** channels pending completion */
	final private Set<Channel> PENDING_CHANNELS;
	
	/** channels that have been connected */
	final private Set<Channel> CONNECTED_CHANNELS;
	
	/** channels that have been connected */
	final private Set<Channel> DISCONNECTED_CHANNELS;
	
	/** object used for waiting and notification */
	final private Object COMPLETION_LOCK;
	
	/** queue to synchronize access to resources */
	final private DispatchQueue RESOURCE_SYNC_QUEUE;
	
	/** request handler */
	final private RequestHandler REQUEST_HANDLER;
	
	/** indicates whether this request has been canceled */
	private volatile boolean _isCanceled;

	
	/** Constructor */
    public BatchConnectionRequest( final Collection<Channel> channels ) {
		MESSAGE_CENTER = new MessageCenter( "BatchConnectionRequest" );
		EVENT_PROXY = MESSAGE_CENTER.registerSource( this, BatchConnectionRequestListener.class );
		
		COMPLETION_LOCK = new Object();
		RESOURCE_SYNC_QUEUE = DispatchQueue.createConcurrentQueue( "Resource Synchronization" );
		
		CONNECTED_CHANNELS = new HashSet<Channel>();
		DISCONNECTED_CHANNELS = new HashSet<Channel>();
		EXCEPTIONS = new HashMap<Channel,Exception>();
		PENDING_CHANNELS = new HashSet<Channel>();
		
		CHANNELS = new HashSet<Channel>( channels.size() );
		CHANNELS.addAll( channels );
		
		REQUEST_HANDLER = new RequestHandler();
    }


	/** dispose of the queue */
	protected void finalize() throws Throwable {
		RESOURCE_SYNC_QUEUE.dispose();
	}
	
	
{'fraction_non_alphanumeric': 0.09327185076503877, 'fraction_numerical': 0.0050303919513728776, 'mean_word_length': 4.447488584474886, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, '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': '4022147', 'n_tokens_mistral': 1413, 'n_tokens_neox': 1288, 'n_words': 418}