All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.ddth.queue.impl.BaseUniversalRedisQueue Maven / Gradle / Ivy

There is a newer version: 1.0.0
Show newest version
package com.github.ddth.queue.impl;

import com.github.ddth.queue.IQueueMessage;
import com.github.ddth.queue.utils.QueueException;

/**
 * Base class for universal Redis queue implementations.
 * 
 * @author Thanh Nguyen
 * 
 * @param 
 * @since 0.3.3
 */
public abstract class BaseUniversalRedisQueue
        extends RedisQueue {

    /**
     * {@inheritDoc}
     */
    @Override
    protected byte[] serialize(IQueueMessage _msg) throws QueueException {
        if (_msg == null) {
            return null;
        }
        if (!(_msg instanceof BaseUniversalQueueMessage)) {
            throw new IllegalArgumentException("This method requires an argument of type ["
                    + BaseUniversalQueueMessage.class.getName() + "]!");
        }

        BaseUniversalQueueMessage msg = (BaseUniversalQueueMessage) _msg;
        try {
            return msg.toBytes();
        } catch (Exception e) {
            throw new QueueException.CannotSerializeQueueMessage(e);
        }
    }

    /**
     * {@inheritDoc}
     */
    @SuppressWarnings("unchecked")
    @Override
    public T take() {
        return (T) super.take();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy