nl.minbzk.dwr.zoeken.enricher.notifier.jms.endpoint.AttenderEndpoint.java Source code

Java tutorial

Introduction

Here is the source code for nl.minbzk.dwr.zoeken.enricher.notifier.jms.endpoint.AttenderEndpoint.java

Source

/**
 * Copyright (C) 2012 Seajas, the Netherlands.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 3, as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package nl.minbzk.dwr.zoeken.enricher.notifier.jms.endpoint;

import nl.minbzk.dwr.zoeken.enricher.notifier.DirectResultCache;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.integration.Message;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import com.seajas.search.attender.bridge.model.notifier.NotifierProfile;

/**
 * A simple replication endpoint.
 * 
 * @author Jasper van Veghel <jasper@seajas.com>
 */
@Lazy(true)
@Component
public class AttenderEndpoint {
    /**
     * The logger.
     */
    private static final Logger logger = LoggerFactory.getLogger(AttenderEndpoint.class);

    /**
     * Constants.
     */
    private static final String HEADER_CHANNEL_ATTENDERACTION = "attender.channel.attenderaction";

    private static final String ATTENDER_ACTION_DELETE_DIRECT_RESULT = "delete-attender";
    private static final String ATTENDER_ACTION_UPDATE_DIRECT_RESULT = "update-attender";

    /**
     * The direct result cache.
     */
    @Autowired
    private DirectResultCache directResultCache;

    /**
     * Process the incoming message and delegate it according to its payload.
     * 
     * @param message
     */
    public void process(final Message<?> message) {
        final String action = message.getHeaders().get(HEADER_CHANNEL_ATTENDERACTION, String.class);

        if (StringUtils.hasText(action)) {
            if (action.equals(ATTENDER_ACTION_DELETE_DIRECT_RESULT))
                directResultCache.delete((String) message.getPayload());
            else if (action.equals(ATTENDER_ACTION_UPDATE_DIRECT_RESULT))
                directResultCache.update((NotifierProfile) message.getPayload());
            else
                logger.error("Unknown attender replication action '" + action + "' received. Discarding.");
        } else
            logger.error("Unknown attender replication action (no action header) received. Discarding.");
    }
}