001/*
002 * JGrapes Event Driven Framework
003 * Copyright (C) 2017-2018 Michael N. Lipp
004 * 
005 * This program is free software; you can redistribute it and/or modify it 
006 * under the terms of the GNU Affero 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, but 
011 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
012 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License 
013 * for more details.
014 * 
015 * You should have received a copy of the GNU Affero General Public License along 
016 * with this program; if not, see <http://www.gnu.org/licenses/>.
017 */
018
019package org.jgrapes.util.events;
020
021import java.util.Map;
022
023import org.jgrapes.core.Channel;
024import org.jgrapes.core.Event;
025
026/**
027 * A query event for a key/value store.
028 */
029public class KeyValueStoreQuery extends Event<Map<String,String>> {
030
031        private String key;
032
033        /**
034         * Creates a new event that queries using the given key. The
035         * result of the event is a map with the retrieved entries.
036         * 
037         * @param key the key
038         */
039        public KeyValueStoreQuery(String key) {
040                this.key = key;
041        }
042
043        /**
044         * Convenience constructor for creating a new event with
045         * a completion event of type {@link KeyValueStoreData}
046         * that is fired on the given channel.
047         *
048         * @param key the key
049         * @param channel the channel
050         */
051        public KeyValueStoreQuery(String key, Channel channel) {
052                this(key);
053                new KeyValueStoreData(this, channel);
054        }
055
056        /**
057         * Returns the key used for the query.
058         * 
059         * @return the key
060         */
061        public String query() {
062                return key;
063        }
064        
065        
066}