scheduleConnect(NO_DELAY_MS); int messageBatchSize = ObjectReader.getInt(topoConf.get(Config.STORM_NETTY_MESSAGE_BATCH_SIZE), 262144); batcher = new MessageBuffer(messageBatchSize); String clazz = (String) topoConf.get(Config.TOPOLOGY_BACKPRESSURE_WAIT_STRATEGY); if (clazz == null) {
/** * Called by Netty thread on change in channel interest * @param channel */ public void notifyInterestChanged(Channel channel) { if(channel.isWritable()){ synchronized (writeLock) { // Channel is writable again, write if there are any messages pending MessageBatch pending = batcher.drain(); flushMessages(channel, pending); } } }
private final DataInputStream in; try { while (!disconnected) { int length = in.readShort() & 0xFFFF; byte[] msgBytes = new byte[length]; in.readFully(msgBytes); // keeps reading until the whole buffer is read. try { MessageBuffer buf = new MessageBuffer(msgBytes); handleApplicationMessage(buf); } catch (Exception ex) { ex.printStackTrace(); } } } catch (EOFException expected) { } catch (Throwable t) { System.err.println("Fatal error"); t.printStackTrace(); }
@SuppressWarnings("rawtypes") Client(Map stormConf, ChannelFactory factory, HashedWheelTimer scheduler, String host, int port, Context context) { this.stormConf = stormConf; closing = false; this.scheduler = scheduler; this.context = context; int bufferSize = Utils.getInt(stormConf.get(Config.STORM_MESSAGING_NETTY_BUFFER_SIZE)); // if SASL authentication is disabled, saslChannelReady is initialized as true; otherwise false saslChannelReady.set(!Utils.getBoolean(stormConf.get(Config.STORM_MESSAGING_NETTY_AUTHENTICATION), false)); LOG.info("creating Netty Client, connecting to {}:{}, bufferSize: {}", host, port, bufferSize); int messageBatchSize = Utils.getInt(stormConf.get(Config.STORM_NETTY_MESSAGE_BATCH_SIZE), 262144); int maxReconnectionAttempts = Utils.getInt(stormConf.get(Config.STORM_MESSAGING_NETTY_MAX_RETRIES)); int minWaitMs = Utils.getInt(stormConf.get(Config.STORM_MESSAGING_NETTY_MIN_SLEEP_MS)); int maxWaitMs = Utils.getInt(stormConf.get(Config.STORM_MESSAGING_NETTY_MAX_SLEEP_MS)); retryPolicy = new StormBoundedExponentialBackoffRetry(minWaitMs, maxWaitMs, maxReconnectionAttempts); // Initiate connection to remote destination bootstrap = createClientBootstrap(factory, bufferSize, stormConf); dstHost = host; dstAddress = new InetSocketAddress(host, port); dstAddressPrefixedName = prefixedName(dstAddress); launchChannelAliveThread(); scheduleConnect(NO_DELAY_MS); batcher = new MessageBuffer(messageBatchSize); }