Author: sascharodekamp
Date: Wed Sep 28 18:56:16 2011 New Revision: 1177018 URL: http://svn.apache.org/viewvc?rev=1177018&view=rev Log: Add a small service to determine the speed differences between a direct repository access and the OCM access Added: ofbiz/branches/jackrabbit20100709/framework/jcr/servicedef/ ofbiz/branches/jackrabbit20100709/framework/jcr/servicedef/services.xml (with props) ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/services/ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/services/JackrabbitServices.java (with props) Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/ofbiz-component.xml Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/ofbiz-component.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/ofbiz-component.xml?rev=1177018&r1=1177017&r2=1177018&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/ofbiz-component.xml (original) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/ofbiz-component.xml Wed Sep 28 18:56:16 2011 @@ -26,6 +26,8 @@ under the License. <classpath type="jar" location="build/lib/*"/> <classpath type="jar" location="lib/*"/> + <service-resource type="model" loader="main" location="servicedef/services.xml"/> <test-suite loader="main" location="testdef/jcrtests.xml"/> + </ofbiz-component> Added: ofbiz/branches/jackrabbit20100709/framework/jcr/servicedef/services.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/servicedef/services.xml?rev=1177018&view=auto ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/servicedef/services.xml (added) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/servicedef/services.xml Wed Sep 28 18:56:16 2011 @@ -0,0 +1,36 @@ +<?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. +--> + +<services xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/services.xsd"> + <description>Jackrabbit Services</description> + <vendor>OFBiz</vendor> + <version>1.0</version> + + <!-- Example Jackrabbit Services --> + <service name="determineJackrabbitRepositorySpeed" engine="java" location="org.ofbiz.jcr.services.JackrabbitServices" + invoke="determineJackrabbitRepositorySpeed" auth="true" use-transaction="false"> + <description>Determine the JCR Repository Overhead</description> + <attribute mode="IN" name="maxNodes" optional="false" type="Integer"/> + <attribute mode="IN" name="userLogin" optional="false" type="org.ofbiz.entity.GenericValue"/> + <attribute mode="OUT" name="repositoryDirectAccessTime" optional="false" type="String"/> + <attribute mode="OUT" name="repositoryOcmAccessTime" optional="false" type="String"/> + </service> +</services> \ No newline at end of file Propchange: ofbiz/branches/jackrabbit20100709/framework/jcr/servicedef/services.xml ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/services/JackrabbitServices.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/services/JackrabbitServices.java?rev=1177018&view=auto ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/services/JackrabbitServices.java (added) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/services/JackrabbitServices.java Wed Sep 28 18:56:16 2011 @@ -0,0 +1,66 @@ +package org.ofbiz.jcr.services; + +import java.util.Date; +import java.util.Map; + +import javax.jcr.Session; + +import org.ofbiz.base.util.Debug; +import org.ofbiz.entity.GenericValue; +import org.ofbiz.jcr.access.jackrabbit.RepositoryAccessJackrabbit; +import org.ofbiz.jcr.loader.JCRFactoryUtil; +import org.ofbiz.jcr.orm.jackrabbit.OfbizRepositoryMappingJackrabbitNews; +import org.ofbiz.service.DispatchContext; +import org.ofbiz.service.ServiceUtil; + +public class JackrabbitServices { + + private static String module = JackrabbitServices.class.getName(); + + public static Map<String, Object> determineJackrabbitRepositorySpeed(DispatchContext ctx, Map<String, Object> context) { + Map<String, Object> result = ServiceUtil.returnSuccess(); + GenericValue userLogin = (GenericValue) context.get("userLogin"); + Integer maxNodes = (Integer) context.get("maxNodes"); + + Long start = 0l; + Long diff = 0l; + + Session session = JCRFactoryUtil.getSession(); + start = new Date().getTime(); + for (int i = 0; i <= maxNodes; i++) { + try { + // add a node + session.getRootNode().addNode("__Speedtest_Node-" + i); + session.save(); + // remove the node + session.removeItem("/__Speedtest_Node-" + i); + session.save(); + } catch (Exception e) { + Debug.logError(e, module); + } + } + + session.logout(); + diff = (new Date().getTime() - start); + result.put("repositoryDirectAccessTime", diff.toString()); + + RepositoryAccessJackrabbit access = new RepositoryAccessJackrabbit(userLogin); + start = new Date().getTime(); + for (int i = 0; i <= maxNodes; i++) { + try { + OfbizRepositoryMappingJackrabbitNews news = new OfbizRepositoryMappingJackrabbitNews("/__Speedtest_Node-" + i, "de", "", null, ""); + access.storeContentObject(news); + access.removeContentObject("/__Speedtest_Node-" + i); + } catch (Exception e) { + Debug.logError(e, module); + } + + } + + access.closeAccess(); + diff = (new Date().getTime() - start); + result.put("repositoryOcmAccessTime", diff.toString()); + + return result; + } +} Propchange: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/services/JackrabbitServices.java ------------------------------------------------------------------------------ svn:mime-type = text/plain |
Free forum by Nabble | Edit this page |