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

com.github.triceo.splitlog.DefaultMessageConsumer Maven / Gradle / Ivy

Go to download

These are the core parts of splitlog. This is where the implementations of the public APIs live. Classes from this package come with no API stability guarantees.

There is a newer version: 1.7.2
Show newest version
package com.github.triceo.splitlog;

import com.github.triceo.splitlog.api.Message;
import com.github.triceo.splitlog.api.MessageConsumer;
import com.github.triceo.splitlog.api.MessageDeliveryStatus;
import com.github.triceo.splitlog.api.MessageListener;
import com.github.triceo.splitlog.api.MessageProducer;

final class DefaultMessageConsumer

> implements MessageConsumer

{ private final MessageListener

listener; private final P producer; public DefaultMessageConsumer(final MessageListener

listener, final P producer) { if ((producer == null) || (listener == null)) { throw new IllegalArgumentException("Neither producer nor listener may be null."); } this.producer = producer; this.listener = listener; } @SuppressWarnings("unchecked") @Override public boolean equals(final Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (this.getClass() != obj.getClass()) { return false; } final DefaultMessageConsumer

other = (DefaultMessageConsumer

) obj; if (this.listener == null) { if (other.listener != null) { return false; } } else if (!this.listener.equals(other.listener)) { return false; } if (this.producer == null) { if (other.producer != null) { return false; } } else if (!this.producer.equals(other.producer)) { return false; } return true; } @Override public int hashCode() { final int prime = 31; int result = 1; result = (prime * result) + ((this.listener == null) ? 0 : this.listener.hashCode()); result = (prime * result) + ((this.producer == null) ? 0 : this.producer.hashCode()); return result; } @Override public boolean isStopped() { return !this.producer.isConsuming(this); } @Override public void messageReceived(final Message message, final MessageDeliveryStatus status, final P producer) { this.listener.messageReceived(message, status, producer); } @Override public boolean stop() { return this.producer.stopConsuming(this); } @Override public String toString() { final StringBuilder builder = new StringBuilder(); builder.append("DefaultMessageConsumer ["); if (this.producer != null) { builder.append("producer=").append(this.producer).append(", "); } if (this.listener != null) { builder.append("listener=").append(this.listener); } builder.append("]"); return builder.toString(); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy