/*
 * Copyright (c) 2004-2017, by Alex Leigh.
 * All rights reserved.
 *
 * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE
 * The copyright notice above does not evidence any
 * actual or intended publication of such source code.
 */

package lc.mecha.fabric;

public class SynchronousFabric<E> implements MessageFabric<E> {
    private final TopicSubscriptionBase<E> subBase = new TopicSubscriptionBase<>();

    @Override
    public void send(final String symbol, final E msg) throws Throwable {
        for (final MessageSubscription<E> sub : subBase.matching(symbol)) {
            // FIXME: This needs some understanding of when to stop processing
            HandlerStatus hs = sub.getSubscriber().receive(msg);

            switch (hs) {
                case CONTINUE:
                    continue;
                case BREAK:
                    return;
            }
        }
    }

    /**
     * Returns the <code>SubscriptionBase</code> associated with this fabric.
     *
     * @return
     */
    @Override
    public SubscriptionBase<E> getSubscriptionBase() {
        return subBase;
    }
}