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

com.tvd12.ezymq.activemq.endpoint.EzyActiveTopicEndpoint Maven / Gradle / Ivy

The newest version!
package com.tvd12.ezymq.activemq.endpoint;

import com.tvd12.ezyfox.util.EzyCloseable;
import com.tvd12.ezymq.activemq.constant.EzyActiveDestinationType;

import javax.jms.Destination;
import javax.jms.Session;

public abstract class EzyActiveTopicEndpoint
    extends EzyActiveEndpoint implements EzyCloseable {

    protected final Destination topic;

    public EzyActiveTopicEndpoint(Session session, Destination topic) {
        super(session);
        this.topic = topic;
    }

    @SuppressWarnings("unchecked")
    public abstract static class Builder>
        extends EzyActiveEndpoint.Builder {

        protected String topicName;
        protected Destination topic;

        public B topic(Destination topic) {
            this.topic = topic;
            return (B) this;
        }

        public B topicName(String topicName) {
            this.topicName = topicName;
            return (B) this;
        }

        @Override
        public EzyActiveTopicEndpoint build() {
            if (topic == null) {
                topic = createDestination(EzyActiveDestinationType.TOPIC, topicName);
            }
            try {
                return newEndpoint();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }

        protected abstract EzyActiveTopicEndpoint newEndpoint() throws Exception;
    }
}