26 using namespace basis;
36 #undef GRAB_CONSUMER_LOCK
37 #define GRAB_CONSUMER_LOCK auto_synchronizer l(*_input_guard)
40 #define LOG(t) CLASS_EMERGENCY_LOG(program_wide_logger::get(), t)
44 struct infoton_record {
46 octopus_request_id _id;
48 infoton_record(infoton *product, octopus_request_id
id)
49 : _product(product), _id(
id) {}
51 ~infoton_record() {
WHACK(_product); }
54 class queueton :
public amorph<infoton_record> {};
58 class pod_motivator :
public ethread
61 pod_motivator(tentacle &parent,
int motivational_rate)
65 void perform_activity(
void *
formal(ptr)) { _parent.propel_arm(); }
73 tentacle::tentacle(
const string_array &group_name,
bool backgrounded,
74 int motivational_rate)
76 _pending(new queueton),
77 _input_guard(new
mutex),
80 _backgrounded(backgrounded)
89 if (_action) _action->stop();
99 {
return common::outcome_name(to_name); }
102 {
if (_action)
return _action->sleep_time();
else return 0; }
108 _products = &storage;
114 if (_action) _action->stop();
124 LOG(
"storage bunker has not been established!");
128 return _products->
add_item(product, original_id);
144 for (
int i = 0; i < _pending->elements(); i++) {
145 curr_size += _pending->borrow(i)->_product->packed_size();
147 if (curr_size + to_chow->
packed_size() > max_size) {
152 *_pending +=
new infoton_record(to_chow, item_id);
162 infoton *to_return = (*_pending)[0]->_product;
165 item_id = (*_pending)[0]->_id;
177 if (!next_item)
break;
181 #ifdef DEBUG_TENTACLE
Provides a dynamically resizable ASCII character string.
A very common template for a dynamic array of bytes.
Outcomes describe the state of completion for an operation.
Stores a set of infotons grouped by the entity that owns them.
int max_bytes_per_entity() const
bool add_item(infoton *to_add, const octopus_request_id &id)
An infoton is an individual request parcel with accompanying information.
virtual int packed_size() const =0
reports how large the infoton will be when packed.
const structures::string_array & classifier() const
this array of strings is the "name" for this infoton.
Identifies requests made on an octopus by users.
bool store_product(infoton *product, const octopus_request_id &original_id)
used by tentacles to store the objects they produce from infotons.
virtual basis::outcome consume(infoton &to_chow, const octopus_request_id &item_id, basis::byte_array &transformed)=0
this is the main function that processes infotons for this tentacle.
basis::outcome enqueue(infoton *to_chow, const octopus_request_id &item_id)
holds onto infotons coming from the octopus for backgrounding.
const structures::string_array & group() const
returns the name of the group that this tentacle services.
static const char * outcome_name(const basis::outcome &to_name)
returns the textual form of the outcome "to_name".
void detach_storage()
unhooks the storage bin from this tentacle.
int motivational_rate() const
returns the background processing rate this was constructed with.
void attach_storage(entity_data_bin &storage)
used when a tentacle is being integrated with an octopus.
infoton * next_request(octopus_request_id &item_id)
pops out the next queued request for processing.
entity_data_bin * get_storage()
returns the current pointer, which might be nil.
void propel_arm()
invoked by our thread to cause requests to be processed.
Provides a platform-independent object for adding threads to a program.
An array of strings with some additional helpful methods.
basis::astring text_form() const
A synonym for the text_format() method.
#define formal(parameter)
This macro just eats what it's passed; it marks unused formal parameters.
#define NULL_POINTER
The value representing a pointer to nothing.
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
The guards collection helps in testing preconditions and reporting errors.
void WHACK(contents *&ptr)
deletion with clearing of the pointer.
A logger that sends to the console screen using the standard output device.
A dynamic container class that holds any kind of object via pointers.
#define GRAB_CONSUMER_LOCK