KickJava   Java API By Example, From Geeks To Geeks.

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


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.DeliveryChannel;
23 import javax.jbi.messaging.InOnly;
24 import javax.jbi.messaging.MessageExchangeFactory;
25 import javax.jbi.messaging.MessagingException;
26 import javax.jbi.messaging.NormalizedMessage;
27 import javax.management.ObjectName JavaDoc;
28
29 import org.apache.servicemix.jbi.jaxp.StringSource;
30
31 /**
32  * @version $Revision: 426415 $
33  */

34 // START SNIPPET: send
35
public class MySender implements ComponentLifeCycle {
36     private ComponentContext context;
37     private ObjectName JavaDoc extensionMBeanName;
38
39
40     /**
41      * Sends a number of messages
42      */

43     public void sendMessages(int count) throws MessagingException {
44         DeliveryChannel deliveryChannel = context.getDeliveryChannel();
45         MessageExchangeFactory factory = deliveryChannel.createExchangeFactory();
46
47         for (int i = 0; i < count; i++) {
48             InOnly exchange = factory.createInOnlyExchange();
49             NormalizedMessage message = exchange.createMessage();
50             exchange.setInMessage(message);
51
52             message.setProperty("id", new Integer JavaDoc(i));
53             message.setContent(new StringSource("<example id='" + i + "'/>"));
54
55             deliveryChannel.send(exchange);
56         }
57     }
58
59     // ComponentLifeCycle interface
60
//-------------------------------------------------------------------------
61
public ObjectName JavaDoc getExtensionMBeanName() {
62         return extensionMBeanName;
63     }
64
65     public void init(ComponentContext context) throws JBIException {
66         this.context = context;
67     }
68
69     public void shutDown() throws JBIException {
70     }
71
72     public void start() throws JBIException {
73     }
74
75     public void stop() throws JBIException {
76     }
77
78
79     // Properties
80
//-------------------------------------------------------------------------
81
public void setExtensionMBeanName(ObjectName JavaDoc extensionMBeanName) {
82         this.extensionMBeanName = extensionMBeanName;
83     }
84 }
85
86 // END SNIPPET: send
87
Popular Tags