Leo,

I don't think you can do that with a servicemix-bean POJO -- this interface is mainly being used on the JBI components themselves, not on a POJO deployed inside of it. We do however support using annotations like @PostConstruct, @PreDestroy and @Callback to be notified of start/stop and other events. There's an example in our unit tests:
http://servicemix.apache.org/dist/servicemix-3.1-incubating/site/deployables/serviceengines/servicemix-bean/xref-test/org/apache/servicemix/bean/beans/ConsumerBean.html

Regards,

Gert

Leo Smiers wrote:
Hello

I have created a pojo component which implements the ComponentLifeCycle.
I did this because I want to know when the component is started so I can
register this component. The problem however is that the
ComponentLifeCycle interface methods are not called. So what do I wrong?

With knid regards

Leo Smiers

Below are the java code and the xbean configuration xml.

--- JAVA code start ---

package com.vialis.vivaldi2.esb.test.logger;

import java.io.StringReader;

import org.apache.servicemix.MessageExchangeListener;

import javax.annotation.Resource;
import javax.jbi.messaging.DeliveryChannel;
import javax.jbi.messaging.ExchangeStatus;
import javax.jbi.messaging.MessageExchange;
import javax.jbi.messaging.MessagingException;
import javax.jbi.messaging.MessageExchangeFactory;
import javax.jbi.messaging.InOnly;
import javax.xml.namespace.QName;
import javax.jbi.messaging.NormalizedMessage;
import javax.xml.transform.stream.StreamSource;
import javax.jbi.component.ComponentLifeCycle;
import javax.jbi.component.ComponentContext;
import javax.management.ObjectName;
import javax.jbi.JBIException;

public class Logger implements ComponentLifeCycle,
MessageExchangeListener {

    @Resource
    private DeliveryChannel channel;
    private ComponentContext context;
    private ObjectName extensionMBeanName;

        // ComponentLifeCycle interface
//----------------------------------------------------------------------
---
    public ObjectName getExtensionMBeanName() {
        return extensionMBeanName;
    }

    public void init(ComponentContext context) throws JBIException {
        System.out.println("Logger: Init");
        this.context = context;
    }

    public void shutDown() throws JBIException {
        System.out.println("Logger: Shutdown");
    }

    public void start() throws JBIException {
        System.out.println("Logger: Start");
    }

    public void stop() throws JBIException {
        System.out.println("Logger: Stop");
    }

    // Properties
//----------------------------------------------------------------------
---
    public void setExtensionMBeanName(ObjectName extensionMBeanName) {
        this.extensionMBeanName = extensionMBeanName;
        System.out.println("Logger: MBeanName = " + extensionMBeanName);
    }


        public Logger()
        {
        System.out.println("Logger: Created: " + toString());
        }

    public void onMessageExchange(MessageExchange exchange) throws
MessagingException {
        System.out.println("Logger:");
        System.out.println("Received exchange: " + exchange);
                if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
                        try {
                                exchange.setStatus(ExchangeStatus.DONE);
                                channel.send(exchange);
        
                                MessageExchangeFactory fac =
channel.createExchangeFactory();
                                InOnly inonly =
fac.createInOnlyExchange();
                                QName service = new
QName("http://com.vialis.vivaldi2.esb.test.logger/logger";, "writelog");
                                NormalizedMessage msg =
inonly.createMessage();
                                msg.setProperty("Naam", "Leo Smiers");
                                msg.setContent(new StreamSource(new
StringReader("<hello>world</hello>")));
                                inonly.setInMessage(msg);
                                inonly.setService(service);
                                channel.send(inonly);
                        }
                        catch (MessagingException e) {
                                System.out.println("Logger exception: "
+ e.getMessage());
                        };
                }
    }
}

--- JAVA code end ---

--- xbean.xml start ---
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:bean="http://servicemix.apache.org/bean/1.0";
       xmlns:logger="http://com.vialis.vivaldi2.esb.test.logger/logger";>
  <bean:endpoint service="logger:service" endpoint="endpoint"
bean="#Logger"/>

  <bean id="Logger" class="com.vialis.vivaldi2.esb.test.logger.Logger"/>
</beans>
--- xbean.xml end --- The information contained in this communication is confidential and may be legally privileged. It is intended solely for the use of the individual or entity to whom it is addressed and others authorised to receive it. If you are not the intended recipient you are hereby notified that any disclosure, copying, distribution or taking any action in reliance on the contents of this information is strictly prohibited and may be unlawful. Vialis is neither liable for the proper and complete transmission of the information contained in this communication nor for any delay in its receipt.

Reply via email to