You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jclouds.apache.org by Dileep Dixith <di...@gmail.com> on 2016/09/13 14:36:50 UTC

Fwd: Need Help to resolve Custom Retry Handler Issue

Hi All,

For our project we need to write a custom retry handler for jclouds during
PUT Operation.. We want to override default BackoffLimitedRetryHandler.

I want to know whether it is possible to write custom retry handler for PUT
operation or not.

Our Code snippet goes as below.

modules = ImmutableSet.<Module> builder()
.addAll(modules)
.add(new AbstractModule()
{
@Override
public void configure()
{
bind(HttpRetryHandler.class).annotatedWith(Redirection.class).to(<our
custom class>.class);
}
})
.build();

<our custom class> implements HttpRetryHandler,IOExceptionRetryHandler
similar to

http://grepcode.com/file/repo1.maven.org/maven2/org.
jclouds/jclouds-core/1.5.1/org/jclouds/http/handlers/
BackoffLimitedRetryHandler.java

But even after failure, our custom retry handler never called, instead
jclouds still makes call to   BackoffLimitedRetryHandler

2016-09-12@07:38:51.812 E            [mcstore-01          ]
koffLimitedRetryHandler:logError - Cannot retry after server error, command
has exceeded retry limit 5: [method=org.jclouds.openstack.
swift.SwiftKeystoneClient.public abstract java.lang.String
org.jclouds.openstack.swift.CommonSwiftClient.putObject(
java.lang.String,org.jclouds.openstack.swift.domain.SwiftObject)[multinode,

Notes:

a. If I change bind(HttpRetryHandler.class).annotatedWith(Redirection.
class).to(ICStoreRetryHandler.class);  to bind(HttpRetryHandler.class).
annotatedWith(ClientEroor.class).to(ICStoreRetryHandler.class);  got error
stating
HttpRetryHandler already registered with ClientError and can not be binded
again at

https://github.com/jclouds/jclouds/blob/master/apis/
openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/config/
KeystoneAuthenticationModule.java

b. Even tried  bind(HttpRetryHandler.class).to(ICStoreRetryHandler.class)
and still custom handler not executed.

Need your help to resolve this issue.

Re: Fwd: Need Help to resolve Custom Retry Handler Issue

Posted by Ignasi Barrera <na...@apache.org>.
Guice does not allow to bind an interface to multiple implementations.
That's why you get the "HttpRetryHandler already registered with
ClientError and can not be binded again" error when you try to bind
your custom handler. jclouds already has a default retry handler
bound, so you can't bind your custom one.

In this case, given the exception message, we can see that there is
actually a binding declared here by jclouds:
https://github.com/jclouds/jclouds/blob/master/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/config/KeystoneAuthenticationModule.java#L193

So HttpRetryHandler is bound to RetryOnRenew.class

You can't re-bind the HttpRetryHandler, but what you *can* to is to
bind the RetryOnRenew class to a different implemenation, your custom
one. So you end up having this binding chain:

HttpRetryHandler > RetryOnRenew (bound by jclouds) > YourCustomImpl
(you bind it to override the default jclouds impl).

So you need to create your class, let it extend the "RetryOnRenew"
class, and modify its behaviour as needed. Then add this binding:

bind(RetryOnRenew.class).to(YourCustomImpl.class);

With this setup, when Guice looks for an implementation of the
HttpRetryHandler interface, it will find that the RetryOnRenew class
is configured, but it will also find that there is a custom binding
that instructs it to provide YourCustomImpl objects when looking for
implementations of the RetryOnRenew class.

Does this help?


I.

On 14 September 2016 at 07:10, Dileep Dixith <di...@gmail.com> wrote:
> Whether our impl need to extend BackoffLimitedRetryHandler or RetryOnRenew
> or need to implement HttpRetryHandler.
>
> Please clarify on this.
>
> Also please share me some examples, if you have.
>
> On Wed, Sep 14, 2016 at 12:19 AM, Ignasi Barrera <na...@apache.org> wrote:
>>
>> Hi,
>>
>> It is not easy to override bindings in Guice modules. The common way to do
>> that is by using the "Modules.override" helper but in this case, since the
>> module that defines the binding is a default module in the api metadata and
>> it is jclouds who instantiates it, you won't be able to use that.
>>
>> What you can do is a linked binding from the default implementation to
>> your custom one. Something like:
>>
>> bind(RetryOnRenew.class).to(YourImpl.class);
>>
>> (If I'm not wrong this is the handler that is already registered)
>> Your impl will have to extend the jclouds default one, apply your logic
>> and/or fallback to the superclass.
>>
>> HTH!
>>
>> I.
>>
>> El 13 sept. 2016 4:37 p. m., "Dileep Dixith" <di...@gmail.com>
>> escribió:
>>
>> >
>>
>> > Hi All,
>> >
>> > For our project we need to write a custom retry handler for jclouds
>> > during PUT Operation.. We want to override default
>> > BackoffLimitedRetryHandler.
>> >
>> > I want to know whether it is possible to write custom retry handler for
>> > PUT operation or not.
>> >
>> > Our Code snippet goes as below.
>> >
>> > modules = ImmutableSet.<Module> builder()
>> > .addAll(modules)
>> > .add(new AbstractModule()
>> > {
>> > @Override
>> > public void configure()
>> > {
>> > bind(HttpRetryHandler.class).annotatedWith(Redirection.class).to(<our
>> > custom class>.class);
>> > }
>> > })
>> > .build();
>> >
>> > <our custom class> implements HttpRetryHandler,IOExceptionRetryHandler
>> > similar to
>> >
>> >
>> > http://grepcode.com/file/repo1.maven.org/maven2/org.jclouds/jclouds-core/1.5.1/org/jclouds/http/handlers/BackoffLimitedRetryHandler.java
>> >
>> > But even after failure, our custom retry handler never called, instead
>> > jclouds still makes call to   BackoffLimitedRetryHandler
>> >
>> > 2016-09-12@07:38:51.812 E            [mcstore-01          ]
>> > koffLimitedRetryHandler:logError - Cannot retry after server error, command
>> > has exceeded retry limit 5:
>> > [method=org.jclouds.openstack.swift.SwiftKeystoneClient.public abstract
>> > java.lang.String
>> > org.jclouds.openstack.swift.CommonSwiftClient.putObject(java.lang.String,org.jclouds.openstack.swift.domain.SwiftObject)[multinode,
>> >
>> > Notes:
>> >
>> > a. If I change
>> > bind(HttpRetryHandler.class).annotatedWith(Redirection.class).to(ICStoreRetryHandler.class);
>> > to
>> > bind(HttpRetryHandler.class).annotatedWith(ClientEroor.class).to(ICStoreRetryHandler.class);
>> > got error stating
>> > HttpRetryHandler already registered with ClientError and can not be
>> > binded again at
>> >
>> >
>> > https://github.com/jclouds/jclouds/blob/master/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/config/KeystoneAuthenticationModule.java
>> >
>> > b. Even tried
>> > bind(HttpRetryHandler.class).to(ICStoreRetryHandler.class) and still custom
>> > handler not executed.
>> >
>> > Need your help to resolve this issue.
>> >
>
>

Re: Fwd: Need Help to resolve Custom Retry Handler Issue

Posted by Dileep Dixith <di...@gmail.com>.
Whether our impl need to extend BackoffLimitedRetryHandler or RetryOnRenew
or need to implement HttpRetryHandler.

Please clarify on this.

Also please share me some examples, if you have.

On Wed, Sep 14, 2016 at 12:19 AM, Ignasi Barrera <na...@apache.org> wrote:

> Hi,
>
> It is not easy to override bindings in Guice modules. The common way to do
> that is by using the "Modules.override" helper but in this case, since the
> module that defines the binding is a default module in the api metadata and
> it is jclouds who instantiates it, you won't be able to use that.
>
> What you can do is a linked binding from the default implementation to
> your custom one. Something like:
>
> bind(RetryOnRenew.class).to(YourImpl.class);
>
> (If I'm not wrong this is the handler that is already registered)
> Your impl will have to extend the jclouds default one, apply your logic
> and/or fallback to the superclass.
>
> HTH!
>
> I.
>
> El 13 sept. 2016 4:37 p. m., "Dileep Dixith" <di...@gmail.com>
> escribió:
>
> >
>
> > Hi All,
> >
> > For our project we need to write a custom retry handler for jclouds
> during PUT Operation.. We want to override default
> BackoffLimitedRetryHandler.
> >
> > I want to know whether it is possible to write custom retry handler for
> PUT operation or not.
> >
> > Our Code snippet goes as below.
> >
> > modules = ImmutableSet.<Module> builder()
> > .addAll(modules)
> > .add(new AbstractModule()
> > {
> > @Override
> > public void configure()
> > {
> > bind(HttpRetryHandler.class).annotatedWith(Redirection.class).to(<our
> custom class>.class);
> > }
> > })
> > .build();
> >
> > <our custom class> implements HttpRetryHandler,IOExceptionRetryHandler
> similar to
> >
> > http://grepcode.com/file/repo1.maven.org/maven2/org.
> jclouds/jclouds-core/1.5.1/org/jclouds/http/handlers/
> BackoffLimitedRetryHandler.java
> <http://grepcode.com/file/repo1.maven.org/maven2/org.jclouds/jclouds-core/1.5.1/org/jclouds/http/handlers/BackoffLimitedRetryHandler.java>
> >
> > But even after failure, our custom retry handler never called, instead
> jclouds still makes call to   BackoffLimitedRetryHandler
> >
> > 2016-09-12@07:38:51.812 E            [mcstore-01          ]
> koffLimitedRetryHandler:logError - Cannot retry after server error,
> command has exceeded retry limit 5: [method=org.jclouds.openstack.
> swift.SwiftKeystoneClient.public abstract java.lang.String
> org.jclouds.openstack.swift.CommonSwiftClient.putObject(
> java.lang.String,org.jclouds.openstack.swift.domain.SwiftObject)[multinode,
>
> >
> > Notes:
> >
> > a. If I change bind(HttpRetryHandler.class).annotatedWith(Redirection.
> class).to(ICStoreRetryHandler.class);  to bind(HttpRetryHandler.class).
> annotatedWith(ClientEroor.class).to(ICStoreRetryHandler.class);  got
> error stating
> > HttpRetryHandler already registered with ClientError and can not be
> binded again at
> >
> > https://github.com/jclouds/jclouds/blob/master/apis/
> openstack-keystone/src/main/java/org/jclouds/openstack/
> keystone/v2_0/config/KeystoneAuthenticationModule.java
> <https://github.com/jclouds/jclouds/blob/master/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/config/KeystoneAuthenticationModule.java>
> >
> > b. Even tried  bind(HttpRetryHandler.class).to(ICStoreRetryHandler.class)
> and still custom handler not executed.
> >
> > Need your help to resolve this issue.
> >
>

Re: Fwd: Need Help to resolve Custom Retry Handler Issue

Posted by Ignasi Barrera <na...@apache.org>.
Hi,

It is not easy to override bindings in Guice modules. The common way to do
that is by using the "Modules.override" helper but in this case, since the
module that defines the binding is a default module in the api metadata and
it is jclouds who instantiates it, you won't be able to use that.

What you can do is a linked binding from the default implementation to your
custom one. Something like:

bind(RetryOnRenew.class).to(YourImpl.class);

(If I'm not wrong this is the handler that is already registered)
Your impl will have to extend the jclouds default one, apply your logic
and/or fallback to the superclass.

HTH!

I.

El 13 sept. 2016 4:37 p. m., "Dileep Dixith" <di...@gmail.com>
escribió:

>

> Hi All,
>
> For our project we need to write a custom retry handler for jclouds
during PUT Operation.. We want to override default
BackoffLimitedRetryHandler.
>
> I want to know whether it is possible to write custom retry handler for
PUT operation or not.
>
> Our Code snippet goes as below.
>
> modules = ImmutableSet.<Module> builder()
> .addAll(modules)
> .add(new AbstractModule()
> {
> @Override
> public void configure()
> {
> bind(HttpRetryHandler.class).annotatedWith(Redirection.class).to(<our
custom class>.class);
> }
> })
> .build();
>
> <our custom class> implements HttpRetryHandler,IOExceptionRetryHandler
similar to
>
>
http://grepcode.com/file/repo1.maven.org/maven2/org.jclouds/jclouds-core/1.5.1/org/jclouds/http/handlers/BackoffLimitedRetryHandler.java
<http://grepcode.com/file/repo1.maven.org/maven2/org.jclouds/jclouds-core/1.5.1/org/jclouds/http/handlers/BackoffLimitedRetryHandler.java>
>
> But even after failure, our custom retry handler never called, instead
jclouds still makes call to   BackoffLimitedRetryHandler
>
> 2016-09-12@07:38:51.812 E            [mcstore-01          ]
koffLimitedRetryHandler:logError - Cannot retry after server error, command
has exceeded retry limit 5:
[method=org.jclouds.openstack.swift.SwiftKeystoneClient.public abstract
java.lang.String
org.jclouds.openstack.swift.CommonSwiftClient.putObject(java.lang.String,org.jclouds.openstack.swift.domain.SwiftObject)[multinode,

>
> Notes:
>
> a. If I change
bind(HttpRetryHandler.class).annotatedWith(Redirection.class).to(ICStoreRetryHandler.class);
to
bind(HttpRetryHandler.class).annotatedWith(ClientEroor.class).to(ICStoreRetryHandler.class);
got error stating
> HttpRetryHandler already registered with ClientError and can not be
binded again at
>
>
https://github.com/jclouds/jclouds/blob/master/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/config/KeystoneAuthenticationModule.java
<https://github.com/jclouds/jclouds/blob/master/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/config/KeystoneAuthenticationModule.java>
>
> b. Even tried  bind(HttpRetryHandler.class).to(ICStoreRetryHandler.class)
and still custom handler not executed.
>
> Need your help to resolve this issue.
>