001    /******************************************************************************
002     * Copyright (C) MActor Developers. All rights reserved.                        *
003     * ---------------------------------------------------------------------------*
004     * This file is part of MActor.                                               *
005     *                                                                            *
006     * MActor is free software; you can redistribute it and/or modify             *
007     * it under the terms of the GNU General Public License as published by       *
008     * the Free Software Foundation; either version 2 of the License, or          *
009     * (at your option) any later version.                                        *
010     *                                                                            *
011     * MActor is distributed in the hope that it will be useful,                  *
012     * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
013     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
014     * GNU General Public License for more details.                               *
015     *                                                                            *
016     * You should have received a copy of the GNU General Public License          *
017     * along with MActor; if not, write to the Free Software                      *
018     * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA *
019     ******************************************************************************/
020    package org.mactor.brokers;
021    
022    import org.mactor.framework.MactorException;
023    import org.mactor.framework.extensioninterface.MessageSelectorCommand;
024    
025    /**
026     * Defines the message broker interface
027     * <p>
028     * Message broker implementations is not requiered to implement both publish and
029     * subscribe (UnsupportedOperationException should be thrown by methods not
030     * implemented by the message broker)
031     * </p>
032     * <p>
033     * Message broker implementations must have contructor that takes a
034     * 
035     * <pre>
036     * MessageBrokerConfig
037     * </pre>
038     * 
039     * as the single parameter
040     * </p>
041     * 
042     * <p>
043     * The simplest way to implement a message broker is to extend the
044     * AbstractMessageBroker class, or the PollingMessageBrokerTemplate if the
045     * protocol is polling based (i.e. the case for FilesMessageBroker)
046     * </p>
047     * 
048     * @author Lars Ivar Almli
049     */
050    public interface MessageBroker {
051            /**
052             * Subscibe to message from a channel
053             * 
054             * @param channel
055             *            the channel
056             * @param subscriber
057             *            the subscriber that will receive the messages
058             * @param messageSelector
059             *            the message selector restricts which messages to receive from
060             *            the channel
061             * @throws MactorException
062             *             if some problem occures (this will cause the test to fail)
063             */
064            void subscribe(String channel, MessageSubscriber subscriber, MessageSelectorCommand messageSelector) throws MactorException;
065            /**
066             * Unsubscribe
067             * 
068             * @param channel
069             *            the channel
070             * @param subscriber
071             *            the subscriber
072             * @throws MactorException
073             *             if some problem occures
074             */
075            void unsubscribe(String channel, MessageSubscriber subscriber) throws MactorException;
076            /**
077             * Publish a message to a channel
078             * 
079             * @param channel
080             *            the channel
081             * @param message
082             *            the message
083             * @throws MactorException
084             *             if some problem occures (this will cause the test to fail)
085             */
086            void publish(String channel, Message message) throws MactorException;
087            /**
088             * Publish a message and expect a reponse (when dealing with synchrounous
089             * protcols)
090             * 
091             * @param channel
092             *            the channel
093             * @param message
094             *            the message
095             * @return the response message
096             * @throws MactorException
097             *             if some problem occures (this will cause the test to fail)
098             */
099            Message publishWithResponse(String channel, Message message) throws MactorException;
100            void terminate();
101    }