Testing library separation: now not in launcher but isolated
[anna.git] / include / anna / diameter.comm / Entity.hpp
index 8dec08c..b372497 100644 (file)
@@ -49,6 +49,16 @@ class ClientSession;
 */
 class Entity {
 
+public:
+
+  /**
+   * Defines behaviour on validation procedure: complete analysis or stop at first validation error over the message (by default)
+   */
+  struct SessionBasedModelsType { enum _v { RoundRobin, SessionIdOptionalPart, SessionIdHighPart, SessionIdLowPart /* default */ }; };
+
+private:
+
+
   std::vector<Server*> a_servers;
   int a_maxServers; // -1 means "no limit to add servers"
   std::string a_description;
@@ -59,6 +69,10 @@ class Entity {
   // Engine
   Engine *a_engine;
 
+  // Balance and socket selection:
+  bool a_balance;
+  SessionBasedModelsType::_v a_sessionBasedModelsType;
+
   // Availability
   bool a_available; // any of the servers must be bound
   void availabilityLost() throw();
@@ -86,6 +100,8 @@ class Entity {
   // Private close/destroy method
   void close(bool destroy) throw(anna::RuntimeException);
 
+  // helpers
+  static const char* asText(const SessionBasedModelsType::_v) throw();
 
 public:
 
@@ -192,6 +208,21 @@ public:
   Server *getLastUsedResource() const throw() { return (a_lastUsedResource); }
 
 
+  /**
+   * Balance over entity servers or use standard behaviour (first primary, secondary if fails, etc.).
+   * New created entities have balance disabled.
+   *
+   * @param balance True or false to enable or disable.
+   */
+   void setBalance (bool balance) throw() { a_balance = balance; }
+
+  /**
+   * Gets the balance mode
+   *
+   * @return True if balance over entity servers is enabled, false if standard behaviour is configured (default).
+   */
+   bool getBalance() const throw() { return a_balance; }
+
 
 // SIMPLE BALANCE or STANDARD documentation version
 //   /**
@@ -223,8 +254,8 @@ public:
   /**
      Sent a message to the entity. First uses primary server, secondary if fails and so on to the
      last defined resource (server) within entity. Another sending algorithm (non standard) could
-     be enabled (balance boolean parameter): it consist in round-robin server selection to set the
-     first resource in a complete cycle (standard behaviour tries all servers from FIRST defined).
+     be enabled (@setBalance): it consist in round-robin server selection to set the first resource
+     in a complete cycle (standard behaviour tries all servers from FIRST defined).
      Anyway, last used delivery resource could be known through #getLastUsedResource().
 
      When the message is a request, a timer will be set automatically to control the response time.
@@ -232,15 +263,26 @@ public:
      timeout value will be configured at #setClassCodeTimeout.
 
      \param message Message sent.
-     \param balance False by default (standard beaviour), but useful to balance over servers within entity.
 
      @return Boolean about success in send operation. Implies true result when any of the entity servers could
      send the message, and false when neither of the servers was available or fail to send the message (an alarm
      and error counter will be generated in this case). Broadcast try to send all over the resources in spite of
      any fail.
   */
-  bool send(const Message *message, bool balance = false) throw(anna::RuntimeException);
-  bool send(const Message &message, bool balance = false) throw(anna::RuntimeException) { return send(&message, balance); }
+  bool send(const Message *message) throw(anna::RuntimeException);
+  bool send(const Message &message) throw(anna::RuntimeException) { return send(&message); }
+
+  /**
+   * Sets sessions based models type.
+   * \param sessionBasedModelsType Session based models type: RoundRobin, SessionIdLowPart (default), SessionIdHighPart or SessionIdOptionalPart.
+   */
+  void setSessionBasedModelsType(const SessionBasedModelsType::_v sessionBasedModelsType)  throw() { a_sessionBasedModelsType = sessionBasedModelsType; }
+
+  /**
+   * Returns sessions based models type.
+   * \return Session based models type: RoundRobin, SessionIdLowPart, SessionIdHighPart or SessionIdOptionalPart.
+   */
+  SessionBasedModelsType::_v getSessionBasedModelsType() const throw() { return a_sessionBasedModelsType; }
 
 
   /**
@@ -286,7 +328,7 @@ public:
      subscriber and service aware contextual load balancing strategies. By default, Session-Id avp
      is used to select the resource. Session-Id is split into 4 sections: diameter identity, high
      part, low part and optional part. Default implementation analizes 'low' part, returning its
-     value as reference for socket selection.
+     value as reference for socket selection. Use @setSessionBasedModelsType to change this behaviour.
      </pre>
 
      When server is configured as single client session (max client sessions equal to 1), entity will ignore