Processes a chunk received from a synchronous message.

@param buffer
@param conversation
@param connectionMessage
335171
private void processSyncMessageChunk(CommsByteBuffer buffer, Conversation conversation,
                                        boolean connectionMessage)
   {
      if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc, "processSyncMessageChunk",
                                           new Object[]{buffer, conversation, connectionMessage});

      // First get the ConnectionProxy for this conversation
      ClientConversationState convState = (ClientConversationState) conversation.getAttachment();
      ConnectionProxy connProxy = (ConnectionProxy) convState.getSICoreConnection();
      if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) SibTr.debug(this, tc, "Found connection: ", connProxy);

      // Now read the connection object Id
      buffer.getShort();                                            // BIT16 ConnectionObjId
      if (connectionMessage)
      {
         if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) SibTr.debug(this, tc, "Adding message part directly to connection");
         connProxy.addMessagePart(buffer);
      }
      else
      {
         short consumerSessionId = buffer.getShort();               // BIT16 ConsumerSessionId
         if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) SibTr.debug(this, tc, "Consumer Session Id:", ""+consumerSessionId);

         // Now simply pass the message buffer off to the consumer
         ConsumerSessionProxy consumer = connProxy.getConsumerSessionProxy(consumerSessionId);
         if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) SibTr.debug(this, tc, "Found consumer:", consumer);
         consumer.addMessagePart(buffer);
      }

      if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "processSyncMessageChunk");
   }
153443
@Override
    public void processMessage() {
        // protection check, we definitely don't want double spending here
        INDArray syn0 = storage.getArray(WordVectorStorage.SYN_0);
        INDArray syn1 = storage.getArray(WordVectorStorage.SYN_1);
        INDArray syn1Neg = storage.getArray(WordVectorStorage.SYN_1_NEGATIVE);
        INDArray expTable = storage.getArray(WordVectorStorage.EXP_TABLE);
        if (syn0 == null) {
            log.info("sI_{} is starting initialization...", transport.getShardIndex());

            // we initialize only syn0/syn1/syn1neg and expTable
            // negTable will be initalized at driver level and will be shared via message
            Nd4j.getRandom().setSeed(seed * (shardIndex + 1));

            if (voidConfiguration.getExecutionMode() == ExecutionMode.AVERAGING) {
                // each shard has full own copy
                columnsPerShard = vectorLength;
            } else if (voidConfiguration.getExecutionMode() == ExecutionMode.SHARDED) {
                // each shard will have only part of the data
                if (voidConfiguration.getNumberOfShards() - 1 == shardIndex) {
                    int modulo = vectorLength % voidConfiguration.getNumberOfShards();
                    if (modulo != 0) {
                        columnsPerShard += modulo;
                        log.info("Got inequal split. using higher number of elements: {}", columnsPerShard);
                    }
                }
            }

            int[] shardShape = new int[] {numWords, columnsPerShard};

            syn0 = Nd4j.rand(shardShape, 'c').subi(0.5).divi(vectorLength);

            if (useHs)
                syn1 = Nd4j.create(shardShape, 'c');

            if (useNeg)
                syn1Neg = Nd4j.create(shardShape, 'c');

            // we handle full exp table here
            expTable = initExpTable(100000);


            storage.setArray(WordVectorStorage.SYN_0, syn0);

            if (useHs)
                storage.setArray(WordVectorStorage.SYN_1, syn1);
            if (useNeg)
                storage.setArray(WordVectorStorage.SYN_1_NEGATIVE, syn1Neg);

            storage.setArray(WordVectorStorage.EXP_TABLE, expTable);

            InitializationAggregation ia = new InitializationAggregation((short) voidConfiguration.getNumberOfShards(),
                            transport.getShardIndex());
            ia.setOriginatorId(this.originatorId);
            transport.sendMessage(ia);
        }
    }
89259
public void addSICoreConnection(SICoreConnection conn, Conversation conversation) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(tc, "addSICoreConnection");

        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            SibTr.debug(tc, "Params: connection, conversation",
                        new Object[] { conn, conversation });
        }

        conversationTable.put(conn, conversation);

        // At this point, if the me has previously been terminated, we know it is
        // back up - so make sure we remove if from our quiesce and terminated table
        // so that if it goes down again, we can notify the clients.
        quiesceNotif.remove(conn.getMeUuid());
        termNotif.remove(conn.getMeUuid());

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "addSICoreConnection");
    }
