mirror of https://github.com/apache/jclouds.git
allowed response parsing to be logged
git-svn-id: http://jclouds.googlecode.com/svn/trunk@1954 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
parent
ccd035df64
commit
b0cc1304bd
|
@ -28,6 +28,8 @@ import java.util.concurrent.Future;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
|
import org.jclouds.logging.Logger;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -39,10 +41,16 @@ public class FutureExceptionParser<T> implements Future<T> {
|
||||||
|
|
||||||
private final Future<T> delegate;
|
private final Future<T> delegate;
|
||||||
private final Function<Exception, T> function;
|
private final Function<Exception, T> function;
|
||||||
|
private final Logger logger;
|
||||||
|
|
||||||
public FutureExceptionParser(Future<T> delegate, Function<Exception, T> function) {
|
public FutureExceptionParser(Future<T> delegate, Function<Exception, T> function) {
|
||||||
|
this(delegate, function, Logger.NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FutureExceptionParser(Future<T> delegate, Function<Exception, T> function, Logger logger) {
|
||||||
this.delegate = delegate;
|
this.delegate = delegate;
|
||||||
this.function = function;
|
this.function = function;
|
||||||
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean cancel(boolean mayInterruptIfRunning) {
|
public boolean cancel(boolean mayInterruptIfRunning) {
|
||||||
|
@ -59,7 +67,10 @@ public class FutureExceptionParser<T> implements Future<T> {
|
||||||
|
|
||||||
private T attemptConvert(ExecutionException e) throws ExecutionException {
|
private T attemptConvert(ExecutionException e) throws ExecutionException {
|
||||||
if (e.getCause() instanceof Exception) {
|
if (e.getCause() instanceof Exception) {
|
||||||
|
|
||||||
|
logger.debug("Processing exception for: %s", e.getCause());
|
||||||
T returnVal = function.apply((Exception) e.getCause());
|
T returnVal = function.apply((Exception) e.getCause());
|
||||||
|
logger.debug("Processed exception for: %s", e.getCause());
|
||||||
if (returnVal != null)
|
if (returnVal != null)
|
||||||
return returnVal;
|
return returnVal;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,8 @@ import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
|
import org.jclouds.logging.Logger;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -38,15 +40,25 @@ public class FutureFunctionCallable<F, T> implements Callable<T> {
|
||||||
|
|
||||||
private final Future<F> future;
|
private final Future<F> future;
|
||||||
private final Function<F, T> function;
|
private final Function<F, T> function;
|
||||||
|
private final Logger logger;
|
||||||
|
|
||||||
public FutureFunctionCallable(Future<F> future, Function<F, T> function) {
|
public FutureFunctionCallable(Future<F> future, Function<F, T> function) {
|
||||||
|
this(future, function, Logger.NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FutureFunctionCallable(Future<F> future, Function<F, T> function, Logger logger) {
|
||||||
this.future = future;
|
this.future = future;
|
||||||
this.function = function;
|
this.function = function;
|
||||||
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T call() throws Exception {
|
public T call() throws Exception {
|
||||||
try {
|
try {
|
||||||
return function.apply(future.get());
|
F input = future.get();
|
||||||
|
logger.debug("Processing intermediate result for: %s", input);
|
||||||
|
T result = function.apply(input);
|
||||||
|
logger.debug("Processed intermediate result for: %s", input);
|
||||||
|
return result;
|
||||||
} catch (ExecutionException e) {
|
} catch (ExecutionException e) {
|
||||||
throw (Exception) e.getCause();
|
throw (Exception) e.getCause();
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ import java.util.concurrent.Executor;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@SingleThreadCompatible
|
@SingleThreadCompatible
|
||||||
|
@SingleThreaded
|
||||||
public class WithinThreadExecutor implements Executor {
|
public class WithinThreadExecutor implements Executor {
|
||||||
|
|
||||||
public void execute(Runnable command) {
|
public void execute(Runnable command) {
|
||||||
|
|
|
@ -0,0 +1,89 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* 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.logging;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JCloud log abstraction layer.
|
||||||
|
* <p/>
|
||||||
|
* Implementations of logging are optional and injected if they are configured.
|
||||||
|
* <p/>
|
||||||
|
* <code> @Resource Logger logger = Logger.NULL;</code> The above will get you a
|
||||||
|
* null-safe instance of <tt>Logger</tt>. If configured, this logger will be
|
||||||
|
* swapped with a real Logger implementation with category set to the current
|
||||||
|
* class name. This is done post-object construction, so do not attempt to use
|
||||||
|
* these loggers in your constructor.
|
||||||
|
* <p/>
|
||||||
|
* If you wish to initialize loggers like these yourself, do not use the @Resource
|
||||||
|
* annotation.
|
||||||
|
* <p/>
|
||||||
|
* This implementation first checks to see if the level is enabled before
|
||||||
|
* issuing the log command. In other words, don't do the following
|
||||||
|
* <code>if (logger.isTraceEnabled()) logger.trace("message");.
|
||||||
|
* <p/>
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
public interface Logger {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assign to member to avoid NPE when no logging module is configured.
|
||||||
|
*/
|
||||||
|
public static final Logger NULL = new NullLogger();
|
||||||
|
|
||||||
|
String getCategory();
|
||||||
|
|
||||||
|
void trace(String message, Object... args);
|
||||||
|
|
||||||
|
boolean isTraceEnabled();
|
||||||
|
|
||||||
|
void debug(String message, Object... args);
|
||||||
|
|
||||||
|
boolean isDebugEnabled();
|
||||||
|
|
||||||
|
void info(String message, Object... args);
|
||||||
|
|
||||||
|
boolean isInfoEnabled();
|
||||||
|
|
||||||
|
void warn(String message, Object... args);
|
||||||
|
|
||||||
|
void warn(Throwable throwable, String message, Object... args);
|
||||||
|
|
||||||
|
boolean isWarnEnabled();
|
||||||
|
|
||||||
|
void error(String message, Object... args);
|
||||||
|
|
||||||
|
void error(Throwable throwable, String message, Object... args);
|
||||||
|
|
||||||
|
boolean isErrorEnabled();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Produces instances of {@link Logger} relevant to the specified category
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static interface LoggerFactory {
|
||||||
|
public Logger getLogger(String category);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,93 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* 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.logging;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <tt>Logger</tt> that doesn't do anything.
|
||||||
|
* <p />
|
||||||
|
* Useful to get baseline performance unaffected by logging.
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class NullLogger implements Logger {
|
||||||
|
|
||||||
|
public void debug(String message, Object... args) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void error(String message, Object... args) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void error(Throwable throwable, String message, Object... args) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCategory() {
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void info(String message, Object... args) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDebugEnabled() {
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isErrorEnabled() {
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isInfoEnabled() {
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isTraceEnabled() {
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isWarnEnabled() {
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void trace(String message, Object... args) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void warn(String message, Object... args) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void warn(Throwable throwable, String message, Object... args) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue