<commit_before>package gr.ntua.vision.monitoring;

import gr.ntua.vision.monitoring.events.Event;
import gr.ntua.vision.monitoring.rules.VismoAggregationResult;
import gr.ntua.vision.monitoring.sinks.EventSink;

import java.util.Map;


/**
 * 
 */
public class SLAPerRequestChannel implements EventSourceListener {
    /** this is used to get a hold of the whole dict, for serialization reasons. */
    private static final String DICT_KEY      = "!dict";
    /***/
    private static final String SPECIAL_FIELD = "transaction-duration";
    /***/
    private static final String topic         = "sla-per-request";
    /***/
    private final EventSink     sink;


    /**
     * Constructor.
     * 
     * @param sink
     */
    public SLAPerRequestChannel(final EventSink sink) {
        this.sink = sink;
    }


    /**
     * @see gr.ntua.vision.monitoring.EventSourceListener#receive(gr.ntua.vision.monitoring.events.Event)
     */
    @SuppressWarnings("unchecked")
    @Override
    public void receive(final Event e) {
        if (!isCompleteObsEvent(e))
            return;

        @SuppressWarnings("rawtypes")
        final Map dict = (Map) e.get(DICT_KEY);

        dict.put("topic", topic);

        final VismoAggregationResult r = new VismoAggregationResult(dict);

        sink.send(r);
    }


    /**
     * Is this a complete object service event? Since we receive all events from object service, some of them are incomplete, in
     * the sense that contain parts of the request/response cycle.
     * 
     * @param e
     *            the event.
     * @return <code>true</code> iff the
     */
    private static boolean isCompleteObsEvent(final Event e) {
        return e.get(SPECIAL_FIELD) != null;
    }
}<commit_msg>fixing sla-per-request event schema<commit_after>package gr.ntua.vision.monitoring;

import gr.ntua.vision.monitoring.events.Event;
import gr.ntua.vision.monitoring.sinks.EventSink;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 
 */
public class SLAPerRequestChannel implements EventSourceListener {
	/***/
	private static final String SPECIAL_FIELD = "transaction-duration";
	/***/
	private final EventSink sink;

	/**
	 * Constructor.
	 * 
	 * @param sink
	 */
	public SLAPerRequestChannel(final EventSink sink) {
		this.sink = sink;
	}

	/**
	 *
	 */
	private static class SLAEvent implements Event {
		private final Event e;
		/***/
		private static final String topic = "sla-per-request";

		/**
		 * Constructor.
		 * 
		 * @param e
		 */
		public SLAEvent(Event e) {
			this.e = e;
		}

		@Override
		public Object get(String key) {
			return e.get(key);
		}

		@Override
		public InetAddress originatingIP() throws UnknownHostException {
			return e.originatingIP();
		}

		@Override
		public String originatingService() {
			return e.originatingService();
		}

		@Override
		public long timestamp() {
			return e.timestamp();
		}

		@Override
		public String topic() {
			return topic;
		}

	}

	/**
	 * @see gr.ntua.vision.monitoring.EventSourceListener#receive(gr.ntua.vision.monitoring.events.Event)
	 */
	@Override
	public void receive(final Event e) {
		if (!isCompleteObsEvent(e))
			return;

		sink.send(new SLAEvent(e));
	}

	/**
	 * Is this a complete object service event? Since we receive all events from
	 * object service, some of them are incomplete, in the sense that contain
	 * parts of the request/response cycle.
	 * 
	 * @param e
	 *            the event.
	 * @return <code>true</code> iff the
	 */
	private static boolean isCompleteObsEvent(final Event e) {
		return e.get(SPECIAL_FIELD) != null;
	}
}
{'fraction_non_alphanumeric': 0.11249653643668606, 'fraction_numerical': 0.0, 'mean_word_length': 2.8692390139335475, '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': '6963592', 'n_tokens_mistral': 1186, 'n_tokens_neox': 1093, 'n_words': 287}