Search in sources :

Example 21 with AbstractExchange

use of com.predic8.membrane.core.exchange.AbstractExchange in project service-proxy by membrane.

the class ElasticSearchExchangeStore method getStatistics.

@Override
public StatisticCollector getStatistics(RuleKey ruleKey) {
    StatisticCollector statistics = new StatisticCollector(false);
    List<AbstractExchange> exchangesList = Arrays.asList(getExchanges(ruleKey));
    if (exchangesList == null || exchangesList.isEmpty())
        return statistics;
    for (int i = 0; i < exchangesList.size(); i++) statistics.collectFrom(exchangesList.get(i));
    return statistics;
}
Also used : AbstractExchange(com.predic8.membrane.core.exchange.AbstractExchange) StatisticCollector(com.predic8.membrane.core.rules.StatisticCollector)

Example 22 with AbstractExchange

use of com.predic8.membrane.core.exchange.AbstractExchange in project service-proxy by membrane.

the class LimitedMemoryExchangeStore method addObservers.

private void addObservers(AbstractExchange exc, AbstractExchange excCopy, Flow flow) throws Exception {
    Message msg = null;
    if (flow == Flow.REQUEST) {
        msg = exc.getRequest();
    } else
        msg = exc.getResponse();
    msg.addObserver(new MessageObserver() {

        @Override
        public void bodyRequested(AbstractBody body) {
        }

        @Override
        public void bodyComplete(AbstractBody body) {
            try {
                cleanSnapshot(Exchange.updateCopy(exc, excCopy));
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    });
    exc.addExchangeViewerListener(new AbstractExchangeViewerListener() {

        @Override
        public void setExchangeFinished() {
            try {
                cleanSnapshot(Exchange.updateCopy(exc, excCopy));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
    cleanSnapshot(Exchange.updateCopy(exc, excCopy));
}
Also used : AbstractExchangeViewerListener(com.predic8.membrane.core.model.AbstractExchangeViewerListener)

Example 23 with AbstractExchange

use of com.predic8.membrane.core.exchange.AbstractExchange in project service-proxy by membrane.

the class LimitedMemoryExchangeStore method getStatistics.

public synchronized StatisticCollector getStatistics(RuleKey key) {
    StatisticCollector statistics = new StatisticCollector(false);
    List<AbstractExchange> exchangesList = getExchangeList(key);
    if (exchangesList == null || exchangesList.isEmpty())
        return statistics;
    for (int i = 0; i < exchangesList.size(); i++) statistics.collectFrom(exchangesList.get(i));
    return statistics;
}
Also used : AbstractExchange(com.predic8.membrane.core.exchange.AbstractExchange) StatisticCollector(com.predic8.membrane.core.rules.StatisticCollector)

Example 24 with AbstractExchange

use of com.predic8.membrane.core.exchange.AbstractExchange in project service-proxy by membrane.

the class LimitedMemoryExchangeStore method newSnap.

private void newSnap(AbstractExchange exc, Flow flow) {
    AbstractExchange excCopy = null;
    try {
        if (flow == Flow.REQUEST) {
            excCopy = cleanSnapshot(exc.createSnapshot());
            snapInternal(excCopy, flow);
        } else
            excCopy = cleanSnapshot(Exchange.updateCopy(exc, getExchangeById((int) exc.getId())));
        addObservers(exc, excCopy, flow);
        modify();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : AbstractExchange(com.predic8.membrane.core.exchange.AbstractExchange)

Example 25 with AbstractExchange

use of com.predic8.membrane.core.exchange.AbstractExchange in project service-proxy by membrane.

the class MemoryExchangeStore method snap.

public void snap(AbstractExchange exc, Flow flow) {
    if (flow != Flow.REQUEST)
        return;
    if (isKeyInStore(exc)) {
        getKeyList(exc).add(exc);
    } else {
        List<AbstractExchange> list = new Vector<AbstractExchange>();
        list.add(exc);
        exchangesMap.put(exc.getRule().getKey(), list);
    }
    totals.add(exc);
    for (IExchangesStoreListener listener : exchangesStoreListeners) {
        exc.addExchangeStoreListener(listener);
        listener.addExchange(exc.getRule(), exc);
    }
}
Also used : IExchangesStoreListener(com.predic8.membrane.core.model.IExchangesStoreListener) AbstractExchange(com.predic8.membrane.core.exchange.AbstractExchange) Vector(java.util.Vector)

Aggregations

AbstractExchange (com.predic8.membrane.core.exchange.AbstractExchange)17 IOException (java.io.IOException)7 Exchange (com.predic8.membrane.core.exchange.Exchange)5 AbstractExchangeSnapshot (com.predic8.membrane.core.exchange.snapshots.AbstractExchangeSnapshot)4 DynamicAbstractExchangeSnapshot (com.predic8.membrane.core.exchange.snapshots.DynamicAbstractExchangeSnapshot)4 Message (com.predic8.membrane.core.http.Message)4 IExchangesStoreListener (com.predic8.membrane.core.model.IExchangesStoreListener)4 StatisticCollector (com.predic8.membrane.core.rules.StatisticCollector)4 UnknownHostException (java.net.UnknownHostException)4 CacheBuilder (com.google.common.cache.CacheBuilder)3 AbstractExchangeViewerListener (com.predic8.membrane.core.model.AbstractExchangeViewerListener)3 JsonGenerationException (com.fasterxml.jackson.core.JsonGenerationException)2 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)2 MCElement (com.predic8.membrane.annot.MCElement)2 AbstractBody (com.predic8.membrane.core.http.AbstractBody)2 Header (com.predic8.membrane.core.http.Header)2 JSONContent (com.predic8.membrane.core.interceptor.rest.JSONContent)2 SQLException (java.sql.SQLException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Cache (com.google.common.cache.Cache)1