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

io.github.nichetoolkit.socket.manager.Jt808SessionManager Maven / Gradle / Ivy

package io.github.nichetoolkit.socket.manager;

import io.github.nichetoolkit.rest.util.GeneralUtils;
import io.netty.channel.ChannelHandlerContext;
import org.apache.mina.core.session.IoSession;

import java.lang.ref.SoftReference;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 

SessionManager

* @author Cyan ([email protected]) * @version v1.0.0 */ public class Jt808SessionManager { public static SoftReference>> PACKAGE_MAP_REFERENCE = new SoftReference<>(new HashMap<>()); public static Map AUTH_MAP = new ConcurrentHashMap<>(); public static Map> SENT_PACKAGE_MAP = new ConcurrentHashMap<>(); private final static Map SESSION_MAP = new ConcurrentHashMap<>(); public static boolean contains(String phone) { return SESSION_MAP.containsKey(phone); } public static Object get(String phone) { return SESSION_MAP.get(phone); } public static void set(String phone, Object session) { SESSION_MAP.put(phone, session); } public static void write(String phone, byte[] data){ Object session = get(phone); if(GeneralUtils.isNotEmpty(phone)) { if (session instanceof ChannelHandlerContext) { ((ChannelHandlerContext) session).writeAndFlush(data); } else if (session instanceof IoSession) { ((IoSession) session).write(data); } } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy