Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 
 package org.apache.whirr.service;
 
 import java.util.Map;
 import java.util.Set;
 
 
 
 public class BlobStoreContextBuilder {
 
   private static final Logger LOG = LoggerFactory.getLogger(Cache.class);
    
   private static enum Cache implements Function<ClusterSpecBlobStoreContext> {
 
     INSTANCE;
 
     @Override
     public BlobStoreContext apply(ClusterSpec arg0) {
       return .get(new Key(arg0));
     }
 
     // this should prevent recreating the same compute context twice
     final Map<KeyBlobStoreContextcache = new MapMaker().makeComputingMap(
        new Function<KeyBlobStoreContext>(){
         private final BlobStoreContextFactory factory =  new BlobStoreContextFactory();
         
         private final Set<AbstractModulewiring = ImmutableSet.of(
             new SLF4JLoggingModule(), 
             new EnterpriseConfigurationModule());        
         
         @Override
         public BlobStoreContext apply(Key arg0) {
           .debug("creating new BlobStoreContext {}"arg0);
           BlobStoreContext context = new IgnoreCloseBlobStoreContext(
               .createContext(arg0.providerarg0.identityarg0.credential,
                                     arg0.overrides));
           .info("created new BlobStoreContext {}"context);
           return context;
        }
       
       }
     );
   }
   
   public static BlobStoreContext build(ClusterSpec spec) {
     return ..apply(spec);
   }
 
 
   private static class IgnoreCloseBlobStoreContext extends ForwardingObject implements BlobStoreContext {
 
     private final BlobStoreContext context;
    public IgnoreCloseBlobStoreContext(final BlobStoreContext context) {
      this. = context;
      Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
          .debug("closing BlobStoreContext {}"context);
          context.close();
        }
      });
    }
    @Override
    protected BlobStoreContext delegate() {
      return ;
    }
    @Override
    public BlobRequestSigner getSigner() {
      return delegate().getSigner();
    }
    @Override
    public InputStreamMap createInputStreamMap(String containerListContainerOptions options) {
      return delegate().createInputStreamMap(containeroptions);
    }
    @Override
    public InputStreamMap createInputStreamMap(String container) {
      return delegate().createInputStreamMap(container);
    }
    @Override
    public BlobMap createBlobMap(String containerListContainerOptions options) {
      return delegate().createBlobMap(containeroptions);
    }
    @Override
    public BlobMap createBlobMap(String container) {
      return delegate().createBlobMap(container);
    }
    @Override
    public AsyncBlobStore getAsyncBlobStore() {
      return delegate().getAsyncBlobStore();
    }
    @Override
    public BlobStore getBlobStore() {
      return delegate().getBlobStore();
    }
    @Override
      return delegate().getConsistencyModel();
    }
    @Override
    public <S, A> RestContext<S, A> getProviderSpecificContext() {
      return delegate().getProviderSpecificContext();
    }
    @Override
    public Utils getUtils() {
      return delegate().getUtils();
    }
    @Override
    public Utils utils() {
      return delegate().utils();
    }
    @Override
    public void close() {
      // ignore; closed by shutdown hook
    }
  }

  
All APIs that are independently configurable.

See also:
  public static final Iterable<StringBLOBSTORE_APIS = ImmutableSet.of("transient""file""swift""walrus",
      "atmos""aws-s3""cloudfiles-us""cloudfiles-uk");

  
jclouds providers and apis that can be used in BlobStoreContextFactory
  public static final Iterable<StringBLOBSTORE_KEYS = Iterables.concat(
      Iterables.transform(Providers.allCompute(), new Function<ProviderMetadataString>() {
        @Override
        public String apply(ProviderMetadata input) {
          return input.getId();
        }
      }), );

  
configurable properties, scoped to a provider.
  public static final Iterable<StringPROVIDER_PROPERTIES = ImmutableSet.of("endpoint""api""apiversion",
      "iso3166-codes");

  
Key class for the blobstore context cache
  private static class Key {
    private final String provider;
    private final String identity;
    private final String credential;
    private final String key;
    private final Properties overrides;
    public Key(ClusterSpec spec) {
       = spec.getBlobStoreProvider();
       = spec.getBlobStoreIdentity();
       = spec.getBlobStoreCredential();
       = String.format("%s-%s-%s");
      Configuration jcloudsConfig = spec.getConfigurationForKeysWithPrefix("jclouds");
      
      // jclouds configuration for providers are not prefixed with jclouds.
      for (String key : ) {
        for (String property : ) {
          String prefixedProperty = "jclouds." + key + "." + property;
          if (jcloudsConfig.containsKey(prefixedProperty))
            jcloudsConfig.setProperty(key + "." + property
                jcloudsConfig.getProperty(prefixedProperty));
        }
      }
       = ConfigurationConverter.getProperties(jcloudsConfig);
    }
    @Override
    public boolean equals(Object that) {
      if (that instanceof Key) {
        return Objects.equal(this., ((Key)that).)
          && Objects.equal(, ((Key)that).);
      }
      return false;
    }
    @Override
    public int hashCode() {
      return Objects.hashCode();
    }
  }
New to GrepCode? Check out our FAQ X