Hi All,

*Question: how should we deal in a very forward and clean fashion with the
implicit ambiguity of -1 or all, or infinite, or forever?*


*Background:*


We are looking to get some feedback on the subject of infinite/all/forever
in the geode/geode-native code.


In looking at the code, we see an example function,


setRetryAttempts
<https://github.com/apache/geode-native/blob/006df0e70eeb481ef5e9e821dba0050dee9c6893/cppcache/include/geode/PoolFactory.hpp#L327>()
[1] currently -1 means try all servers before failing. 0 means try 1 server
before failing, and a number greater than 0 means try number of servers +1
before failing. In the case of setRetryAttempts, we don’t know how many
servers there are. This means that -1 for "All" servers has no relation to
the actual number of servers that we have. Perhaps setRetryAttempts could
be renamed to setNumberOfAttempts to clarify as well, but the problem still
stands...


*Discussion:*


In an attempt to provide the best code possible to the geode community,
there has been some discussion of the use of infinite/all/forever as an
overload of a count. Often -1 indicates infinite, while 0 indicates never,
and 1 to MAXINT, inclusive, indicates a count.


There are three obvious approaches to solve the problem of the overloading
of -1. The first approach is do nothing… Status quo.


The second approach to clarify things would be to create an enumeration
that would be passed in as well as the number or an object..


struct Retries

{

  typedef enum { eINFINITE, eCOUNT, eNONE} eCount;

  eCount approach;

  unsigned int count;

};



The third approach would be to pass a continue object of some sort such
that it tells you if it is ok to continue through the use of an algorithm.


An example would be


class Continue

{

virtual bool Continue() = 0;

}


class InfiniteContinue : public Continue

{

bool Continue()

{

return true;

}

}


Continue co = InfiniteContinue;


while( co.Continue() )

{

//do a thing

}


Another example would be a Continue limited to 5 let’s say,


class CountContinue : public Continue

{

private:

int count;


public:

CountContinue(int count)

{

this.count = count;

}

bool Continue()

{

  return count— > 0;

}

}


In both of these cases what is happening is that the algorithm is being
outsourced.


*Conclusion:*


We are putting this out, to start a discussion on the best way to move this
forward… *What do people think? What direction would be the best going
forward?*


[1]
https://github.com/apache/geode-native/blob/006df0e70eeb481ef5e9e821dba0050dee9c6893/cppcache/include/geode/PoolFactory.hpp#L327

Reply via email to