io.github.quickmsg.interate.IgniteChannels Maven / Gradle / Ivy
package io.github.quickmsg.interate;
import cn.hutool.db.sql.Condition;
import cn.hutool.db.sql.SqlBuilder;
import io.github.quickmsg.common.channel.MqttChannel;
import io.github.quickmsg.common.context.ContextHolder;
import io.github.quickmsg.common.integrate.IgniteCacheRegion;
import io.github.quickmsg.common.integrate.Integrate;
import io.github.quickmsg.common.integrate.cache.ConnectCache;
import io.github.quickmsg.common.integrate.cache.IntegrateCache;
import io.github.quickmsg.common.integrate.channel.IntegrateChannels;
import io.github.quickmsg.common.integrate.job.CloseJob;
import io.github.quickmsg.common.log.LogEvent;
import io.github.quickmsg.common.log.LogStatus;
import io.github.quickmsg.common.sql.ConnectionQueryModel;
import io.github.quickmsg.common.sql.PageRequest;
import io.github.quickmsg.common.sql.PageResult;
import io.github.quickmsg.common.utils.JacksonUtil;
import io.netty.handler.codec.mqtt.MqttVersion;
import org.apache.ignite.cache.CachePeekMode;
import org.apache.ignite.cache.query.QueryCursor;
import org.apache.ignite.cache.query.SqlFieldsQuery;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
/**
* @author luxurong
*/
public class IgniteChannels implements IntegrateChannels {
private final ConcurrentHashMap localChannelCache;
private final IntegrateCache shareChannelCache;
private final IgniteIntegrate integrate;
private final CloseJob closeConnectJob = new CloseJob();
@Override
public Integrate getIntegrate() {
return this.integrate;
}
public IgniteChannels(IgniteIntegrate integrate, ConcurrentHashMap channelMap) {
this.integrate = integrate;
this.localChannelCache = channelMap;
this.shareChannelCache = this.integrate.getCache(IgniteCacheRegion.CHANNEL);
}
@Override
public void add(String clientIdentifier, MqttChannel mqttChannel) {
Collection closeJobs = integrate.getJobExecutor().callBroadcast(this.closeConnectJob, clientIdentifier);
localChannelCache.put(clientIdentifier, mqttChannel);
this.shareChannelCache.put(mqttChannel.getId(), mqttChannel.getConnectCache());
}
@Override
public boolean exists(String clientIdentifier) {
return localChannelCache.containsKey(clientIdentifier);
}
@Override
public MqttChannel get(String clientIdentifier) {
return localChannelCache.get(clientIdentifier);
}
@Override
public Integer counts() {
return localChannelCache.size();
}
@Override
public Collection getChannels() {
return localChannelCache.values();
}
@Override
public void remove(MqttChannel mqttChannel) {
localChannelCache.remove(mqttChannel.getClientId(), mqttChannel);
shareChannelCache.remove(mqttChannel.getId());
}
@Override
public PageResult queryConnectionSql(ConnectionQueryModel model) {
List conditionList = new ArrayList<>();
List