Exemplo n.º 1
0
        private void WriteCurrentChunk()
        {
            if (!_channel.Open || !_channel.Connected || !_channel.Bound)
            {
                throw new ComException("Channel has been closed, so no need to try to write to it anymore. Client closed it?");
            }

            WaitForClientToCatchUpOnReadingChunks();
            ChannelFuture future = _channel.write(_buffer);

            future.addListener(NewChannelFutureListener(_buffer));
            _writeAheadCounter.incrementAndGet();
        }
Exemplo n.º 2
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
//ORIGINAL LINE: private synchronized void send(final org.neo4j.cluster.com.message.Message message)
        private void Send(Message message)
        {
            lock (this)
            {
                _monitor.queuedMessage(message);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.net.URI to = java.net.URI.create(message.getHeader(org.neo4j.cluster.com.message.Message.HEADER_TO));
                URI to = URI.create(message.getHeader(Message.HEADER_TO));

                ExecutorService senderExecutor = _senderExecutors.computeIfAbsent(to, t => Executors.newSingleThreadExecutor(new NamedThreadFactory("Cluster Sender " + t.toASCIIString(), _monitor)));

                senderExecutor.submit(() =>
                {
                    Channel channel = GetChannel(to);

                    try
                    {
                        if (channel == null)
                        {
                            channel = OpenChannel(to);
                            OpenedChannel(to, channel);

                            // Instance could be connected to, remove any marker of it being failed
                            _failedInstances.remove(to);
                        }
                    }
                    catch (Exception e)
                    {
                        // Only print out failure message on first fail
                        if (!_failedInstances.Contains(to))
                        {
                            _msgLog.warn(e.Message);
                            _failedInstances.Add(to);
                        }

                        return;
                    }

                    try
                    {
                        // Set HEADER_FROM header
                        message.setHeader(Message.HEADER_FROM, _me.toASCIIString());

                        _msgLog.debug("Sending to " + to + ": " + message);

                        ChannelFuture future = channel.write(message);
                        future.addListener(future1 =>
                        {
                            _monitor.sentMessage(message);

                            if (!future1.Success)
                            {
                                _msgLog.debug("Unable to write " + message + " to " + future1.Channel, future1.Cause);
                                ClosedChannel(future1.Channel);

                                // Try again
                                Send(message);
                            }
                        });
                    }
                    catch (Exception e)
                    {
                        if (Exceptions.contains(e, typeof(ClosedChannelException)))
                        {
                            _msgLog.warn("Could not send message, because the connection has been closed.");
                        }
                        else
                        {
                            _msgLog.warn("Could not send message", e);
                        }
                        channel.close();
                    }
                });
            }
        }