com.yahoo.imapnio.async.netty.ImapClientConnectHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of imapnio.core Show documentation
Show all versions of imapnio.core Show documentation
imapnio component ${project.name}
The newest version!
package com.yahoo.imapnio.async.netty;
import java.net.UnknownHostException;
import java.time.Clock;
import java.util.List;
import javax.annotation.Nonnull;
import org.slf4j.Logger;
import com.sun.mail.imap.protocol.IMAPResponse;
import com.yahoo.imapnio.async.client.ImapAsyncCreateSessionResponse;
import com.yahoo.imapnio.async.client.ImapAsyncSession.DebugMode;
import com.yahoo.imapnio.async.client.ImapFuture;
import com.yahoo.imapnio.async.exception.ImapAsyncClientException;
import com.yahoo.imapnio.async.exception.ImapAsyncClientException.FailureType;
import com.yahoo.imapnio.async.internal.ImapAsyncSessionImpl;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.ConnectTimeoutException;
import io.netty.handler.codec.MessageToMessageDecoder;
import io.netty.handler.timeout.IdleState;
import io.netty.handler.timeout.IdleStateEvent;
/**
* This class handles the business logic of how to process messages and handle events.
*/
public class ImapClientConnectHandler extends MessageToMessageDecoder {
/** Literal for the name registered in pipeline. */
public static final String HANDLER_NAME = "ImapClientConnectHandler";
/** Future for the created session. */
private ImapFuture sessionCreatedFuture;
/** Logger instance. */
private Logger logger;
/** Logging option for this session. */
private DebugMode logOpt;
/** Session Id. */
private long sessionId;
/** Clock instance. */
private Clock clock;
/** Context for session information, its toString() method will be called to be used for logging and exception getMessage(). */
private Object sessionCtx;
/**
* Initializes {@link ImapClientConnectHandler} to process ok greeting after connection.
*
* @param clock The Clock instance
* @param sessionFuture imap session future, should be set to done once ok is received
* @param logger the {@link Logger} instance for @{ImapAsyncSessionImpl}
* @param logOpt logging option for the session to be created
* @param sessionId the session id
* @param sessionCtx context for the session information, its toString() method will be called to be used for logging and exception getMessage()
*/
public ImapClientConnectHandler(@Nonnull final Clock clock, @Nonnull final ImapFuture sessionFuture,
@Nonnull final Logger logger, @Nonnull final DebugMode logOpt, final long sessionId, @Nonnull final Object sessionCtx) {
this.sessionCreatedFuture = sessionFuture;
this.logger = logger;
this.logOpt = logOpt;
this.sessionId = sessionId;
this.sessionCtx = sessionCtx;
this.clock = clock;
}
/**
* Closes the connection.
*
* @param ctx the ChannelHandlerContext
*/
private void close(final ChannelHandlerContext ctx) {
if (ctx.channel().isActive()) {
// closing the channel if server is still active
ctx.close();
}
}
@Override
public void decode(final ChannelHandlerContext ctx, final IMAPResponse serverResponse, final List
© 2015 - 2024 Weber Informatics LLC | Privacy Policy