<commit_before>package graphsearch.commonCompositionSearch;

import graphcreation.GraphCreationListener;
import graphcreation.GraphCreator;
import graphcreation.GraphCreator.GraphType;
import graphcreation.collisionbased.CollisionGraphCreator;
import graphcreation.collisionbased.ServiceDistance;
import graphcreation.graph.extendedServiceGraph.ExtendedServiceGraph;
import graphcreation.services.Service;
import graphcreation.services.ServiceList;
import graphsearch.CompositionListener;
import graphsearch.CompositionSearch;
import graphsearch.SearchID;
import graphsearch.compositionData.CompositionData;
import graphsearch.compositionData.localSearchesTable.LocalSearchesTable.SearchStatus;
import graphsearch.compositionData.localSearchesTable.SearchExpiredListener;
import graphsearch.connectionsFilter.ConnectionsFilter;
import graphsearch.shortestpathnotificator.ShortestPathListener;
import graphsearch.shortestpathnotificator.ShortestPathNotificator;
import graphsearch.util.Utility;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import multicast.MulticastMessageListener;
import peer.CommunicationLayer;
import peer.Peer;
import peer.RegisterCommunicationLayerException;
import peer.message.BroadcastMessage;
import util.logger.Logger;
import config.Configuration;

public abstract class CommonCompositionSearch implements CommunicationLayer, SearchExpiredListener, MulticastMessageListener, GraphCreationListener, CompositionSearch, ShortestPathListener {

	// a reference to the communication peer
	protected final Peer peer;

	// a reference to the graph creation layer
	protected final GraphCreator gCreator;

	// the listener used to notify compositions related events
	private final CompositionListener compositionListener;

	private ShortestPathNotificator shortestPathNotificator;

	// expiration checking time
	protected final long EXPIRATION_CHECK_TIME = 1000;

	// used to store composition data
	protected CompositionData compositionData;

	// default values
	protected int MAX_TTL = 5;
	protected long SEARCH_EXPIRATION = 10000;

	private final Logger logger = Logger.getLogger(CommonCompositionSearch.class);

	public CommonCompositionSearch(final Peer peer, final CompositionListener compositionListener, final GraphType graphType) {
		this.peer = peer;
		this.gCreator = new CollisionGraphCreator(peer, this, this, graphType);
		this.compositionListener = compositionListener;

		try {
			peer.addCommunicationLayer(this, new HashSet<Class<? extends BroadcastMessage>>());
		} catch (final RegisterCommunicationLayerException e) {
			logger.error("Peer " + peer.getPeerID() + " had problem registering communication layer: " + e.getMessage());
		}
	}

	public void disableMulticastLayer() {
		((CollisionGraphCreator)gCreator).disableMulticastLayer();
	}
	
	public void disableGraphCreationLayer() {
		((CollisionGraphCreator)gCreator).setDisabled();
	}

	@Override
	public void filterConnections(final Map<Service, Set<ServiceDistance>> foundRemoteSuccessors, final Map<Service, Set<ServiceDistance>> foundRemoteAncestors) {
		ConnectionsFilter.filter(foundRemoteSuccessors, foundRemoteAncestors);
	}

	public void notifyComposition(final SearchID searchID, final Set<Service> services, final int hops) {
		// create the extended service graph using the received services
		// TODO when the composition graph is created there could appear more
		// connections. Indirect paths exists among some services/nodes.
		final ExtendedServiceGraph composition = new ExtendedServiceGraph(gCreator.getPSearch().getDisseminationLayer().getTaxonomy());
		for (final Service service : services)
			composition.merge(service);

		logger.debug("Peer " + peer.getPeerID() + " received composition for search " + searchID);
		compositionListener.compositionFound(composition, searchID, hops);
	}

	public void notifyCompositionsLost(final SearchID searchID, final Set<Service> services) {
		final ExtendedServiceGraph invalidComposition = new ExtendedServiceGraph(gCreator.getPSearch().getDisseminationLayer().getTaxonomy());
		for (final Service service : services)
			invalidComposition.merge(service);

		logger.debug("Peer " + peer.getPeerID() + " received invalid composition for search " + searchID);
		compositionListener.compositionsLost(searchID, invalidComposition);
	}<commit_msg> * Average number of hops per composition measured.<commit_after>package graphsearch.commonCompositionSearch;

import graphcreation.GraphCreationListener;
import graphcreation.GraphCreator;
import graphcreation.GraphCreator.GraphType;
import graphcreation.collisionbased.CollisionGraphCreator;
import graphcreation.collisionbased.ServiceDistance;
import graphcreation.graph.extendedServiceGraph.ExtendedServiceGraph;
import graphcreation.services.Service;
import graphcreation.services.ServiceList;
import graphsearch.CompositionListener;
import graphsearch.CompositionSearch;
import graphsearch.SearchID;
import graphsearch.compositionData.CompositionData;
import graphsearch.compositionData.localSearchesTable.LocalSearchesTable.SearchStatus;
import graphsearch.compositionData.localSearchesTable.SearchExpiredListener;
import graphsearch.connectionsFilter.ConnectionsFilter;
import graphsearch.shortestpathnotificator.ShortestPathListener;
import graphsearch.shortestpathnotificator.ShortestPathNotificator;
import graphsearch.util.Utility;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import multicast.MulticastMessageListener;
import peer.CommunicationLayer;
import peer.Peer;
import peer.RegisterCommunicationLayerException;
import peer.message.BroadcastMessage;
import util.logger.Logger;
import config.Configuration;

public abstract class CommonCompositionSearch implements CommunicationLayer, SearchExpiredListener, MulticastMessageListener, GraphCreationListener, CompositionSearch, ShortestPathListener {

	// a reference to the communication peer
	protected final Peer peer;

	// a reference to the graph creation layer
	protected final GraphCreator gCreator;

	// the listener used to notify compositions related events
	private final CompositionListener compositionListener;

	private ShortestPathNotificator shortestPathNotificator;

	// expiration checking time
	protected final long EXPIRATION_CHECK_TIME = 1000;

	// used to store composition data
	protected CompositionData compositionData;

	// default values
	protected int MAX_TTL = 5;
	protected long SEARCH_EXPIRATION = 10000;

	private final Logger logger = Logger.getLogger(CommonCompositionSearch.class);

	public CommonCompositionSearch(final Peer peer, final CompositionListener compositionListener, final GraphType graphType) {
		this.peer = peer;
		this.gCreator = new CollisionGraphCreator(peer, this, this, graphType);
		this.compositionListener = compositionListener;

		try {
			peer.addCommunicationLayer(this, new HashSet<Class<? extends BroadcastMessage>>());
		} catch (final RegisterCommunicationLayerException e) {
			logger.error("Peer " + peer.getPeerID() + " had problem registering communication layer: " + e.getMessage());
		}
	}

	public void disableMulticastLayer() {
		((CollisionGraphCreator)gCreator).disableMulticastLayer();
	}
	
	public void disableGraphCreationLayer() {
		((CollisionGraphCreator)gCreator).setDisabled();
	}

	@Override
	public void filterConnections(final Map<Service, Set<ServiceDistance>> foundRemoteSuccessors, final Map<Service, Set<ServiceDistance>> foundRemoteAncestors) {
		ConnectionsFilter.filter(foundRemoteSuccessors, foundRemoteAncestors);
	}

	public void notifyComposition(final SearchID searchID, final Set<Service> services, final int hops) {
		// create the extended service graph using the received services
		// TODO when the composition graph is created there could appear more
		// connections. Indirect paths exists among some services/nodes.
		final ExtendedServiceGraph composition = new ExtendedServiceGraph(gCreator.getPSearch().getDisseminationLayer().getTaxonomy());
		for (final Service service : services)
			composition.merge(service);

		logger.debug("Peer " + peer.getPeerID() + " received composition for search " + searchID + " hops: " + hops);
		compositionListener.compositionFound(composition, searchID, hops);
	}

	public void notifyCompositionsLost(final SearchID searchID, final Set<Service> services) {
		final ExtendedServiceGraph invalidComposition = new ExtendedServiceGraph(gCreator.getPSearch().getDisseminationLayer().getTaxonomy());
		for (final Service service : services)
			invalidComposition.merge(service);

		logger.debug("Peer " + peer.getPeerID() + " received invalid composition for search " + searchID);
		compositionListener.compositionsLost(searchID, invalidComposition);
	}
{'fraction_non_alphanumeric': 0.07471594169631585, 'fraction_numerical': 0.002295420635831516, 'mean_word_length': 6.994495412844037, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '4442215', 'n_tokens_mistral': 2390, 'n_tokens_neox': 2187, 'n_words': 575}