KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > common > BaseLifeCycle


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.servicemix.common;
18
19 import javax.jbi.messaging.MessageExchange;
20 import javax.transaction.Status JavaDoc;
21
22 import org.apache.servicemix.MessageExchangeListener;
23
24 /**
25  * Base class for life cycle management of components.
26  * This lifecycle uses Push delivery by implementing MessageExchangeListerner interface
27  *
28  * @author Guillaume Nodet
29  * @version $Revision: 433981 $
30  * @since 3.0
31  */

32 public class BaseLifeCycle extends AsyncBaseLifeCycle implements MessageExchangeListener {
33
34     public BaseLifeCycle(BaseComponent component) {
35         super(component);
36     }
37     
38     /* (non-Javadoc)
39      * @see org.apache.servicemix.common.AsyncBaseLifeCycle#onMessageExchange(javax.jbi.messaging.MessageExchange)
40      */

41     public void onMessageExchange(MessageExchange exchange) {
42         try {
43             processExchange(exchange);
44         } catch (Exception JavaDoc e) {
45             logger.error("Error processing exchange " + exchange, e);
46             try {
47                 // If we are transacted and this is a runtime exception
48
// try to mark transaction as rollback
49
if (transactionManager != null &&
50                     transactionManager.getStatus() == Status.STATUS_ACTIVE &&
51                     exceptionShouldRollbackTx(e)) {
52                     transactionManager.setRollbackOnly();
53                 }
54                 exchange.setError(e);
55                 channel.send(exchange);
56             } catch (Exception JavaDoc inner) {
57                 logger.error("Error setting exchange status to ERROR", inner);
58             }
59         }
60     }
61     
62 }
63
Popular Tags