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; 022import org.jgrapes.core.Channel; 023import org.jgrapes.core.Event; 024 025/** 026 * A query event for a key/value store. 027 */ 028public class KeyValueStoreQuery extends Event<Map<String, String>> { 029 030 private String key; 031 032 /** 033 * Creates a new event that queries using the given key. The 034 * result of the event is a map with the retrieved entries. 035 * 036 * @param key the key 037 */ 038 public KeyValueStoreQuery(String key) { 039 this.key = key; 040 } 041 042 /** 043 * Convenience constructor for creating a new event with 044 * a completion event of type {@link KeyValueStoreData} 045 * that is fired on the given channel. 046 * 047 * @param key the key 048 * @param channel the channel 049 */ 050 public KeyValueStoreQuery(String key, Channel channel) { 051 this(key); 052 new KeyValueStoreData(this, channel); 053 } 054 055 /** 056 * Returns the key used for the query. 057 * 058 * @return the key 059 */ 060 public String query() { 061 return key; 062 } 063 064}