Skip to content

Commit

Permalink
Merge pull request #399 from WindowsAzure/master
Browse files Browse the repository at this point in the history
merge the master to dev for release 0.4.5
  • Loading branch information
xuezhai committed Sep 12, 2013
2 parents 4134be0 + 599f8c9 commit f1d13e2
Show file tree
Hide file tree
Showing 71 changed files with 3,776 additions and 212 deletions.
6 changes: 5 additions & 1 deletion ChangeLog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
2013.08.26 Version 0.4.5
* Added support for managing affinity groups
* Added support for Media Services job notification

2013.07.03 Version 0.4.4
* Windows Azure China environemnt support
* Windows Azure China environment support
* Service Bus metadata support updated to the latest version
* Rich Odata entity query support for Service Bus Queue/Topic/Subscription
* Added support for Service Bus message forwarding
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ This project provides a client library in Java that makes it easy to consume Win
* Create/Read/Update/Delete assets
* Create/Read/Update/Delete/Rebind content keys
* Create/Read/Update/Cancel/Delete jobs
* Add/Get job notifications
* Create/Read/Update/Delete notification endpoints
* Service Management
* Manage affinity groups
* Service Runtime
* Retrieve information about the state of your Azure Compute instances

Expand All @@ -59,7 +63,7 @@ within your project you can also have them installed by the Java package manager
<dependency>
<groupId>com.microsoft.windowsazure</groupId>
<artifactId>microsoft-windowsazure-api</artifactId>
<version>0.4.4</version>
<version>0.4.5</version>
</dependency>
```

Expand Down
32 changes: 30 additions & 2 deletions microsoft-azure-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.microsoft.windowsazure</groupId>
<artifactId>microsoft-windowsazure-api</artifactId>
<version>0.4.4</version>
<version>0.4.5</version>
<packaging>jar</packaging>

<name>Microsoft Windows Azure Client API</name>
Expand Down Expand Up @@ -134,7 +134,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
Expand All @@ -146,10 +146,38 @@
<version>0.8.3</version>
<executions>
<execution>
<id>serviceBus</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<generateDirectory>target/generated-sources/xjc</generateDirectory>
<schemaDirectory>src/main/resources/serviceBus</schemaDirectory>
<schemaIncludes>
<include>servicebus-atom.xsd</include>
</schemaIncludes>
<generatePackage>com.microsoft.windowsazure.services.serviceBus.implementation</generatePackage>
<removeOldOutput>false</removeOldOutput>
<forceRegenerate>true</forceRegenerate>
</configuration>
</execution>
<execution>
<id>management</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<generateDirectory>target/generated-sources/xjc</generateDirectory>
<schemaDirectory>src/main/resources/management/</schemaDirectory>
<schemaIncludes>
<include>schemas.microsoft.com.windowsazure.xsd</include>
</schemaIncludes>
<generatePackage>com.microsoft.windowsazure.services.management.implementation</generatePackage>
<removeOldOutput>false</removeOldOutput>
<forceRegenerate>true</forceRegenerate>
</configuration>
</execution>
</executions>
<configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@
* 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
* 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.
* 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.services.core;

import java.util.Map;

public interface Builder {

public abstract <T> T build(String profile, Class<T> service, Map<String, Object> properties);
public abstract <S, T> T build(String profile, Class<S> service, Class<T> instance, Map<String, Object> properties);

public interface Factory<T> {
T create(String profile, Builder builder, Map<String, Object> properties);
<S> T create(String profile, Class<S> service, Builder builder, Map<String, Object> properties);
}

public interface Alteration<T> {
T alter(T instance, Builder builder, Map<String, Object> properties);
T alter(String profile, T instance, Builder builder, Map<String, Object> properties);
}

public interface Registry {
Expand All @@ -35,7 +35,7 @@ public interface Registry {

<T> Registry add(Factory<T> factory);

<T> void alter(Class<T> service, Alteration<T> alteration);
<S, T> void alter(Class<S> service, Class<T> instance, Alteration<T> alteration);
}

public interface Exports {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ public static Configuration load() throws IOException {
}

public <T> T create(Class<T> service) {
return builder.build("", service, properties);
return builder.build("", service, service, properties);
}

public <T> T create(String profile, Class<T> service) {
return builder.build(profile, service, properties);
return builder.build(profile, service, service, properties);
}

public Builder getBuilder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
* 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
* 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.
* 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.services.core;

Expand All @@ -30,11 +30,11 @@

public class DefaultBuilder implements Builder, Builder.Registry {
Map<Class<?>, Factory<?>> factories;
Map<Class<?>, List<Alteration<?>>> alterations;
Map<Class<?>, Map<Class<?>, List<Alteration<?>>>> alterations;

public DefaultBuilder() {
factories = new HashMap<Class<?>, Factory<?>>();
alterations = new HashMap<Class<?>, List<Alteration<?>>>();
alterations = new HashMap<Class<?>, Map<Class<?>, List<Alteration<?>>>>();
}

public static DefaultBuilder create() {
Expand All @@ -51,6 +51,7 @@ void addFactory(Class<?> service, Factory<?> factory) {
factories.put(service, factory);
}

@Override
public <T> Builder.Registry add(Class<T> service) {
return add(service, service);
}
Expand Down Expand Up @@ -84,15 +85,17 @@ Constructor<?> findInjectConstructor(Class<?> implementation) {
return withoutInject;
}

@Override
public <T, TImpl> Builder.Registry add(Class<T> service, final Class<TImpl> implementation) {
final Constructor<?> ctor = findInjectConstructor(implementation);
final Class<?>[] parameterTypes = ctor.getParameterTypes();
final Annotation[][] parameterAnnotations = ctor.getParameterAnnotations();

addFactory(service, new Builder.Factory<T>() {
@Override
@SuppressWarnings("unchecked")
public T create(String profile, Builder builder, Map<String, Object> properties) {
Object[] initargs = new Object[parameterTypes.length];
public <S> T create(String profile, Class<S> service, Builder builder, Map<String, Object> properties) {
Object[] initializationArguments = new Object[parameterTypes.length];
for (int i = 0; i != parameterTypes.length; ++i) {

boolean located = false;
Expand All @@ -103,10 +106,10 @@ public T create(String profile, Builder builder, Map<String, Object> properties)
boolean probeProperties = fullName != null && fullName != "";
int startingIndex = 0;
while (!located && probeProperties) {
String probeName = fullName.substring(startingIndex);
if (!located && named != null && properties.containsKey(probeName)) {
String nameProbe = fullName.substring(startingIndex);
if (!located && named != null && properties.containsKey(nameProbe)) {
located = true;
initargs[i] = properties.get(probeName);
initializationArguments[i] = properties.get(nameProbe);
}
else {
startingIndex = fullName.indexOf('.', startingIndex) + 1;
Expand All @@ -118,12 +121,12 @@ public T create(String profile, Builder builder, Map<String, Object> properties)

if (!located) {
located = true;
initargs[i] = builder.build(fullName, parameterTypes[i], properties);
initializationArguments[i] = builder.build(fullName, service, parameterTypes[i], properties);
}
}

try {
return (T) ctor.newInstance(initargs);
return (T) ctor.newInstance(initializationArguments);
}
catch (InstantiationException e) {
throw new ConfigurationException(e);
Expand Down Expand Up @@ -158,6 +161,7 @@ protected String findNamedAnnotation(Annotation[] annotations) {
return null;
}

@Override
public <T> Registry add(Factory<T> factory) {
for (Type genericInterface : factory.getClass().getGenericInterfaces()) {
ParameterizedType parameterizedType = (ParameterizedType) genericInterface;
Expand All @@ -169,27 +173,35 @@ public <T> Registry add(Factory<T> factory) {
return this;
}

@Override
@SuppressWarnings("unchecked")
public <T> T build(String profile, Class<T> service, Map<String, Object> properties) {
Factory<T> factory = (Factory<T>) factories.get(service);
public <S, T> T build(String profile, Class<S> service, Class<T> instanceClass, Map<String, Object> properties) {
Factory<T> factory = (Factory<T>) factories.get(instanceClass);
if (factory == null) {
throw new RuntimeException("Service or property not registered: " + profile + " " + service.getName());
}
T instance = factory.create(profile, this, properties);
List<Alteration<?>> alterationList = alterations.get(service);
if (alterationList != null) {
for (Alteration<?> alteration : alterationList) {
instance = ((Alteration<T>) alteration).alter(instance, this, properties);
T instance = factory.create(profile, service, this, properties);
Map<Class<?>, List<Alteration<?>>> alterationMap = alterations.get(service);
if (alterationMap != null) {
List<Alteration<?>> alterationList = alterationMap.get(instanceClass);
if (alterationList != null) {
for (Alteration<?> alteration : alterationList) {
instance = ((Alteration<T>) alteration).alter(profile, instance, this, properties);
}
}
}
return instance;
}

public <T> void alter(Class<T> service, Alteration<T> alteration) {
@Override
public <S, T> void alter(Class<S> service, Class<T> instance, Alteration<T> alteration) {
if (!this.alterations.containsKey(service)) {
this.alterations.put(service, new ArrayList<Alteration<?>>());
this.alterations.put(service, new HashMap<Class<?>, List<Alteration<?>>>());
}
if (!this.alterations.get(service).containsKey(instance)) {
this.alterations.get(service).put(instance, new ArrayList<Alteration<?>>());
}
this.alterations.get(service).add(alteration);
this.alterations.get(service).get(instance).add(alteration);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
*/
package com.microsoft.windowsazure.services.core.utils.pipeline;

import static com.microsoft.windowsazure.services.core.utils.ExportUtils.*;

import java.util.Map;

import com.microsoft.windowsazure.services.core.Builder;
Expand All @@ -23,17 +25,16 @@
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.api.client.config.DefaultClientConfig;

import static com.microsoft.windowsazure.services.core.utils.ExportUtils.getPropertyIfExists;

public class Exports implements Builder.Exports {

@Override
public void register(Registry registry) {
registry.add(new Builder.Factory<ClientConfig>() {
@Override
public ClientConfig create(String profile, Builder builder, Map<String, Object> properties) {
public <S> ClientConfig create(String profile, Class<S> service, Builder builder,
Map<String, Object> properties) {
ClientConfig clientConfig = new DefaultClientConfig();
ClientConfigSettings settings = builder.build(profile, ClientConfigSettings.class, properties);
ClientConfigSettings settings = builder.build(profile, service, ClientConfigSettings.class, properties);
settings.applyConfig(clientConfig);
return clientConfig;
}
Expand All @@ -42,20 +43,22 @@ public ClientConfig create(String profile, Builder builder, Map<String, Object>
registry.add(new Builder.Factory<ClientConfigSettings>() {

@Override
public ClientConfigSettings create(String profile, Builder builder, Map<String, Object> properties) {
public <S> ClientConfigSettings create(String profile, Class<S> service, Builder builder,
Map<String, Object> properties) {
Object connectTimeout = getPropertyIfExists(profile, properties, Configuration.PROPERTY_CONNECT_TIMEOUT);
Object readTimeout = getPropertyIfExists(profile, properties, Configuration.PROPERTY_READ_TIMEOUT);

return new ClientConfigSettings(connectTimeout, readTimeout, getPropertyIfExists(profile, properties,
Configuration.PROPERTY_LOG_HTTP_REQUESTS) != null);
}

});

registry.add(new Builder.Factory<Client>() {
@Override
public Client create(String profile, Builder builder, Map<String, Object> properties) {
ClientConfig clientConfig = builder.build(profile, ClientConfig.class, properties);
ClientConfigSettings settings = builder.build(profile, ClientConfigSettings.class, properties);
public <S> Client create(String profile, Class<S> service, Builder builder, Map<String, Object> properties) {
ClientConfig clientConfig = builder.build(profile, service, ClientConfig.class, properties);
ClientConfigSettings settings = builder.build(profile, service, ClientConfigSettings.class, properties);
Client client = Client.create(clientConfig);
settings.applyConfig(client);
return client;
Expand All @@ -64,9 +67,10 @@ public Client create(String profile, Builder builder, Map<String, Object> proper

registry.add(new Builder.Factory<HttpURLConnectionClient>() {
@Override
public HttpURLConnectionClient create(String profile, Builder builder, Map<String, Object> properties) {
ClientConfig clientConfig = builder.build(profile, ClientConfig.class, properties);
ClientConfigSettings settings = builder.build(profile, ClientConfigSettings.class, properties);
public <S> HttpURLConnectionClient create(String profile, Class<S> service, Builder builder,
Map<String, Object> properties) {
ClientConfig clientConfig = builder.build(profile, service, ClientConfig.class, properties);
ClientConfigSettings settings = builder.build(profile, service, ClientConfigSettings.class, properties);
HttpURLConnectionClient client = HttpURLConnectionClient.create(clientConfig);
settings.applyConfig(client);
return client;
Expand Down
Loading

0 comments on commit f1d13e2

Please sign in to comment.