583326
private void dumpServerConversation(IncidentStream is, Conversation conv)
   {
      if(TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc, "dumpServerConversation", new Object[]{is, conv});
      
      final ConversationState convState = (ConversationState) conv.getAttachment();
      
      final List allObjs = convState.getAllObjects();
      is.writeLine("Number of associated resources", allObjs.size());
      
      for (final Iterator i2 = allObjs.iterator(); i2.hasNext();)
      {
         final Object obj = i2.next();
         if (obj instanceof SICoreConnection)
         {
            final SICoreConnection conn = (SICoreConnection) obj;
            is.writeLine("  ", 
                         "SICoreConnection@" + Integer.toHexString(obj.hashCode()) + ": " +
                         "ME Name: " + conn.getMeName() + " [" + conn.getMeUuid() + "] " +
                         "Version: " + conn.getApiLevelDescription());
         }
         else
         {
            is.writeLine("  ", obj);
         }         
      }
      
      if(TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "dumpServerConversation");
   }
743729
protected void clientMessageHandler(DirectBuffer buffer, int offset, int length, Header header) {
        /**
         *  All incoming messages here are supposed to be "just messages", only unicast communication
         *  All of them should implement MeaningfulMessage interface
         */
        // TODO: to be implemented
        //  log.info("clientMessageHandler message request incoming");

        byte[] data = new byte[length];
        buffer.getBytes(offset, data);

        MeaningfulMessage message = (MeaningfulMessage) VoidMessage.fromBytes(data);
        completed.put(message.getTaskId(), message);
    }
704609
protected synchronized void reset(Connection connection,
                        ReceiveListener listener,
                        WsByteBuffer data,
                        int size,
                        int segmentType,
                        int requestNumber,
                        int priority,
                        boolean allocatedFromPool,
                        boolean partOfExchange,
                        Conversation conversation)
   {
      if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc, "reset",
                                           new Object[]
                                           {
                                              connection,
                                              listener,
                                              data,
                                              ""+size,
                                              ""+segmentType,
                                              ""+requestNumber,
                                              ""+priority,
                                              ""+allocatedFromPool,
                                              ""+partOfExchange,
                                              conversation
                                           });

      this.connection = connection;
      this.listener = listener;
      this.data = data;
      this.size = size;
      this.segmentType = segmentType;
      this.requestNumber = requestNumber;
      this.priority = priority;
      this.allocatedFromPool = allocatedFromPool;
      this.partOfExchange = partOfExchange;
      this.conversation = conversation;
      setDispatchable(null);

      if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "reset");
   }
860175
protected void putToRingBuffer(IQueueMessage<ID, DATA> msg) throws QueueException.QueueIsFull {
        if (msg == null) {
            throw new NullPointerException("Supplied queue message is null!");
        }
        LOCK_PUT.lock();
        try {
            if (!ringBuffer.tryPublishEvent((event, _seq) -> {
                event.set(msg);
                knownPublishedSeq = _seq > knownPublishedSeq ? _seq : knownPublishedSeq;
            })) {
                throw new QueueException.QueueIsFull(getRingSize());
            }
        } finally {
            LOCK_PUT.unlock();
        }
    }
812900
void processAck(Message msg) {
        PubAck pa;
        Exception ex = null;
        try {
            pa = PubAck.parseFrom(msg.getData());
        } catch (InvalidProtocolBufferException e) {
            // If we are speaking to a server we don't understand, let the
            // user know.
            System.err.println("Protocol error: " +  e.getStackTrace());
            return;
        }

        // Remove
        AckClosure ackClosure = removeAck(pa.getGuid());
        if (ackClosure != null) {
            // Capture error if it exists.
            String ackError = pa.getError();

            if (ackClosure.ah != null) {
                if (!ackError.isEmpty()) {
                    ex = new IOException(ackError);
                }
                // Perform the ackHandler callback
                ackClosure.ah.onAck(pa.getGuid(), ex);
            } else if (ackClosure.ch != null) {
                try {
                    ackClosure.ch.put(ackError);
                } catch (InterruptedException e) {
                    // ignore
                }
            }
        }
    }
