001/**
002 * Copyright 2005-2011 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.ksb.messaging;
017
018import org.kuali.rice.ksb.messaging.exceptionhandling.DefaultExceptionServiceImpl;
019import org.kuali.rice.test.TestUtilities;
020import org.kuali.rice.test.ThreadMonitor;
021
022
023public class TestExceptionRoutingServiceImpl extends DefaultExceptionServiceImpl {
024
025        private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
026                .getLogger(TestExceptionRoutingServiceImpl.class);
027    
028        public void placeInExceptionRouting(Throwable throwable, PersistedMessageBO message, Object service) {
029                ExceptionThreader exceptionThreader = new ExceptionThreader(throwable, message, service, this);
030                ThreadMonitor.addThread(exceptionThreader);
031                exceptionThreader.start();
032        }
033        
034        private static class ExceptionThreader extends Thread {
035
036                private Throwable throwable;
037                private PersistedMessageBO message;
038                private Object service;
039                private TestExceptionRoutingServiceImpl testExceptionService;
040                
041                public ExceptionThreader(Throwable throwable, PersistedMessageBO message, Object service, TestExceptionRoutingServiceImpl testExceptionService) {
042                        this.throwable = throwable;
043                        this.message = message;
044                        this.service = service;
045                        this.testExceptionService = testExceptionService;
046                        TestUtilities.setExceptionThreader(this);
047                }
048
049                public void run() {
050                    try {
051                        this.testExceptionService.callRealPlaceInExceptionRouting(this.throwable, this.message, this.service);
052                    } catch (Throwable t) {
053                        LOG.fatal("Error executing callRealPlaceInExceptionRouting.", t);
054                    }
055                }
056        }
057        
058        public void callRealPlaceInExceptionRouting(Throwable throwable, PersistedMessageBO message, Object service) throws Exception {
059                super.placeInExceptionRouting(throwable, message, service);
060        }
061        
062}