com.liferay.portal.fabric.netty.handlers.NettyChannelAttributes Maven / Gradle / Ivy
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.portal.fabric.netty.handlers;
import com.liferay.petra.concurrent.AsyncBroker;
import com.liferay.petra.concurrent.FutureListener;
import com.liferay.petra.concurrent.NoticeableFuture;
import com.liferay.portal.fabric.netty.agent.NettyFabricAgentStub;
import com.liferay.portal.fabric.netty.rpc.RPCUtil;
import com.liferay.portal.fabric.worker.FabricWorker;
import io.netty.channel.Channel;
import io.netty.util.Attribute;
import io.netty.util.AttributeKey;
import java.io.Serializable;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicLong;
/**
* @author Shuyang Zhou
*/
public class NettyChannelAttributes {
public static AsyncBroker getAsyncBroker(
Channel channel) {
Attribute> attribute = channel.attr(
_asyncBrokerKey);
AsyncBroker asyncBroker = attribute.get();
if (asyncBroker == null) {
asyncBroker = new AsyncBroker<>();
AsyncBroker previousAsyncBroker =
attribute.setIfAbsent(asyncBroker);
if (previousAsyncBroker != null) {
asyncBroker = previousAsyncBroker;
}
}
return (AsyncBroker)asyncBroker;
}
public static FabricWorker getFabricWorker(
Channel channel, long id) {
Map> fabricWorkers = getFabricWorkers(channel);
if (fabricWorkers == null) {
return null;
}
return (FabricWorker)fabricWorkers.get(id);
}
public static Map> getFabricWorkers(Channel channel) {
Attribute