View Javadoc

1   /**
2    * Copyright 2005-2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.ksb.messaging.exceptionhandling;
17  
18  import org.kuali.rice.ksb.messaging.PersistedMessageBO;
19  import org.kuali.rice.test.TestUtilities;
20  
21  
22  public class TestExceptionHandlerServiceImpl extends DefaultExceptionServiceImpl {
23  
24      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
25  	    .getLogger(TestExceptionHandlerServiceImpl.class);
26          
27      public void placeInExceptionRouting(Throwable throwable, PersistedMessageBO message, Object service) {
28  		LOG.info("Executing placeInExceptionRouting - creating and starting the ExceptionThreader");
29  		ExceptionThreader exceptionThreader = new ExceptionThreader(throwable, message, service, this);
30  		exceptionThreader.start();
31  	}
32  	
33  	private static class ExceptionThreader extends Thread {
34  
35  		private Throwable throwable;
36  		private PersistedMessageBO message;
37  		private Object service;
38  		private TestExceptionHandlerServiceImpl testExceptionService;
39  		
40  		public ExceptionThreader(Throwable throwable, PersistedMessageBO message, Object service, TestExceptionHandlerServiceImpl testExceptionService) {
41  			this.throwable = throwable;
42  			this.message = message;
43  			this.service = service;
44  			this.testExceptionService = testExceptionService;
45  			TestUtilities.setExceptionThreader(this);
46  		}
47  
48  		public void run() {
49  			LOG.info("Running the ExceptionThreader - sleeping for 3 seconds - " + this.toString());
50  		    try {
51  			Thread.sleep(3000);
52  		    } catch (InterruptedException e) {
53  			e.printStackTrace();
54  		    }
55  		    try {
56  		    	LOG.info("Executing 'real' placeInExceptionRouting from ExceptionThreader.");
57  		    	this.testExceptionService.callRealPlaceInExceptionRouting(this.throwable, this.message, this.service);
58  		    } catch (Throwable t) {
59  		    	LOG.fatal("Error executing callRealPlaceInExceptionRouting.", t);
60  		    }
61  		}
62  	}
63  	
64  	public void callRealPlaceInExceptionRouting(Throwable throwable, PersistedMessageBO message, Object service) throws Exception {
65  		LOG.info("Executing callRealPlaceInExceptionRouting from TestExceptionHandlerServiceImpl.");
66  		super.placeInExceptionRouting(throwable, message, service);
67  		LOG.info("Message was successfully placed in exception routing.");
68  	}
69  	
70  }