feisty meow concerns codebase  2.140
octopus.h
Go to the documentation of this file.
1 #ifndef OCTOPUS_CLASS
2 #define OCTOPUS_CLASS
3 
4 /*****************************************************************************\
5 * *
6 * Name : octopus *
7 * Author : Chris Koeritz *
8 * *
9 *******************************************************************************
10 * Copyright (c) 2001-$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 <mathematics/chaos.h>
20 #include <processes/safe_roller.h>
21 #include <structures/set.h>
22 #include <timely/time_stamp.h>
23 
24 namespace octopi {
25 
26 // forward.
27 class entity_data_bin;
28 class filter_list;
29 class infoton;
30 class modula_oblongata;
31 class octopus_entity;
32 class octopus_request_id;
33 class tentacle;
34 
36 
46 class octopus : public virtual basis::root_object
47 {
48 public:
49  octopus(const basis::astring &name, int max_size_per_entity);
51 
57  virtual ~octopus();
58 
59  DEFINE_CLASS_NAME("octopus");
60 
61  const basis::astring &name() const;
63 
64  // tentacle management functions...
65 
66  basis::outcome add_tentacle(tentacle *to_add, bool filter = false);
68 
78  basis::outcome remove_tentacle(const structures::string_array &group_name, tentacle * &free_me);
80 
87 
88  // entity management methods...
89 
92 
96  void expunge(const octopus_entity &to_remove);
98 
103 
105  // main functionality: restoring infotons, evaluating requests and
106  // locating responses.
107 
108  basis::outcome restore(const structures::string_array &classifier, basis::byte_array &packed_form,
109  infoton * &reformed);
111 
115  basis::outcome evaluate(infoton *request, const octopus_request_id &item_id,
116  bool now = false);
118 
132  infoton *acquire_result(const octopus_entity &requester,
133  octopus_request_id &original_id);
135 
143 
147 
148  // tentacle accessors: careful with these--you must always unlock after
149  // you have locked.
150 
151  tentacle *lock_tentacle(const structures::string_array &tentacle_name);
153 
156  void unlock_tentacle(tentacle *to_unlock);
158 
161  void lock_tentacles();
163 
164  // the following are only valid if the tentacle list is locked.
165  int locked_tentacle_count();
166  tentacle *locked_get_tentacle(int indy);
167  void unlock_tentacles();
168 
170 
171  // used internally; don't mess with externally.
172 
173  void periodic_cleaning();
175 
176 private:
177  basis::astring *_name;
178  modula_oblongata *_tentacles;
179  basis::mutex *_molock;
180  entity_data_bin *_responses;
181  int _disallow_removals;
183 
185  timely::time_stamp *_next_cleaning;
186  basis::mutex *_clean_lock;
187  filter_list *_filters;
188  processes::safe_roller *_sequencer;
189  mathematics::chaos *_rando;
190 
191  // not accessible.
192  octopus(const octopus &);
193  octopus &operator =(const octopus &);
194 };
195 
196 } //namespace.
197 
198 #endif
199 
Provides a dynamically resizable ASCII character string.
Definition: astring.h:35
A very common template for a dynamic array of bytes.
Definition: byte_array.h:36
Outcomes describe the state of completion for an operation.
Definition: outcome.h:31
a platform-independent way to acquire random numbers in a specific range.
Definition: chaos.h:51
Stores a set of infotons grouped by the entity that owns 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.
Definition: entity_defs.h:114
Octopus is a design pattern for generalized request processing systems.
Definition: octopus.h:47
entity_data_bin & responses()
allows external access to our set of results.
Definition: octopus.cpp:178
tentacle * locked_get_tentacle(int indy)
access indy'th tentacle.
Definition: octopus.cpp:184
void unlock_tentacles()
unlocks the list.
Definition: octopus.cpp:176
basis::outcome add_tentacle(tentacle *to_add, bool filter=false)
hooks a tentacle in to provide processing of one type of infoton.
Definition: octopus.cpp:253
void periodic_cleaning()
flushes any abandoned data from the response bin.
Definition: octopus.cpp:498
tentacle * lock_tentacle(const structures::string_array &tentacle_name)
locates the tentacle with the "tentacle_name" and returns it.
Definition: octopus.cpp:515
int locked_tentacle_count()
number of tentacles.
Definition: octopus.cpp:180
infoton * acquire_result(const octopus_entity &requester, octopus_request_id &original_id)
acquires responses to previous requests if there are any waiting.
Definition: octopus.cpp:190
basis::outcome evaluate(infoton *request, const octopus_request_id &item_id, bool now=false)
tries to process the "request" using the current set of tentacles.
Definition: octopus.cpp:351
void unlock_tentacle(tentacle *to_unlock)
unlocks the octopus when given a previously locked tentacle.
Definition: octopus.cpp:194
octopus(const basis::astring &name, int max_size_per_entity)
constructs an octopus named "name".
Definition: octopus.cpp:142
virtual ~octopus()
Definition: octopus.cpp:160
octopus_entity issue_identity()
creates an entity identifier that is unique for this octopus.
Definition: octopus.cpp:527
infoton * acquire_specific_result(const octopus_request_id &original_id)
supports seeking the result for a specific request.
Definition: octopus.cpp:187
basis::outcome restore(const structures::string_array &classifier, basis::byte_array &packed_form, infoton *&reformed)
regenerates a packed infoton given its classifier.
Definition: octopus.cpp:318
basis::outcome zap_tentacle(const structures::string_array &group_name)
similar to remove_tentacle(), but destroys the tentacle.
Definition: octopus.cpp:245
const basis::astring & name() const
returns the name that the octopus was constructed with.
Definition: octopus.cpp:182
DEFINE_CLASS_NAME("octopus")
void expunge(const octopus_entity &to_remove)
invokes every tentacle's expunge() method on the id "to_remove".
Definition: octopus.cpp:200
basis::outcome remove_tentacle(const structures::string_array &group_name, tentacle *&free_me)
removes the tentacle listed for the "group_name", if any.
Definition: octopus.cpp:279
void lock_tentacles()
locks the tentacle list for use with locked_get_tentacle.
Definition: octopus.cpp:174
Manages a service within an octopus by processing certain infotons.
Definition: tentacle.h:36
Implements a thread-safe roller object.
Definition: safe_roller.h:30
An array of strings with some additional helpful methods.
Definition: string_array.h:32
Represents a point in time relative to the operating system startup time.
Definition: time_stamp.h:38
time_locus now()
returns our current locus in the time continuum.
Definition: earth_time.cpp:352