Pregunta

I have a spymemcached client that runs operations against a set of hosts. I've noticed that in get operations, you can do something like this:

Future<Object> result = client.asyncGet(key);
Object data = result.get(timeoutmillis, TimeUnit.MILLISECONDS);

What is different from doing this?

ConnectionFactoryBuilder cfb = new ConnectionFactoryBuilder();
cfb.setOpTimeout(timeoutmillis);
¿Fue útil?

Solución

I see that this question was asked really long time ago... But still if anyone will need an answer:

ConnectionFactoryBuilder is just a builder of ConnectionFactory. ConnectionFactory is being used to set up memcached client and opTimeout is just one of the parameters we can set through this builder with:

cfb.setOpTimeout(timeoutmillis);

This timeoutmillis will be transferred to the client and used as a timeout on Futures that wrap memcached async operations inside the client. As you can see there are pairs of async and synchronous versions of methods you can use on memcached client (e.g. asyncGet and get). While asyncGet returns a future object that we can use with our own timeout with asynchronous code, get eliminates it and does all the future mechanic inside client and uses opTimeout as a timeout to get a result from an internal future object that is not being exposed to us.

So usage of cfb.setOpTimeout(timeoutmillis) just delegating handling all the asynchronous work to the client and simplifies our code base when we use simple methods like get, getBulk, etc.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top