KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > components > pojo > MyReceiver


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.components.pojo;
18
19 import javax.jbi.JBIException;
20 import javax.jbi.component.ComponentContext;
21 import javax.jbi.component.ComponentLifeCycle;
22 import javax.jbi.messaging.ExchangeStatus;
23 import javax.jbi.messaging.MessageExchange;
24 import javax.jbi.messaging.MessagingException;
25 import javax.jbi.messaging.NormalizedMessage;
26 import javax.management.ObjectName JavaDoc;
27 import javax.xml.namespace.QName JavaDoc;
28
29 import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
31 import org.apache.servicemix.MessageExchangeListener;
32 import org.apache.servicemix.tck.MessageList;
33
34 /**
35  * @version $Revision: 426415 $
36  */

37
38 // START SNIPPET: receive
39
public class MyReceiver implements ComponentLifeCycle, MessageExchangeListener {
40     private static final Log log = LogFactory.getLog(MyReceiver.class);
41     
42     private ComponentContext context;
43     private ObjectName JavaDoc extensionMBeanName;
44     private MessageList messageList = new MessageList();
45
46
47     // ComponentLifeCycle interface
48
//-------------------------------------------------------------------------
49
public ObjectName JavaDoc getExtensionMBeanName() {
50         return extensionMBeanName;
51     }
52
53     public void init(ComponentContext context) throws JBIException {
54         this.context = context;
55
56         // Lets activate myself
57
context.activateEndpoint(new QName JavaDoc("http://servicemix.org/cheese/", "receiver"), "receiver");
58     }
59
60     public void shutDown() throws JBIException {
61     }
62
63     public void start() throws JBIException {
64     }
65
66     public void stop() throws JBIException {
67     }
68
69     // MessageExchangeListener interface
70
//-------------------------------------------------------------------------
71
public void onMessageExchange(MessageExchange exchange) throws MessagingException {
72         log.info("Received message " + exchange);
73         NormalizedMessage message = exchange.getMessage("in");
74         getMessageList().addMessage(message);
75         exchange.setStatus(ExchangeStatus.DONE);
76         context.getDeliveryChannel().send(exchange);
77     }
78
79     // Properties
80
//-------------------------------------------------------------------------
81
public void setExtensionMBeanName(ObjectName JavaDoc extensionMBeanName) {
82         this.extensionMBeanName = extensionMBeanName;
83     }
84
85     public MessageList getMessageList() {
86         return messageList;
87     }
88
89     public void setMessageList(MessageList messageList) {
90         this.messageList = messageList;
91     }
92 }
93 // END SNIPPET: receive
94
Popular Tags