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

org.apache.hudi.org.apache.hbase.thirdparty.io.netty.channel.ChannelHandlerContext Maven / Gradle / Ivy

/*
 * Copyright 2012 The Netty Project
 *
 * The Netty Project licenses this file to you under the Apache License,
 * version 2.0 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at:
 *
 *   https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */
package org.apache.hbase.thirdparty.io.netty.channel;

import org.apache.hbase.thirdparty.io.netty.buffer.ByteBuf;
import org.apache.hbase.thirdparty.io.netty.buffer.ByteBufAllocator;
import org.apache.hbase.thirdparty.io.netty.util.Attribute;
import org.apache.hbase.thirdparty.io.netty.util.AttributeKey;
import org.apache.hbase.thirdparty.io.netty.util.AttributeMap;
import org.apache.hbase.thirdparty.io.netty.util.concurrent.EventExecutor;

import java.nio.channels.Channels;

/**
 * Enables a {@link ChannelHandler} to interact with its {@link ChannelPipeline}
 * and other handlers. Among other things a handler can notify the next {@link ChannelHandler} in the
 * {@link ChannelPipeline} as well as modify the {@link ChannelPipeline} it belongs to dynamically.
 *
 * 

Notify

* * You can notify the closest handler in the same {@link ChannelPipeline} by calling one of the various methods * provided here. * * Please refer to {@link ChannelPipeline} to understand how an event flows. * *

Modifying a pipeline

* * You can get the {@link ChannelPipeline} your handler belongs to by calling * {@link #pipeline()}. A non-trivial application could insert, remove, or * replace handlers in the pipeline dynamically at runtime. * *

Retrieving for later use

* * You can keep the {@link ChannelHandlerContext} for later use, such as * triggering an event outside the handler methods, even from a different thread. *
 * public class MyHandler extends {@link ChannelDuplexHandler} {
 *
 *     private {@link ChannelHandlerContext} ctx;
 *
 *     public void beforeAdd({@link ChannelHandlerContext} ctx) {
 *         this.ctx = ctx;
 *     }
 *
 *     public void login(String username, password) {
 *         ctx.write(new LoginMessage(username, password));
 *     }
 *     ...
 * }
 * 
* *

Storing stateful information

* * {@link #attr(AttributeKey)} allow you to * store and access stateful information that is related with a {@link ChannelHandler} / {@link Channel} and its * context. Please refer to {@link ChannelHandler} to learn various recommended * ways to manage stateful information. * *

A handler can have more than one {@link ChannelHandlerContext}

* * Please note that a {@link ChannelHandler} instance can be added to more than * one {@link ChannelPipeline}. It means a single {@link ChannelHandler} * instance can have more than one {@link ChannelHandlerContext} and therefore * the single instance can be invoked with different * {@link ChannelHandlerContext}s if it is added to one or more {@link ChannelPipeline}s more than once. * Also note that a {@link ChannelHandler} that is supposed to be added to multiple {@link ChannelPipeline}s should * be marked as {@link org.apache.hbase.thirdparty.io.netty.channel.ChannelHandler.Sharable}. * *

Additional resources worth reading

*

* Please refer to the {@link ChannelHandler}, and * {@link ChannelPipeline} to find out more about inbound and outbound operations, * what fundamental differences they have, how they flow in a pipeline, and how to handle * the operation in your application. */ public interface ChannelHandlerContext extends AttributeMap, ChannelInboundInvoker, ChannelOutboundInvoker { /** * Return the {@link Channel} which is bound to the {@link ChannelHandlerContext}. */ Channel channel(); /** * Returns the {@link EventExecutor} which is used to execute an arbitrary task. */ EventExecutor executor(); /** * The unique name of the {@link ChannelHandlerContext}.The name was used when then {@link ChannelHandler} * was added to the {@link ChannelPipeline}. This name can also be used to access the registered * {@link ChannelHandler} from the {@link ChannelPipeline}. */ String name(); /** * The {@link ChannelHandler} that is bound this {@link ChannelHandlerContext}. */ ChannelHandler handler(); /** * Return {@code true} if the {@link ChannelHandler} which belongs to this context was removed * from the {@link ChannelPipeline}. Note that this method is only meant to be called from with in the * {@link EventLoop}. */ boolean isRemoved(); @Override ChannelHandlerContext fireChannelRegistered(); @Override ChannelHandlerContext fireChannelUnregistered(); @Override ChannelHandlerContext fireChannelActive(); @Override ChannelHandlerContext fireChannelInactive(); @Override ChannelHandlerContext fireExceptionCaught(Throwable cause); @Override ChannelHandlerContext fireUserEventTriggered(Object evt); @Override ChannelHandlerContext fireChannelRead(Object msg); @Override ChannelHandlerContext fireChannelReadComplete(); @Override ChannelHandlerContext fireChannelWritabilityChanged(); @Override ChannelHandlerContext read(); @Override ChannelHandlerContext flush(); /** * Return the assigned {@link ChannelPipeline} */ ChannelPipeline pipeline(); /** * Return the assigned {@link ByteBufAllocator} which will be used to allocate {@link ByteBuf}s. */ ByteBufAllocator alloc(); /** * @deprecated Use {@link Channel#attr(AttributeKey)} */ @Deprecated @Override Attribute attr(AttributeKey key); /** * @deprecated Use {@link Channel#hasAttr(AttributeKey)} */ @Deprecated @Override boolean hasAttr(AttributeKey key); }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy