You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2013/01/13 03:18:32 UTC
[5/7] git commit: Add IOOperation and OperationTracker.perform()
Streamline the code inside OperationTrackerImpl
Add IOOperation and OperationTracker.perform()
Streamline the code inside OperationTrackerImpl
Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/d8dba804
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/d8dba804
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/d8dba804
Branch: refs/heads/master
Commit: d8dba804700d7a23d9e596816dd1a26cdf6b7025
Parents: b751d6c
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Fri Jan 11 18:46:41 2013 -0500
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Fri Jan 11 18:46:41 2013 -0500
----------------------------------------------------------------------
54_RELEASE_NOTES.txt | 6 +-
.../org/apache/tapestry5/internal/IOOperation.java | 34 ----
.../tapestry5/internal/TapestryInternalUtils.java | 28 +---
.../internal/services/RequestOperationTracker.java | 28 +--
.../internal/services/ResourceStreamerImpl.java | 11 +-
.../services/assets/StackAssetRequestHandler.java | 13 +-
.../javascript/ModuleAssetRequestHandler.java | 17 +-
.../ComponentPageElementResourcesImpl.java | 24 ++-
.../java/org/apache/tapestry5/ioc/IOOperation.java | 29 ++++
.../java/org/apache/tapestry5/ioc/Invokable.java | 5 +-
.../org/apache/tapestry5/ioc/OperationTracker.java | 33 +++-
.../ioc/internal/OperationTrackerImpl.java | 131 +++++++++++----
.../ioc/internal/PerThreadOperationTracker.java | 16 ++-
.../ioc/internal/QuietOperationTracker.java | 11 +-
.../tapestry5/ioc/internal/RegistryImpl.java | 8 +-
.../internal/yuicompressor/AbstractMinimizer.java | 10 +-
16 files changed, 240 insertions(+), 164 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/d8dba804/54_RELEASE_NOTES.txt
----------------------------------------------------------------------
diff --git a/54_RELEASE_NOTES.txt b/54_RELEASE_NOTES.txt
index 5bad19f..c58608b 100644
--- a/54_RELEASE_NOTES.txt
+++ b/54_RELEASE_NOTES.txt
@@ -169,4 +169,8 @@ its @AfterRender phase.
## LocalizationSetter service
The method setNonPeristentLocaleFromLocaleName() was renamed to setNonPersistentLocaleFromLocaleName() to correct
-the typo (the missing 's').
\ No newline at end of file
+the typo (the missing 's').
+
+## OperationTracker Extended
+
+The OperationTracker interface has had a new method added, for performing an IO Operation (that may throw IOException).
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/d8dba804/tapestry-core/src/main/java/org/apache/tapestry5/internal/IOOperation.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/IOOperation.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/IOOperation.java
deleted file mode 100644
index f9fae2e..0000000
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/IOOperation.java
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright 2011 The Apache Software Foundation
-//
-// 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 org.apache.tapestry5.internal;
-
-import java.io.IOException;
-
-/**
- * This interface is similar to {@link Runnable}, except that
- * the operation may throw an {@link IOException}.
- *
- * @since 5.3
- * @see TapestryInternalUtils#performIO(org.apache.tapestry5.ioc.OperationTracker, String, IOOperation)
- */
-public interface IOOperation
-{
- /**
- * Perform some work.
- *
- * @throws IOException
- */
- void perform() throws IOException;
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/d8dba804/tapestry-core/src/main/java/org/apache/tapestry5/internal/TapestryInternalUtils.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/TapestryInternalUtils.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/TapestryInternalUtils.java
index f1aa65f..de17ee7 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/TapestryInternalUtils.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/TapestryInternalUtils.java
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008, 2009, 2010, 2011 The Apache Software Foundation
+// Copyright 2006-2013 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -566,32 +566,6 @@ public class TapestryInternalUtils
}
/**
- * Performs an operation and re-throws the IOException that may occur.
- */
- public static void performIO(OperationTracker tracker, String description, final IOOperation operation)
- throws IOException
- {
- final Holder<IOException> exceptionHolder = Holder.create();
-
- tracker.run(description, new Runnable()
- {
- public void run()
- {
- try
- {
- operation.perform();
- } catch (IOException ex)
- {
- exceptionHolder.put(ex);
- }
- }
- });
-
- if (exceptionHolder.hasValue())
- throw exceptionHolder.get();
- }
-
- /**
* Extracts a value from a map of references. Handles the case where the reference does not exist,
* and the case where the reference itself now contains null.
*
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/d8dba804/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RequestOperationTracker.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RequestOperationTracker.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RequestOperationTracker.java
index 3e85aea..f070e09 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RequestOperationTracker.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RequestOperationTracker.java
@@ -15,6 +15,7 @@
package org.apache.tapestry5.internal.services;
import org.apache.tapestry5.internal.util.Holder;
+import org.apache.tapestry5.ioc.IOOperation;
import org.apache.tapestry5.ioc.OperationTracker;
import org.apache.tapestry5.services.*;
@@ -43,30 +44,19 @@ public class RequestOperationTracker implements ComponentRequestFilter
? parameters.getContainingPageName()
: parameters.getContainingPageName() + ":" + parameters.getNestedComponentId();
- final Holder<IOException> holder = Holder.create();
-
- tracker.run(String.format("Handling %s '%s' component event request for %s.",
+ tracker.perform(String.format("Handling %s '%s' component event request for %s.",
request.isXHR() ? "Ajax" : "traditional",
parameters.getEventType(),
componentId),
- new Runnable()
- {
- public void run()
- {
- try
- {
- handler.handleComponentEvent(parameters);
- } catch (IOException e)
+ new IOOperation<Void>()
{
- holder.put(e);
- }
- }
- });
+ public Void perform() throws IOException
+ {
+ handler.handleComponentEvent(parameters);
- if (holder.hasValue())
- {
- throw holder.get();
- }
+ return null;
+ }
+ });
}
public void handlePageRender(final PageRenderRequestParameters parameters, final ComponentRequestHandler handler) throws IOException
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/d8dba804/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceStreamerImpl.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceStreamerImpl.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceStreamerImpl.java
index ab29e86..04c2a65 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceStreamerImpl.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceStreamerImpl.java
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012 The Apache Software Foundation
+// Copyright 2006-2013 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -15,10 +15,9 @@
package org.apache.tapestry5.internal.services;
import org.apache.tapestry5.SymbolConstants;
-import org.apache.tapestry5.internal.IOOperation;
import org.apache.tapestry5.internal.InternalConstants;
-import org.apache.tapestry5.internal.TapestryInternalUtils;
import org.apache.tapestry5.internal.services.assets.ResourceChangeTracker;
+import org.apache.tapestry5.ioc.IOOperation;
import org.apache.tapestry5.ioc.OperationTracker;
import org.apache.tapestry5.ioc.Resource;
import org.apache.tapestry5.ioc.annotations.Symbol;
@@ -83,9 +82,9 @@ public class ResourceStreamerImpl implements ResourceStreamer
return;
}
- TapestryInternalUtils.performIO(tracker, String.format("Streaming %s", resource), new IOOperation()
+ tracker.perform(String.format("Streaming %s", resource), new IOOperation<Void>()
{
- public void perform() throws IOException
+ public Void perform() throws IOException
{
StreamableResourceProcessing processing = analyzer.isGZipSupported() ? StreamableResourceProcessing.COMPRESSION_ENABLED
: StreamableResourceProcessing.COMPRESSION_DISABLED;
@@ -93,6 +92,8 @@ public class ResourceStreamerImpl implements ResourceStreamer
StreamableResource streamable = streamableResourceSource.getStreamableResource(resource, processing, resourceChangeTracker);
streamResource(streamable);
+
+ return null;
}
});
}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/d8dba804/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StackAssetRequestHandler.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StackAssetRequestHandler.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StackAssetRequestHandler.java
index c0c8165..fcdef02 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StackAssetRequestHandler.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StackAssetRequestHandler.java
@@ -1,4 +1,4 @@
-// Copyright 2010, 2011, 2012 The Apache Software Foundation
+// Copyright 2010-2013 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -16,8 +16,6 @@ package org.apache.tapestry5.internal.services.assets;
import org.apache.tapestry5.Asset;
import org.apache.tapestry5.SymbolConstants;
-import org.apache.tapestry5.internal.IOOperation;
-import org.apache.tapestry5.internal.TapestryInternalUtils;
import org.apache.tapestry5.internal.services.ResourceStreamer;
import org.apache.tapestry5.ioc.OperationTracker;
import org.apache.tapestry5.ioc.Resource;
@@ -97,16 +95,19 @@ public class StackAssetRequestHandler implements AssetRequestHandler
public boolean handleAssetRequest(Request request, Response response, final String extraPath) throws IOException
{
- TapestryInternalUtils.performIO(tracker, String.format("Streaming asset stack %s", extraPath),
- new IOOperation()
+ tracker.perform(String.format("Streaming asset stack %s", extraPath),
+ new org.apache.tapestry5.ioc.IOOperation<Void>()
{
- public void perform() throws IOException
+ @Override
+ public Void perform() throws IOException
{
boolean compress = compressionAnalyzer.isGZipSupported();
StreamableResource resource = getResource(extraPath, compress);
resourceStreamer.streamResource(resource);
+
+ return null;
}
});
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/d8dba804/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/ModuleAssetRequestHandler.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/ModuleAssetRequestHandler.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/ModuleAssetRequestHandler.java
index c0bdf79..7506ec5 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/ModuleAssetRequestHandler.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/ModuleAssetRequestHandler.java
@@ -1,4 +1,4 @@
-// Copyright 2012 The Apache Software Foundation
+// Copyright 2012, 2013 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -14,11 +14,10 @@
package org.apache.tapestry5.internal.services.javascript;
-import org.apache.tapestry5.internal.IOOperation;
-import org.apache.tapestry5.internal.TapestryInternalUtils;
import org.apache.tapestry5.internal.services.AssetDispatcher;
import org.apache.tapestry5.internal.services.ResourceStreamer;
import org.apache.tapestry5.internal.util.Holder;
+import org.apache.tapestry5.ioc.IOOperation;
import org.apache.tapestry5.ioc.OperationTracker;
import org.apache.tapestry5.ioc.Resource;
import org.apache.tapestry5.services.Request;
@@ -66,11 +65,9 @@ public class ModuleAssetRequestHandler implements AssetRequestHandler
final String moduleName = extraPath.substring(0, dotx);
- final Holder<Boolean> handledHolder = Holder.create(false);
-
- TapestryInternalUtils.performIO(tracker, String.format("Streaming module %s", extraPath), new IOOperation()
+ return tracker.perform(String.format("Streaming module %s", extraPath), new IOOperation<Boolean>()
{
- public void perform() throws IOException
+ public Boolean perform() throws IOException
{
Resource resource = moduleManager.findResourceForModule(moduleName);
@@ -78,11 +75,11 @@ public class ModuleAssetRequestHandler implements AssetRequestHandler
{
streamer.streamResource(resource);
- handledHolder.put(true);
+ return true;
}
+
+ return false;
}
});
-
- return handledHolder.get();
}
}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/d8dba804/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementResourcesImpl.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementResourcesImpl.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementResourcesImpl.java
index c3e1a54..58adf4f 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementResourcesImpl.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementResourcesImpl.java
@@ -1,4 +1,4 @@
-// Copyright 2008, 2009, 2010, 2011 The Apache Software Foundation
+// Copyright 2008-2013 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -20,10 +20,7 @@ import org.apache.tapestry5.internal.InternalConstants;
import org.apache.tapestry5.internal.services.ComponentClassCache;
import org.apache.tapestry5.internal.services.LinkSource;
import org.apache.tapestry5.internal.services.RequestPageCache;
-import org.apache.tapestry5.ioc.Invokable;
-import org.apache.tapestry5.ioc.LoggerSource;
-import org.apache.tapestry5.ioc.Messages;
-import org.apache.tapestry5.ioc.OperationTracker;
+import org.apache.tapestry5.ioc.*;
import org.apache.tapestry5.ioc.services.PerThreadValue;
import org.apache.tapestry5.ioc.services.PerthreadManager;
import org.apache.tapestry5.ioc.services.TypeCoercer;
@@ -34,6 +31,8 @@ import org.apache.tapestry5.services.messages.ComponentMessagesSource;
import org.apache.tapestry5.services.pageload.ComponentResourceSelector;
import org.slf4j.Logger;
+import java.io.IOException;
+
public class ComponentPageElementResourcesImpl implements ComponentPageElementResources
{
private final ComponentResourceSelector selector;
@@ -59,10 +58,10 @@ public class ComponentPageElementResourcesImpl implements ComponentPageElementRe
private final PerthreadManager perThreadManager;
public ComponentPageElementResourcesImpl(ComponentResourceSelector selector,
- ComponentMessagesSource componentMessagesSource, TypeCoercer typeCoercer,
- ComponentClassCache componentClassCache, ContextValueEncoder contextValueEncoder, LinkSource linkSource,
- RequestPageCache requestPageCache, ComponentClassResolver componentClassResolver,
- LoggerSource loggerSource, OperationTracker tracker, PerthreadManager perThreadManager)
+ ComponentMessagesSource componentMessagesSource, TypeCoercer typeCoercer,
+ ComponentClassCache componentClassCache, ContextValueEncoder contextValueEncoder, LinkSource linkSource,
+ RequestPageCache requestPageCache, ComponentClassResolver componentClassResolver,
+ LoggerSource loggerSource, OperationTracker tracker, PerthreadManager perThreadManager)
{
this.selector = selector;
this.componentMessagesSource = componentMessagesSource;
@@ -98,7 +97,7 @@ public class ComponentPageElementResourcesImpl implements ComponentPageElementRe
}
public Link createComponentEventLink(ComponentResources resources, String eventType, boolean forForm,
- Object... context)
+ Object... context)
{
Page page = requestPageCache.get(resources.getPageName());
@@ -146,6 +145,11 @@ public class ComponentPageElementResourcesImpl implements ComponentPageElementRe
return tracker.invoke(description, operation);
}
+ public <T> T perform(String description, IOOperation<T> operation) throws IOException
+ {
+ return tracker.perform(description, operation);
+ }
+
public void run(String description, Runnable operation)
{
tracker.run(description, operation);
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/d8dba804/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/IOOperation.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/IOOperation.java b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/IOOperation.java
new file mode 100644
index 0000000..f56b5de
--- /dev/null
+++ b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/IOOperation.java
@@ -0,0 +1,29 @@
+// Copyright 2013 The Apache Software Foundation
+//
+// 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 org.apache.tapestry5.ioc;
+
+import java.io.IOException;
+
+/**
+ * An operation that, when performed, returns a value (like {@link Invokable}, but may throw an {@link java.io.IOException}.
+ *
+ * @since 5.4
+ * @see OperationTracker#perform(String, IOOperation)
+ */
+public interface IOOperation<T>
+{
+ /** Perform an operation and return a value, or throw the exception. */
+ T perform() throws IOException;
+}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/d8dba804/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/Invokable.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/Invokable.java b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/Invokable.java
index 80aacd0..aeb7792 100644
--- a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/Invokable.java
+++ b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/Invokable.java
@@ -1,4 +1,4 @@
-// Copyright 2006, 2009, 2011 The Apache Software Foundation
+// Copyright 2006, 2009, 2011, 2013 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -16,12 +16,13 @@ package org.apache.tapestry5.ioc;
/**
- * Similiar to {@link Runnable} execept that it returns a value. Used to represent any operation which can return a
+ * Similar to {@link Runnable} except that it returns a value. Used to represent any operation which can return a
* value. This is often used in situations where the code is to be executed in another threads.
*
* @param <T> the return value type
* @see org.apache.tapestry5.ioc.OperationTracker#invoke(String, Invokable)
* @see org.apache.tapestry5.ioc.services.ParallelExecutor#invoke(Invokable)
+ * @see IOOperation
*/
public interface Invokable<T>
{
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/d8dba804/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/OperationTracker.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/OperationTracker.java b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/OperationTracker.java
index 8fb1ee3..f6b0f2b 100644
--- a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/OperationTracker.java
+++ b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/OperationTracker.java
@@ -1,4 +1,4 @@
-// Copyright 2008, 2009 The Apache Software Foundation
+// Copyright 2008, 2009, 2013 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -14,6 +14,8 @@
package org.apache.tapestry5.ioc;
+import java.io.IOException;
+
/**
* Used to track some set of operations in such a way that a failure (a thrown RuntimeException) will be logged along
* with a trace of the stack of operations.
@@ -21,19 +23,36 @@ package org.apache.tapestry5.ioc;
public interface OperationTracker
{
/**
- * Executes the operation.
+ * Executes the operation. If the operation throws a {@link RuntimeException} it will be logged and rethrown
+ * wrapped as a {@link org.apache.tapestry5.ioc.internal.OperationException}.
*
- * @param description used if there is an exception
- * @param operation to execute
+ * @param description
+ * used if there is an exception
+ * @param operation
+ * to execute
*/
void run(String description, Runnable operation);
/**
- * Executes the operation, returning its value.
+ * As with {@link #run(String, Runnable)}, but the operation may return a value.
*
- * @param description used if there is an exception
- * @param operation to invoke
+ * @param description
+ * used if there is an exception
+ * @param operation
+ * to invoke
* @return result of operation
*/
<T> T invoke(String description, Invokable<T> operation);
+
+ /**
+ * As with {@link #invoke(String, Invokable)}, but the operation may throw an {@link java.io.IOException}.
+ *
+ * @param description
+ * used if there is an exception (outside of IOException)
+ * @param operation
+ * to perform
+ * @return result of operation
+ * @since 5.4
+ */
+ <T> T perform(String description, IOOperation<T> operation) throws IOException;
}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/d8dba804/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/OperationTrackerImpl.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/OperationTrackerImpl.java b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/OperationTrackerImpl.java
index b8d72cd..5a0dfde 100644
--- a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/OperationTrackerImpl.java
+++ b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/OperationTrackerImpl.java
@@ -1,4 +1,4 @@
-// Copyright 2008, 2009, 2010, 2011 The Apache Software Foundation
+// Copyright 2008-2013 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -14,6 +14,7 @@
package org.apache.tapestry5.ioc.internal;
+import org.apache.tapestry5.ioc.IOOperation;
import org.apache.tapestry5.ioc.Invokable;
import org.apache.tapestry5.ioc.OperationTracker;
import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
@@ -21,6 +22,8 @@ import org.apache.tapestry5.ioc.internal.util.InternalUtils;
import org.apache.tapestry5.ioc.util.Stack;
import org.slf4j.Logger;
+import java.io.IOException;
+
/**
* Core implementation that manages a logger and catches and reports exception.
*
@@ -44,15 +47,24 @@ public class OperationTrackerImpl implements OperationTracker
assert InternalUtils.isNonBlank(description);
assert operation != null;
- invoke(description, new Invokable<Void>()
+ long startNanos = start(description);
+
+ try
{
- public Void invoke()
- {
- operation.run();
+ operation.run();
- return null;
- }
- });
+ finish(description, startNanos);
+
+ } catch (RuntimeException ex)
+ {
+ logAndRethrow(ex);
+ } catch (Error ex)
+ {
+ handleError(ex);
+ } finally
+ {
+ handleFinally();
+ }
}
public <T> T invoke(String description, Invokable<T> operation)
@@ -60,57 +72,103 @@ public class OperationTrackerImpl implements OperationTracker
assert InternalUtils.isNonBlank(description);
assert operation != null;
- long startNanos = System.nanoTime();
+ long startNanos = start(description);
- if (logger.isDebugEnabled())
+ try
{
- logger.debug(String.format("[%3d] --> %s", operations.getDepth() + 1, description));
+ T result = operation.invoke();
+
+ finish(description, startNanos);
+
+ return result;
+
+ } catch (RuntimeException ex)
+ {
+ return logAndRethrow(ex);
+ } catch (Error ex)
+ {
+ return handleError(ex);
+ } finally
+ {
+ handleFinally();
}
+ }
- operations.push(description);
+ public <T> T perform(String description, IOOperation<T> operation) throws IOException
+ {
+ InternalUtils.isNonBlank(description);
+ assert operation != null;
+
+ long startNanos = start(description);
try
{
- T result = operation.invoke();
-
- if (logger.isDebugEnabled())
- {
- long elapsedNanos = System.nanoTime() - startNanos;
- double elapsedMillis = ((double) elapsedNanos) / 1000000.d;
+ T result = operation.perform();
- logger.debug(String.format("[%3d] <-- %s [%,.2f ms]", operations.getDepth(), description, elapsedMillis));
- }
+ finish(description, startNanos);
return result;
} catch (RuntimeException ex)
{
- logAndRethrow(ex);
-
- throw ex;
+ return logAndRethrow(ex);
} catch (Error ex)
{
- if (!logged)
- {
- log(ex);
- logged = true;
- }
-
- throw ex;
+ return handleError(ex);
} finally
{
- operations.pop();
+ handleFinally();
+ }
+ }
+
+ private void handleFinally()
+ {
+ operations.pop();
+
+ // We've finally backed out of the operation stack ... but there may be more to come!
+
+ if (operations.isEmpty())
+ {
+ logged = false;
+ }
+ }
+
+ private <T> T handleError(Error error)
+ {
+ if (!logged)
+ {
+ log(error);
+ logged = true;
+ }
- // We've finally backed out of the operation stack ... but there may be more to come!
+ throw error;
+ }
- if (operations.isEmpty())
- logged = false;
+ private void finish(String description, long startNanos)
+ {
+ if (logger.isDebugEnabled())
+ {
+ long elapsedNanos = System.nanoTime() - startNanos;
+ double elapsedMillis = ((double) elapsedNanos) / 1000000.d;
+
+ logger.debug(String.format("[%3d] <-- %s [%,.2f ms]", operations.getDepth(), description, elapsedMillis));
}
+ }
+ private long start(String description)
+ {
+ long startNanos = System.nanoTime();
+ if (logger.isDebugEnabled())
+ {
+ logger.debug(String.format("[%3d] --> %s", operations.getDepth() + 1, description));
+ }
+
+ operations.push(description);
+ return startNanos;
}
- private void logAndRethrow(Throwable ex)
+ private <T> T logAndRethrow(RuntimeException ex)
{
if (!logged)
{
@@ -120,6 +178,8 @@ public class OperationTrackerImpl implements OperationTracker
throw new OperationException(ex, trace);
}
+
+ throw ex;
}
private String[] log(Throwable ex)
@@ -136,6 +196,7 @@ public class OperationTrackerImpl implements OperationTracker
logger.error(String.format("[%2d] %s", i + 1, trace[i]));
}
+
return trace;
}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/d8dba804/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/PerThreadOperationTracker.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/PerThreadOperationTracker.java b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/PerThreadOperationTracker.java
index 3683105..f1837ad 100644
--- a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/PerThreadOperationTracker.java
+++ b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/PerThreadOperationTracker.java
@@ -1,4 +1,4 @@
-// Copyright 2008, 2009, 2011 The Apache Software Foundation
+// Copyright 2008-2013 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -14,11 +14,13 @@
package org.apache.tapestry5.ioc.internal;
+import org.apache.tapestry5.ioc.IOOperation;
import org.apache.tapestry5.ioc.Invokable;
import org.apache.tapestry5.ioc.OperationTracker;
import org.apache.tapestry5.ioc.internal.util.JDKUtils;
import org.slf4j.Logger;
+import java.io.IOException;
import java.util.concurrent.locks.Lock;
/**
@@ -90,4 +92,16 @@ public class PerThreadOperationTracker implements OperationTracker
cleanup();
}
}
+
+ @Override
+ public <T> T perform(String description, IOOperation<T> operation) throws IOException
+ {
+ try
+ {
+ return get().perform(description, operation);
+ } finally
+ {
+ cleanup();
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/d8dba804/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/QuietOperationTracker.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/QuietOperationTracker.java b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/QuietOperationTracker.java
index 0ea7bc6..b470fb1 100644
--- a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/QuietOperationTracker.java
+++ b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/QuietOperationTracker.java
@@ -1,4 +1,4 @@
-// Copyright 2008, 2009 The Apache Software Foundation
+// Copyright 2008, 2009, 2013 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -14,9 +14,12 @@
package org.apache.tapestry5.ioc.internal;
+import org.apache.tapestry5.ioc.IOOperation;
import org.apache.tapestry5.ioc.Invokable;
import org.apache.tapestry5.ioc.OperationTracker;
+import java.io.IOException;
+
/**
* Minimal implementation used for testing, that does no logging, tracking, or exception catching.
*/
@@ -31,4 +34,10 @@ public class QuietOperationTracker implements OperationTracker
{
return operation.invoke();
}
+
+ @Override
+ public <T> T perform(String description, IOOperation<T> operation) throws IOException
+ {
+ return operation.perform();
+ }
}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/d8dba804/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/RegistryImpl.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/RegistryImpl.java b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/RegistryImpl.java
index f671440..791c916 100644
--- a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/RegistryImpl.java
+++ b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/RegistryImpl.java
@@ -1,4 +1,4 @@
-// Copyright 2006-2012 The Apache Software Foundation
+// Copyright 2006-2013 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -30,6 +30,7 @@ import org.apache.tapestry5.ioc.util.UnknownValueException;
import org.apache.tapestry5.services.UpdateListenerHub;
import org.slf4j.Logger;
+import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationHandler;
@@ -1110,6 +1111,11 @@ public class RegistryImpl implements Registry, InternalRegistry, ServiceProxyPro
return operationTracker.invoke(description, operation);
}
+ public <T> T perform(String description, IOOperation<T> operation) throws IOException
+ {
+ return operationTracker.perform(description, operation);
+ }
+
public Set<Class> getMarkerAnnotations()
{
return markerToServiceDef.keySet();
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/d8dba804/tapestry-yuicompressor/src/main/java/org/apache/tapestry5/internal/yuicompressor/AbstractMinimizer.java
----------------------------------------------------------------------
diff --git a/tapestry-yuicompressor/src/main/java/org/apache/tapestry5/internal/yuicompressor/AbstractMinimizer.java b/tapestry-yuicompressor/src/main/java/org/apache/tapestry5/internal/yuicompressor/AbstractMinimizer.java
index 9370f54..47b4540 100644
--- a/tapestry-yuicompressor/src/main/java/org/apache/tapestry5/internal/yuicompressor/AbstractMinimizer.java
+++ b/tapestry-yuicompressor/src/main/java/org/apache/tapestry5/internal/yuicompressor/AbstractMinimizer.java
@@ -1,4 +1,4 @@
-// Copyright 2011-2012 The Apache Software Foundation
+// Copyright 2011-2013 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -14,10 +14,9 @@
package org.apache.tapestry5.internal.yuicompressor;
-import org.apache.tapestry5.internal.IOOperation;
-import org.apache.tapestry5.internal.TapestryInternalUtils;
import org.apache.tapestry5.internal.services.assets.BytestreamCache;
import org.apache.tapestry5.internal.services.assets.StreamableResourceImpl;
+import org.apache.tapestry5.ioc.IOOperation;
import org.apache.tapestry5.ioc.OperationTracker;
import org.apache.tapestry5.ioc.internal.util.InternalUtils;
import org.apache.tapestry5.services.assets.CompressionStatus;
@@ -58,9 +57,9 @@ public abstract class AbstractMinimizer implements ResourceMinimizer
final Writer writer = new OutputStreamWriter(bos);
- TapestryInternalUtils.performIO(tracker, "Minimizing " + resourceType, new IOOperation()
+ tracker.perform("Minimizing " + resourceType, new IOOperation<Void>()
{
- public void perform() throws IOException
+ public Void perform() throws IOException
{
try
{
@@ -71,6 +70,7 @@ public abstract class AbstractMinimizer implements ResourceMinimizer
InternalUtils.toMessage(ex)), ex);
}
+ return null;
}
});