cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From reinh...@apache.org
Subject svn commit: r806346 [2/3] - in /cocoon/cocoon3/trunk: cocoon-profiling/ cocoon-profiling/src/main/java/org/ cocoon-profiling/src/main/java/org/apache/ cocoon-profiling/src/main/java/org/apache/cocoon/ cocoon-profiling/src/main/java/org/apache/cocoon/pr...
Date Thu, 20 Aug 2009 20:43:22 GMT
Added: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingDataComparator.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingDataComparator.java?rev=806346&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingDataComparator.java (added)
+++ cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingDataComparator.java Thu Aug 20 20:43:20 2009
@@ -0,0 +1,32 @@
+/*
+ * 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.apache.cocoon.profiling.data;
+
+import java.util.Comparator;
+
+/**
+ * Comparator that compares profiling data objects using their invocation start time.
+ */
+public class ProfilingDataComparator implements Comparator<ProfilingData> {
+
+    /**
+     * {@inheritDoc}
+     */
+    public int compare(ProfilingData arg0, ProfilingData arg1) {
+        return (int) Math.signum(arg0.getInvocationStartTime() - arg1.getInvocationStartTime());
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingDataComparator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingDataComparator.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingDataComparator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingDataHolder.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingDataHolder.java?rev=806346&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingDataHolder.java (added)
+++ cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingDataHolder.java Thu Aug 20 20:43:20 2009
@@ -0,0 +1,45 @@
+/*
+ * 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.apache.cocoon.profiling.data;
+
+/**
+ * Interface for the storage layer of the profiling module. Supports storage and retrieval of
+ * {@link ProfilingData} objects based on a key.
+ * <p>
+ * The stored {@link ProfilingData} objects may be discarded at any point in time.
+ * </p>
+ */
+public interface ProfilingDataHolder {
+
+    /**
+     * Store the given {@link ProfilingData} objects using the given id as key.
+     * 
+     * @param id
+     * @param data
+     */
+    void store(String id, ProfilingData data);
+
+    /**
+     * Retrieve the {@link ProfilingData} objects stored with the given id as key.
+     * 
+     * @param id
+     * @return the {@link ProfilingData} stored with the given id as key or null if there is no
+     *         mapping for the given id.
+     */
+    ProfilingData get(String id);
+}

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingDataHolder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingDataHolder.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingDataHolder.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingDataManager.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingDataManager.java?rev=806346&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingDataManager.java (added)
+++ cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingDataManager.java Thu Aug 20 20:43:20 2009
@@ -0,0 +1,41 @@
+/*
+ * 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.apache.cocoon.profiling.data;
+
+/**
+ * The {@link ProfilingDataManager} is responsible for building the data structure by linking the
+ * {@link ProfilingData} elements together.
+ * 
+ * <p>
+ * The creation of the data structure is solely in the responsibility of the
+ * {@link ProfilingDataManager} and has to be accomplished using the information stored in the
+ * {@link ProfilingData} objects. Furthermore it has to group the incoming {@link ProfilingData}
+ * objects and to move the whole data structure to the {@link ProfilingDataHolder} after one group
+ * was completely processed.
+ * </p>
+ */
+public interface ProfilingDataManager {
+
+    /**
+     * Add and process the given profiling data.
+     * 
+     * @param data
+     */
+    public void add(ProfilingData data);
+
+    public void setProfilingDataHolder(ProfilingDataHolder profilingDataHolder);
+}

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingDataManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingDataManager.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingDataManager.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingDataManagerImpl.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingDataManagerImpl.java?rev=806346&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingDataManagerImpl.java (added)
+++ cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingDataManagerImpl.java Thu Aug 20 20:43:20 2009
@@ -0,0 +1,161 @@
+/*
+ * 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.apache.cocoon.profiling.data;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * This class connects ProfilingData objects according to request id
+ */
+public class ProfilingDataManagerImpl implements ProfilingDataManager {
+
+    private HashMap<String, LinkedList<ProfilingData>> dataMap = new HashMap<String, LinkedList<ProfilingData>>();
+
+    private ProfilingDataHolder profilingDataHolder;
+
+    /**
+     * {@inheritDoc}
+     */
+    public void add(ProfilingData data) {
+        String id = data.getProfilingId();
+        LinkedList<ProfilingData> temp = this.dataMap.get(id);
+
+        if (temp != null) {
+            temp.add(data);
+            if (data.isRoot()) {
+                this.finish(id);
+            }
+        } else {
+            // new request
+            temp = new LinkedList<ProfilingData>();
+            this.dataMap.put(id, temp);
+            temp.add(data);
+        }
+    }
+
+    /**
+     * build a tree structure
+     *
+     * @param list
+     *            a list sorted according to invocation timestamp
+     * @return the root tree node
+     */
+    private ProfilingData buildTree(List<ProfilingData> list) {
+        ProfilingData root = list.remove(0);
+        int maxLevel = 0;
+
+        while (!list.isEmpty()) {
+            maxLevel = Math.max(maxLevel, list.get(0).getInvocationDepth());
+            this.addNode(root, list);
+        }
+
+        for (int i = maxLevel; i > 1; i--) {
+            this.correctChildAssignments(root, i);
+        }
+        return root;
+    }
+
+    /**
+     * links children at the specified level to the correct parents so the time ordering is correct
+     */
+    private void correctChildAssignments(ProfilingData root, int level) {
+        while (root.getInvocationDepth() < level - 2) {
+            root = root.getChild(0);
+        }
+        List<ProfilingData> children = new ArrayList<ProfilingData>(root.getChild(0).getChildren());
+        root.getChild(0).removeAllChildren();
+        int size = root.getChildCount();
+        ProfilingData temp = null;
+
+        for (int i = 1; i < size; i++) {
+            while (!children.isEmpty()
+                    && root.getChild(i).getInvocationStartTime() > children.get(0).getInvocationStartTime()) {
+                temp = children.remove(0);
+                root.getChild(i - 1).addChild(temp);
+            }
+        }
+        while (!children.isEmpty()) {
+            temp = children.remove(0);
+            root.getChild(size - 1).addChild(temp);
+        }
+    }
+
+    /**
+     * Insert data into tree structure
+     *
+     * @param root
+     *            the root node of the tree structure
+     */
+    private void addNode(ProfilingData root, List<ProfilingData> list) {
+        ProfilingData data = list.remove(0);
+
+        // iterate to nearest tree node
+        while (root.getInvocationDepth() < data.getInvocationDepth() && root.hasChildren()) {
+            root = root.getChild(0);
+        }
+        // add before current node
+        if (root.getInvocationDepth() > data.getInvocationDepth()) {
+            data.addChildren(root.getParent().getChildren());
+            root.getParent().removeAllChildren();
+            root.getParent().addChild(data);
+            return;
+        }
+        // add on the same level as current node
+        if (root.getInvocationDepth() == data.getInvocationDepth()) {
+            root.getParent().addChild(data);
+            return;
+        }
+        // add as child
+        if (!root.hasChildren()) {
+            root.addChild(data);
+            return;
+        }
+        throw new RuntimeException("Cannot add ProfilingData object to tree structure");
+    }
+
+    /**
+     * To be called when a request was finished. build a tree and store it in
+     * {@link ProfilingDataHolder}
+     *
+     * @param id the request id
+     */
+    private void finish(String id) {
+        try {
+            LinkedList<ProfilingData> list = this.dataMap.get(id);
+
+            // remove useless method calls
+            if (list.size() <= 3) {
+                return;
+            }
+
+            Collections.sort(list, new ProfilingDataComparator());
+            ProfilingData data = this.buildTree(list);
+
+            this.profilingDataHolder.store(id, data);
+        } finally {
+            this.dataMap.remove(id);
+        }
+    }
+
+    public void setProfilingDataHolder(ProfilingDataHolder profilingDataHolder) {
+        this.profilingDataHolder = profilingDataHolder;
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingDataManagerImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingDataManagerImpl.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingDataManagerImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingIdGenerator.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingIdGenerator.java?rev=806346&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingIdGenerator.java (added)
+++ cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingIdGenerator.java Thu Aug 20 20:43:20 2009
@@ -0,0 +1,50 @@
+/*
+ * 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.apache.cocoon.profiling.data;
+
+/**
+ * The {@link ProfilingIdGenerator} has to work thread dependent. So the id generated by
+ * {@link ProfilingIdGenerator#create()} should only be retrievable by calls to
+ * {@link ProfilingIdGenerator#getCurrent()} and removable by calls to
+ * {@link ProfilingIdGenerator#remove()} from the same thread. The id for one thread has to be equal
+ * for all calls to {@link ProfilingIdGenerator#getCurrent()} between an initial call to
+ * {@link ProfilingIdGenerator#create()} and a call to {@link ProfilingIdGenerator#remove()}. Ids
+ * should be unique within a reasonable amount of time.
+ * 
+ */
+public interface ProfilingIdGenerator {
+
+    /**
+     * Creates and returns a new id for the current thread.
+     * 
+     * @return the newly created id.
+     */
+    String create();
+
+    /**
+     * Get the current id for the current thread.
+     * 
+     * @return the current id for the current thread, or null if none has been created or remove was
+     *         called.
+     */
+    String getCurrent();
+
+    /**
+     * Discard the id for the current thread.
+     */
+    void remove();
+}

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingIdGenerator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingIdGenerator.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/ProfilingIdGenerator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/UUIDProfilingIdGenerator.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/UUIDProfilingIdGenerator.java?rev=806346&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/UUIDProfilingIdGenerator.java (added)
+++ cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/UUIDProfilingIdGenerator.java Thu Aug 20 20:43:20 2009
@@ -0,0 +1,52 @@
+/*
+ * 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.apache.cocoon.profiling.data;
+
+import java.util.UUID;
+
+/**
+ * The {@link UUIDProfilingIdGenerator} uses {@link ThreadLocal} to separate the id management for
+ * different threads and generates ids based on {@link UUID} objects created by
+ * {@link UUID#randomUUID()}, which should be reasonably unique for profiling purposes.
+ */
+public class UUIDProfilingIdGenerator implements ProfilingIdGenerator {
+
+    private ThreadLocal<String> currentId = new ThreadLocal<String>();;
+
+    /**
+     * {@inheritDoc}
+     */
+    public String create() {
+        String id = UUID.randomUUID().toString();
+        this.currentId.set(id);
+        return id;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getCurrent() {
+        return this.currentId.get();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void remove() {
+        this.currentId.remove();
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/UUIDProfilingIdGenerator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/UUIDProfilingIdGenerator.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/UUIDProfilingIdGenerator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/package-info.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/package-info.java?rev=806346&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/package-info.java (added)
+++ cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/package-info.java Thu Aug 20 20:43:20 2009
@@ -0,0 +1,22 @@
+/*
+ * 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.
+ */
+/**
+ * Contains classes and interfaces for the storage and the construction of data structures of profiling data.
+ *  
+ */
+package org.apache.cocoon.profiling.data;
+

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/package-info.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/package-info.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/data/package-info.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/jmx/ProfilingManagement.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/jmx/ProfilingManagement.java?rev=806346&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/jmx/ProfilingManagement.java (added)
+++ cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/jmx/ProfilingManagement.java Thu Aug 20 20:43:20 2009
@@ -0,0 +1,41 @@
+/*
+ * 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.apache.cocoon.profiling.jmx;
+
+/**
+ * 
+ * This MBean provides management functionality for cocoon-profiling and offers a possibility to
+ * enable/disable cocoon profiling.
+ * 
+ * If you want to test this, simply run cocoon-sample and connect with jconsole
+ */
+public class ProfilingManagement implements ProfilingManagementMBean {
+
+    private boolean enabled = true;
+
+    public boolean isEnabled() {
+        return this.enabled;
+    }
+
+    public void enable() {
+        this.enabled = true;
+    }
+
+    public void disable() {
+        this.enabled = false;
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/jmx/ProfilingManagement.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/jmx/ProfilingManagement.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/jmx/ProfilingManagement.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/jmx/ProfilingManagementMBean.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/jmx/ProfilingManagementMBean.java?rev=806346&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/jmx/ProfilingManagementMBean.java (added)
+++ cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/jmx/ProfilingManagementMBean.java Thu Aug 20 20:43:20 2009
@@ -0,0 +1,30 @@
+/*
+ * 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.apache.cocoon.profiling.jmx;
+
+/**
+ * This is the interface for an MBean that makes it possible to manage (enable/disable) cocoon
+ * profiling.
+ */
+public interface ProfilingManagementMBean {
+
+    public boolean isEnabled();
+
+    public void enable();
+
+    public void disable();
+}

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/jmx/ProfilingManagementMBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/jmx/ProfilingManagementMBean.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/jmx/ProfilingManagementMBean.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/jmx/package-info.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/jmx/package-info.java?rev=806346&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/jmx/package-info.java (added)
+++ cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/jmx/package-info.java Thu Aug 20 20:43:20 2009
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+/**
+ * Provides JMX support for cocoon-profiling.
+ */
+package org.apache.cocoon.profiling.jmx;
+

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/jmx/package-info.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/jmx/package-info.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/jmx/package-info.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/package-info.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/package-info.java?rev=806346&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/package-info.java (added)
+++ cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/package-info.java Thu Aug 20 20:43:20 2009
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+/**
+ * The main package for cocoon-profiling.
+ */
+package org.apache.cocoon.profiling;
+

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/package-info.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/package-info.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/package-info.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/GenerateNodeProfiler.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/GenerateNodeProfiler.java?rev=806346&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/GenerateNodeProfiler.java (added)
+++ cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/GenerateNodeProfiler.java Thu Aug 20 20:43:20 2009
@@ -0,0 +1,58 @@
+/*
+ * 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.apache.cocoon.profiling.profiler;
+
+import java.lang.reflect.Field;
+
+import org.apache.cocoon.profiling.ProfileMethod;
+import org.apache.cocoon.profiling.data.ProfilingData;
+import org.apache.cocoon.sitemap.node.GenerateNode;
+
+public class GenerateNodeProfiler extends Profiler<GenerateNode> {
+
+    public GenerateNodeProfiler() {
+        super(GenerateNode.class);
+    }
+
+    @ProfileMethod(name = "invoke")
+    public void beforeInvoke(ProfilingData data, GenerateNode component, Object[] args) {
+        try {
+            Field srcField = GenerateNode.class.getDeclaredField("src");
+
+            srcField.setAccessible(true);
+            String src = (String) srcField.get(component);
+
+            if (src != null) {
+                data.addData("src", src);
+            }
+
+            Field typeField = GenerateNode.class.getDeclaredField("type");
+
+            typeField.setAccessible(true);
+            String type = (String) typeField.get(component);
+
+            if (type != null) {
+                data.addData("type", type);
+
+                String simpleName = component.getClass().getSimpleName();
+                data.setDisplayName(String.format("%s (%s=%s)", simpleName, "type", type));
+            }
+        } catch (Exception e) {
+            throw new RuntimeException("Error reading private fields from GenerateNode", e);
+        }
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/GenerateNodeProfiler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/GenerateNodeProfiler.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/GenerateNodeProfiler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/MatchNodeProfiler.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/MatchNodeProfiler.java?rev=806346&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/MatchNodeProfiler.java (added)
+++ cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/MatchNodeProfiler.java Thu Aug 20 20:43:20 2009
@@ -0,0 +1,54 @@
+/*
+ * 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.apache.cocoon.profiling.profiler;
+
+import java.lang.reflect.Field;
+
+import org.apache.cocoon.profiling.ProfileMethod;
+import org.apache.cocoon.profiling.data.ProfilingData;
+import org.apache.cocoon.sitemap.node.MatchNode;
+
+public class MatchNodeProfiler extends Profiler<MatchNode> {
+
+    private final String[] fields = {"pattern", "regexp", "equals", "contains", "wildcard", "startsWith", "endsWith"};
+
+    public MatchNodeProfiler() {
+        super(MatchNode.class);
+    }
+
+    @ProfileMethod(name = "invoke")
+    public void beforeInvoke(ProfilingData data, MatchNode component, Object[] args) {
+        try {
+            for (String fieldname : this.fields) {
+                Field field = MatchNode.class.getDeclaredField(fieldname);
+
+                field.setAccessible(true);
+                String value = (String) field.get(component);
+
+                if (value != null) {
+                    data.addData(fieldname, value);
+
+                    String simpleName = component.getClass().getSimpleName();
+                    data.setDisplayName(String.format("%s (%s=%s)", simpleName, fieldname, value));
+                    return;
+                }
+            }
+        } catch (Exception e) {
+            throw new RuntimeException("Error reading pattern from MatchNode", e);
+        }
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/MatchNodeProfiler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/MatchNodeProfiler.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/MatchNodeProfiler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/PipelineComponentProfiler.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/PipelineComponentProfiler.java?rev=806346&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/PipelineComponentProfiler.java (added)
+++ cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/PipelineComponentProfiler.java Thu Aug 20 20:43:20 2009
@@ -0,0 +1,26 @@
+/*
+ * 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.apache.cocoon.profiling.profiler;
+
+import org.apache.cocoon.pipeline.component.PipelineComponent;
+
+public class PipelineComponentProfiler extends Profiler<PipelineComponent> {
+
+    public PipelineComponentProfiler() {
+        super(PipelineComponent.class);
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/PipelineComponentProfiler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/PipelineComponentProfiler.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/PipelineComponentProfiler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/PipelineNodeProfiler.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/PipelineNodeProfiler.java?rev=806346&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/PipelineNodeProfiler.java (added)
+++ cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/PipelineNodeProfiler.java Thu Aug 20 20:43:20 2009
@@ -0,0 +1,50 @@
+/*
+ * 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.apache.cocoon.profiling.profiler;
+
+import java.lang.reflect.Field;
+
+import org.apache.cocoon.profiling.ProfileMethod;
+import org.apache.cocoon.profiling.data.ProfilingData;
+import org.apache.cocoon.sitemap.node.PipelineNode;
+
+public class PipelineNodeProfiler extends Profiler<PipelineNode> {
+
+    public PipelineNodeProfiler() {
+        super(PipelineNode.class);
+    }
+
+    @ProfileMethod(name = "invoke")
+    public void beforeInvoke(ProfilingData data, PipelineNode component, Object[] args) {
+        try {
+            Field field = PipelineNode.class.getDeclaredField("type");
+
+            field.setAccessible(true);
+            String value = (String) field.get(component);
+
+            if (value != null) {
+                data.addData("type", value);
+
+                String simpleName = component.getClass().getSimpleName();
+                data.setDisplayName(String.format("%s (%s=%s)", simpleName, "type", value));
+                return;
+            }
+        } catch (Exception e) {
+            throw new RuntimeException("Error reading type from PipelineNode", e);
+        }
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/PipelineNodeProfiler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/PipelineNodeProfiler.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/PipelineNodeProfiler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/PipelineProfiler.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/PipelineProfiler.java?rev=806346&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/PipelineProfiler.java (added)
+++ cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/PipelineProfiler.java Thu Aug 20 20:43:20 2009
@@ -0,0 +1,27 @@
+/*
+ * 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.apache.cocoon.profiling.profiler;
+
+import org.apache.cocoon.pipeline.Pipeline;
+
+@SuppressWarnings("unchecked")
+public class PipelineProfiler extends Profiler<Pipeline> {
+
+    public PipelineProfiler() {
+        super(Pipeline.class);
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/PipelineProfiler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/PipelineProfiler.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/PipelineProfiler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/Profiler.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/Profiler.java?rev=806346&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/Profiler.java (added)
+++ cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/Profiler.java Thu Aug 20 20:43:20 2009
@@ -0,0 +1,292 @@
+/*
+ * 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.apache.cocoon.profiling.profiler;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cocoon.callstack.CallStack;
+import org.apache.cocoon.profiling.ProfileMethod;
+import org.apache.cocoon.profiling.ProfileMethodType;
+import org.apache.cocoon.profiling.data.ProfilingData;
+import org.apache.cocoon.profiling.data.ProfilingDataManager;
+import org.apache.cocoon.profiling.data.ProfilingIdGenerator;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Base class for all profiling data handlers. A new instance is created for each method invocation
+ * and the methods before and after/exception are called.
+ *
+ * It stores invocation time and end time of the invocation.
+ *
+ * Implementors of subclasses can provide methods annotated with {@link ProfileMethod}. Depending on
+ * the {@link ProfileMethodType} the method has to have a specific signature:
+ *
+ * <ul>
+ * <li>ProfileMethodType.BEFORE_INVOCATION: (ProfilingData data, T target, Object[] args)</li>
+ * <li>ProfileMethodType.AFTER_INVOCATION: (ProfilingData data, Object returnValue)</li>
+ * <li>ProfileMethodType.ON_EXCEPTION: (ProfilingData data, Exception exception)</li>
+ * </ul>
+ *
+ * If in the {@link ProfileMethod} annotation no method name is specified, the profile method will
+ * be installed as default and called for all method invocations.
+ */
+public abstract class Profiler<T> {
+
+    private static ThreadLocal<Integer> depth = new ThreadLocal<Integer>() {
+
+        @Override
+        protected Integer initialValue() {
+            return 0;
+        }
+    };
+
+    protected final Log logger = LogFactory.getLog(this.getClass());
+
+    private ProfilingDataManager dataManager;
+
+    private Map<ProfileMethodType, List<Method>> defaultProfileMethods;
+
+    private ProfilingIdGenerator idGenerator;
+
+    private Map<ProfileMethodType, Map<String, List<Method>>> profileMethods;
+
+    private Class<? extends T> targetClass;
+
+    /**
+     * @param targetClass class for which this profiler should be registered
+     */
+    public Profiler(Class<? extends T> targetClass) {
+        this.targetClass = targetClass;
+        this.profileMethods = new HashMap<ProfileMethodType, Map<String, List<Method>>>();
+        this.defaultProfileMethods = new HashMap<ProfileMethodType, List<Method>>();
+
+        for (ProfileMethodType type : ProfileMethodType.values()) {
+            this.profileMethods.put(type, new HashMap<String, List<Method>>());
+        }
+
+        this.findProfilingMethods();
+    }
+
+    /**
+     * This method is called after the invocation was successfully finished.
+     *
+     * @param data the {@link ProfilingData} object used to store the profiling information for this
+     *            invocation.
+     * @param methodName the name of the method that was intercepted.
+     * @param returnValue the return value of the method that was intercepted
+     */
+    public final void after(ProfilingData data, String methodName, Object returnValue) {
+        data.setInvocationEndTime(System.nanoTime());
+
+        this.invokeSpecificMethods(ProfileMethodType.AFTER_INVOCATION, methodName, data, returnValue);
+        this.invokeDefaultMethods(ProfileMethodType.AFTER_INVOCATION, data, returnValue);
+
+        data.setReturnValue(returnValue);
+
+        this.postProcessInvocation(data);
+    }
+
+    /**
+     * This method is called before the invocation takes place on the given target object.
+     *
+     * @param data the {@link ProfilingData} object used to store the profiling information for this
+     *            invocation.
+     * @param target the object on which the intercepted invocation is performed.
+     * @param methodName the name of the method that has been intercepted.
+     * @param args the arguments of the intercepted method.
+     */
+    public final void before(ProfilingData data, Object target, String methodName, Object[] args) {
+        String id = this.idGenerator.getCurrent();
+
+        if (id == null) {
+            data.setRoot(true);
+            id = this.idGenerator.create();
+        }
+
+        data.setProfilingId(id);
+        data.setInvocationDepth(depth.get());
+        depth.set(depth.get() + 1);
+        data.setTarget(target);
+        data.setProfiler(this.getClass().getName());
+        data.setMethod(methodName);
+        data.setArguments(args);
+        data.setCallFrameId(System.identityHashCode(CallStack.getCurrentFrame()));
+
+        this.invokeSpecificMethods(ProfileMethodType.BEFORE_INVOCATION, methodName, data, target, args);
+        this.invokeDefaultMethods(ProfileMethodType.BEFORE_INVOCATION, data, target, args);
+
+        data.setInvocationStartTime(System.nanoTime());
+    }
+
+    /**
+     * This method is called after the invocation was successfully finished.
+     *
+     * @param data the {@link ProfilingData} object used to store the profiling information for this
+     *            invocation.
+     * @param methodName the name of the method that was intercepted.
+     * @param exception the exception that was thrown by the method that was intercepted
+     */
+    public final void exception(ProfilingData data, String methodName, Exception exception) {
+        data.setInvocationEndTime(System.nanoTime());
+        data.setException(exception);
+
+        this.invokeSpecificMethods(ProfileMethodType.ON_EXCEPTION, methodName, data, exception);
+        this.invokeDefaultMethods(ProfileMethodType.ON_EXCEPTION, data, exception);
+
+        this.postProcessInvocation(data);
+    }
+
+    /**
+     * @return The {@link Class}, whose instances will be profiled by this profiler.
+     */
+    public final Class<? extends T> getTargetClass() {
+        return this.targetClass;
+    }
+
+    public void setProfilingDataManager(ProfilingDataManager dataManager) {
+        this.dataManager = dataManager;
+    }
+
+    public void setProfilingIdGenerator(ProfilingIdGenerator idGenerator) {
+        this.idGenerator = idGenerator;
+    }
+
+    private void checkProfileMethodSignature(Method method, String name, ProfileMethodType type) {
+        Class<?>[] pt = method.getParameterTypes();
+
+        switch (type) {
+        case BEFORE_INVOCATION:
+            if (pt.length != 3 || pt[0] != ProfilingData.class || !pt[1].isAssignableFrom(this.targetClass)
+                    || pt[2] != Object[].class) {
+                throw new RuntimeException("Signature of method " + method.getName()
+                        + " does not conform to (ProfilingData, " + this.targetClass.getName() + ", Object[])");
+            }
+            break;
+
+        case AFTER_INVOCATION:
+            if (pt.length != 2 || pt[0] != ProfilingData.class || pt[1] != Object.class) {
+                throw new RuntimeException("Signature of method " + method.getName()
+                        + " does not conform to (ProfilingData, Object)");
+            }
+            break;
+
+        case ON_EXCEPTION:
+            if (pt.length != 2 || pt[0] != ProfilingData.class || pt[1] != Exception.class) {
+                throw new RuntimeException("Signature of method " + method.getName()
+                        + " does not conform to (ProfilingData, Exception)");
+            }
+            break;
+
+        default:
+            throw new AssertionError("Unknown ProfileMethodType");
+        }
+    }
+
+    private void findProfilingMethods() {
+        Class<?> clazz = this.getClass();
+        Method[] methods = clazz.getMethods();
+
+        for (Method method : methods) {
+            this.processMethod(method);
+        }
+    }
+
+    private void installDefaultMethod(Method method, ProfileMethodType type) {
+        List<Method> list = this.defaultProfileMethods.get(type);
+
+        if (list == null) {
+            list = new ArrayList<Method>();
+            this.defaultProfileMethods.put(type, list);
+        }
+
+        list.add(method);
+
+        if (this.logger.isInfoEnabled()) {
+            this.logger.info(String.format("Installed '%s' as default %s method", method.getName(), type));
+        }
+    }
+
+    private void installProfileMethod(Method method, String name, ProfileMethodType type) {
+        if (name.equals(ProfileMethod.DEFAULT_NAME)) {
+            this.installDefaultMethod(method, type);
+            return;
+        }
+
+        List<Method> list = this.profileMethods.get(type).get(name);
+        if (list == null) {
+            list = new ArrayList<Method>();
+            this.profileMethods.get(type).put(name, list);
+        }
+
+        list.add(method);
+
+        if (this.logger.isInfoEnabled()) {
+            this.logger.info(String.format("Installed '%s' for '%s'/%s", method.getName(), name, type));
+        }
+    }
+
+    private void invokeDefaultMethods(ProfileMethodType type, Object... args) {
+        this.invokeMethods(this.defaultProfileMethods.get(type), args);
+    }
+
+    private void invokeMethods(List<Method> methods, Object... args) {
+        if (methods == null) {
+            return;
+        }
+
+        for (Method m : methods) {
+            try {
+                m.invoke(this, args);
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+        }
+    }
+
+    private void invokeSpecificMethods(ProfileMethodType type, String methodName, Object... args) {
+        this.invokeMethods(this.profileMethods.get(type).get(methodName), args);
+    }
+
+    private void postProcessInvocation(ProfilingData data) {
+        depth.set(depth.get() - 1);
+
+        this.dataManager.add(data);
+
+        if (data.isRoot()) {
+            this.idGenerator.remove();
+        }
+    }
+
+    private void processMethod(Method method) {
+        ProfileMethod profileMethod = method.getAnnotation(ProfileMethod.class);
+
+        if (profileMethod == null) {
+            return;
+        }
+
+        String name = profileMethod.name();
+        ProfileMethodType type = profileMethod.type();
+
+        this.checkProfileMethodSignature(method, name, type);
+        this.installProfileMethod(method, name, type);
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/Profiler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/Profiler.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/Profiler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/ServletProfiler.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/ServletProfiler.java?rev=806346&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/ServletProfiler.java (added)
+++ cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/ServletProfiler.java Thu Aug 20 20:43:20 2009
@@ -0,0 +1,107 @@
+/*
+ * 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.apache.cocoon.profiling.profiler;
+
+import javax.servlet.Servlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.cocoon.profiling.ProfileMethod;
+import org.apache.cocoon.profiling.ProfileMethodType;
+import org.apache.cocoon.profiling.data.ProfilingData;
+
+/**
+ * The profiler for {@link Servlet}, which intercepts the service method to add the profiling id
+ * information to the HTTP header.
+ */
+public class ServletProfiler extends Profiler<Servlet> {
+
+    private final static String PROFILING_CONTROLLER_PATH = "controller/profiling/";
+    private final static String PROFILING_ID_HEADER = "X-Cocoon-Profiling-ID";
+    private final static String PROFILING_URL_HEADER = "X-Cocoon-Profiling-URL";
+    private String mountPath;
+
+    public ServletProfiler() {
+        this(Servlet.class);
+    }
+
+    protected ServletProfiler(Class<? extends Servlet> clazz) {
+        super(clazz);
+        this.setMountPath("/");// TODO
+    }
+
+    @ProfileMethod(name = "service", type = ProfileMethodType.BEFORE_INVOCATION)
+    public final void beforeService(ProfilingData data, Servlet component, Object[] args) {
+        if (data.isRoot()) {
+            HttpServletRequest request = (HttpServletRequest) args[0];
+            HttpServletResponse response = (HttpServletResponse) args[1];
+            String profilingId = data.getProfilingId();
+            String requestUrl = request.getRequestURL().toString();
+            response.addHeader(PROFILING_ID_HEADER, profilingId);
+            response.addHeader(PROFILING_URL_HEADER, this.createRelativeUrl(requestUrl, profilingId));
+        }
+
+        HttpServletRequest request = (HttpServletRequest) args[0];
+        String requestURI = request.getRequestURI();
+        String className = component.getClass().getSimpleName();
+
+        data.setDisplayName(String.format("%s (request=%s)", className, requestURI));
+    }
+
+    public String createRelativeUrl(String inputUrl, String profilingId) {
+        String mountPath = this.getMountPath();
+
+        int questionMarkIndex = inputUrl.indexOf('?');
+        if (questionMarkIndex != -1) {
+            // ignore parameters (could contain slashes)
+            inputUrl = inputUrl.substring(0, questionMarkIndex);
+        }
+
+        // Don't count the slashes of http://
+        int inputUrlSlashes = this.countOccurenceOfCharacter('/', inputUrl) - 2;
+        int mountPathSlashes = this.countOccurenceOfCharacter('/', mountPath);
+
+        StringBuilder sb = new StringBuilder();
+
+        for (int i = mountPathSlashes; i < inputUrlSlashes; i++) {
+            sb.append("../");
+        }
+
+        sb.append(PROFILING_CONTROLLER_PATH);
+        sb.append(profilingId);
+
+        return sb.toString();
+    }
+
+    public String getMountPath() {
+        return this.mountPath;
+    }
+
+    public void setMountPath(String mountPath) {
+        this.mountPath = mountPath;
+    }
+
+    private int countOccurenceOfCharacter(char c, String s) {
+        int count = 0;
+        for (int i = 0; i < s.length(); i++) {
+            if (s.charAt(i) == c) {
+                count++;
+            }
+        }
+        return count;
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/ServletProfiler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/ServletProfiler.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/ServletProfiler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/SitemapNodeProfiler.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/SitemapNodeProfiler.java?rev=806346&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/SitemapNodeProfiler.java (added)
+++ cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/SitemapNodeProfiler.java Thu Aug 20 20:43:20 2009
@@ -0,0 +1,26 @@
+/*
+ * 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.apache.cocoon.profiling.profiler;
+
+import org.apache.cocoon.sitemap.node.SitemapNode;
+
+public class SitemapNodeProfiler extends Profiler<SitemapNode> {
+
+    public SitemapNodeProfiler() {
+        super(SitemapNode.class);
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/SitemapNodeProfiler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/SitemapNodeProfiler.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/SitemapNodeProfiler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/TransformNodeProfiler.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/TransformNodeProfiler.java?rev=806346&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/TransformNodeProfiler.java (added)
+++ cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/TransformNodeProfiler.java Thu Aug 20 20:43:20 2009
@@ -0,0 +1,58 @@
+/*
+ * 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.apache.cocoon.profiling.profiler;
+
+import java.lang.reflect.Field;
+
+import org.apache.cocoon.profiling.ProfileMethod;
+import org.apache.cocoon.profiling.data.ProfilingData;
+import org.apache.cocoon.sitemap.node.TransformNode;
+
+public class TransformNodeProfiler extends Profiler<TransformNode> {
+
+    public TransformNodeProfiler() {
+        super(TransformNode.class);
+    }
+
+    @ProfileMethod(name = "invoke")
+    public void beforeInvoke(ProfilingData data, TransformNode component, Object[] args) {
+        try {
+            Field srcField = TransformNode.class.getDeclaredField("src");
+
+            srcField.setAccessible(true);
+            String src = (String) srcField.get(component);
+
+            if (src != null) {
+                data.addData("src", src);
+            }
+
+            Field typeField = TransformNode.class.getDeclaredField("type");
+
+            typeField.setAccessible(true);
+            String type = (String) typeField.get(component);
+
+            if (type != null) {
+                data.addData("type", type);
+
+                String simpleName = component.getClass().getSimpleName();
+                data.setDisplayName(String.format("%s (%s=%s)", simpleName, "type", type));
+            }
+        } catch (Exception e) {
+            throw new RuntimeException("Error reading private fields from TransformNode", e);
+        }
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/TransformNodeProfiler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/TransformNodeProfiler.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/TransformNodeProfiler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/package-info.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/package-info.java?rev=806346&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/package-info.java (added)
+++ cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/package-info.java Thu Aug 20 20:43:20 2009
@@ -0,0 +1,22 @@
+/*
+ * 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.
+ */
+/**
+ *  Provides the abstract base class {@link org.apache.cocoon.profiling.profiler.Profiler} and some specific
+ *  implementations.
+ */
+package org.apache.cocoon.profiling.profiler;
+

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/package-info.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/package-info.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/profiler/package-info.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/spring/AutomaticProfilerInstaller.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/spring/AutomaticProfilerInstaller.java?rev=806346&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/spring/AutomaticProfilerInstaller.java (added)
+++ cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/spring/AutomaticProfilerInstaller.java Thu Aug 20 20:43:20 2009
@@ -0,0 +1,146 @@
+/*
+ * 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.apache.cocoon.profiling.spring;
+
+import java.util.Map;
+
+import javax.servlet.Servlet;
+
+import org.apache.cocoon.pipeline.Pipeline;
+import org.apache.cocoon.pipeline.component.PipelineComponent;
+import org.apache.cocoon.profiling.aspects.InvocationDispatcher;
+import org.apache.cocoon.profiling.data.ProfilingDataManager;
+import org.apache.cocoon.profiling.data.ProfilingIdGenerator;
+import org.apache.cocoon.profiling.profiler.Profiler;
+import org.apache.cocoon.sitemap.node.SitemapNode;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * This class is used to install {@link Profiler} to the correct {@link InvocationDispatcher}. The
+ * dependencies that all {@link Profiler} share are also managed by this class.
+ * <p>
+ * This class is especially useful in combination with spring, which can be configured to inject all
+ * {@link Profiler} that are declared as Spring-Managed beans into this class. So additional
+ * Profilers can be registered simply by defining them as Spring-bean.
+ * </p>
+ */
+public class AutomaticProfilerInstaller {
+
+    private final Log logger = LogFactory.getLog(this.getClass());
+
+    private InvocationDispatcher pipelineComponentInvocationDispatcher;
+
+    private InvocationDispatcher pipelineInvocationDispatcher;
+
+    private Map<String, Profiler<?>> profilers;
+
+    private ProfilingDataManager profilingDataManager;
+
+    private ProfilingIdGenerator profilingIdGenerator;
+
+    private InvocationDispatcher servletInvocationDispatcher;
+
+    private InvocationDispatcher sitemapNodeInvocationDispatcher;
+
+    /**
+     * Install all profilers. {@link AutomaticProfilerInstaller#setProfilers(Map)} has to be called
+     * first.
+     */
+    public void installProfilers() {
+        for (Profiler<?> p : this.profilers.values()) {
+            this.install(p);
+        }
+    }
+
+    public void setPipelineComponentInvocationDispatcher(InvocationDispatcher pipelineComponentInvocationDispatcher) {
+        this.pipelineComponentInvocationDispatcher = pipelineComponentInvocationDispatcher;
+    }
+
+    public void setPipelineInvocationDispatcher(InvocationDispatcher pipelineInvocationDispatcher) {
+        this.pipelineInvocationDispatcher = pipelineInvocationDispatcher;
+    }
+
+    public void setProfilers(Map<String, Profiler<?>> profilers) {
+        this.profilers = profilers;
+    }
+
+    public void setProfilingDataManager(ProfilingDataManager profilingDataManager) {
+        this.profilingDataManager = profilingDataManager;
+    }
+
+    public void setProfilingIdGenerator(ProfilingIdGenerator profilingIdGenerator) {
+        this.profilingIdGenerator = profilingIdGenerator;
+    }
+
+    public void setServletInvocationDispatcher(InvocationDispatcher servletInvocationDispatcher) {
+        this.servletInvocationDispatcher = servletInvocationDispatcher;
+    }
+
+    public void setSitemapNodeInvocationDispatcher(InvocationDispatcher sitemapNodeInvocationDispatcher) {
+        this.sitemapNodeInvocationDispatcher = sitemapNodeInvocationDispatcher;
+    }
+
+    private void install(Profiler<?> profiler) {
+        profiler.setProfilingDataManager(this.profilingDataManager);
+        profiler.setProfilingIdGenerator(this.profilingIdGenerator);
+
+        if (Servlet.class.isAssignableFrom(profiler.getTargetClass())) {
+            this.installServletProfiler(profiler);
+        }
+
+        if (SitemapNode.class.isAssignableFrom(profiler.getTargetClass())) {
+            this.installSitemapNodeProfiler(profiler);
+        }
+
+        if (PipelineComponent.class.isAssignableFrom(profiler.getTargetClass())) {
+            this.installPipelineComponentProfiler(profiler);
+        }
+
+        if (Pipeline.class.isAssignableFrom(profiler.getTargetClass())) {
+            this.installPipelineProfiler(profiler);
+        }
+    }
+
+    private void installPipelineComponentProfiler(Profiler<?> profiler) {
+        if (this.logger.isInfoEnabled()) {
+            this.logger.info("Installing PipelineComponent Profiler: " + profiler);
+        }
+        this.pipelineComponentInvocationDispatcher.installProfiler(profiler);
+    }
+
+    private void installPipelineProfiler(Profiler<?> profiler) {
+        if (this.logger.isInfoEnabled()) {
+            this.logger.info("Installing Pipeline Profiler: " + profiler);
+        }
+        this.pipelineInvocationDispatcher.installProfiler(profiler);
+    }
+
+    private void installServletProfiler(Profiler<?> profiler) {
+        if (this.logger.isInfoEnabled()) {
+            this.logger.info("Installing Servlet Profiler: " + profiler);
+        }
+        this.servletInvocationDispatcher.installProfiler(profiler);
+    }
+
+    private void installSitemapNodeProfiler(Profiler<?> profiler) {
+        if (this.logger.isInfoEnabled()) {
+            this.logger.info("Installing SitemapNode Profiler: " + profiler);
+        }
+        this.sitemapNodeInvocationDispatcher.installProfiler(profiler);
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/spring/AutomaticProfilerInstaller.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/spring/AutomaticProfilerInstaller.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/spring/AutomaticProfilerInstaller.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/spring/package-info.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/spring/package-info.java?rev=806346&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/spring/package-info.java (added)
+++ cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/spring/package-info.java Thu Aug 20 20:43:20 2009
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+/**
+ * Provides components to interact with Spring.
+ */
+package org.apache.cocoon.profiling.spring;
+

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/spring/package-info.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/spring/package-info.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/java/org/apache/cocoon/profiling/spring/package-info.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-profiling/src/main/resources/COB-INF/sitemap.xmap
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-profiling/src/main/resources/COB-INF/sitemap.xmap?rev=806346&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-profiling/src/main/resources/COB-INF/sitemap.xmap (added)
+++ cocoon/cocoon3/trunk/cocoon-profiling/src/main/resources/COB-INF/sitemap.xmap Thu Aug 20 20:43:20 2009
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+ -->
+<map:sitemap xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:map="http://apache.org/cocoon/sitemap"
+  xmlns:servlet="http://apache.org/cocoon/servlet" xmlns:controller="http://apache.org/cocoon/controller">
+
+  <map:pipelines>
+
+    <!-- ~~~~~~~~~~~~~~~~ profiling controller ~~~~~~~~~~~~~~~ -->
+    <map:pipeline>
+      <map:match pattern="controller/profiling/{id}.png">
+        <map:serialize type="profilingpng" id="{map:id}" />
+      </map:match>
+      <map:match pattern="controller/profiling/{id}">
+        <map:generate type="profiling" id="{map:id}" />
+        <map:serialize type="xml" />
+      </map:match>
+    </map:pipeline>
+
+  </map:pipelines>
+</map:sitemap>

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/resources/COB-INF/sitemap.xmap
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/resources/COB-INF/sitemap.xmap
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-profiling/src/main/resources/COB-INF/sitemap.xmap
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message