gu.dtalk.cmd.FreshedChannelSupplier Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dtalk-cmd Show documentation
Show all versions of dtalk-cmd Show documentation
implement cmd/task manager
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;
}
}