01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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.bpmscript.jbi.component;
18:
19: import java.io.StringReader;
20: import java.util.Timer;
21: import java.util.TimerTask;
22:
23: import javax.jbi.JBIException;
24: import javax.jbi.messaging.InOut;
25: import javax.jbi.messaging.MessageExchangeFactory;
26: import javax.jbi.messaging.MessagingException;
27: import javax.jbi.messaging.NormalizedMessage;
28: import javax.xml.namespace.QName;
29: import javax.xml.transform.stream.StreamSource;
30:
31: import org.apache.servicemix.components.util.ComponentSupport;
32:
33: public class PingingComponent extends ComponentSupport {
34:
35: private final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory
36: .getLog(PingingComponent.class);
37:
38: private Timer timer = new Timer();
39:
40: @Override
41: public void start() throws JBIException {
42: timer.schedule(new TimerTask() {
43:
44: @Override
45: public void run() {
46: try {
47: MessageExchangeFactory factory = getDeliveryChannel()
48: .createExchangeFactoryForService(
49: new QName(
50: "http://bpmscript.org/jbi",
51: "corellator"));
52: InOut inOut = factory.createInOutExchange();
53: NormalizedMessage in = inOut.createMessage();
54: in.setContent(new StreamSource(new StringReader(
55: "<ping/>")));
56: inOut.setInMessage(in);
57: log.info("sending ping");
58: getDeliveryChannel().sendSync(inOut);
59: log.info("received pong");
60: } catch (MessagingException e) {
61: log.info(e.getMessage());
62: }
63: }
64:
65: }, 3000, 1000);
66: }
67:
68: @Override
69: public void stop() throws JBIException {
70: timer.cancel();
71: }
72:
73: }
|