当前位置: 首页>>代码示例>>Java>>正文


Java ChannelId类代码示例

本文整理汇总了Java中io.netty.channel.ChannelId的典型用法代码示例。如果您正苦于以下问题:Java ChannelId类的具体用法?Java ChannelId怎么用?Java ChannelId使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ChannelId类属于io.netty.channel包,在下文中一共展示了ChannelId类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: remove

import io.netty.channel.ChannelId; //导入依赖的package包/类
protected void remove(Session session) {
	if (session == null) { return; }

	synchronized (this) {
		try {
			if (session.cleanSession()) { // [MQTT-3.1.2-5]
				sessions.remove(session.clientId());
			}

			ChannelId channelId = session.channelId();
			if (channelId == null) { return; }

			clientIds.remove(channelId);
			ctxs.remove(session.clientId());
		}
		finally {
			if (logger.isDebugEnabled()) {
				logger.debug("session removed [clientId={}, sessionsSize={}, clientIdsSize={}, ctxsSize={}]",
						session.clientId(), sessions.size(), clientIds.size(), ctxs.size());
			}
		}
	}
}
 
开发者ID:anyflow,项目名称:lannister,代码行数:24,代码来源:Sessions.java

示例2: executeNormalChannelRead0

import io.netty.channel.ChannelId; //导入依赖的package包/类
private MqttConnAckMessage executeNormalChannelRead0(String clientId, boolean cleanSession, ChannelId channelId)
		throws Exception {
	MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.CONNECT, false, MqttQoS.AT_MOST_ONCE, false,
			10);
	MqttConnectVariableHeader variableHeader = new MqttConnectVariableHeader("MQTT", 4, true, true, true, 0, true,
			cleanSession, 60);
	MqttConnectPayload payload = new MqttConnectPayload(clientId, "willtopic", "willmessage", "username",
			"password");

	MqttConnectMessage msg = new MqttConnectMessage(fixedHeader, variableHeader, payload);

	ChannelId cid = channelId == null ? TestUtil.newChannelId(clientId, false) : channelId;

	EmbeddedChannel channel = new EmbeddedChannel(cid, new ConnectReceiver());

	channel.writeInbound(msg);

	return channel.readOutbound();
}
 
开发者ID:anyflow,项目名称:lannister,代码行数:20,代码来源:ConnectReceiverTest.java

示例3: isOnline

import io.netty.channel.ChannelId; //导入依赖的package包/类
/**
 * 用户是否在线
 *
 * @param userId
 * @return
 */
boolean isOnline(long userId) {
    ChannelId channelId = LOGIN_USERS.inverse().get(userId);
    if (channelId == null) {
        return false;
    }
    Channel channel = CHANNEL_GROUP.find(channelId);
    if (channel == null || !channel.isActive()) {
        if (removeLock.tryLock()) {
            try {
                LOGIN_USERS.inverse().remove(userId);
            } finally {
                removeLock.unlock();
            }
        }
        return false;
    }
    return true;
}
 
开发者ID:freedompy,项目名称:commelina,代码行数:25,代码来源:NettyServerContext.java

示例4: getUserChannel

import io.netty.channel.ChannelId; //导入依赖的package包/类
/**
 * 获取用户的 channel
 *
 * @param userId
 * @return
 */
Channel getUserChannel(long userId) {
    ChannelId channelId = LOGIN_USERS.inverse().get(userId);
    if (channelId == null) {
        // 用户未登录
        throw new UserUnLoginException();
    }
    Channel channel = CHANNEL_GROUP.find(channelId);
    if (channel == null) {
        // 用户下线了
        throw new UserChannelNotFoundException();
    }
    if (!channel.isActive()) {
        this.channelInactive(channel);
        throw new UserChannelUnActiveException();
    }
    return channel;
}
 
开发者ID:freedompy,项目名称:commelina,代码行数:24,代码来源:NettyServerContext.java

示例5: remove

import io.netty.channel.ChannelId; //导入依赖的package包/类
@Override
public boolean remove(Object o) {
    Channel c = null;
    if (o instanceof ChannelId) {
        c = nonServerChannels.remove(o);
        if (c == null) {
            c = serverChannels.remove(o);
        }
    } else if (o instanceof Channel) {
        c = (Channel) o;
        if (c instanceof ServerChannel) {
            c = serverChannels.remove(c.id());
        } else {
            c = nonServerChannels.remove(c.id());
        }
    }

    if (c == null) {
        return false;
    }

    c.closeFuture().removeListener(remover);
    return true;
}
 
开发者ID:nathanchen,项目名称:netty-netty-5.0.0.Alpha1,代码行数:25,代码来源:DefaultChannelGroup.java

示例6: instange

import io.netty.channel.ChannelId; //导入依赖的package包/类
/**
 * 获取单例
 * @return
 */
public static SessionHelper instange(){
    synchronized (SessionHelper.class) {
        if (manager == null) {
            manager = new SessionHelper();
            if (manager.sessionMap == null) {
                // 需要线程安全的Map
                manager.sessionMap = new ConcurrentHashMap<ChannelId,HttpSession>();
            }
        }
    }
    return manager;
}
 
开发者ID:all4you,项目名称:redant,代码行数:17,代码来源:SessionHelper.java

示例7: clearExpireSession

import io.netty.channel.ChannelId; //导入依赖的package包/类
/**
 * 清除过期的session
 * 需要在定时器中执行该方法
 */
