List of usage examples for io.netty.channel ChannelHandlerContext attr
@Deprecated @Override <T> Attribute<T> attr(AttributeKey<T> key);
From source file:com.tesora.dve.db.mysql.portal.MSPComPrepareStmtRequest.java
License:Open Source License
@Override public void execute(ExecutorService clientExecutorService, ChannelHandlerContext ctx, SSConnection ssCon, MSPMessage protocolMessage) throws PEException { MSPComPrepareStmtRequestMessage prepareRequest = castProtocolMessage(MSPComPrepareStmtRequestMessage.class, protocolMessage);// w w w.j av a 2 s.com byte[] query = prepareRequest.getPrepareBytes(); MyPrepStmtConnectionContext mpscc = ctx.attr(MyPrepStmtConnectionContext.PSTMT_CONTEXT_KEY).get(); if (mpscc == null) { mpscc = new MyPrepStmtConnectionContext(ssCon); ctx.attr(MyPrepStmtConnectionContext.PSTMT_CONTEXT_KEY).set(mpscc); } MyPreparedStatement<String> pStmt = new MyPreparedStatement<String>(null); pStmt.setQuery(query); mpscc.addPreparedStatement(pStmt); NativeCharSet clientCharSet = MysqlNativeCharSet.UTF8; MysqlPrepareStatementForwarder resultConsumer = new MysqlPrepareStatementForwarder(ctx, pStmt); try { PrepareRequestExecutor.execute(ssCon, resultConsumer, pStmt.getStmtId(), clientCharSet.getJavaCharset(), query); } catch (PEException e) { if (logger.isDebugEnabled()) logger.warn("Reducing exception for user - original exception: ", e); resultConsumer.sendError(e.rootCause()); } catch (Throwable t) { logger.warn("Reducing exception for user - original exception: ", t); resultConsumer.sendError(new Exception(t)); } }
From source file:com.tesora.dve.db.mysql.portal.MSPComStmtCloseRequest.java
License:Open Source License
@Override public void execute(ExecutorService clientExecutorService, ChannelHandlerContext ctx, SSConnection ssCon, MSPMessage protocolMessage) throws PEException { MSPComStmtCloseRequestMessage stmtCloseMessage = castProtocolMessage(MSPComStmtCloseRequestMessage.class, protocolMessage);/*from w w w . j a v a 2s . c om*/ Long stmtId = stmtCloseMessage.getStatementID(); MyPrepStmtConnectionContext mpscc = ctx.attr(MyPrepStmtConnectionContext.PSTMT_CONTEXT_KEY).get(); MyPreparedStatement<String> pStmt = mpscc.getPreparedStatement(stmtId); if (pStmt == null) { throw new PEException( "A prepared statement with id " + stmtId + " could not be found in the connection's context"); } mpscc.removePreparedStatement(stmtId); QueryPlanner.destroyPreparedStatement(ssCon, Long.toString(stmtId)); }
From source file:com.tesora.dve.db.mysql.portal.MSPComStmtExecuteRequest.java
License:Open Source License
@Override public void execute(ExecutorService clientExecutorService, ChannelHandlerContext ctx, SSConnection ssCon, MSPMessage protocolMessage) throws PEException { MSPComStmtExecuteRequestMessage executeMessage = castProtocolMessage(MSPComStmtExecuteRequestMessage.class, protocolMessage);/*w ww .ja va 2s . c o m*/ long stmtId = executeMessage.getStatementID(); // Get the prepared statement and copy the parameters from the // packet MyPrepStmtConnectionContext mpscc = ctx.attr(MyPrepStmtConnectionContext.PSTMT_CONTEXT_KEY).get(); MyPreparedStatement<String> pStmt = mpscc.getPreparedStatement(stmtId); if (pStmt == null) { throw new PEException( "A prepared statement with id " + stmtId + " could not be found in the connection's context"); } MysqlSyntheticPreparedResultForwarder resultConsumer = new MysqlSyntheticPreparedResultForwarder(ctx); try { Timer readMetaTimer = timingService.startSubTimer(TimingDesc.FRONTEND_STMT_EXEC_DECODE_META); executeMessage.readParameterMetadata(pStmt); // Execute the statement with the last parameters List<Object> params = new ArrayList<Object>(pStmt.getNumParams()); for (MyParameter mp : pStmt.getParameters()) params.add((mp.getValue() == null ? null : mp.getValueForQuery())); readMetaTimer.end(); ExecutePreparedStatementRequestExecutor.execute(ssCon, pStmt.getStmtId(), params, resultConsumer); resultConsumer.sendSuccess(ssCon); } catch (PEException e) { if (logger.isDebugEnabled()) logger.warn("Reducing exception for user - original exception: ", e); resultConsumer.sendError(e.rootCause()); } catch (Throwable t) { logger.warn("Reducing exception for user - original exception: ", t); resultConsumer.sendError(new Exception(t)); } }
From source file:com.tesora.dve.server.connectionmanager.loaddata.LoadDataBlockExecutor.java
License:Open Source License
public static List<List<byte[]>> processDataBlock(ChannelHandlerContext ctx, SSConnection connMgr, byte[] dataBlock) throws Throwable { MyLoadDataInfileContext loadDataInfileContext = ctx .attr(MyLoadDataInfileContext.LOAD_DATA_INFILE_CONTEXT_KEY).get(); if (loadDataInfileContext == null) { throw new PEException( "Cannot process Load Data Infile data block because load data infile context is missing."); }/* w ww. jav a 2 s . c om*/ //TODO: this is the only place we touch the session during the parse. As long as this isn't sensitive to being in the session context, we can move the decode into the netty thread. -sgossard if (loadDataInfileContext.getCharset() == null) { loadDataInfileContext .setCharset(KnownVariables.CHARACTER_SET_CLIENT.getSessionValue(connMgr).getJavaCharset()); } if (logger.isDebugEnabled()) { logger.debug("Processing datablock: line prefix[" + loadDataInfileContext.getLineOption().getStarting() + "], line term[" + loadDataInfileContext.getLineOption().getTerminated() + "], col enclosed[" + loadDataInfileContext.getColOption().getEnclosed() + "], col escaped[" + loadDataInfileContext.getColOption().getEscaped() + "], col term[" + loadDataInfileContext.getColOption().getTerminated() + "]"); // logger.debug("Processing datablock: data[" + query + "]" ); } byte[] newDataBlock = appendPartialBlockData(loadDataInfileContext, dataBlock); LoadDataBlockParser parser = new LoadDataBlockParser(loadDataInfileContext); parser.parse(newDataBlock); // determine partial block if (dataBlock.length > 0) { int lastlineindex = parser.getLastLineEndIndex(); loadDataInfileContext.appendPartialInfileDataBlock( ArrayUtils.subarray(newDataBlock, lastlineindex, newDataBlock.length)); parser.getRows().remove(parser.getRows().size() - 1); } return parser.getRows(); }
From source file:com.tesora.dve.server.connectionmanager.loaddata.LoadDataBlockExecutor.java
License:Open Source License
public static void executeInsert(ChannelHandlerContext ctx, SSConnection connMgr, List<List<byte[]>> rows) throws Throwable { MyLoadDataInfileContext loadDataInfileContext = ctx .attr(MyLoadDataInfileContext.LOAD_DATA_INFILE_CONTEXT_KEY).get(); if (loadDataInfileContext == null) { throw new PEException( "Cannot process Load Data Infile data block because load data infile context is missing."); }/*from w ww . ja v a 2s. c om*/ if (loadDataInfileContext.getCharset() == null) { loadDataInfileContext .setCharset(KnownVariables.CHARACTER_SET_CLIENT.getSessionValue(connMgr).getJavaCharset()); } List<Object> params = new ArrayList<Object>(); int targetNumTuples = rows.size(); int currentTupleCount = 1; for (List<byte[]> cols : rows) { if (cols.size() == 0) continue; buildInsertStatement(loadDataInfileContext, cols, params); if (optimalTuples(loadDataInfileContext, targetNumTuples, currentTupleCount)) { MyPreparedStatement<String> pStmt = loadDataInfileContext.getPreparedStatement(currentTupleCount); if (pStmt == null) { throw new PEException("A prepared statement with no id found in the connection's context"); } MysqlSyntheticPreparedResultForwarder resultConsumer = new MysqlSyntheticPreparedResultForwarder( ctx); ExecutePreparedStatementRequestExecutor.execute(connMgr, pStmt.getStmtId(), params, resultConsumer); loadDataInfileContext.incrementRowsAffected(resultConsumer.getNumRowsAffected()); loadDataInfileContext.incrementInfileWarnings(resultConsumer.getWarnings()); targetNumTuples -= currentTupleCount; params.clear(); currentTupleCount = 0; } currentTupleCount++; } }
From source file:com.vmware.dcp.common.http.netty.NettyHttpClientRequestHandler.java
License:Open Source License
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { Operation op = ctx.attr(NettyChannelContext.OPERATION_KEY).get(); if (op != null) { this.host.log(Level.SEVERE, "Listener channel exception: %s, in progress op: %s", cause.getMessage(), op.toString());/*from ww w .j a v a 2s . c om*/ } ctx.channel().attr(NettyChannelContext.OPERATION_KEY).remove(); ctx.close(); }
From source file:com.xx_dev.apn.proxy.ApnProxySchemaHandler.java
License:Apache License
@Override public void channelRead(ChannelHandlerContext uaChannelCtx, final Object msg) throws Exception { if (msg instanceof HttpRequest) { HttpRequest httpRequest = (HttpRequest) msg; String originalHost = HostNamePortUtil.getHostName(httpRequest); int originalPort = HostNamePortUtil.getPort(httpRequest); ApnProxyRemote apnProxyRemote = ApnProxyRemoteChooser.chooseRemoteAddr(originalHost, originalPort); Channel uaChannel = uaChannelCtx.channel(); ApnProxyConnectionAttribute apnProxyConnectionAttribute = ApnProxyConnectionAttribute.build( uaChannel.remoteAddress().toString(), httpRequest.getMethod().name(), httpRequest.getUri(), httpRequest.getProtocolVersion().text(), httpRequest.headers().get(HttpHeaders.Names.USER_AGENT), apnProxyRemote); uaChannelCtx.attr(ApnProxyConnectionAttribute.ATTRIBUTE_KEY).set(apnProxyConnectionAttribute); uaChannel.attr(ApnProxyConnectionAttribute.ATTRIBUTE_KEY).set(apnProxyConnectionAttribute); if (httpRequest.getMethod().equals(HttpMethod.CONNECT)) { if (uaChannelCtx.pipeline().get(ApnProxyUserAgentForwardHandler.HANDLER_NAME) != null) { uaChannelCtx.pipeline().remove(ApnProxyUserAgentForwardHandler.HANDLER_NAME); }/* w w w.ja v a 2 s.com*/ if (uaChannelCtx.pipeline().get(ApnProxyUserAgentTunnelHandler.HANDLER_NAME) == null) { uaChannelCtx.pipeline().addLast(ApnProxyUserAgentTunnelHandler.HANDLER_NAME, new ApnProxyUserAgentTunnelHandler()); } } else { if (uaChannelCtx.pipeline().get(ApnProxyUserAgentForwardHandler.HANDLER_NAME) == null) { uaChannelCtx.pipeline().addLast(ApnProxyUserAgentForwardHandler.HANDLER_NAME, new ApnProxyUserAgentForwardHandler()); } } } LoggerUtil.debug(logger, uaChannelCtx.attr(ApnProxyConnectionAttribute.ATTRIBUTE_KEY), "UA msg", msg); uaChannelCtx.fireChannelRead(msg); }
From source file:com.xx_dev.apn.proxy.ApnProxyUserAgentForwardHandler.java
License:Apache License
@Override public void channelInactive(ChannelHandlerContext uaChannelCtx) throws Exception { if (logger.isDebugEnabled()) { logger.debug("UA channel: inactive" + uaChannelCtx.attr(ApnProxyConnectionAttribute.ATTRIBUTE_KEY)); }/*from www.ja va 2 s. c o m*/ LoggerUtil.debug(logger, uaChannelCtx.attr(ApnProxyConnectionAttribute.ATTRIBUTE_KEY), "UA channel inactive"); for (Map.Entry<String, Channel> entry : remoteChannelMap.entrySet()) { final Channel remoteChannel = entry.getValue(); remoteChannel.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { remoteChannel.close(); } }); } }
From source file:com.xx_dev.apn.proxy.ApnProxyUserAgentForwardHandler.java
License:Apache License
@Override public void exceptionCaught(ChannelHandlerContext uaChannelCtx, Throwable cause) throws Exception { logger.error(cause.getMessage() + " " + uaChannelCtx.attr(ApnProxyConnectionAttribute.ATTRIBUTE_KEY), cause);/*from w w w .ja v a 2 s .c o m*/ uaChannelCtx.close(); }
From source file:com.xx_dev.apn.proxy.ApnProxyUserAgentTunnelHandler.java
License:Apache License
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { LoggerUtil.error(logger, cause.getMessage(), cause, ctx.attr(ApnProxyConnectionAttribute.ATTRIBUTE_KEY)); ctx.close();//from w ww . jav a2 s . c om }