00001 #ifndef ENTITY_DATA_BIN_CLASS 00002 #define ENTITY_DATA_BIN_CLASS 00003 00004 /*****************************************************************************\ 00005 * * 00006 * Name : entity_data_bin * 00007 * Author : Chris Koeritz * 00008 * * 00009 ******************************************************************************* 00010 * Copyright (c) 2002-$now By Author. This program is free software; you can * 00011 * redistribute it and/or modify it under the terms of the GNU General Public * 00012 * License as published by the Free Software Foundation; either version 2 of * 00013 * the License or (at your option) any later version. This is online at: * 00014 * http://www.fsf.org/copyleft/gpl.html * 00015 * Please send any updates to: fred@gruntose.com * 00016 \*****************************************************************************/ 00017 00018 #include "dll_octopus.h" 00019 00020 #include <basis/object_base.h> 00021 00022 // forward. 00023 class basketcase; 00024 class entity_basket; 00025 class entity_item_hash; 00026 class infoton; 00027 class infoton_list; 00028 class octopus_entity; 00029 class octopus_request_id; 00030 class string_set; 00031 class time_stamp; 00032 00034 00035 class OCTOPUS_CLASS_STYLE entity_data_bin 00036 { 00037 public: 00038 entity_data_bin(int max_bytes_per_entity); 00039 // allows each entity in the bin to have "max_bytes_per_entity" bytes 00040 // stored. any storage attempts that would go beyond that limit are 00041 // rejected. 00042 00043 virtual ~entity_data_bin(); 00044 00045 IMPLEMENT_CLASS_NAME("entity_data_bin"); 00046 00047 int max_bytes_per_entity() const { return _max_per_ent; } 00048 // reports the maximum size allowed per entity for storage. 00049 void max_bytes_per_entity(int max_bytes_per) { _max_per_ent = max_bytes_per; } 00050 // allows resetting of the storage size allowed per entity. note that if 00051 // this value is made smaller and the bin is already holding more than 00052 // the new limit, then no additional stores will be allowed until some of 00053 // the data is removed. 00054 00055 int entities() const; 00056 // returns the number of entities that currently possess storage bins. 00057 // this is a very costly call. 00058 00059 inline int items_held() const { return _items_held; } 00060 // returns the number of items held here, if any. this is a very 00061 // inexpensive call that should be used prior to checking for data. 00062 // it's safe to check this at any time, since it's just an int. there's 00063 // every likelihood that the number might change by the time one acquires 00064 // the lock on the bin, but if it's zero then that's a good reason to 00065 // avoid looking for data yet. 00066 00067 bool get_sizes(const octopus_entity &id, int &items, int &bytes); 00068 // finds the storage for "id". if there is any there, true is returned 00069 // and "items" is set to the number of pending items and "bytes" is set 00070 // to the number of bytes for those items. 00071 00072 bool add_item(infoton *to_add, const octopus_request_id &id); 00073 // stores an item "to_add" for an entity listed in "id". if the item 00074 // cannot be stored due to space constraints, false is returned and 00075 // "to_add" is deleted. 00076 00077 infoton *acquire_for_identifier(const octopus_request_id &id); 00078 // locates an item for the specific "id". this will generally be a 00079 // response to a previous request. if no object can be found that matches 00080 // the "id", then NIL is returned. 00081 00082 infoton *acquire_for_entity(const octopus_entity &requester, 00083 octopus_request_id &id); 00084 // this returns an infoton for the "requester", if any are available. call 00085 // this function repeatedly to ensure that all available items have 00086 // been provided. the "original_id" is a copy of the "item_id" that was 00087 // originally passed to evaluate_request(). the returned object must 00088 // eventually be destroyed if non-NIL. 00089 00090 int acquire_for_entity(const octopus_entity &requester, 00091 infoton_list &items, int maximum_size); 00092 // retrieves up to "maximum_size" in bytes of pending items for the 00093 // "requester" into "items". the number of items found is returned. 00094 00095 infoton *acquire_for_any(octopus_request_id &id); 00096 // acquires an infoton for any random entity. if no items are ready at 00097 // all, then NIL is returned. 00098 00099 istring text_form() const; 00100 // returns a textual list of what's held here. 00101 00102 void clean_out_deadwood(); 00103 // gets rid of any items that haven't been picked up in a timely manner. 00104 // note that this should be called periodically by the controlling object. 00105 // it will not be called automatically. 00106 00107 private: 00108 entity_item_hash *_table; // our main storage object. 00109 mutex *_ent_lock; // protects our structures. 00110 int _action_count; 00111 // used for debugging; tracks how many acquires have occurred since the 00112 // last dump of item count. 00113 int _max_per_ent; // the maximum size allowed per entity. 00114 int _items_held; // the number of items in residence. 00115 00116 int scramble_counter(); // counts the number of items used. 00117 00118 // not available. 00119 entity_data_bin(const entity_data_bin &); 00120 entity_data_bin &operator =(const entity_data_bin &); 00121 }; 00122 00123 #endif 00124
1.5.1