feisty meow concerns codebase 2.140
entity_data_bin.h
Go to the documentation of this file.
1#ifndef ENTITY_DATA_BIN_CLASS
2#define ENTITY_DATA_BIN_CLASS
3
4/*****************************************************************************\
5* *
6* Name : entity_data_bin *
7* Author : Chris Koeritz *
8* *
9*******************************************************************************
10* Copyright (c) 2002-$now By Author. This program is free software; you can *
11* redistribute it and/or modify it under the terms of the GNU General Public *
12* License as published by the Free Software Foundation; either version 2 of *
13* the License or (at your option) any later version. This is online at: *
14* http://www.fsf.org/copyleft/gpl.html *
15* Please send any updates to: fred@gruntose.com *
16\*****************************************************************************/
17
18#include <basis/contracts.h>
19#include <basis/definitions.h>
20#include <basis/mutex.h>
21#include <structures/set.h>
22
23// forward.
24class monk_the_detective;
25
26namespace octopi {
27
28// forward.
29class basketcase;
30class entity_basket;
31class entity_item_hash;
32class infoton;
33class infoton_list;
34class octopus_entity;
35class octopus_request_id;
36
38
40{
41public:
44
46 virtual ~entity_data_bin();
47
48 DEFINE_CLASS_NAME("entity_data_bin");
49
50 int max_bytes_per_entity() const { return _max_per_ent; }
51 // reports the maximum size allowed per entity for storage.
52 void max_bytes_per_entity(int max_bytes_per) { _max_per_ent = max_bytes_per; }
53 // allows resetting of the storage size allowed per entity. note that if
54 // this value is made smaller and the bin is already holding more than
55 // the new limit, then no additional stores will be allowed until some of
56 // the data is removed.
57
58 int entities() const;
59 // returns the number of entities that currently possess storage bins.
60 // this is a very costly call.
61
62 int items_held() const { return _items_held; }
63 // returns the number of items held here, if any. this is a very
64 // inexpensive call that should be used prior to checking for data.
65 // it's safe to check this at any time, since it's just an int. there's
66 // every likelihood that the number might change by the time one acquires
67 // the lock on the bin, but if it's zero then that's a good reason to
68 // avoid looking for data yet.
69
70 bool get_sizes(const octopus_entity &id, int &items, int &bytes) const;
71 // finds the storage for "id". if there is any there, true is returned
72 // and "items" is set to the number of pending items and "bytes" is set
73 // to the number of bytes for those items.
74
75 bool add_item(infoton *to_add, const octopus_request_id &id);
76 // stores an item "to_add" for an entity listed in "id". if the item
77 // cannot be stored due to space constraints, false is returned and
78 // "to_add" is deleted.
79
81 // locates an item for the specific "id". this will generally be a
82 // response to a previous request. if no object can be found that matches
83 // the "id", then NULL_POINTER is returned.
84
87 // this returns an infoton for the "requester", if any are available. call
88 // this function repeatedly to ensure that all available items have
89 // been provided. the "original_id" is a copy of the "item_id" that was
90 // originally passed to evaluate_request(). the returned object must
91 // eventually be destroyed if non-null.
92
93 int acquire_for_entity(const octopus_entity &requester,
94 infoton_list &items, int maximum_size);
95 // retrieves up to "maximum_size" in bytes of pending items for the
96 // "requester" into "items". the number of items found is returned.
97
99 // acquires an infoton for any random entity. if no items are ready at
100 // all, then NULL_POINTER is returned.
101
103 // returns a textual list of what's held here.
104
105 void clean_out_deadwood(int decay_interval = 4 * basis::MINUTE_ms);
106 // gets rid of any items that haven't been picked up in a timely manner.
107 // note that this should be called periodically by the controlling object.
108 // it will not be called automatically.
109
110private:
111 entity_item_hash *_table; // our main storage object.
112 basis::mutex *_ent_lock; // protects our structures.
113 int _action_count;
114 // used for debugging; tracks how many acquires have occurred since the
115 // last dump of item count.
116 int _max_per_ent; // the maximum size allowed per entity.
117 int _items_held; // the number of items in residence.
118
119 friend class ::monk_the_detective; // eerie supernatural powers, for testing.
120
121 basis::base_synchronizer &locker() { return *_ent_lock; }
123
124 int scramble_counter(); // counts the number of items used.
125
126 // not available.
128 entity_data_bin &operator =(const entity_data_bin &);
129};
130
131} //namespace.
132
133#endif
134
Provides a dynamically resizable ASCII character string.
Definition astring.h:35
Interface for a simple form of synchronization.
Definition contracts.h:98
Stores a set of infotons grouped by the entity that owns them.
DEFINE_CLASS_NAME("entity_data_bin")
bool add_item(infoton *to_add, const octopus_request_id &id)
infoton * acquire_for_any(octopus_request_id &id)
infoton * acquire_for_identifier(const octopus_request_id &id)
void clean_out_deadwood(int decay_interval=4 *basis::MINUTE_ms)
basis::astring text_form() const
bool get_sizes(const octopus_entity &id, int &items, int &bytes) const
void max_bytes_per_entity(int max_bytes_per)
infoton * acquire_for_entity(const octopus_entity &requester, octopus_request_id &id)
a list of pending requests and who made them.
An infoton is an individual request parcel with accompanying information.
Definition infoton.h:32
Provides a way of identifying users of an octopus object.
Definition entity_defs.h:35
Identifies requests made on an octopus by users.
Constants and objects used throughout HOOPLE.
const int MINUTE_ms
Number of milliseconds in a minute.