Drizzled Public API Documentation

memc_behavior_get.h
Go to the documentation of this file.
00001 /* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  * Copyright (C) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
00005  * All rights reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions are met:
00009  *
00010  *   * Redistributions of source code must retain the above copyright notice,
00011  *     this list of conditions and the following disclaimer.
00012  *   * Redistributions in binary form must reproduce the above copyright notice,
00013  *     this list of conditions and the following disclaimer in the documentation
00014  *     and/or other materials provided with the distribution.
00015  *   * Neither the name of Patrick Galbraith nor the names of its contributors
00016  *     may be used to endorse or promote products derived from this software
00017  *     without specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00020  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00021  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00022  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00023  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00024  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00025  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00026  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00027  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00028  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
00029  * THE POSSIBILITY OF SUCH DAMAGE.
00030  */
00031 
00032 #pragma once
00033 
00034 #include <drizzled/item/func.h>
00035 
00036 #include <libmemcached/memcached.h>
00037 
00038 #include <map>
00039 #include <string>
00040 
00045 class MemcachedBehaviorGet : public drizzled::Item_str_func
00046 {
00047 public:
00048   MemcachedBehaviorGet()
00049     : 
00050       Item_str_func(),
00051       failure_buff("FAILURE", &drizzled::my_charset_bin),
00052       return_buff("", &drizzled::my_charset_bin),
00053       behavior_map(),
00054       behavior_reverse_map(),
00055       dist_settings_reverse_map(),
00056       hash_settings_reverse_map(),
00057       ketama_hash_settings_reverse_map()
00058   {
00059     /*
00060      * std::map for mapping string behaviors to int behavior values
00061      * This is used to take user input behaviors from the UDF and 
00062      * be able to set the correct int behavior
00063      */
00064     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00065       ("MEMCACHED_BEHAVIOR_SUPPORT_CAS", MEMCACHED_BEHAVIOR_SUPPORT_CAS));
00066     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00067       ("MEMCACHED_BEHAVIOR_NO_BLOCK", MEMCACHED_BEHAVIOR_NO_BLOCK));
00068     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00069       ("MEMCACHED_BEHAVIOR_TCP_NODELAY", MEMCACHED_BEHAVIOR_TCP_NODELAY));
00070     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00071       ("MEMCACHED_BEHAVIOR_HASH", MEMCACHED_BEHAVIOR_HASH));
00072     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00073       ("MEMCACHED_BEHAVIOR_CACHE_LOOKUPS", MEMCACHED_BEHAVIOR_CACHE_LOOKUPS));
00074     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00075       ("MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE", MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE));
00076     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00077       ("MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE", MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE));
00078     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00079       ("MEMCACHED_BEHAVIOR_BUFFER_REQUESTS", MEMCACHED_BEHAVIOR_BUFFER_REQUESTS));
00080     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00081       ("MEMCACHED_BEHAVIOR_KETAMA", MEMCACHED_BEHAVIOR_KETAMA));
00082     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00083       ("MEMCACHED_BEHAVIOR_POLL_TIMEOUT", MEMCACHED_BEHAVIOR_POLL_TIMEOUT));
00084     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00085       ("MEMCACHED_BEHAVIOR_RETRY_TIMEOUT", MEMCACHED_BEHAVIOR_RETRY_TIMEOUT));
00086     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00087       ("MEMCACHED_BEHAVIOR_DISTRIBUTION", MEMCACHED_BEHAVIOR_DISTRIBUTION));
00088     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00089       ("MEMCACHED_BEHAVIOR_USER_DATA", MEMCACHED_BEHAVIOR_USER_DATA));
00090     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00091       ("MEMCACHED_BEHAVIOR_SORT_HOSTS", MEMCACHED_BEHAVIOR_SORT_HOSTS));
00092     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00093       ("MEMCACHED_BEHAVIOR_VERIFY_KEY", MEMCACHED_BEHAVIOR_VERIFY_KEY));
00094     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00095       ("MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT", MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT));
00096     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00097       ("MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED", MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED));
00098     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00099       ("MEMCACHED_BEHAVIOR_KETAMA_HASH", MEMCACHED_BEHAVIOR_KETAMA_HASH));
00100     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00101       ("MEMCACHED_BEHAVIOR_BINARY_PROTOCOL", MEMCACHED_BEHAVIOR_BINARY_PROTOCOL));
00102     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00103       ("MEMCACHED_BEHAVIOR_SND_TIMEOUT", MEMCACHED_BEHAVIOR_SND_TIMEOUT));
00104     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00105       ("MEMCACHED_BEHAVIOR_RCV_TIMEOUT", MEMCACHED_BEHAVIOR_RCV_TIMEOUT));
00106     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00107       ("MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT", MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT));
00108     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00109       ("MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK", MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK));
00110     behavior_map.insert(std::pair<const std::string, memcached_behavior>
00111       ("MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK", MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK));
00112 
00113     /*
00114      * std::map for mapping int behavior values to behavior strings
00115      * This is used to take int behaviors from the the clien and be
00116      * able to print the string value of the behavior in memc_behavior_get 
00117      * UDF 
00118      */
00119     behavior_reverse_map.insert(std::pair<memcached_behavior, const std::string>
00120       (MEMCACHED_BEHAVIOR_SUPPORT_CAS, "MEMCACHED_BEHAVIOR_SUPPORT_CAS"));
00121     behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
00122       (MEMCACHED_BEHAVIOR_NO_BLOCK, "MEMCACHED_BEHAVIOR_NO_BLOCK"));
00123     behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
00124       (MEMCACHED_BEHAVIOR_TCP_NODELAY, "MEMCACHED_BEHAVIOR_TCP_NODELAY"));
00125     behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
00126       (MEMCACHED_BEHAVIOR_HASH, "MEMCACHED_BEHAVIOR_HASH"));
00127     behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
00128       (MEMCACHED_BEHAVIOR_CACHE_LOOKUPS, "MEMCACHED_BEHAVIOR_CACHE_LOOKUPS"));
00129     behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
00130       (MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE, "MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE"));
00131     behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
00132       (MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE, "MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE"));
00133     behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
00134       (MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, "MEMCACHED_BEHAVIOR_BUFFER_REQUESTS"));
00135     behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
00136       (MEMCACHED_BEHAVIOR_KETAMA, "MEMCACHED_BEHAVIOR_KETAMA"));
00137     behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
00138       (MEMCACHED_BEHAVIOR_POLL_TIMEOUT, "MEMCACHED_BEHAVIOR_POLL_TIMEOUT"));
00139     behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
00140       (MEMCACHED_BEHAVIOR_RETRY_TIMEOUT, "MEMCACHED_BEHAVIOR_RETRY_TIMEOUT"));
00141     behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
00142       (MEMCACHED_BEHAVIOR_DISTRIBUTION, "MEMCACHED_BEHAVIOR_DISTRIBUTION"));
00143     behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
00144       (MEMCACHED_BEHAVIOR_USER_DATA, "MEMCACHED_BEHAVIOR_USER_DATA"));
00145     behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
00146       (MEMCACHED_BEHAVIOR_SORT_HOSTS, "MEMCACHED_BEHAVIOR_SORT_HOSTS"));
00147     behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
00148       (MEMCACHED_BEHAVIOR_VERIFY_KEY, "MEMCACHED_BEHAVIOR_VERIFY_KEY"));
00149     behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
00150       (MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT, "MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT"));
00151     behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
00152       (MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED, "MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED"));
00153     behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
00154       (MEMCACHED_BEHAVIOR_KETAMA_HASH, "MEMCACHED_BEHAVIOR_KETAMA_HASH"));
00155     behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
00156       (MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, "MEMCACHED_BEHAVIOR_BINARY_PROTOCOL"));
00157     behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
00158       (MEMCACHED_BEHAVIOR_SND_TIMEOUT, "MEMCACHED_BEHAVIOR_SND_TIMEOUT"));
00159     behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
00160       (MEMCACHED_BEHAVIOR_RCV_TIMEOUT, "MEMCACHED_BEHAVIOR_RCV_TIMEOUT"));
00161     behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
00162       (MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT, "MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT"));
00163     behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
00164       (MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK, "MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK"));
00165     behavior_reverse_map.insert(std::pair<memcached_behavior,const std::string>
00166       (MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK, "MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK"));
00167 
00168     /*
00169      * std::map for mapping distribution string values to int distribution values
00170      * For being able to map int distribution values to string distribution values
00171      * Used by memc_behavior_get() for distribution types
00172      */
00173     dist_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
00174       (MEMCACHED_DISTRIBUTION_MODULA, "MEMCACHED_DISTRIBUTION_MODULA"));
00175     dist_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
00176       (MEMCACHED_DISTRIBUTION_CONSISTENT, "MEMCACHED_DISTRIBUTION_CONSISTENT"));
00177     dist_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
00178       (MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA, "MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA"));
00179 
00180     /*
00181      * std::map for mapping distribution string values to int distribution values
00182      * For being able to map int distribution values to string distribution values
00183      * Used by memc_behavior_get() for hash types
00184      */
00185     hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
00186       (MEMCACHED_HASH_DEFAULT, "MEMCACHED_HASH_DEFAULT"));
00187     hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
00188       (MEMCACHED_HASH_MD5, "MEMCACHED_HASH_MD5"));
00189     hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
00190       (MEMCACHED_HASH_CRC, "MEMCACHED_HASH_CRC"));
00191     hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
00192       (MEMCACHED_HASH_FNV1_64, "MEMCACHED_HASH_FNV1_64"));
00193     hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
00194       (MEMCACHED_HASH_FNV1A_64, "MEMCACHED_HASH_FNV1A_64"));
00195     hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
00196       (MEMCACHED_HASH_FNV1_32, "MEMCACHED_HASH_FNV1_32"));
00197     hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
00198       (MEMCACHED_HASH_FNV1A_32, "MEMCACHED_HASH_FNV1A_32"));
00199     hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
00200       (MEMCACHED_HASH_JENKINS, "MEMCACHED_HASH_JENKINS"));
00201     hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
00202       (MEMCACHED_HASH_HSIEH, "MEMCACHED_HASH_HSIEH"));
00203     hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
00204       (MEMCACHED_HASH_MURMUR, "MEMCACHED_HASH_MURMUR"));
00205 
00206     /*
00207      * std::map for mapping distribution string values to int distribution values
00208      * For being able to map int distribution values to string distribution values
00209      * Used by memc_behavior_get() for ketama hash types
00210      */
00211     ketama_hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
00212       (MEMCACHED_HASH_DEFAULT, "MEMCACHED_HASH_DEFAULT"));
00213     ketama_hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
00214       (MEMCACHED_HASH_MD5, "MEMCACHED_HASH_MD5"));
00215     ketama_hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
00216       (MEMCACHED_HASH_CRC, "MEMCACHED_HASH_CRC"));
00217     ketama_hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
00218       (MEMCACHED_HASH_FNV1_64, "MEMCACHED_HASH_FNV1_64"));
00219     ketama_hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
00220       (MEMCACHED_HASH_FNV1A_64, "MEMCACHED_HASH_FNV1A_64"));
00221     ketama_hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
00222       (MEMCACHED_HASH_FNV1_32, "MEMCACHED_HASH_FNV1_32"));
00223     ketama_hash_settings_reverse_map.insert(std::pair<uint64_t, const std::string>
00224       (MEMCACHED_HASH_FNV1A_32, "MEMCACHED_HASH_FNV1A_32"));
00225   }
00226 
00227   const char *func_name() const
00228   {
00229     return "memc_behavior_set";
00230   }
00231 
00232   drizzled::String *val_str(drizzled::String *);
00233 
00234   void fix_length_and_dec()
00235   {
00236     max_length= 32;
00237   }
00238 
00239 private:
00240   void setFailureString(const char *error);
00241 
00242   drizzled::String failure_buff;
00243   drizzled::String return_buff;
00244 
00245   /*
00246    * std::map for behavioral get/set UDFs
00247    */
00248   std::map<const std::string, memcached_behavior> behavior_map;
00249   std::map<memcached_behavior, const std::string> behavior_reverse_map;
00250   std::map<uint64_t, const std::string> dist_settings_reverse_map;
00251   std::map<uint64_t, const std::string> hash_settings_reverse_map;
00252   std::map<uint64_t, const std::string> ketama_hash_settings_reverse_map;
00253 };
00254