<commit_before>package org.qfox.jestful.interception;

import org.qfox.jestful.core.*;
import org.qfox.jestful.core.exception.BeanConfigException;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

/**
 * Created by Payne on 2017/5/5.
 */
public class Interception implements Plugin, Initialable, Destroyable {
    private final Collection<Listener> listeners = new ArrayList<Listener>();
    private final Interceptor interceptor = new Interceptor() {
        @Override
        public Object intercept(Invocation invocation) throws Exception {
            return invocation.execute();
        }
    };
    private final Queue<Invocation> queue = new ConcurrentLinkedQueue<Invocation>();

    @Override
    public void config(Map<String, String> arguments) throws BeanConfigException {
        for (Listener listener : listeners) listener.config(arguments);
    }

    @Override
    public Object react(Action action) throws Exception {
        Invocation invocation = queue.poll();
        if (invocation == null) invocation = new Invocation();
        try {
            invocation.reset(action);
            for (Listener listener : listeners) if (listener.matches(action)) invocation.accept(listener);
            invocation.accept(interceptor);
            Object value = invocation.invoke();
            action.getResult().getBody().setValue(value);
            return value;
        } catch (Exception e) {
            throw e;
        } finally {
            queue.offer(invocation);
        }
    }

    @Override
    public void initialize(BeanContainer beanContainer) {
        Collection<Interceptor> interceptors = beanContainer.find(Interceptor.class).values();
        for (Interceptor interceptor : interceptors) listeners.add(new Listener(interceptor));
    }

    @Override
    public void destroy() {
        for (Listener listener : listeners) listener.destroy();
        listeners.clear();
    }

}
<commit_msg>Add Interception Module<commit_after>package org.qfox.jestful.interception;

import org.qfox.jestful.core.*;
import org.qfox.jestful.core.exception.BeanConfigException;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

/**
 * Created by Payne on 2017/5/5.
 */
public class Interception implements Plugin, Initialable, Destroyable {
    private final Collection<Listener> listeners = new ArrayList<Listener>();
    private final Interceptor interceptor = new Interceptor() {
        @Override
        public Object intercept(Invocation invocation) throws Exception {
            return invocation.execute();
        }
    };
    private final Queue<Invocation> queue = new ConcurrentLinkedQueue<Invocation>();

    @Override
    public void config(Map<String, String> arguments) throws BeanConfigException {
        for (Listener listener : listeners) listener.config(arguments);
    }

    @Override
    public Object react(Action action) throws Exception {
        Invocation invocation = queue.poll();
        if (invocation == null) invocation = new Invocation();
        try {
            Result result = action.getResult();
            Body body = result.getBody();

            invocation.reset(action);
            for (Listener listener : listeners) if (listener.matches(action)) invocation.accept(listener);
            invocation.accept(interceptor);
            Object value = invocation.invoke();

            result.setValue(value);
            body.setValue(value);

            return value;
        } catch (Exception e) {
            throw e;
        } finally {
            queue.offer(invocation);
        }
    }

    @Override
    public void initialize(BeanContainer beanContainer) {
        Collection<Interceptor> interceptors = beanContainer.find(Interceptor.class).values();
        for (Interceptor interceptor : interceptors) listeners.add(new Listener(interceptor));
    }

    @Override
    public void destroy() {
        for (Listener listener : listeners) listener.destroy();
        listeners.clear();
    }

}

{'fraction_non_alphanumeric': 0.09839980893240984, 'fraction_numerical': 0.002866013852400287, 'mean_word_length': 2.93609022556391, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '2565325', 'n_tokens_mistral': 1077, 'n_tokens_neox': 1030, 'n_words': 271}