Package com.microsoft.windowsazure.core.pipeline.apache

Source Code of com.microsoft.windowsazure.core.pipeline.apache.Exports

/**
* Copyright Microsoft Corporation
*
* Licensed 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 com.microsoft.windowsazure.core.pipeline.apache;

import java.util.Map;

import com.microsoft.windowsazure.core.Builder;
import com.microsoft.windowsazure.core.Builder.Registry;
import com.microsoft.windowsazure.credentials.CloudCredentials;
import com.microsoft.windowsazure.management.configuration.ManagementConfiguration;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;

public class Exports implements Builder.Exports {

    @Override
    public void register(Registry registry) {
        registry.add(new Builder.Factory<ExecutorService>() {
            @Override
            public <S> ExecutorService create(String profile, Class<S> service,
                    Builder builder, Map<String, Object> properties) {

                return Executors.newCachedThreadPool();
            }
        });

        registry.add(new Builder.Factory<ApacheConfigSettings>() {
            @Override
            public <S> ApacheConfigSettings create(String profile,
                    Class<S> service, Builder builder,
                    Map<String, Object> properties) {

                if (properties
                        .containsKey(ManagementConfiguration.SUBSCRIPTION_CLOUD_CREDENTIALS)) {
                    CloudCredentials cloudCredentials = (CloudCredentials) properties
              .get(ManagementConfiguration.SUBSCRIPTION_CLOUD_CREDENTIALS);
                    cloudCredentials.applyConfig(profile, properties);
                }

                return new ApacheConfigSettings(profile, properties);
            }
        });

        registry.add(new Builder.Factory<HttpClientBuilder>() {
            @Override
            public <S> HttpClientBuilder create(String profile,
                    Class<S> service, Builder builder,
                    Map<String, Object> properties) {

                HttpClientBuilder httpClientBuilder = HttpClients.custom();
                ApacheConfigSettings settings = builder.build(profile, service,
                        ApacheConfigSettings.class, properties);

                return settings.applyConfig(httpClientBuilder);
            }
        });
    }
}
TOP

Related Classes of com.microsoft.windowsazure.core.pipeline.apache.Exports

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.