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

gu.dtalk.cmd.FreshedChannelSupplier Maven / Gradle / Ivy

There is a newer version: 0.6.9
Show newest version
package gu.dtalk.cmd;

import static com.google.common.base.Preconditions.checkNotNull;

import com.google.common.base.Strings;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;

import gu.dtalk.DeviceInstruction;
import gu.simplemq.Channel;

public class FreshedChannelSupplier implements Supplier>{
	private final Supplier taskQueueSupplier;
	private Channel taskChannel;
	public FreshedChannelSupplier(Supplier taskQueueSupplier) {
		this.taskQueueSupplier = checkNotNull(taskQueueSupplier,"taskQueueSupplier is null");
	}
	public FreshedChannelSupplier(String taskQueue) {
		this(Suppliers.ofInstance(checkNotNull(Strings.emptyToNull(taskQueue),"taskQueue is null or empty")));
	}
	@Override
    public Channel get(){
    	String name = checkNotNull(taskQueueSupplier.get(),"taskQueue provided by taskQueueSupplier  is null");
    	if(taskChannel == null || !taskChannel.name.equals(name)){
    		Channel ch = new Channel(name){};
    		taskChannel = ch;
    	}
    	return taskChannel;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy