
package org.apache.camel.component.milo.server;

import org.apache.camel.Exchange;
import org.apache.camel.component.milo.server.internal.CamelServerItem;
import org.apache.camel.support.DefaultProducer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MiloServerProducer extends DefaultProducer {

    private static final Logger LOG = LoggerFactory.getLogger(MiloServerProducer.class);

    private CamelServerItem item;

    public MiloServerProducer(final MiloServerEndpoint endpoint) {
        super(endpoint);
    }

    @Override
    public MiloServerEndpoint getEndpoint() {
        return (MiloServerEndpoint) super.getEndpoint();
    }

    @Override
    protected void doStart() throws Exception {
        super.doStart();
        this.item = getEndpoint().getItem();
    }

    @Override
    public void process(final Exchange exchange) throws Exception {
        final Object value = exchange.getIn().getBody();

        LOG.trace("Update item value - {} = {}", this.item, value);

        this.item.update(value);
    }
}
