svn commit: r899496 - in /ofbiz/branches/executioncontext20091231/framework: api/src/org/ofbiz/api/authorization/ entity/src/org/ofbiz/entity/ entityext/src/org/ofbiz/entityext/data/ service/src/org/ofbiz/service/ service/src/org/ofbiz/service/job/ web...

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r899496 - in /ofbiz/branches/executioncontext20091231/framework: api/src/org/ofbiz/api/authorization/ entity/src/org/ofbiz/entity/ entityext/src/org/ofbiz/entityext/data/ service/src/org/ofbiz/service/ service/src/org/ofbiz/service/job/ web...

adrianc
Author: adrianc
Date: Fri Jan 15 00:25:00 2010
New Revision: 899496

URL: http://svn.apache.org/viewvc?rev=899496&view=rev
Log:
Better push/pop handling.

Modified:
    ofbiz/branches/executioncontext20091231/framework/api/src/org/ofbiz/api/authorization/OfbizSecurityTransform.java
    ofbiz/branches/executioncontext20091231/framework/entity/src/org/ofbiz/entity/GenericDelegator.java
    ofbiz/branches/executioncontext20091231/framework/entityext/src/org/ofbiz/entityext/data/EntityDataLoadContainer.java
    ofbiz/branches/executioncontext20091231/framework/service/src/org/ofbiz/service/ServiceDispatcher.java
    ofbiz/branches/executioncontext20091231/framework/service/src/org/ofbiz/service/job/GenericServiceJob.java
    ofbiz/branches/executioncontext20091231/framework/service/src/org/ofbiz/service/job/JobPoller.java
    ofbiz/branches/executioncontext20091231/framework/webapp/src/org/ofbiz/webapp/control/ControlServlet.java
    ofbiz/branches/executioncontext20091231/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java
    ofbiz/branches/executioncontext20091231/framework/widget/src/org/ofbiz/widget/form/ModelForm.java
    ofbiz/branches/executioncontext20091231/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java
    ofbiz/branches/executioncontext20091231/framework/widget/src/org/ofbiz/widget/screen/HtmlWidget.java
    ofbiz/branches/executioncontext20091231/framework/widget/src/org/ofbiz/widget/screen/ModelScreen.java

Modified: ofbiz/branches/executioncontext20091231/framework/api/src/org/ofbiz/api/authorization/OfbizSecurityTransform.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/executioncontext20091231/framework/api/src/org/ofbiz/api/authorization/OfbizSecurityTransform.java?rev=899496&r1=899495&r2=899496&view=diff
==============================================================================
--- ofbiz/branches/executioncontext20091231/framework/api/src/org/ofbiz/api/authorization/OfbizSecurityTransform.java (original)
+++ ofbiz/branches/executioncontext20091231/framework/api/src/org/ofbiz/api/authorization/OfbizSecurityTransform.java Fri Jan 15 00:25:00 2010
@@ -61,8 +61,8 @@
             Debug.logError("Unknown permission \"" + permStr + "\", unable to execute transform", module);
             return;
         }
