Author: lindner
Date: Mon Mar 23 18:09:18 2009
New Revision: 757479
URL: http://svn.apache.org/viewvc?rev=757479&view=rev
Log:
SHINDIG-990 | Add executed lifecycle phase to allow for profiling
implementations, add sample logging implementation/docs
Modified:
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/DefaultHandlerRegistry.java
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/HandlerExecutionListener.java
Modified:
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/DefaultHandlerRegistry.java
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/DefaultHandlerRegistry.java?rev=757479&r1=757478&r2=757479&view=diff
==============================================================================
---
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/DefaultHandlerRegistry.java
(original)
+++
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/DefaultHandlerRegistry.java
Mon Mar 23 18:09:18 2009
@@ -253,6 +253,10 @@
private void executing(RequestItem req) {
listener.executing(service, operation, req);
}
+
+ private void executed(RequestItem req) {
+ listener.executed(service, operation, req);
+ }
}
@@ -279,14 +283,21 @@
public Future<?> execute(JSONObject rpc, Map<String, FormDataItem>
formItems,
SecurityToken token, BeanConverter converter) {
+ RequestItem item;
try {
JSONObject params = rpc.has("params") ? (JSONObject)rpc.get("params")
: new JSONObject();
- RequestItem item = methodCaller.getRpcRequestItem(params, formItems,
token, beanJsonConverter);
+ item = methodCaller.getRpcRequestItem(params, formItems, token,
beanJsonConverter);
+ } catch (Exception e) {
+ return ImmediateFuture.errorInstance(e);
+ }
+ try {
listener.executing(item);
return methodCaller.call(handlerProvider.get(), item);
} catch (Exception e) {
return ImmediateFuture.errorInstance(e);
+ } finally {
+ listener.executed(item);
}
}
}
Modified:
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/HandlerExecutionListener.java
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/HandlerExecutionListener.java?rev=757479&r1=757478&r2=757479&view=diff
==============================================================================
---
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/HandlerExecutionListener.java
(original)
+++
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/HandlerExecutionListener.java
Mon Mar 23 18:09:18 2009
@@ -20,11 +20,13 @@
import com.google.inject.ImplementedBy;
+import java.util.logging.Logger;
+
/**
* Called by the handler dispatcher prior to executing a handler. Used to allow
* containers to implement cross-cutting features such as request logging.
*/
-...@implementedby(HandlerExecutionListener.NoOpHandlerExecutionListener.class)
+...@implementedby(HandlerExecutionListener.NoOpHandler.class)
public interface HandlerExecutionListener {
/**
@@ -34,15 +36,37 @@
* @param request being executed
*/
void executing(String service, String operation, RequestItem request);
+ void executed(String service, String operation, RequestItem request);
/**
* Default no-op implementation
*/
- public static class NoOpHandlerExecutionListener implements
HandlerExecutionListener {
+ public static class NoOpHandler implements HandlerExecutionListener {
public void executing(String service, String operation, RequestItem
request) {
// No-op
}
+ public void executed(String service, String operation, RequestItem
request) {
+ // No-op
+ }
+ }
+
+ /**
+ * A simple implementation that logs the start/stop times of requests
+ *
+ * You can configure this for use by adding a binding in your Guice Module
like this:
+ *
bind(HandlerExecutionListener.class).to(HandlerExecutionListener.LoggingHandler.class);
+ */
+
+ public static class LoggingHandler implements HandlerExecutionListener {
+ public static final Logger LOG =
Logger.getLogger(HandlerExecutionListener.class.toString());
+
+ public void executing(String service, String operation, RequestItem
request) {
+ LOG.info("start - " + service + " " + operation);
+ }
+ public void executed(String service, String operation, RequestItem
request) {
+ LOG.info(" end - " + service + " " + operation);
+ }
}
}