diff --git a/core/src/main/java/org/jclouds/Utils.java b/core/src/main/java/org/jclouds/Utils.java index 7210c5b178..b673b62064 100644 --- a/core/src/main/java/org/jclouds/Utils.java +++ b/core/src/main/java/org/jclouds/Utils.java @@ -23,12 +23,12 @@ */ package org.jclouds; -import org.apache.commons.io.IOUtils; - import java.io.IOException; import java.io.InputStream; import java.util.concurrent.ExecutionException; +import org.apache.commons.io.IOUtils; + /** * // TODO: Adrian: Document this! * @@ -37,6 +37,7 @@ import java.util.concurrent.ExecutionException; public class Utils { + @SuppressWarnings("unchecked") public static void rethrowIfRuntimeOrSameType(Exception e) throws E { if (e instanceof ExecutionException) { Throwable nested = e.getCause(); diff --git a/core/src/main/java/org/jclouds/command/FutureCommandClient.java b/core/src/main/java/org/jclouds/command/FutureCommandClient.java index 0af69706d2..cdf57d7c8c 100644 --- a/core/src/main/java/org/jclouds/command/FutureCommandClient.java +++ b/core/src/main/java/org/jclouds/command/FutureCommandClient.java @@ -28,7 +28,6 @@ package org.jclouds.command; * * @author Adrian Cole */ -public interface FutureCommandClient { - @SuppressWarnings("unchecked") - void submit(O operation); +public interface FutureCommandClient> { + void submit(O operation); } diff --git a/core/src/main/java/org/jclouds/command/pool/FutureCommandConnectionHandle.java b/core/src/main/java/org/jclouds/command/pool/FutureCommandConnectionHandle.java index 813f93d75a..a2591cc610 100644 --- a/core/src/main/java/org/jclouds/command/pool/FutureCommandConnectionHandle.java +++ b/core/src/main/java/org/jclouds/command/pool/FutureCommandConnectionHandle.java @@ -39,31 +39,28 @@ import com.google.inject.assistedinject.Assisted; * * @author Adrian Cole */ -public abstract class FutureCommandConnectionHandle { +public abstract class FutureCommandConnectionHandle> { protected final BlockingQueue available; protected final Semaphore maxConnections; protected final Semaphore completed; protected C conn; - @SuppressWarnings("unchecked") - protected FutureCommand operation; + protected O command; @Resource protected Logger logger = Logger.NULL; - @SuppressWarnings("unchecked") public FutureCommandConnectionHandle(Semaphore maxConnections, - @Assisted FutureCommand operation, @Assisted C conn, - BlockingQueue available) throws InterruptedException { + @Assisted O command, @Assisted C conn, BlockingQueue available) + throws InterruptedException { this.maxConnections = maxConnections; - this.operation = operation; + this.command = command; this.conn = conn; this.available = available; this.completed = new Semaphore(1); completed.acquire(); } - @SuppressWarnings("unchecked") - public FutureCommand getOperation() { - return operation; + public O getCommand() { + return command; } public abstract void startConnection(); @@ -79,7 +76,7 @@ public abstract class FutureCommandConnectionHandle { logger.trace("%1s - %2d - releasing to pool", conn, conn.hashCode()); available.put(conn); conn = null; - operation = null; + command = null; completed.release(); } @@ -94,7 +91,7 @@ public abstract class FutureCommandConnectionHandle { shutdownConnection(); } finally { conn = null; - operation = null; + command = null; maxConnections.release(); } } diff --git a/core/src/main/java/org/jclouds/command/pool/FutureCommandConnectionPool.java b/core/src/main/java/org/jclouds/command/pool/FutureCommandConnectionPool.java index 75c662edec..23c857fa32 100644 --- a/core/src/main/java/org/jclouds/command/pool/FutureCommandConnectionPool.java +++ b/core/src/main/java/org/jclouds/command/pool/FutureCommandConnectionPool.java @@ -41,41 +41,38 @@ import com.google.inject.name.Named; * * @author Adrian Cole */ -public abstract class FutureCommandConnectionPool extends BaseLifeCycle { +public abstract class FutureCommandConnectionPool> + extends BaseLifeCycle { protected final Semaphore allConnections; protected final BlockingQueue available; - protected final FutureCommandConnectionHandleFactory futureCommandConnectionHandleFactory; + protected final BlockingQueue commandQueue; + protected final FutureCommandConnectionHandleFactory futureCommandConnectionHandleFactory; protected final int maxConnectionReuse; protected final AtomicInteger currentSessionFailures = new AtomicInteger(0); - protected final FutureCommandConnectionRetry futureCommandConnectionRetry; protected volatile boolean hitBottom = false; public FutureCommandConnectionPool( ExecutorService executor, - FutureCommandConnectionRetry futureCommandConnectionRetry, Semaphore allConnections, - FutureCommandConnectionHandleFactory futureCommandConnectionHandleFactory, + BlockingQueue commandQueue, + FutureCommandConnectionHandleFactory futureCommandConnectionHandleFactory, @Named("maxConnectionReuse") int maxConnectionReuse, BlockingQueue available, BaseLifeCycle... dependencies) { super(executor, dependencies); - this.futureCommandConnectionRetry = futureCommandConnectionRetry; this.allConnections = allConnections; + this.commandQueue = commandQueue; this.futureCommandConnectionHandleFactory = futureCommandConnectionHandleFactory; this.maxConnectionReuse = maxConnectionReuse; this.available = available; } - @SuppressWarnings("unchecked") protected void setResponseException(Exception ex, C conn) { - FutureCommand command = futureCommandConnectionRetry - .getHandleFromConnection(conn).getOperation(); + O command = getHandleFromConnection(conn).getCommand(); command.getResponseFuture().setException(ex); } - @SuppressWarnings("unchecked") protected void cancel(C conn) { - FutureCommand command = futureCommandConnectionRetry - .getHandleFromConnection(conn).getOperation(); + O command = getHandleFromConnection(conn).getCommand(); command.cancel(true); } @@ -119,22 +116,49 @@ public abstract class FutureCommandConnectionPool extends BaseLifeCycle { protected abstract boolean connectionValid(C conn); - public FutureCommandConnectionHandle getHandle( - FutureCommand command) throws InterruptedException, - TimeoutException { + public FutureCommandConnectionHandle getHandle(O command) + throws InterruptedException, TimeoutException { exceptionIfNotActive(); C conn = getConnection(); - FutureCommandConnectionHandle handle = futureCommandConnectionHandleFactory + FutureCommandConnectionHandle handle = futureCommandConnectionHandleFactory .create(command, conn); - futureCommandConnectionRetry - .associateHandleWithConnection(handle, conn); + associateHandleWithConnection(handle, conn); return handle; } + protected void resubmitCommand(C connection) { + O command = getCommandFromConnection(connection); + if (command != null) { + logger.info("resubmitting command: %1s", command); + commandQueue.add(command); + } + } + + O getCommandFromConnection(C connection) { + FutureCommandConnectionHandle handle = getHandleFromConnection(connection); + if (handle != null && handle.getCommand() != null) { + return handle.getCommand(); + } + return null; + } + + protected void setExceptionOnCommand(C connection, Exception e) { + FutureCommand command = getCommandFromConnection(connection); + if (command != null) { + logger.warn(e, "exception in command: %1s", command); + command.setException(e); + } + } + + protected abstract void associateHandleWithConnection( + FutureCommandConnectionHandle handle, C connection); + + protected abstract FutureCommandConnectionHandle getHandleFromConnection( + C connection); + protected abstract void createNewConnection() throws InterruptedException; - public interface FutureCommandConnectionHandleFactory { - @SuppressWarnings("unchecked") - FutureCommandConnectionHandle create(FutureCommand command, C conn); + public interface FutureCommandConnectionHandleFactory> { + FutureCommandConnectionHandle create(O command, C conn); } } diff --git a/core/src/main/java/org/jclouds/command/pool/FutureCommandConnectionPoolClient.java b/core/src/main/java/org/jclouds/command/pool/FutureCommandConnectionPoolClient.java index 794eccb70a..cf612f3262 100644 --- a/core/src/main/java/org/jclouds/command/pool/FutureCommandConnectionPoolClient.java +++ b/core/src/main/java/org/jclouds/command/pool/FutureCommandConnectionPoolClient.java @@ -40,15 +40,15 @@ import com.google.inject.Inject; * * @author Adrian Cole */ -public class FutureCommandConnectionPoolClient extends BaseLifeCycle - implements FutureCommandClient { - private final FutureCommandConnectionPool futureCommandConnectionPool; - private final BlockingQueue commandQueue; +public class FutureCommandConnectionPoolClient> + extends BaseLifeCycle implements FutureCommandClient { + private final FutureCommandConnectionPool futureCommandConnectionPool; + private final BlockingQueue commandQueue; @Inject public FutureCommandConnectionPoolClient(ExecutorService executor, - FutureCommandConnectionPool futureCommandConnectionPool, - BlockingQueue commandQueue) { + FutureCommandConnectionPool futureCommandConnectionPool, + BlockingQueue commandQueue) { super(executor, futureCommandConnectionPool); this.futureCommandConnectionPool = futureCommandConnectionPool; this.commandQueue = commandQueue; @@ -66,7 +66,8 @@ public class FutureCommandConnectionPoolClient extends BaseLifeCycle exception.compareAndSet(null, futureCommandConnectionPool .getException()); while (!commandQueue.isEmpty()) { - FutureCommand command = commandQueue.remove(); + FutureCommand command = (FutureCommand) commandQueue + .remove(); if (command != null) { if (exception.get() != null) command.setException(exception.get()); @@ -78,7 +79,7 @@ public class FutureCommandConnectionPoolClient extends BaseLifeCycle @Override protected void doWork() throws InterruptedException { - FutureCommand command = commandQueue.poll(1, TimeUnit.SECONDS); + O command = commandQueue.poll(1, TimeUnit.SECONDS); if (command != null) { try { invoke(command); @@ -89,37 +90,37 @@ public class FutureCommandConnectionPoolClient extends BaseLifeCycle } } - public void submit(O operation) { + public void submit(O command) { exceptionIfNotActive(); - commandQueue.add(operation); + commandQueue.add(command); } - protected void invoke(O operation) { + protected void invoke(O command) { exceptionIfNotActive(); - FutureCommandConnectionHandle connectionHandle = null; + FutureCommandConnectionHandle connectionHandle = null; try { - connectionHandle = futureCommandConnectionPool.getHandle(operation); + connectionHandle = futureCommandConnectionPool.getHandle(command); } catch (InterruptedException e) { logger .warn( e, - "Interrupted getting a connection for operation %1s; retrying", - operation); - commandQueue.add(operation); + "Interrupted getting a connection for command %1s; retrying", + command); + commandQueue.add(command); return; } catch (TimeoutException e) { logger.warn(e, - "Timeout getting a connection for operation %1s; retrying", - operation); - commandQueue.add(operation); + "Timeout getting a connection for command %1s; retrying", + command); + commandQueue.add(command); return; } if (connectionHandle == null) { logger.error( - "Failed to obtain connection for operation %1s; retrying", - operation); - commandQueue.add(operation); + "Failed to obtain connection for command %1s; retrying", + command); + commandQueue.add(command); return; } connectionHandle.startConnection(); diff --git a/core/src/main/java/org/jclouds/command/pool/FutureCommandConnectionRetry.java b/core/src/main/java/org/jclouds/command/pool/FutureCommandConnectionRetry.java deleted file mode 100644 index 496c204294..0000000000 --- a/core/src/main/java/org/jclouds/command/pool/FutureCommandConnectionRetry.java +++ /dev/null @@ -1,79 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * 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.jclouds.command.pool; - -import java.io.IOException; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.atomic.AtomicInteger; - -import javax.annotation.Resource; - -import org.jclouds.command.FutureCommand; -import org.jclouds.logging.Logger; - -/** - * // TODO: Adrian: Document this! - * - * @author Adrian Cole - */ -public abstract class FutureCommandConnectionRetry { - protected final BlockingQueue commandQueue; - protected final AtomicInteger errors; - @Resource - protected Logger logger = Logger.NULL; - - public FutureCommandConnectionRetry( - BlockingQueue commandQueue, AtomicInteger errors) { - this.commandQueue = commandQueue; - this.errors = errors; - } - - public abstract void associateHandleWithConnection( - FutureCommandConnectionHandle handle, C connection); - - public abstract FutureCommandConnectionHandle getHandleFromConnection( - C connection); - - public boolean shutdownConnectionAndRetryOperation(C connection) { - FutureCommandConnectionHandle handle = getHandleFromConnection(connection); - if (handle != null) { - try { - logger.info("%1s - shutting down connection", connection); - handle.shutdownConnection(); - incrementErrorCountAndRetry(handle.getOperation()); - return true; - } catch (IOException e) { - logger.error(e, "%1s - error shutting down connection", - connection); - } - } - return false; - } - - public void incrementErrorCountAndRetry(FutureCommand command) { - errors.getAndIncrement(); - logger.info("resubmitting command %1s", command); - commandQueue.add(command); - } -} diff --git a/core/src/main/java/org/jclouds/command/pool/config/FutureCommandConnectionPoolClientModule.java b/core/src/main/java/org/jclouds/command/pool/config/FutureCommandConnectionPoolClientModule.java index 05f05e4696..f9c1ecac0f 100644 --- a/core/src/main/java/org/jclouds/command/pool/config/FutureCommandConnectionPoolClientModule.java +++ b/core/src/main/java/org/jclouds/command/pool/config/FutureCommandConnectionPoolClientModule.java @@ -23,48 +23,51 @@ */ package org.jclouds.command.pool.config; -import com.google.inject.*; -import com.google.inject.name.Named; -import org.jclouds.command.FutureCommand; -import org.jclouds.lifecycle.config.LifeCycleModule; -import org.jclouds.command.pool.PoolConstants; - import java.util.concurrent.BlockingQueue; -import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.Semaphore; import java.util.concurrent.atomic.AtomicInteger; +import org.jclouds.command.pool.PoolConstants; +import org.jclouds.lifecycle.config.LifeCycleModule; + +import com.google.inject.AbstractModule; +import com.google.inject.Provides; +import com.google.inject.Singleton; +import com.google.inject.name.Named; + /** * // TODO: Adrian: Document this! - * + * * @author Adrian Cole */ -public abstract class FutureCommandConnectionPoolClientModule extends AbstractModule { +public abstract class FutureCommandConnectionPoolClientModule extends + AbstractModule { protected void configure() { - install(new LifeCycleModule()); - bind(AtomicInteger.class).toInstance(new AtomicInteger());// max errors - bind(new TypeLiteral>() { - }).to(new TypeLiteral>() { - }).in(Scopes.SINGLETON); + install(new LifeCycleModule()); + bind(AtomicInteger.class).toInstance(new AtomicInteger());// max errors } - @Provides @Singleton - public abstract BlockingQueue provideAvailablePool(@Named(PoolConstants.PROPERTY_POOL_MAX_CONNECTIONS) int max) throws Exception; + public abstract BlockingQueue provideAvailablePool( + @Named(PoolConstants.PROPERTY_POOL_MAX_CONNECTIONS) int max) + throws Exception; + /** * controls production and destruction of real connections. *

- * aquire before a new connection is created - * release after an error has occurred - * + * aquire before a new connection is created release after an error has + * occurred + * * @param max * @return * @throws Exception */ @Provides @Singleton - public Semaphore provideTotalConnectionSemaphore(@Named(PoolConstants.PROPERTY_POOL_MAX_CONNECTIONS) int max) throws Exception { - return new Semaphore(max, true); + public Semaphore provideTotalConnectionSemaphore( + @Named(PoolConstants.PROPERTY_POOL_MAX_CONNECTIONS) int max) + throws Exception { + return new Semaphore(max, true); } } diff --git a/core/src/main/java/org/jclouds/http/HttpException.java b/core/src/main/java/org/jclouds/http/HttpException.java index 5b94068184..62f8685c63 100644 --- a/core/src/main/java/org/jclouds/http/HttpException.java +++ b/core/src/main/java/org/jclouds/http/HttpException.java @@ -25,19 +25,22 @@ package org.jclouds.http; /** * // TODO: Adrian: Document this! - * + * * @author Adrian Cole */ public class HttpException extends Exception { + + private static final long serialVersionUID = 1L; + public HttpException(String s) { - super(s); // TODO: Adrian: Customise this generated block + super(s); } public HttpException(String s, Throwable throwable) { - super(s, throwable); // TODO: Adrian: Customise this generated block + super(s, throwable); } public HttpException(Throwable throwable) { - super(throwable); // TODO: Adrian: Customise this generated block + super(throwable); } } diff --git a/core/src/main/java/org/jclouds/http/HttpFutureCommandClient.java b/core/src/main/java/org/jclouds/http/HttpFutureCommandClient.java index a412732f8f..3438696084 100644 --- a/core/src/main/java/org/jclouds/http/HttpFutureCommandClient.java +++ b/core/src/main/java/org/jclouds/http/HttpFutureCommandClient.java @@ -25,7 +25,6 @@ package org.jclouds.http; import java.util.List; -import org.jclouds.command.FutureCommand; import org.jclouds.command.FutureCommandClient; import com.google.inject.Inject; @@ -35,11 +34,11 @@ import com.google.inject.Inject; * * @author Adrian Cole */ -public interface HttpFutureCommandClient extends FutureCommandClient { +public interface HttpFutureCommandClient + extends FutureCommandClient> { List getRequestFilters(); @Inject void setRequestFilters(List requestFilters); - void submit(O operation); } diff --git a/core/src/main/java/org/jclouds/http/JavaUrlHttpFutureCommandClient.java b/core/src/main/java/org/jclouds/http/JavaUrlHttpFutureCommandClient.java index 121e7138e1..4ba19f9420 100644 --- a/core/src/main/java/org/jclouds/http/JavaUrlHttpFutureCommandClient.java +++ b/core/src/main/java/org/jclouds/http/JavaUrlHttpFutureCommandClient.java @@ -40,7 +40,6 @@ import javax.annotation.Resource; import org.apache.commons.io.IOUtils; import org.jclouds.Utils; -import org.jclouds.command.FutureCommand; import org.jclouds.logging.Logger; import com.google.inject.Inject; @@ -71,7 +70,7 @@ public class JavaUrlHttpFutureCommandClient implements HttpFutureCommandClient { this.target = target; } - public void submit(O operation) { + public void submit(HttpFutureCommand operation) { HttpRequest request = (HttpRequest) operation.getRequest(); HttpURLConnection connection = null; try { diff --git a/core/src/main/java/org/jclouds/http/commands/CommandFactory.java b/core/src/main/java/org/jclouds/http/commands/CommandFactory.java index ac38507474..12ce9760d4 100644 --- a/core/src/main/java/org/jclouds/http/commands/CommandFactory.java +++ b/core/src/main/java/org/jclouds/http/commands/CommandFactory.java @@ -41,6 +41,7 @@ public class CommandFactory { ParseSax create(ParseSax.HandlerWithResult handler); } + @SuppressWarnings("unchecked") public GetAndParseSax createGetAndParseSax(String uri, ParseSax.HandlerWithResult handler) { return new GetAndParseSax(uri, parseSaxFactory.create(handler)); diff --git a/core/src/test/java/org/jclouds/http/BaseHttpFutureCommandClientTest.java b/core/src/test/java/org/jclouds/http/BaseHttpFutureCommandClientTest.java index 2092fccf65..60855349b2 100644 --- a/core/src/test/java/org/jclouds/http/BaseHttpFutureCommandClientTest.java +++ b/core/src/test/java/org/jclouds/http/BaseHttpFutureCommandClientTest.java @@ -57,6 +57,7 @@ import org.testng.annotations.Test; import com.google.inject.AbstractModule; import com.google.inject.Guice; import com.google.inject.Injector; +import com.google.inject.Key; import com.google.inject.Module; import com.google.inject.TypeLiteral; import com.google.inject.name.Names; @@ -126,7 +127,7 @@ public abstract class BaseHttpFutureCommandClientTest { }).toInstance(filters); } }); - factory = injector.getInstance(CommandFactory.class); + factory = injector.getInstance(Key.get(CommandFactory.class)); client = injector.getInstance(HttpFutureCommandClient.class); closer = injector.getInstance(Closer.class); assert client != null; @@ -187,7 +188,7 @@ public abstract class BaseHttpFutureCommandClientTest { @Test(invocationCount = 500, timeOut = 1500) void testGetAndParseSax() throws MalformedURLException, ExecutionException, InterruptedException, TimeoutException { - GetAndParseSax getAndParseSax = factory.createGetAndParseSax("/", + GetAndParseSax getAndParseSax = factory.createGetAndParseSax("/", new ParseSax.HandlerWithResult() { @Override public String getResult() { diff --git a/core/src/test/java/org/jclouds/http/commands/config/HttpCommandsModuleTest.java b/core/src/test/java/org/jclouds/http/commands/config/HttpCommandsModuleTest.java index dd0f383da2..be3d99f78a 100644 --- a/core/src/test/java/org/jclouds/http/commands/config/HttpCommandsModuleTest.java +++ b/core/src/test/java/org/jclouds/http/commands/config/HttpCommandsModuleTest.java @@ -23,46 +23,48 @@ */ package org.jclouds.http.commands.config; -import com.google.inject.Guice; -import com.google.inject.Injector; import org.jclouds.http.HttpFutureCommand; import org.jclouds.http.commands.CommandFactory; import org.jclouds.http.commands.callables.xml.ParseSax; import org.testng.annotations.Test; +import com.google.inject.Guice; +import com.google.inject.Injector; + /** * // TODO: Adrian: Document this! - * + * * @author Adrian Cole */ @Test public class HttpCommandsModuleTest { public void testGetString() { - Injector i = Guice.createInjector(new HttpCommandsModule()); - CommandFactory factory = i.getInstance(CommandFactory.class); - HttpFutureCommand get = factory.createGetString("/index.html"); - assert get != null; - assert get.getResponseFuture() != null; + Injector i = Guice.createInjector(new HttpCommandsModule()); + CommandFactory factory = i.getInstance(CommandFactory.class); + HttpFutureCommand get = factory.createGetString("/index.html"); + assert get != null; + assert get.getResponseFuture() != null; } public void testHead() { - Injector i = Guice.createInjector(new HttpCommandsModule()); - CommandFactory factory = i.getInstance(CommandFactory.class); - HttpFutureCommand Head = factory.createHead("/index.html"); - assert Head != null; - assert Head.getResponseFuture() != null; + Injector i = Guice.createInjector(new HttpCommandsModule()); + CommandFactory factory = i.getInstance(CommandFactory.class); + HttpFutureCommand Head = factory.createHead("/index.html"); + assert Head != null; + assert Head.getResponseFuture() != null; } public void testGetAndParseXml() { - Injector i = Guice.createInjector(new HttpCommandsModule()); - CommandFactory factory = i.getInstance(CommandFactory.class); - HttpFutureCommand GetAndParseXml = factory.createGetAndParseSax("/index.html", new ParseSax.HandlerWithResult(){ - public String getResult() { - return "hello"; - } - }); - assert GetAndParseXml != null; - assert GetAndParseXml.getResponseFuture() != null; + Injector i = Guice.createInjector(new HttpCommandsModule()); + CommandFactory factory = i.getInstance(CommandFactory.class); + HttpFutureCommand GetAndParseXml = factory.createGetAndParseSax( + "/index.html", new ParseSax.HandlerWithResult() { + public String getResult() { + return "hello"; + } + }); + assert GetAndParseXml != null; + assert GetAndParseXml.getResponseFuture() != null; } } \ No newline at end of file diff --git a/core/src/test/java/org/jclouds/lifecycle/config/LifeCycleModuleTest.java b/core/src/test/java/org/jclouds/lifecycle/config/LifeCycleModuleTest.java index 62a8cb1ec4..84f3059572 100644 --- a/core/src/test/java/org/jclouds/lifecycle/config/LifeCycleModuleTest.java +++ b/core/src/test/java/org/jclouds/lifecycle/config/LifeCycleModuleTest.java @@ -23,20 +23,13 @@ */ package org.jclouds.lifecycle.config; -import static com.google.inject.matcher.Matchers.*; -import static org.testng.Assert.assertEquals; - import java.io.IOException; import java.util.concurrent.ExecutorService; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; -import javax.annotation.Resource; import org.jclouds.lifecycle.Closer; -import org.jclouds.logging.Logger; -import org.jclouds.logging.config.BindLoggersAnnotatedWithResource; -import org.jclouds.logging.jdk.JDKLogger; import org.testng.annotations.Test; import com.google.inject.AbstractModule; diff --git a/core/src/test/java/org/jclouds/logging/config/BindLoggersAnnotatedWithResourceTest.java b/core/src/test/java/org/jclouds/logging/config/BindLoggersAnnotatedWithResourceTest.java index e046061d05..0a0f9c75a3 100644 --- a/core/src/test/java/org/jclouds/logging/config/BindLoggersAnnotatedWithResourceTest.java +++ b/core/src/test/java/org/jclouds/logging/config/BindLoggersAnnotatedWithResourceTest.java @@ -106,6 +106,7 @@ public class BindLoggersAnnotatedWithResourceTest { } public static class C { + @SuppressWarnings("unused") @Inject private Logger logger = Logger.NULL; } @@ -118,9 +119,11 @@ public class BindLoggersAnnotatedWithResourceTest { } public static class D { + @SuppressWarnings("unused") @Resource private Logger logger = Logger.NULL; + @SuppressWarnings("unused") @Resource private Logger blogger; diff --git a/extensions/httpnio/src/main/java/org/jclouds/http/httpnio/config/HttpNioConnectionPoolClientModule.java b/extensions/httpnio/src/main/java/org/jclouds/http/httpnio/config/HttpNioConnectionPoolClientModule.java index dee1439e55..32823e324e 100644 --- a/extensions/httpnio/src/main/java/org/jclouds/http/httpnio/config/HttpNioConnectionPoolClientModule.java +++ b/extensions/httpnio/src/main/java/org/jclouds/http/httpnio/config/HttpNioConnectionPoolClientModule.java @@ -25,20 +25,16 @@ package org.jclouds.http.httpnio.config; import java.net.InetSocketAddress; -import org.apache.http.nio.NHttpConnection; -import org.jclouds.command.pool.FutureCommandConnectionRetry; import org.jclouds.http.HttpConstants; import org.jclouds.http.HttpFutureCommandClient; import org.jclouds.http.config.HttpFutureCommandClientModule; import org.jclouds.http.httpnio.config.internal.NonSSLHttpNioConnectionPoolClientModule; import org.jclouds.http.httpnio.config.internal.SSLHttpNioConnectionPoolClientModule; import org.jclouds.http.httpnio.pool.HttpNioConnectionPoolClient; -import org.jclouds.http.httpnio.pool.HttpNioFutureCommandConnectionRetry; import com.google.inject.AbstractModule; import com.google.inject.Provides; import com.google.inject.Singleton; -import com.google.inject.TypeLiteral; import com.google.inject.name.Named; /** @@ -59,8 +55,6 @@ public class HttpNioConnectionPoolClientModule extends AbstractModule { install(new SSLHttpNioConnectionPoolClientModule()); else install(new NonSSLHttpNioConnectionPoolClientModule()); - bind(new TypeLiteral>() { - }).to(HttpNioFutureCommandConnectionRetry.class); bind(HttpFutureCommandClient.class).to( HttpNioConnectionPoolClient.class); } diff --git a/extensions/httpnio/src/main/java/org/jclouds/http/httpnio/config/internal/BaseHttpNioConnectionPoolClientModule.java b/extensions/httpnio/src/main/java/org/jclouds/http/httpnio/config/internal/BaseHttpNioConnectionPoolClientModule.java index 99a1d12b1c..5fce93376e 100644 --- a/extensions/httpnio/src/main/java/org/jclouds/http/httpnio/config/internal/BaseHttpNioConnectionPoolClientModule.java +++ b/extensions/httpnio/src/main/java/org/jclouds/http/httpnio/config/internal/BaseHttpNioConnectionPoolClientModule.java @@ -25,6 +25,7 @@ package org.jclouds.http.httpnio.config.internal; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; +import java.util.concurrent.LinkedBlockingQueue; import org.apache.http.ConnectionReuseStrategy; import org.apache.http.HttpEntity; @@ -48,12 +49,11 @@ import org.apache.http.protocol.RequestContent; import org.apache.http.protocol.RequestExpectContinue; import org.apache.http.protocol.RequestTargetHost; import org.apache.http.protocol.RequestUserAgent; -import org.jclouds.command.pool.FutureCommandConnectionRetry; import org.jclouds.command.pool.PoolConstants; import org.jclouds.command.pool.config.FutureCommandConnectionPoolClientModule; +import org.jclouds.http.HttpFutureCommand; import org.jclouds.http.httpnio.pool.HttpNioFutureCommandConnectionHandle; import org.jclouds.http.httpnio.pool.HttpNioFutureCommandConnectionPool; -import org.jclouds.http.httpnio.pool.HttpNioFutureCommandConnectionRetry; import org.jclouds.http.httpnio.pool.HttpNioFutureCommandExecutionHandler; import com.google.inject.Inject; @@ -112,6 +112,9 @@ public abstract class BaseHttpNioConnectionPoolClientModule extends protected void configure() { super.configure(); + bind(new TypeLiteral>>() { + }).to(new TypeLiteral>>() { + }).in(Scopes.SINGLETON); bind( HttpNioFutureCommandExecutionHandler.ConsumingNHttpEntityFactory.class) .toProvider( @@ -126,8 +129,6 @@ public abstract class BaseHttpNioConnectionPoolClientModule extends bind(ConnectionReuseStrategy.class).to( DefaultConnectionReuseStrategy.class).in(Scopes.SINGLETON); bind(ByteBufferAllocator.class).to(HeapByteBufferAllocator.class); - bind(FutureCommandConnectionRetry.class).to( - HttpNioFutureCommandConnectionRetry.class); bind( HttpNioFutureCommandConnectionPool.FutureCommandConnectionHandleFactory.class) .toProvider( diff --git a/extensions/httpnio/src/main/java/org/jclouds/http/httpnio/pool/HttpNioConnectionPoolClient.java b/extensions/httpnio/src/main/java/org/jclouds/http/httpnio/pool/HttpNioConnectionPoolClient.java index 22eaa3b53e..a944b9d3e7 100644 --- a/extensions/httpnio/src/main/java/org/jclouds/http/httpnio/pool/HttpNioConnectionPoolClient.java +++ b/extensions/httpnio/src/main/java/org/jclouds/http/httpnio/pool/HttpNioConnectionPoolClient.java @@ -29,9 +29,9 @@ import java.util.concurrent.BlockingQueue; import java.util.concurrent.ExecutorService; import org.apache.http.nio.NHttpConnection; -import org.jclouds.command.FutureCommand; import org.jclouds.command.pool.FutureCommandConnectionPoolClient; import org.jclouds.http.HttpException; +import org.jclouds.http.HttpFutureCommand; import org.jclouds.http.HttpFutureCommandClient; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequestFilter; @@ -45,9 +45,10 @@ import com.google.inject.Singleton; * @author Adrian Cole */ @Singleton -public class HttpNioConnectionPoolClient extends - FutureCommandConnectionPoolClient implements - HttpFutureCommandClient { +public class HttpNioConnectionPoolClient + extends + FutureCommandConnectionPoolClient> + implements HttpFutureCommandClient { private List requestFilters = Collections.emptyList(); public List getRequestFilters() { @@ -60,15 +61,15 @@ public class HttpNioConnectionPoolClient extends } @Override - protected void invoke(O operation) { - HttpRequest request = (HttpRequest) operation.getRequest(); + protected void invoke(HttpFutureCommand command) { + HttpRequest request = (HttpRequest) command.getRequest(); try { for (HttpRequestFilter filter : getRequestFilters()) { filter.filter(request); } - super.invoke(operation); + super.invoke(command); } catch (HttpException e) { - operation.setException(e); + command.setException(e); } } @@ -76,7 +77,7 @@ public class HttpNioConnectionPoolClient extends public HttpNioConnectionPoolClient( ExecutorService executor, HttpNioFutureCommandConnectionPool httpFutureCommandConnectionHandleNHttpConnectionNioFutureCommandConnectionPool, - BlockingQueue commandQueue) { + BlockingQueue> commandQueue) { super( executor, httpFutureCommandConnectionHandleNHttpConnectionNioFutureCommandConnectionPool, diff --git a/extensions/httpnio/src/main/java/org/jclouds/http/httpnio/pool/HttpNioFutureCommandConnectionHandle.java b/extensions/httpnio/src/main/java/org/jclouds/http/httpnio/pool/HttpNioFutureCommandConnectionHandle.java index 7186b5a8ae..37b80b5eb8 100644 --- a/extensions/httpnio/src/main/java/org/jclouds/http/httpnio/pool/HttpNioFutureCommandConnectionHandle.java +++ b/extensions/httpnio/src/main/java/org/jclouds/http/httpnio/pool/HttpNioFutureCommandConnectionHandle.java @@ -28,8 +28,8 @@ import java.util.concurrent.BlockingQueue; import java.util.concurrent.Semaphore; import org.apache.http.nio.NHttpConnection; -import org.jclouds.command.FutureCommand; import org.jclouds.command.pool.FutureCommandConnectionHandle; +import org.jclouds.http.HttpFutureCommand; import com.google.inject.Inject; import com.google.inject.assistedinject.Assisted; @@ -40,20 +40,20 @@ import com.google.inject.assistedinject.Assisted; * @author Adrian Cole */ public class HttpNioFutureCommandConnectionHandle extends - FutureCommandConnectionHandle { + FutureCommandConnectionHandle> { @Inject public HttpNioFutureCommandConnectionHandle( BlockingQueue available, Semaphore maxConnections, - @Assisted NHttpConnection conn, @Assisted FutureCommand operation) - throws InterruptedException { - super(maxConnections, operation, conn, available); + @Assisted NHttpConnection conn, + @Assisted HttpFutureCommand command) throws InterruptedException { + super(maxConnections, command, conn, available); } public void startConnection() { - conn.getContext().setAttribute("operation", operation); - logger.trace("invoking %1s on connection %2s", operation, conn); + conn.getContext().setAttribute("command", command); + logger.trace("invoking %1s on connection %2s", command, conn); conn.requestOutput(); } diff --git a/extensions/httpnio/src/main/java/org/jclouds/http/httpnio/pool/HttpNioFutureCommandConnectionPool.java b/extensions/httpnio/src/main/java/org/jclouds/http/httpnio/pool/HttpNioFutureCommandConnectionPool.java index 2e8eef2b84..30a292cde7 100644 --- a/extensions/httpnio/src/main/java/org/jclouds/http/httpnio/pool/HttpNioFutureCommandConnectionPool.java +++ b/extensions/httpnio/src/main/java/org/jclouds/http/httpnio/pool/HttpNioFutureCommandConnectionPool.java @@ -40,9 +40,10 @@ import org.apache.http.nio.reactor.IOReactorStatus; import org.apache.http.nio.reactor.SessionRequest; import org.apache.http.nio.reactor.SessionRequestCallback; import org.jclouds.command.FutureCommand; +import org.jclouds.command.pool.FutureCommandConnectionHandle; import org.jclouds.command.pool.FutureCommandConnectionPool; -import org.jclouds.command.pool.FutureCommandConnectionRetry; import org.jclouds.command.pool.PoolConstants; +import org.jclouds.http.HttpFutureCommand; import com.google.inject.Inject; import com.google.inject.name.Named; @@ -53,7 +54,8 @@ import com.google.inject.name.Named; * @author Adrian Cole */ public class HttpNioFutureCommandConnectionPool extends - FutureCommandConnectionPool implements EventListener { + FutureCommandConnectionPool> + implements EventListener { private final NHttpClientConnectionPoolSessionRequestCallback sessionCallback; private final DefaultConnectingIOReactor ioReactor; @@ -65,17 +67,17 @@ public class HttpNioFutureCommandConnectionPool extends public HttpNioFutureCommandConnectionPool( ExecutorService executor, Semaphore allConnections, + BlockingQueue> commandQueue, BlockingQueue available, AsyncNHttpClientHandler clientHandler, DefaultConnectingIOReactor ioReactor, IOEventDispatch dispatch, FutureCommandConnectionHandleFactory requestHandleFactory, InetSocketAddress target, - FutureCommandConnectionRetry futureCommandConnectionRetry, @Named(PoolConstants.PROPERTY_POOL_MAX_CONNECTION_REUSE) int maxConnectionReuse, @Named(PoolConstants.PROPERTY_POOL_MAX_SESSION_FAILURES) int maxSessionFailures) { - super(executor, futureCommandConnectionRetry, allConnections, - requestHandleFactory, maxConnectionReuse, available); + super(executor, allConnections, commandQueue, requestHandleFactory, + maxConnectionReuse, available); this.ioReactor = ioReactor; this.dispatch = dispatch; this.target = target; @@ -160,6 +162,20 @@ public class HttpNioFutureCommandConnectionPool extends } } + @Override + protected void associateHandleWithConnection( + FutureCommandConnectionHandle> handle, + NHttpConnection connection) { + connection.getContext().setAttribute("command-handle", handle); + } + + @Override + protected HttpNioFutureCommandConnectionHandle getHandleFromConnection( + NHttpConnection connection) { + return (HttpNioFutureCommandConnectionHandle) connection.getContext() + .getAttribute("command-handle"); + } + class NHttpClientConnectionPoolSessionRequestCallback implements SessionRequestCallback { @@ -191,7 +207,7 @@ public class HttpNioFutureCommandConnectionPool extends private void releaseConnectionAndSetResponseException( SessionRequest request, Exception e) { allConnections.release(); - FutureCommand frequest = (FutureCommand) request + HttpFutureCommand frequest = (HttpFutureCommand) request .getAttachment(); if (frequest != null) { logger.error(e, @@ -240,7 +256,7 @@ public class HttpNioFutureCommandConnectionPool extends public void connectionTimeout(NHttpConnection conn) { logger.warn("%1s - %2d - timeout %2d", conn, conn.hashCode(), conn .getSocketTimeout()); - futureCommandConnectionRetry.shutdownConnectionAndRetryOperation(conn); + resubmitCommand(conn); } public void connectionClosed(NHttpConnection conn) { @@ -248,32 +264,22 @@ public class HttpNioFutureCommandConnectionPool extends } public void fatalIOException(IOException ex, NHttpConnection conn) { - exception.set(ex); logger.error(ex, "%3s-%1d{%2s} - io error", conn, conn.hashCode(), target); - if (!futureCommandConnectionRetry - .shutdownConnectionAndRetryOperation(conn)) - try { - conn.shutdown(); - } catch (IOException e) { - logger.error(e, - "%3s-%1d{%2s} - error shutting down connection", conn, - conn.hashCode(), target); - } + resubmitCommand(conn); } public void fatalProtocolException(HttpException ex, NHttpConnection conn) { - exception.set(ex); logger.error(ex, "%3s-%1d{%2s} - http error", conn, conn.hashCode(), target); - fatalException(ex, conn); + setExceptionOnCommand(conn, ex); } public static interface FutureCommandConnectionHandleFactory extends - FutureCommandConnectionPool.FutureCommandConnectionHandleFactory { - HttpNioFutureCommandConnectionHandle create(FutureCommand command, - NHttpConnection conn); + FutureCommandConnectionPool.FutureCommandConnectionHandleFactory> { + HttpNioFutureCommandConnectionHandle create( + HttpFutureCommand command, NHttpConnection conn); } } \ No newline at end of file diff --git a/extensions/httpnio/src/main/java/org/jclouds/http/httpnio/pool/HttpNioFutureCommandConnectionRetry.java b/extensions/httpnio/src/main/java/org/jclouds/http/httpnio/pool/HttpNioFutureCommandConnectionRetry.java deleted file mode 100644 index bb28d3ac30..0000000000 --- a/extensions/httpnio/src/main/java/org/jclouds/http/httpnio/pool/HttpNioFutureCommandConnectionRetry.java +++ /dev/null @@ -1,67 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * 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.jclouds.http.httpnio.pool; - -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.atomic.AtomicInteger; - -import org.apache.http.nio.NHttpConnection; -import org.jclouds.command.FutureCommand; -import org.jclouds.command.pool.FutureCommandConnectionHandle; -import org.jclouds.command.pool.FutureCommandConnectionRetry; - -import com.google.inject.Inject; - -public class HttpNioFutureCommandConnectionRetry extends - FutureCommandConnectionRetry { - - @Inject - public HttpNioFutureCommandConnectionRetry( - BlockingQueue commandQueue, AtomicInteger errors) { - super(commandQueue, errors); - } - - @Override - public void associateHandleWithConnection( - FutureCommandConnectionHandle handle, - NHttpConnection connection) { - connection.getContext().setAttribute("operation-handle", handle); - } - - @Override - public HttpNioFutureCommandConnectionHandle getHandleFromConnection( - NHttpConnection connection) { - return (HttpNioFutureCommandConnectionHandle) connection.getContext() - .getAttribute("operation-handle"); - } - - // @Override - // public void incrementErrorCountAndRetry(FutureCommand operation) { - // ((HttpEntityEnclosingRequest) - // operation.getRequest()).removeHeaders(HTTP.CONTENT_LEN); - // ((HttpEntityEnclosingRequest) - // operation.getRequest()).removeHeaders(HTTP.DATE_HEADER); - // super.incrementErrorCountAndRetry(operation); - // } -} \ No newline at end of file diff --git a/extensions/httpnio/src/main/java/org/jclouds/http/httpnio/pool/HttpNioFutureCommandExecutionHandler.java b/extensions/httpnio/src/main/java/org/jclouds/http/httpnio/pool/HttpNioFutureCommandExecutionHandler.java index 56de0c5e72..b68602842b 100644 --- a/extensions/httpnio/src/main/java/org/jclouds/http/httpnio/pool/HttpNioFutureCommandExecutionHandler.java +++ b/extensions/httpnio/src/main/java/org/jclouds/http/httpnio/pool/HttpNioFutureCommandExecutionHandler.java @@ -24,6 +24,7 @@ package org.jclouds.http.httpnio.pool; import java.io.IOException; +import java.util.concurrent.BlockingQueue; import java.util.concurrent.ExecutorService; import javax.annotation.Resource; @@ -31,12 +32,9 @@ import javax.annotation.Resource; import org.apache.http.HttpEntity; import org.apache.http.HttpEntityEnclosingRequest; import org.apache.http.HttpResponse; -import org.apache.http.nio.NHttpClientConnection; import org.apache.http.nio.entity.ConsumingNHttpEntity; import org.apache.http.nio.protocol.NHttpRequestExecutionHandler; -import org.apache.http.protocol.ExecutionContext; import org.apache.http.protocol.HttpContext; -import org.jclouds.command.FutureCommand; import org.jclouds.http.HttpFutureCommand; import org.jclouds.http.HttpRequest; import org.jclouds.http.httpnio.HttpNioUtils; @@ -55,7 +53,7 @@ public class HttpNioFutureCommandExecutionHandler implements @Resource protected Logger logger = Logger.NULL; private final ConsumingNHttpEntityFactory entityFactory; - private final HttpNioFutureCommandConnectionRetry futureOperationRetry; + private final BlockingQueue> commandQueue; public interface ConsumingNHttpEntityFactory { public ConsumingNHttpEntity create(HttpEntity httpEntity); @@ -65,21 +63,20 @@ public class HttpNioFutureCommandExecutionHandler implements public HttpNioFutureCommandExecutionHandler( ConsumingNHttpEntityFactory entityFactory, ExecutorService executor, - HttpNioFutureCommandConnectionRetry futureOperationRetry) { + BlockingQueue> commandQueue) { this.executor = executor; this.entityFactory = entityFactory; - this.futureOperationRetry = futureOperationRetry; + this.commandQueue = commandQueue; } public void initalizeContext(HttpContext context, Object attachment) { } public HttpEntityEnclosingRequest submitRequest(HttpContext context) { - HttpFutureCommand operation = (HttpFutureCommand) context - .removeAttribute("operation"); - if (operation != null) { - // TODO determine why type is lost - HttpRequest object = (HttpRequest) operation.getRequest(); + HttpFutureCommand command = (HttpFutureCommand) context + .removeAttribute("command"); + if (command != null) { + HttpRequest object = command.getRequest(); return HttpNioUtils.convertToApacheRequest(object); } return null; @@ -94,21 +91,19 @@ public class HttpNioFutureCommandExecutionHandler implements public void handleResponse(HttpResponse response, HttpContext context) throws IOException { HttpNioFutureCommandConnectionHandle handle = (HttpNioFutureCommandConnectionHandle) context - .removeAttribute("operation-handle"); + .removeAttribute("command-handle"); if (handle != null) { try { - FutureCommand command = handle.getOperation(); + HttpFutureCommand command = handle.getCommand(); int code = response.getStatusLine().getStatusCode(); // normal codes for rest commands if ((code >= 200 && code < 300) || code == 404) { processResponse(response, command); } else { if (isRetryable(response)) { - futureOperationRetry - .shutdownConnectionAndRetryOperation((NHttpClientConnection) context - .getAttribute(ExecutionContext.HTTP_CONNECTION)); + commandQueue.add(command); } else { - operationFailed(command); + commandFailed(command); } } } finally { @@ -116,8 +111,7 @@ public class HttpNioFutureCommandExecutionHandler implements } } else { throw new IllegalStateException(String.format( - "No operation-handle associated with operation %1s", - context)); + "No command-handle associated with command %1s", context)); } } @@ -135,14 +129,15 @@ public class HttpNioFutureCommandExecutionHandler implements } } - protected void operationFailed(FutureCommand command) throws IOException { + protected void commandFailed(HttpFutureCommand command) + throws IOException { String message = String.format("command failed: %1s", command); logger.error(message); command.getResponseFuture().setException(new IOException(message)); } protected void processResponse(HttpResponse apacheResponse, - FutureCommand command) throws IOException { + HttpFutureCommand command) throws IOException { org.jclouds.http.HttpResponse response = HttpNioUtils .convertToJavaCloudsResponse(apacheResponse); command.getResponseFuture().setResponse(response); @@ -153,7 +148,7 @@ public class HttpNioFutureCommandExecutionHandler implements public void finalizeContext(HttpContext context) { HttpNioFutureCommandConnectionHandle handle = (HttpNioFutureCommandConnectionHandle) context - .removeAttribute("operation-handle"); + .removeAttribute("command-handle"); if (handle != null) { try { handle.cancel(); diff --git a/extensions/jets3t/src/main/java/org/jclouds/aws/s3/jets3t/JCloudsS3Service.java b/extensions/jets3t/src/main/java/org/jclouds/aws/s3/jets3t/JCloudsS3Service.java index 1f66006156..c9e7d4eaa6 100644 --- a/extensions/jets3t/src/main/java/org/jclouds/aws/s3/jets3t/JCloudsS3Service.java +++ b/extensions/jets3t/src/main/java/org/jclouds/aws/s3/jets3t/JCloudsS3Service.java @@ -85,6 +85,10 @@ public class JCloudsS3Service extends S3Service { throw new UnsupportedOperationException(); } + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") @Override protected Map copyObjectImpl(String sourceBucketName, String sourceObjectKey, String destinationBucketName, @@ -206,26 +210,26 @@ public class JCloudsS3Service extends S3Service { @Override protected S3Bucket[] listAllBucketsImpl() throws S3ServiceException { try { - List jcBucketList = - connection.getBuckets().get( - requestTimeoutMilliseconds, TimeUnit.MILLISECONDS); - - ArrayList jsBucketList = - new ArrayList(); - for (org.jclouds.aws.s3.domain.S3Bucket jcBucket: jcBucketList) { - org.jets3t.service.model.S3Bucket jsBucket = - new org.jets3t.service.model.S3Bucket(jcBucket.getName()); - jsBucket.setOwner(new org.jets3t.service.model.S3Owner( - jcBucket.getCanonicalUser().getId(), - jcBucket.getCanonicalUser().getDisplayName())); - jsBucketList.add(jsBucket); + List jcBucketList = connection + .getBuckets().get(requestTimeoutMilliseconds, + TimeUnit.MILLISECONDS); + + ArrayList jsBucketList = new ArrayList(); + for (org.jclouds.aws.s3.domain.S3Bucket jcBucket : jcBucketList) { + org.jets3t.service.model.S3Bucket jsBucket = new org.jets3t.service.model.S3Bucket( + jcBucket.getName()); + jsBucket.setOwner(new org.jets3t.service.model.S3Owner(jcBucket + .getCanonicalUser().getId(), jcBucket + .getCanonicalUser().getDisplayName())); + jsBucketList.add(jsBucket); } - return (org.jets3t.service.model.S3Bucket[]) jsBucketList.toArray( - new org.jets3t.service.model.S3Bucket[jsBucketList.size()]); + return (org.jets3t.service.model.S3Bucket[]) jsBucketList + .toArray(new org.jets3t.service.model.S3Bucket[jsBucketList + .size()]); } catch (Exception e) { Utils. rethrowIfRuntimeOrSameType(e); throw new S3ServiceException("error listing buckets", e); - } + } } @Override diff --git a/extensions/s3nio/src/main/java/org/jclouds/aws/s3/nio/S3HttpNioFutureCommandExecutionHandler.java b/extensions/s3nio/src/main/java/org/jclouds/aws/s3/nio/S3HttpNioFutureCommandExecutionHandler.java index 34f9090ce3..8e30327091 100644 --- a/extensions/s3nio/src/main/java/org/jclouds/aws/s3/nio/S3HttpNioFutureCommandExecutionHandler.java +++ b/extensions/s3nio/src/main/java/org/jclouds/aws/s3/nio/S3HttpNioFutureCommandExecutionHandler.java @@ -25,12 +25,13 @@ package org.jclouds.aws.s3.nio; import java.io.IOException; import java.io.InputStream; +import java.util.concurrent.BlockingQueue; import java.util.concurrent.ExecutorService; import org.apache.commons.io.IOUtils; import org.apache.http.HttpResponse; import org.apache.http.nio.entity.NStringEntity; -import org.jclouds.http.httpnio.pool.HttpNioFutureCommandConnectionRetry; +import org.jclouds.http.HttpFutureCommand; import org.jclouds.http.httpnio.pool.HttpNioFutureCommandExecutionHandler; import com.google.inject.Inject; @@ -49,8 +50,8 @@ public class S3HttpNioFutureCommandExecutionHandler extends public S3HttpNioFutureCommandExecutionHandler( ConsumingNHttpEntityFactory entityFactory, ExecutorService executor, - HttpNioFutureCommandConnectionRetry futureOperationRetry) { - super(entityFactory, executor, futureOperationRetry); + BlockingQueue> commandQueue) { + super(entityFactory, executor, commandQueue); } @Override diff --git a/extensions/s3nio/src/test/java/org/jclouds/aws/s3/nio/S3HttpNioFutureCommandExecutionHandlerTest.java b/extensions/s3nio/src/test/java/org/jclouds/aws/s3/nio/S3HttpNioFutureCommandExecutionHandlerTest.java index 6fb09a93ef..5aa2072c2a 100644 --- a/extensions/s3nio/src/test/java/org/jclouds/aws/s3/nio/S3HttpNioFutureCommandExecutionHandlerTest.java +++ b/extensions/s3nio/src/test/java/org/jclouds/aws/s3/nio/S3HttpNioFutureCommandExecutionHandlerTest.java @@ -30,6 +30,7 @@ import static org.easymock.classextension.EasyMock.replay; import static org.easymock.classextension.EasyMock.verify; import java.io.IOException; +import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.ExecutorService; import org.apache.commons.io.IOUtils; @@ -37,7 +38,7 @@ import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.StatusLine; import org.apache.http.nio.entity.NStringEntity; -import org.jclouds.http.httpnio.pool.HttpNioFutureCommandConnectionRetry; +import org.jclouds.http.HttpFutureCommand; import org.jclouds.http.httpnio.pool.HttpNioFutureCommandExecutionHandler; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -58,7 +59,7 @@ public class S3HttpNioFutureCommandExecutionHandlerTest { handler = new S3HttpNioFutureCommandExecutionHandler( createMock(HttpNioFutureCommandExecutionHandler.ConsumingNHttpEntityFactory.class), createMock(ExecutorService.class), - createMock(HttpNioFutureCommandConnectionRetry.class)); + new ArrayBlockingQueue>(1)); response = createMock(HttpResponse.class); statusline = createMock(StatusLine.class); expect(response.getStatusLine()).andReturn(statusline).atLeastOnce(); diff --git a/gae/src/main/java/org/jclouds/gae/URLFetchServiceClient.java b/gae/src/main/java/org/jclouds/gae/URLFetchServiceClient.java index a4f3d8ca4b..5f694dbec7 100644 --- a/gae/src/main/java/org/jclouds/gae/URLFetchServiceClient.java +++ b/gae/src/main/java/org/jclouds/gae/URLFetchServiceClient.java @@ -38,8 +38,8 @@ import java.util.List; import javax.annotation.Resource; import org.apache.commons.io.IOUtils; -import org.jclouds.command.FutureCommand; import org.jclouds.http.HttpConstants; +import org.jclouds.http.HttpFutureCommand; import org.jclouds.http.HttpFutureCommandClient; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequestFilter; @@ -83,7 +83,7 @@ public class URLFetchServiceClient implements HttpFutureCommandClient { this.logger.info("configured to connect to target: %1s", target); } - public void submit(O operation) { + public void submit(HttpFutureCommand operation) { HttpRequest request = (HttpRequest) operation.getRequest(); HTTPResponse gaeResponse = null; try { diff --git a/s3/perftest/src/test/java/com/amazon/s3/AmazonPerformance.java b/s3/perftest/src/test/java/com/amazon/s3/AmazonPerformance.java index 3ced0fccab..0a22f37188 100644 --- a/s3/perftest/src/test/java/com/amazon/s3/AmazonPerformance.java +++ b/s3/perftest/src/test/java/com/amazon/s3/AmazonPerformance.java @@ -26,6 +26,7 @@ package com.amazon.s3; import java.io.File; import java.io.InputStream; import java.util.Arrays; +import java.util.List; import java.util.Map; import java.util.TreeMap; import java.util.concurrent.ExecutionException; @@ -47,8 +48,10 @@ public class AmazonPerformance extends BasePerformance { @Override @BeforeTest - @Parameters( { S3Constants.PROPERTY_AWS_ACCESSKEYID, S3Constants.PROPERTY_AWS_SECRETACCESSKEY }) - protected void setUpClient(@Optional String AWSAccessKeyId, @Optional String AWSSecretAccessKey) throws Exception { + @Parameters( { S3Constants.PROPERTY_AWS_ACCESSKEYID, + S3Constants.PROPERTY_AWS_SECRETACCESSKEY }) + protected void setUpClient(@Optional String AWSAccessKeyId, + @Optional String AWSSecretAccessKey) throws Exception { super.setUpClient(AWSAccessKeyId, AWSSecretAccessKey); amzClient = new AWSAuthConnection(AWSAccessKeyId, AWSSecretAccessKey, false); @@ -91,7 +94,7 @@ public class AmazonPerformance extends BasePerformance { protected boolean putByteArray(String bucket, String key, byte[] data, String contentType) throws Exception { com.amazon.s3.S3Object object = new com.amazon.s3.S3Object(data, null); - Map headers = new TreeMap(); + Map> headers = new TreeMap>(); headers .put("Content-Type", Arrays .asList(new String[] { contentType })); diff --git a/s3/perftest/src/test/java/com/amazon/s3/S3ParserTest.java b/s3/perftest/src/test/java/com/amazon/s3/S3ParserTest.java index 45050d0c29..ed8fad78b0 100644 --- a/s3/perftest/src/test/java/com/amazon/s3/S3ParserTest.java +++ b/s3/perftest/src/test/java/com/amazon/s3/S3ParserTest.java @@ -97,6 +97,7 @@ public class S3ParserTest extends org.jclouds.aws.s3.commands.S3ParserTest { assert completer.take().get(); } + @SuppressWarnings("unchecked") @Test public void testAmazonCanParseListAllMyBuckets() throws IOException { ListAllMyBucketsResponse response = runAmazonParseListAllMyBuckets(); diff --git a/s3/src/main/java/org/jclouds/aws/s3/DateService.java b/s3/src/main/java/org/jclouds/aws/s3/DateService.java index c9ff19c7db..1222f87fe6 100644 --- a/s3/src/main/java/org/jclouds/aws/s3/DateService.java +++ b/s3/src/main/java/org/jclouds/aws/s3/DateService.java @@ -29,21 +29,20 @@ import org.joda.time.format.DateTimeFormat; import org.joda.time.format.DateTimeFormatter; public class DateService { - private DateTimeFormatter headerDateFormat = DateTimeFormat.forPattern("EEE, dd MMM yyyy HH:mm:ss 'GMT'"); - private DateTimeFormatter dataDateFormat = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); - + private DateTimeFormatter headerDateFormat = DateTimeFormat + .forPattern("EEE, dd MMM yyyy HH:mm:ss 'GMT'"); public DateTime dateTimeFromXMLFormat(String toParse) { - //return dataDateFormat.parseDateTime(toParse); - return new DateTime(toParse); + // the format is natively parseable from the DateTime constructor + return new DateTime(toParse); } public DateTime dateTimeFromHeaderFormat(String toParse) { - return headerDateFormat.parseDateTime(toParse); + return headerDateFormat.parseDateTime(toParse); } public String timestampAsHeaderString() { - return headerDateFormat.print(new DateTime(DateTimeZone.UTC)); + return headerDateFormat.print(new DateTime(DateTimeZone.UTC)); } } diff --git a/s3/src/main/java/org/jclouds/aws/s3/commands/callables/CopyObjectCallable.java b/s3/src/main/java/org/jclouds/aws/s3/commands/callables/CopyObjectCallable.java index d9434cae28..fbe5b24787 100644 --- a/s3/src/main/java/org/jclouds/aws/s3/commands/callables/CopyObjectCallable.java +++ b/s3/src/main/java/org/jclouds/aws/s3/commands/callables/CopyObjectCallable.java @@ -56,11 +56,10 @@ public class CopyObjectCallable extends } throw new HttpException("Error copying source " + reason); } else if (getResponse().getStatusCode() == 200) { - String response; InputStream content = getResponse().getContent(); if (content != null) { try { - response = Utils.toStringAndClose(content); + Utils.toStringAndClose(content); // TODO parse response of format: 2009-05-02T18:29:48.000Z"29f1a7935898965c45f756e5f936fad2" } catch (IOException e) { diff --git a/s3/src/main/java/org/jclouds/aws/s3/config/S3ContextModule.java b/s3/src/main/java/org/jclouds/aws/s3/config/S3ContextModule.java index bbb65e661c..bf87d74981 100644 --- a/s3/src/main/java/org/jclouds/aws/s3/config/S3ContextModule.java +++ b/s3/src/main/java/org/jclouds/aws/s3/config/S3ContextModule.java @@ -35,7 +35,6 @@ import org.jclouds.aws.s3.internal.GuiceS3Context; import org.jclouds.aws.s3.internal.LiveS3Connection; import org.jclouds.aws.s3.internal.LiveS3InputStreamMap; import org.jclouds.aws.s3.internal.LiveS3ObjectMap; -import org.jclouds.aws.s3.internal.GuiceS3Context.S3ObjectMapFactory; import org.jclouds.http.HttpRequestFilter; import com.google.inject.AbstractModule; diff --git a/s3/src/main/java/org/jclouds/aws/s3/filters/RemoveTransferEncodingHeader.java b/s3/src/main/java/org/jclouds/aws/s3/filters/RemoveTransferEncodingHeader.java index 754fb0a52e..155a36ed67 100644 --- a/s3/src/main/java/org/jclouds/aws/s3/filters/RemoveTransferEncodingHeader.java +++ b/s3/src/main/java/org/jclouds/aws/s3/filters/RemoveTransferEncodingHeader.java @@ -31,7 +31,6 @@ import org.jclouds.http.HttpRequestFilter; * @author Adrian Cole */ public class RemoveTransferEncodingHeader implements HttpRequestFilter { - private final static String errorFromAmazonIfYouDontRemove = "NotImplementedA header you provided implies functionality that is not implemented

Transfer-Encoding
7C59925D75D15561fbskVU51OZJg2yZS/wNIxoE2PmCf0ZqFd0iH6Vrzw0uKG3KmokswBytL/Bfp/GWb"; public void filter(org.jclouds.http.HttpRequest request) throws org.jclouds.http.HttpException { diff --git a/s3/src/test/java/org/jclouds/aws/s3/S3IntegrationTest.java b/s3/src/test/java/org/jclouds/aws/s3/S3IntegrationTest.java index 593068aa64..c61bb8e3dc 100644 --- a/s3/src/test/java/org/jclouds/aws/s3/S3IntegrationTest.java +++ b/s3/src/test/java/org/jclouds/aws/s3/S3IntegrationTest.java @@ -82,6 +82,7 @@ public class S3IntegrationTest { } } + String errorFromAmazonIfYouDontRemoveTransferEncodingHeader = "NotImplementedA header you provided implies functionality that is not implemented
Transfer-Encoding
7C59925D75D15561fbskVU51OZJg2yZS/wNIxoE2PmCf0ZqFd0iH6Vrzw0uKG3KmokswBytL/Bfp/GWb
"; String badRequestWhenSourceIsDestBucketOnCopy400 = "InvalidRequestThe Source and Destination may not be the same when the MetadataDirective is Copy.54C77CAF4D42474BSJecknEUUUx88/65VAKbCdKSOCkpuVTeu7ZG9in9x9NTNglGnoxdbALCfS4k/DUZ"; String noSuchSourceKeyOrBucketOnCopy404 = "NoSuchKeyThe specified key does not exist.null9CCDF1DACA78B36F63cqk9YsTFBVfBfks840JVGsepPEdQM42mU+r7HN35sF4Nk5xAcWDEUPaQpK2eFU"; String noSuchDestinationBucketOnCopy404 = "NoSuchBucketThe specified bucket does not existcopydestination4F0CF319C5535975hdZyHOm7VK+JI2UCdye3d6TVkKhRBIoWflldXVDTKbgipYlamy8HgPBzHrUAVQNJ"; diff --git a/samples/googleappengine/src/it/java/org/jclouds/samples/googleappengine/functest/BaseGoogleAppEngineTest.java b/samples/googleappengine/src/it/java/org/jclouds/samples/googleappengine/functest/BaseGoogleAppEngineTest.java index 36c49be4e5..f63fb5d9af 100644 --- a/samples/googleappengine/src/it/java/org/jclouds/samples/googleappengine/functest/BaseGoogleAppEngineTest.java +++ b/samples/googleappengine/src/it/java/org/jclouds/samples/googleappengine/functest/BaseGoogleAppEngineTest.java @@ -66,6 +66,7 @@ public abstract class BaseGoogleAppEngineTest { Thread.sleep(7 * 1000); } + @SuppressWarnings("deprecation") @AfterTest public void stopDevAppServer() throws Exception { server.stop();