+        ThreadContext.pushExecutionArtifact(module, artifactId);
         try {
-            ThreadContext.pushExecutionArtifact(module, artifactId);
             ThreadContext.getAccessController().checkPermission(permission);
             body.render(env.getOut());
         } catch (AccessControlException e) {

Modified: ofbiz/branches/executioncontext20091231/framework/entity/src/org/ofbiz/entity/GenericDelegator.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/executioncontext20091231/framework/entity/src/org/ofbiz/entity/GenericDelegator.java?rev=899496&r1=899495&r2=899496&view=diff
==============================================================================
--- ofbiz/branches/executioncontext20091231/framework/entity/src/org/ofbiz/entity/GenericDelegator.java (original)
+++ ofbiz/branches/executioncontext20091231/framework/entity/src/org/ofbiz/entity/GenericDelegator.java Fri Jan 15 00:25:00 2010
@@ -794,8 +794,8 @@
      */
     public GenericValue create(GenericValue value, boolean doCacheClear) throws GenericEntityException {
         boolean beganTransaction = false;
+        ThreadContext.pushExecutionArtifact(value);
         try {
-            ThreadContext.pushExecutionArtifact(value);
             ThreadContext.getAccessController().checkPermission(Create);
             if (alwaysUseTransaction) {
                 beganTransaction = TransactionUtil.begin();
@@ -949,8 +949,8 @@
      */
     public int removeByPrimaryKey(GenericPK primaryKey, boolean doCacheClear) throws GenericEntityException {
         boolean beganTransaction = false;
+        ThreadContext.pushExecutionArtifact(primaryKey);
         try {
-            ThreadContext.pushExecutionArtifact(primaryKey);
             ThreadContext.getAccessController().checkPermission(Delete);
             if (alwaysUseTransaction) {
                 beganTransaction = TransactionUtil.begin();
@@ -1019,8 +1019,8 @@
     public int removeValue(GenericValue value, boolean doCacheClear) throws GenericEntityException {
         // NOTE: this does not call the GenericDelegator.removeByPrimaryKey method because it has more information to pass to the ECA rule hander
         boolean beganTransaction = false;
+        ThreadContext.pushExecutionArtifact(value);
         try {
-            ThreadContext.pushExecutionArtifact(value);
             ThreadContext.getAccessController().checkPermission(Delete);
             if (alwaysUseTransaction) {
                 beganTransaction = TransactionUtil.begin();
@@ -1117,8 +1117,8 @@
      */
     public int removeByCondition(String entityName, EntityCondition condition, boolean doCacheClear) throws GenericEntityException {
         boolean beganTransaction = false;
+        ThreadContext.pushExecutionArtifact("GenericDelegator.removeByCondition", entityName);
         try {
-            ThreadContext.pushExecutionArtifact("GenericDelegator.removeByCondition", entityName);
             ThreadContext.getAccessController().checkPermission(Delete);
             if (alwaysUseTransaction) {
                 beganTransaction = TransactionUtil.begin();
@@ -1231,8 +1231,8 @@
      */
     public int storeByCondition(String entityName, Map<String, ? extends Object> fieldsToSet, EntityCondition condition, boolean doCacheClear) throws GenericEntityException {
         boolean beganTransaction = false;
+        ThreadContext.pushExecutionArtifact("GenericDelegator.storeByCondition", entityName);
         try {
-            ThreadContext.pushExecutionArtifact("GenericDelegator.storeByCondition", entityName);
             ThreadContext.getAccessController().checkPermission(Update);
             if (alwaysUseTransaction) {
                 beganTransaction = TransactionUtil.begin();
@@ -1289,8 +1289,8 @@
      */
     public int store(GenericValue value, boolean doCacheClear) throws GenericEntityException {
         boolean beganTransaction = false;
+        ThreadContext.pushExecutionArtifact(value);
         try {
-            ThreadContext.pushExecutionArtifact(value);
             ThreadContext.getAccessController().checkPermission(Update);
             if (alwaysUseTransaction) {
                 beganTransaction = TransactionUtil.begin();

Modified: ofbiz/branches/executioncontext20091231/framework/entityext/src/org/ofbiz/entityext/data/EntityDataLoadContainer.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/executioncontext20091231/framework/entityext/src/org/ofbiz/entityext/data/EntityDataLoadContainer.java?rev=899496&r1=899495&r2=899496&view=diff
==============================================================================
--- ofbiz/branches/executioncontext20091231/framework/entityext/src/org/ofbiz/entityext/data/EntityDataLoadContainer.java (original)
+++ ofbiz/branches/executioncontext20091231/framework/entityext/src/org/ofbiz/entityext/data/EntityDataLoadContainer.java Fri Jan 15 00:25:00 2010
@@ -377,11 +377,11 @@
             }
 
             Debug.logImportant("=-=-=-=-=-=-= Starting the data load...", module);
+            ThreadContext.pushExecutionArtifact(module, "EntityDataLoad");
+            ThreadContext.runUnprotected();
             try {
                 // Set up the execution context
-                ThreadContext.runUnprotected();
                 ThreadContext.setDelegator(delegator);
-                ThreadContext.pushExecutionArtifact(module, "EntityDataLoad");
                 for (URL dataUrl: urlList) {
                     try {
                         int rowsChanged = EntityDataLoader.loadData(dataUrl, helperName, delegator, errorMessages, txTimeout, useDummyFks, maintainTxs, tryInserts);

Modified: ofbiz/branches/executioncontext20091231/framework/service/src/org/ofbiz/service/ServiceDispatcher.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/executioncontext20091231/framework/service/src/org/ofbiz/service/ServiceDispatcher.java?rev=899496&r1=899495&r2=899496&view=diff
==============================================================================
--- ofbiz/branches/executioncontext20091231/framework/service/src/org/ofbiz/service/ServiceDispatcher.java (original)
+++ ofbiz/branches/executioncontext20091231/framework/service/src/org/ofbiz/service/ServiceDispatcher.java Fri Jan 15 00:25:00 2010
@@ -297,9 +297,9 @@
 
         // start the transaction
         boolean beganTrans = false;
+        ThreadContext.initializeContext(context);
+        ThreadContext.pushExecutionArtifact(modelService, context);
         try {
-            ThreadContext.initializeContext(context);
-            ThreadContext.pushExecutionArtifact(modelService, context);
             boolean permissionService = false;
             for (ModelServiceIface iface: modelService.implServices) {
                 if ("permissionInterface".equals(iface.getService())) {

Modified: ofbiz/branches/executioncontext20091231/framework/service/src/org/ofbiz/service/job/GenericServiceJob.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/executioncontext20091231/framework/service/src/org/ofbiz/service/job/GenericServiceJob.java?rev=899496&r1=899495&r2=899496&view=diff
==============================================================================
--- ofbiz/branches/executioncontext20091231/framework/service/src/org/ofbiz/service/job/GenericServiceJob.java (original)
+++ ofbiz/branches/executioncontext20091231/framework/service/src/org/ofbiz/service/job/GenericServiceJob.java Fri Jan 15 00:25:00 2010
@@ -63,14 +63,16 @@
     @Override
     public void exec() throws InvalidJobException {
         ThreadContext.reset();
+        ThreadContext.runUnprotected();
+        ThreadContext.pushExecutionArtifact(module, "ServiceJob");
         try {
-            ThreadContext.runUnprotected();
-            ThreadContext.pushExecutionArtifact(module, "ServiceJob");
             init();
         } finally {
+            ThreadContext.popExecutionArtifact();
             ThreadContext.endRunUnprotected();
         }
         // no transaction is necessary since runSync handles this
+        ThreadContext.pushExecutionArtifact(module, "ServiceJob");
         try {
             ThreadContext.setDispatcher(this.dctx.getDispatcher());
             Map<String, Object> serviceCtx = getContext();
@@ -100,6 +102,7 @@
             this.failed(t);
         } finally {
             ThreadContext.popExecutionArtifact();
+            ThreadContext.endRunUnprotected();
         }
 
         // call the finish method

Modified: ofbiz/branches/executioncontext20091231/framework/service/src/org/ofbiz/service/job/JobPoller.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/executioncontext20091231/framework/service/src/org/ofbiz/service/job/JobPoller.java?rev=899496&r1=899495&r2=899496&view=diff
==============================================================================
--- ofbiz/branches/executioncontext20091231/framework/service/src/org/ofbiz/service/job/JobPoller.java (original)
+++ ofbiz/branches/executioncontext20091231/framework/service/src/org/ofbiz/service/job/JobPoller.java Fri Jan 15 00:25:00 2010
@@ -87,26 +87,30 @@
         }
         ThreadContext.runUnprotected();
         ThreadContext.pushExecutionArtifact(module, "JobPoller");
-        while (isRunning) {
-            try {
-                // grab a list of jobs to run.
-                List<Job> pollList = jm.poll();
-                //Debug.logInfo("Received poll list from JobManager [" + pollList.size() + "]", module);
-
-                for (Job job : pollList) {
-                    if (job.isValid()) {
-                        queueNow(job);
-                        //Debug.logInfo("Job [" + job.getJobId() + "] is queued", module);
+        try {
+            while (isRunning) {
+                try {
+                    // grab a list of jobs to run.
+                    List<Job> pollList = jm.poll();
+                    //Debug.logInfo("Received poll list from JobManager [" + pollList.size() + "]", module);
+
+                    for (Job job : pollList) {
+                        if (job.isValid()) {
+                            queueNow(job);
+                            //Debug.logInfo("Job [" + job.getJobId() + "] is queued", module);
+                        }
                     }
+                    // NOTE: using sleep instead of wait for stricter locking
+                    java.lang.Thread.sleep(pollWaitTime());
+                } catch (InterruptedException e) {
+                    Debug.logError(e, module);
+                    stop();
                 }
-                // NOTE: using sleep instead of wait for stricter locking
-                java.lang.Thread.sleep(pollWaitTime());
-            } catch (InterruptedException e) {
-                Debug.logError(e, module);
-                stop();
             }
+        } finally {
+            ThreadContext.popExecutionArtifact();
+            ThreadContext.endRunUnprotected();
         }
-        ThreadContext.popExecutionArtifact();
     }
 
     /**

Modified: ofbiz/branches/executioncontext20091231/framework/webapp/src/org/ofbiz/webapp/control/ControlServlet.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/executioncontext20091231/framework/webapp/src/org/ofbiz/webapp/control/ControlServlet.java?rev=899496&r1=899495&r2=899496&view=diff
==============================================================================
--- ofbiz/branches/executioncontext20091231/framework/webapp/src/org/ofbiz/webapp/control/ControlServlet.java (original)
+++ ofbiz/branches/executioncontext20091231/framework/webapp/src/org/ofbiz/webapp/control/ControlServlet.java Fri Jan 15 00:25:00 2010
@@ -319,8 +319,8 @@
             // without a session we can't log the hit, etc; so just do nothing; this should NOT happen much!
             Debug.logError("Error in ControlServlet output where response isCommitted and there is no session (probably because of a logout); not saving ServerHit/Bin information because there is no session and as the response isCommitted we can't get a new one. The output was successful, but we just can't save ServerHit/Bin info.", module);
         } else {
+            ThreadContext.pushExecutionArtifact(module, webappName);
             try {
-                ThreadContext.pushExecutionArtifact(module, webappName);
                 UtilHttp.setInitialRequestInfo(request);
                 VisitHandler.getVisitor(request, response);
                 if (requestHandler.trackStats(request)) {

Modified: ofbiz/branches/executioncontext20091231/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/executioncontext20091231/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java?rev=899496&r1=899495&r2=899496&view=diff
==============================================================================
--- ofbiz/branches/executioncontext20091231/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java (original)
+++ ofbiz/branches/executioncontext20091231/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java Fri Jan 15 00:25:00 2010
@@ -276,8 +276,8 @@
                 GenericValue visit = VisitHandler.getVisit(session);
                 if (visit != null) {
                     for (ConfigXMLReader.Event event: controllerConfig.firstVisitEventList.values()) {
+                        ThreadContext.pushExecutionArtifact(event.path, event.invoke);
                         try {
-                            ThreadContext.pushExecutionArtifact(event.path, event.invoke);
                             String returnString = this.runEvent(request, response, event, null, "firstvisit");
                             if (returnString != null && !returnString.equalsIgnoreCase("success")) {
                                 throw new EventHandlerException("First-Visit event did not return 'success'.");
@@ -295,8 +295,8 @@
 
             // Invoke the pre-processor (but NOT in a chain)
             for (ConfigXMLReader.Event event: controllerConfig.preprocessorEventList.values()) {
+                ThreadContext.pushExecutionArtifact(event.path, event.invoke);
                 try {
-                    ThreadContext.pushExecutionArtifact(event.path, event.invoke);
                     String returnString = this.runEvent(request, response, event, null, "preprocessor");
                     if (returnString != null && !returnString.equalsIgnoreCase("success")) {
                         if (!returnString.contains(":_protect_:")) {
@@ -347,8 +347,8 @@
             ConfigXMLReader.Event checkLoginEvent = controllerConfig.requestMapMap.get("checkLogin").event;
             String checkLoginReturnString = null;
 
+            ThreadContext.pushExecutionArtifact(checkLoginEvent.path, checkLoginEvent.invoke);
             try {
-                ThreadContext.pushExecutionArtifact(checkLoginEvent.path, checkLoginEvent.invoke);
                 checkLoginReturnString = this.runEvent(request, response, checkLoginEvent, null, "security-auth");
             } catch (EventHandlerException e) {
                 throw new RequestHandlerException(e.getMessage(), e);
@@ -380,8 +380,8 @@
         // Invoke the defined event (unless login failed)
         if (eventReturn == null && requestMap.event != null) {
             if (requestMap.event.type != null && requestMap.event.path != null && requestMap.event.invoke != null) {
+                ThreadContext.pushExecutionArtifact(requestMap.event.path, requestMap.event.invoke);
                 try {
-                    ThreadContext.pushExecutionArtifact(requestMap.event.path, requestMap.event.invoke);
                     long eventStartTime = System.currentTimeMillis();
 
                     // run the request event
@@ -534,8 +534,8 @@
 
             // first invoke the post-processor events.
             for (ConfigXMLReader.Event event: controllerConfig.postprocessorEventList.values()) {
+                ThreadContext.pushExecutionArtifact(event.path, event.invoke);
                 try {
-                    ThreadContext.pushExecutionArtifact(event.path, event.invoke);
                     String returnString = this.runEvent(request, response, event, requestMap, "postprocessor");
                     if (returnString != null && !returnString.equalsIgnoreCase("success")) {
                         throw new EventHandlerException("Post-Processor event did not return 'success'.");
@@ -1111,8 +1111,8 @@
 
     public void runAfterLoginEvents(HttpServletRequest request, HttpServletResponse response) {
         for (ConfigXMLReader.Event event: getControllerConfig().afterLoginEventList.values()) {
+            ThreadContext.pushExecutionArtifact(event.path, event.invoke);
             try {
-                ThreadContext.pushExecutionArtifact(event.path, event.invoke);
                 String returnString = this.runEvent(request, response, event, null, "after-login");
                 if (returnString != null && !returnString.equalsIgnoreCase("success")) {
                     throw new EventHandlerException("Pre-Processor event did not return 'success'.");
@@ -1127,8 +1127,8 @@
 
     public void runBeforeLogoutEvents(HttpServletRequest request, HttpServletResponse response) {
         for (ConfigXMLReader.Event event: getControllerConfig().beforeLogoutEventList.values()) {
+            ThreadContext.pushExecutionArtifact(event.path, event.invoke);
             try {
-                ThreadContext.pushExecutionArtifact(event.path, event.invoke);
                 String returnString = this.runEvent(request, response, event, null, "before-logout");
                 if (returnString != null && !returnString.equalsIgnoreCase("success")) {
                     throw new EventHandlerException("Pre-Processor event did not return 'success'.");

Modified: ofbiz/branches/executioncontext20091231/framework/widget/src/org/ofbiz/widget/form/ModelForm.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/executioncontext20091231/framework/widget/src/org/ofbiz/widget/form/ModelForm.java?rev=899496&r1=899495&r2=899496&view=diff
==============================================================================
--- ofbiz/branches/executioncontext20091231/framework/widget/src/org/ofbiz/widget/form/ModelForm.java (original)
+++ ofbiz/branches/executioncontext20091231/framework/widget/src/org/ofbiz/widget/form/ModelForm.java Fri Jan 15 00:25:00 2010
@@ -791,8 +791,8 @@
      *   use the same form definitions for many types of form UIs
      */
     public void renderFormString(Appendable writer, Map<String, Object> context, FormStringRenderer formStringRenderer) throws IOException {
+        ThreadContext.pushExecutionArtifact(this);
         try {
-            ThreadContext.pushExecutionArtifact(this);
             ThreadContext.getAccessController().checkPermission(View);
             //  increment the paginator, only for list and multi forms
             if ("list".equals(this.type) || "multi".equals(this.type)) {

Modified: ofbiz/branches/executioncontext20091231/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/executioncontext20091231/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java?rev=899496&r1=899495&r2=899496&view=diff
==============================================================================
--- ofbiz/branches/executioncontext20091231/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java (original)
+++ ofbiz/branches/executioncontext20091231/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java Fri Jan 15 00:25:00 2010
@@ -596,10 +596,10 @@
     }
 
     public void renderFieldString(Appendable writer, Map<String, Object> context, FormStringRenderer formStringRenderer) throws IOException {
+        ThreadContext.pushExecutionArtifact(this);
         try {
             // Permissions should be checked by renderers, this is here
             // for demonstration only
-            ThreadContext.pushExecutionArtifact(this);
             ThreadContext.getAccessController().checkPermission(View);
             this.fieldInfo.renderFieldString(writer, context, formStringRenderer);
         } catch (AccessControlException e) {

Modified: ofbiz/branches/executioncontext20091231/framework/widget/src/org/ofbiz/widget/screen/HtmlWidget.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/executioncontext20091231/framework/widget/src/org/ofbiz/widget/screen/HtmlWidget.java?rev=899496&r1=899495&r2=899496&view=diff
==============================================================================
--- ofbiz/branches/executioncontext20091231/framework/widget/src/org/ofbiz/widget/screen/HtmlWidget.java (original)
+++ ofbiz/branches/executioncontext20091231/framework/widget/src/org/ofbiz/widget/screen/HtmlWidget.java Fri Jan 15 00:25:00 2010
@@ -205,9 +205,9 @@
                     return;
                 }
             }
+            String artifactName = template.getName().replace("component://", "").replace(".ftl", "");
+            ThreadContext.pushExecutionArtifact(location, artifactName);
             try {
-                String artifactName = template.getName().replace("component://", "").replace(".ftl", "");
-                ThreadContext.pushExecutionArtifact(location, artifactName);
                 FreeMarkerWorker.renderTemplate(template, context, writer);
                 if (insertWidgetBoundaryComments) {
                     writer.append(HtmlWidgetRenderer.formatBoundaryComment("End", "Template", location));

Modified: ofbiz/branches/executioncontext20091231/framework/widget/src/org/ofbiz/widget/screen/ModelScreen.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/executioncontext20091231/framework/widget/src/org/ofbiz/widget/screen/ModelScreen.java?rev=899496&r1=899495&r2=899496&view=diff
==============================================================================
--- ofbiz/branches/executioncontext20091231/framework/widget/src/org/ofbiz/widget/screen/ModelScreen.java (original)
+++ ofbiz/branches/executioncontext20091231/framework/widget/src/org/ofbiz/widget/screen/ModelScreen.java Fri Jan 15 00:25:00 2010
@@ -363,8 +363,8 @@
         // wrap the whole screen rendering in a transaction, should improve performance in querying and such
         Map<String, String> parameters = UtilGenerics.cast(context.get("parameters"));
         boolean beganTransaction = false;
+        ThreadContext.pushExecutionArtifact(this);
         try {
-            ThreadContext.pushExecutionArtifact(this);
             ThreadContext.getAccessController().checkPermission(View);
             int transactionTimeout = -1;
             if (parameters != null) {