240986
private void receiveMessage(ClientSocket client, DataInputStream buffer, byte from, StateConnection expected)
            throws IOException
    {
        if (ServerImpl.checkValidity(client, from, expected))
        {
            final byte dest = buffer.readByte();
            final byte type = buffer.readByte();
            final int size = buffer.readInt();
            if (size > 0)
            {
                final byte[] clientData = new byte[size];
                if (buffer.read(clientData) != -1) // CHECKSTYLE IGNORE LINE: TrailingComment|NestedIfDepth
                {
                    final DataInputStream clientBuffer = new DataInputStream(new ByteArrayInputStream(clientData));
                    decodeMessage(type, from, dest, clientBuffer);
                }
            }
            final int headerSize = 4;
            bandwidth += headerSize + size;
        }
    }
257811
@Override
    public void processConnect(WebSocketChannel channel, WSURI uri, String[] protocols) {
        LOG.entering(CLASS_NAME, "connect", channel);
        
        if (((WebSocketSelectedChannel)channel).readyState == ReadyState.CLOSED) {
            throw new IllegalStateException("WebSocket is already closed");
        }
        
        nextHandler.processConnect(channel, uri, protocols);
    }
849893
protected void decodeMessage(byte type, byte from, byte dest, DataInputStream buffer) throws IOException
    {
        final NetworkMessage message = decoder.getNetworkMessageFromType(type);
        if (message != null)
        {
            final int skip = 3;
            if (buffer.skipBytes(skip) == skip)
            {
                message.decode(type, from, dest, buffer);
                messagesIn.add(message);
            }
        }
    }
157740
public void queueErrorOccurredInvocation(Connection connection,
                                               ConversationReceiveListener listener,
                                               SIConnectionLostException exception,
                                               int segmentType,
                                               int requestNumber,
                                               int priority,
                                               Conversation conversation)
   {
      if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc, "queueErrorOccurredInvocation", new Object[] {connection, listener, exception, ""+segmentType, ""+requestNumber, ""+priority, conversation});

      AbstractInvocation invocation =
         allocateErrorOccurredInvocation(connection,
                                         listener,
                                         exception,
                                         segmentType,
                                         requestNumber,
                                         priority,
                                         conversation);

      // Start F201521
      // We don't always want to queue this as it could end up on some random thread.
      // As such, ask the conversation how many things it has left to process - if that
      // is 0, then queue it - otherwise, save it in the Conversation so that the last
      // thread working on that Conversatioon will invoke it.
      ConversationImpl convImpl = (ConversationImpl) conversation;

      int conversationRequestCount = 0;
      // Start D262285
      boolean queueIt = true;
      synchronized (convImpl.getTotalOutstandingRequestCountLock())
      {
         if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) SibTr.debug(this, tc, "Queueing a errorOccurred invocation for ", conversation);
         conversationRequestCount = convImpl.getTotalOutstandingRequestCount();
         if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) SibTr.debug(tc, "Request count is: " + conversationRequestCount);

         if (conversationRequestCount != 0)
         {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) SibTr.debug(this, tc, "Count != 0, saving");
            convImpl.setErrorOccurredInvocation(invocation);
            queueIt = false;
         }
      }

      if (queueIt)
      {
         if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) SibTr.debug(this, tc, "Count = 0, queueing");
         queueInvocationCommon(invocation, convImpl);
      }
      // End D262285
      // End F201521

      if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "queueErrorOccurredInvocation");
   }
841200
void messageReceived(MessagePacket packet) {
        if (!getCluster().isMaster())
            return;
        LOG.debug("Received packet {}", packet);

        final long now = System.nanoTime();
        packet.setTimestamp(now);

        final short node = packet.getNode();
        final NodePeer peer = peers.get(node);
        if (peer == null)
            throw new RuntimeException("Message received from unhandled node " + node);

        try {
            peer.receivePacket(packet); // we're now running in the executor we installed in the netty pipeline.
        } catch (InterruptedException ex) {
            LOG.error("InterruptedException", ex);
            throw new RuntimeException(ex);
        }
    }