public void clearExpireSession(){
    Iterator<Map.Entry<ChannelId,HttpSession>> iterator = manager.sessionMap.entrySet().iterator();
    while(iterator.hasNext()){
        Map.Entry<ChannelId,HttpSession> sessionEntry = iterator.next();
        if(sessionEntry.getValue()==null || sessionEntry.getValue().isExpire()){
            iterator.remove();
        }
    }
}
 
开发者ID:all4you,项目名称:redant,代码行数:14,代码来源:SessionHelper.java

示例8: HttpSession

import io.netty.channel.ChannelId; //导入依赖的package包/类
public HttpSession(ChannelId id,ChannelHandlerContext context,Long createTime,Long expireTime){
    this.id = id;
    this.context = context;
    this.createTime = createTime;
    this.expireTime = expireTime;
    assertSessionMapNotNull();
}
 
开发者ID:all4you,项目名称:redant,代码行数:8,代码来源:HttpSession.java

示例9: getLoginUserId

import io.netty.channel.ChannelId; //导入依赖的package包/类
/**
 * 根据channel id 获取用户登录的 user id
 *
 * @param channelId
 * @return
 */
Long getLoginUserId(ChannelId channelId) {
    if (CHANNEL_GROUP.find(channelId) == null) {
        return null;
    }
    return LOGIN_USERS.get(channelId);
}
 
开发者ID:freedompy,项目名称:commelina,代码行数:13,代码来源:NettyServerContext.java

示例10: WebPlayerBridge

import io.netty.channel.ChannelId; //导入依赖的package包/类
public WebPlayerBridge(WebSocketServerThread webSocketServerThread, Settings settings) {
    this.webSocketServerThread = webSocketServerThread;
    this.setCustomNames = settings.setCustomNames;
    this.disableGravity = settings.disableGravity;
    this.disableAI = settings.disableAI;

    if (settings.entityClassName == null || "".equals(settings.entityClassName)) {
        this.entityClass = null;
    } else {
        try {
            this.entityClass = Class.forName("org.bukkit.entity." + settings.entityClassName);
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();

            // HumanEntity.class fails on Glowstone with https://gist.github.com/satoshinm/ebc87cdf1d782ba91b893fe24cd8ffd2
            // so use sheep instead for now. TODO: spawn ala GlowNPC: https://github.com/satoshinm/WebSandboxMC/issues/13
            webSocketServerThread.log(Level.WARNING, "No such entity class " + settings.entityClassName + ", falling back to Sheep");
            this.entityClass = Sheep.class;
        }
    }

    this.constrainToSandbox = settings.entityMoveSandbox;
    this.dieDisconnect = settings.entityDieDisconnect;

    this.clickableLinks = settings.clickableLinks;
    this.clickableLinksTellraw = settings.clickableLinksTellraw;
    this.publicURL = settings.publicURL;

    this.allowAnonymous = settings.allowAnonymous;
    this.lastPlayerID = 0;
    this.channelId2name = new HashMap<ChannelId, String>();
    this.channelId2Entity = new HashMap<ChannelId, Entity>();
    this.entityId2Username = new HashMap<Integer, String>();
    this.name2channel = new HashMap<String, Channel>();
}
 
开发者ID:satoshinm,项目名称:WebSandboxMC,代码行数:36,代码来源:WebPlayerBridge.java

示例11: broadcastLineExcept

import io.netty.channel.ChannelId; //导入依赖的package包/类
public void broadcastLineExcept(ChannelId excludeChannelId, String message) {
    for (Channel channel: allUsersGroup) {
        if (channel.id().equals(excludeChannelId)) {
            continue;
        }

        channel.writeAndFlush(new BinaryWebSocketFrame(Unpooled.copiedBuffer((message + "\n").getBytes())));
    }
}
 
开发者ID:satoshinm,项目名称:WebSandboxMC,代码行数:10,代码来源:WebSocketServerThread.java

示例12: channelId

import io.netty.channel.ChannelId; //导入依赖的package包/类
@JsonSerialize(using = ChannelIdSerializer.class)
@JsonProperty
public ChannelId channelId() {
	ChannelHandlerContext ctx = NEXUS.channelHandlerContext(clientId);
	if (ctx == null) { return null; }

	return ctx.channel().id();
}
 
开发者ID:anyflow,项目名称:lannister,代码行数:9,代码来源:Session.java

示例13: find

import io.netty.channel.ChannelId; //导入依赖的package包/类
@Override
public Channel find(ChannelId id) {
    Channel c = nonServerChannels.get(id);
    if (c != null) {
        return c;
    } else {
        return serverChannels.get(id);
    }
}
 
开发者ID:nathanchen,项目名称:netty-netty-5.0.0.Alpha1,代码行数:10,代码来源:DefaultChannelGroup.java

示例14: add

import io.netty.channel.ChannelId; //导入依赖的package包/类
@Override
public boolean add(Channel channel) {
    ConcurrentMap<ChannelId, Channel> map =
        channel instanceof ServerChannel? serverChannels : nonServerChannels;

    boolean added = map.putIfAbsent(channel.id(), channel) == null;
    if (added) {
        channel.closeFuture().addListener(remover);
    }
    return added;
}
 
开发者ID:nathanchen,项目名称:netty-netty-5.0.0.Alpha1,代码行数:12,代码来源:DefaultChannelGroup.java

示例15: getId

import io.netty.channel.ChannelId; //导入依赖的package包/类
public ChannelId getId() {
    return id;
}
 
开发者ID:all4you,项目名称:redant,代码行数:4,代码来源:HttpSession.java


注:本文中的io.netty.channel.ChannelId类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。