001/*
002 * HA-JDBC: High-Availability JDBC
003 * Copyright (C) 2012  Paul Ferraro
004 *
005 * This program is free software: you can redistribute it and/or modify
006 * it under the terms of the GNU Lesser General Public License as published by
007 * the Free Software Foundation, either version 3 of the License, or
008 * (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013 * GNU Lesser General Public License for more details.
014 *
015 * You should have received a copy of the GNU Lesser General Public License
016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
017 */
018package net.sf.hajdbc.distributed;
019
020import java.util.Map;
021
022import net.sf.hajdbc.Lifecycle;
023
024/**
025 * RPC dispatcher that uses the command pattern.
026 * @author Paul Ferraro
027 *
028 * @param <C> the command context type
029 */
030public interface CommandDispatcher<C> extends Lifecycle
031{
032        /**
033         * Execute the specified command on all members, potentially excluding some.
034         * @param <R> the return value type
035         * @param command the command to execute
036         * @param excludedMembers list of members to optionally exclude
037         * @return a map of command execution results per member.
038         */
039        <R> Map<Member, R> executeAll(Command<R, C> command, Member... excludedMembers);
040
041        /**
042         * Execute the specified command on the specified member.
043         * @param <R> the return value type
044         * @param command the command to execute
045         * @param member the member on which to execute the command
046         * @return the result of the command execution
047         */
048        <R> R execute(Command<R, C> command, Member member);
049
050        /**
051         * Returns the local member.
052         * @return the local member.
053         */
054        Member getLocal();
055        
056        /**
057         * Returns the group coordinator.
058         * @return the group coordinator.
059         */
060        Member getCoordinator();
061}