1263786
public void processReceivedMessage( Message message, Session session ) throws IOException {
		this.logger.fine( "The DM's HTTP client is about to process a message (" + message + ") received through a web socket." );

		// HttpMessage
		if( message instanceof HttpMessage ) {
			HttpMessage httpMsg = (HttpMessage) message;

			// Store the session
			registerSession( httpMsg.getOwnerId(), session );

			// Publish the message
			publish( httpMsg.getCtx(), httpMsg.getMessage());
		}

		// Subscription message
		else if( message instanceof SubscriptionMessage ) {
			SubscriptionMessage sub = (SubscriptionMessage) message;

			// Store the session
			registerSession( sub.getOwnerId(), session );

			// Update the subscriptions
			if( sub.isSubscribe())
				subscribe( sub.getOwnerId(), sub.getCtx());
			else
				unsubscribe( sub.getOwnerId(), sub.getCtx());
		}
	}
1129884
public void messageReceived(NextFilter nextFilter, ByteBuffer buf) throws SSLException {
        // append buf to inNetBuffer
        if (inNetBuffer == null) {
            inNetBuffer = allocator.wrap(allocator.allocate(buf.remaining())).setAutoExpander(allocator);
        }

        inNetBuffer.put(buf);
        if (!handshakeComplete) {
            handshake(nextFilter);
        }

        // Application data will be in the same message as the handshake
        // during False Start
        if (handshakeComplete) {
            decrypt(nextFilter);
        }

        if (isInboundDone()) {
            // Rewind the MINA buffer if not all data is processed and inbound is finished.
            int inNetBufferPosition = inNetBuffer == null? 0 : inNetBuffer.position();
            buf.position(buf.position() - inNetBufferPosition);
            inNetBuffer = null;
        }
    }
796043
@Override
	public void processMessage(WebSocketMessage webSocketData) throws FrameworkException {

		setDoTransactionNotifications(true);

		final String mode                     = webSocketData.getNodeDataStringValue("mode");		// default: list    start | pause | resume | cancel | abort
		final Long jobId                      = webSocketData.getNodeDataLongValue("jobId");

		final JobQueueManager mgr = JobQueueManager.getInstance();

		final List<GraphObject> result = new LinkedList<>();

		switch (mode) {

			case "start":
				mgr.startJob(jobId);
				break;

			case "pause":
				mgr.pauseRunningJob(jobId);
				break;

			case "resume":
				mgr.resumePausedJob(jobId);
				break;

			case "abort":
				mgr.abortActiveJob(jobId);
				break;

			case "cancel":
				mgr.cancelQueuedJob(jobId);
				break;

			case "list":
			default:
				final GraphObjectMap importsContainer = new GraphObjectMap();

				importsContainer.put(importJobsProperty, mgr.listJobs());
				result.add(importsContainer);
		}

			webSocketData.setResult(result);
			webSocketData.setRawResultCount(1);
			getWebSocket().send(webSocketData, true);

	}
25632
private void send(final byte[] buffer, final Object destination) {
        if (LOG.isTraceEnabled()) {
            LOG.trace("Sending from thread: id: " + Thread.currentThread().getName() + ", name: "
                    + Thread.currentThread().getName());
        }

        final WsOutbound outbound = ((MessageInbound) destination).getWsOutbound();

        final ExecutorService executorService = connectionThreads.get(destination);
        // execute asynchronously to avoid slower clients from interfering with faster clients
        executorService.execute(new Runnable() {
            @Override
            public void run() {
                try {
                    outbound.writeBinaryMessage(ByteBuffer.wrap(buffer));
                } catch (final IOException e) {
                    LOG.warn("Sending data to a client failed. Closing connection to this client.");
                    try {
                        outbound.close(1002, null);
                        // CHECKSTYLE:OFF
                    } catch (final IOException e1) {
                        // Maybe the connection is already closed. This is no exceptional state but rather the
                        // default in
                        // this case. So it's safe to ignore this exception.
                    }
                    // CHECKSTYLE:ON
                    connectionCloses((SynchronizeFXTomcatConnection) destination);
                }
            }
        });
    }