1 | /* |
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
3 | * contributor license agreements. See the NOTICE file distributed with |
4 | * this work for additional information regarding copyright ownership. |
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
6 | * (the "License"); you may not use this file except in compliance with |
7 | * the License. You may obtain a copy of the License at |
8 | * |
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
10 | * |
11 | * Unless required by applicable law or agreed to in writing, software |
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 | * See the License for the specific language governing permissions and |
15 | * limitations under the License. |
16 | */ |
17 | package org.jclouds.glesys.config; |
18 | |
19 | import java.util.Map; |
20 | |
21 | import org.jclouds.glesys.GleSYSApi; |
22 | import org.jclouds.glesys.GleSYSAsyncApi; |
23 | import org.jclouds.glesys.features.ArchiveApi; |
24 | import org.jclouds.glesys.features.ArchiveAsyncApi; |
25 | import org.jclouds.glesys.features.DomainApi; |
26 | import org.jclouds.glesys.features.DomainAsyncApi; |
27 | import org.jclouds.glesys.features.EmailAccountApi; |
28 | import org.jclouds.glesys.features.EmailAccountAsyncApi; |
29 | import org.jclouds.glesys.features.IpApi; |
30 | import org.jclouds.glesys.features.IpAsyncApi; |
31 | import org.jclouds.glesys.features.ServerApi; |
32 | import org.jclouds.glesys.features.ServerAsyncApi; |
33 | import org.jclouds.glesys.handlers.GleSYSErrorHandler; |
34 | import org.jclouds.http.HttpErrorHandler; |
35 | import org.jclouds.http.HttpRetryHandler; |
36 | import org.jclouds.http.annotation.ClientError; |
37 | import org.jclouds.http.annotation.Redirection; |
38 | import org.jclouds.http.annotation.ServerError; |
39 | import org.jclouds.http.handlers.BackoffLimitedRetryHandler; |
40 | import org.jclouds.location.suppliers.ImplicitLocationSupplier; |
41 | import org.jclouds.location.suppliers.implicit.OnlyLocationOrFirstZone; |
42 | import org.jclouds.rest.ConfiguresRestClient; |
43 | import org.jclouds.rest.config.RestClientModule; |
44 | |
45 | import com.google.common.collect.ImmutableMap; |
46 | import com.google.inject.Scopes; |
47 | |
48 | /** |
49 | * Configures the GleSYS connection. |
50 | * |
51 | * @author Adrian Cole |
52 | */ |
53 | @ConfiguresRestClient |
54 | public class GleSYSRestClientModule extends RestClientModule<GleSYSApi, GleSYSAsyncApi> { |
55 | |
56 | public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()// |
57 | .put(ServerApi.class, ServerAsyncApi.class)// |
58 | .put(IpApi.class, IpAsyncApi.class)// |
59 | .put(ArchiveApi.class, ArchiveAsyncApi.class)// |
60 | .put(DomainApi.class, DomainAsyncApi.class)// |
61 | .put(EmailAccountApi.class, EmailAccountAsyncApi.class)// |
62 | .build(); |
63 | |
64 | public GleSYSRestClientModule() { |
65 | super(DELEGATE_MAP); |
66 | } |
67 | |
68 | @Override |
69 | protected void configure() { |
70 | install(new GleSYSParserModule()); |
71 | super.configure(); |
72 | } |
73 | |
74 | @Override |
75 | protected void bindErrorHandlers() { |
76 | bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(GleSYSErrorHandler.class); |
77 | bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(GleSYSErrorHandler.class); |
78 | bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(GleSYSErrorHandler.class); |
79 | } |
80 | |
81 | @Override |
82 | protected void bindRetryHandlers() { |
83 | bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to(BackoffLimitedRetryHandler.class); |
84 | } |
85 | |
86 | @Override |
87 | protected void installLocations() { |
88 | super.installLocations(); |
89 | bind(ImplicitLocationSupplier.class).to(OnlyLocationOrFirstZone.class).in(Scopes.SINGLETON); |
90 | } |
91 | } |