| 1 | /** |
| 2 | * |
| 3 | * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com> |
| 4 | * |
| 5 | * ==================================================================== |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | * ==================================================================== |
| 18 | */ |
| 19 | package org.jclouds.ec2.compute.config; |
| 20 | |
| 21 | import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; |
| 22 | |
| 23 | import java.util.Map; |
| 24 | |
| 25 | import javax.inject.Named; |
| 26 | import javax.inject.Singleton; |
| 27 | |
| 28 | import org.jclouds.compute.ComputeServiceContext; |
| 29 | import org.jclouds.compute.config.BaseComputeServiceContextModule; |
| 30 | import org.jclouds.compute.domain.Image; |
| 31 | import org.jclouds.ec2.compute.EC2ComputeService; |
| 32 | import org.jclouds.ec2.compute.domain.RegionAndName; |
| 33 | import org.jclouds.ec2.compute.suppliers.RegionAndNameToImageSupplier; |
| 34 | import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier; |
| 35 | |
| 36 | import com.google.common.base.Supplier; |
| 37 | import com.google.inject.Provides; |
| 38 | |
| 39 | /** |
| 40 | * Configures the {@link ComputeServiceContext}; requires {@link EC2ComputeService} bound. |
| 41 | * |
| 42 | * @author Adrian Cole |
| 43 | */ |
| 44 | public class EC2ComputeServiceContextModule extends BaseComputeServiceContextModule { |
| 45 | @Override |
| 46 | protected void configure() { |
| 47 | installDependencies(); |
| 48 | install(new EC2BindComputeStrategiesByClass()); |
| 49 | install(new EC2BindComputeSuppliersByClass()); |
| 50 | super.configure(); |
| 51 | } |
| 52 | |
| 53 | protected void installDependencies(){ |
| 54 | install(new EC2ComputeServiceDependenciesModule()); |
| 55 | } |
| 56 | |
| 57 | @Provides |
| 58 | @Singleton |
| 59 | protected Supplier<Map<RegionAndName, ? extends Image>> provideRegionAndNameToImageSupplierCache( |
| 60 | @Named(PROPERTY_SESSION_INTERVAL) long seconds, final RegionAndNameToImageSupplier supplier) { |
| 61 | return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<RegionAndName, ? extends Image>>( |
| 62 | authException, seconds, new Supplier<Map<RegionAndName, ? extends Image>>() { |
| 63 | @Override |
| 64 | public Map<RegionAndName, ? extends Image> get() { |
| 65 | return supplier.get(); |
| 66 | } |
| 67 | }); |
| 68 | } |
| 69 | |
| 70 | } |