/*
(non-Javadoc)

@see javax.jms.JMSConsumer#receive()
355089
@Override
    public Message receive() throws JMSRuntimeException {

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "receive");

        try {
            return receive(0);
        } finally {
            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                SibTr.exit(this, tc, "receive");
        }
    }
299623
private Message receiveInboundMessage(boolean waiting, long timeout) throws JMSException {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "receiveInboundMessage", new Object[] { waiting, timeout });
        Message msg = null;
        String bus = null;
        String destName = null;
        SIBusMessage coreMsg = null;

        SITransaction st = session.getTransaction();

        // 304501.api Check for XD pacing
        MessagePacingControl mpc = MessagePacingControlFactory.getInstance();
        if (mpc != null && mpc.isActive()) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                SibTr.debug(this, tc, "about to call preSynchReceive");
            Object context = coreConsumerSession;
            bus = coreConsumerSession.getDestinationAddress().getBusName();
            if (bus == null)
                bus = defaultBusName; // Default to the value from the connection factory
            destName = coreConsumerSession.getDestinationAddress().getDestinationName();
            if (waiting) {
                timeout = mpc.preSynchReceive(bus, destName, context, timeout);
            }
            else {
                mpc.preSynchReceive(bus, destName, context, -1);
            }
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                SibTr.debug(this, tc, "preSynchReceive complete");
        }

        try {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                SibTr.debug(this, tc, "About to call receive method; transaction: " + st + (waiting ? " timeout: " + timeout : ""));
                // Put a big warning in if they have called receive without starting
                // the connection.
                // This won't cause a problem if the connection is started before the timeout
                // elapses, but in 90% of cases is caused by a rookie programming error because
                // they have forgotton to start the application at all - then they wonder why
                // no messages are received. (Note that you can still send messages - just not
                // receive them).
                if (session.getState() != STARTED) {
                    SibTr.debug(this, tc, "WARNING - APPLICATION CALLED RECEIVE BUT CONNECTION IS NOT STARTED");
                }
            }

            // We now branch depending on which of the two core receive
            // calls we are interested in.
            if (waiting) {
                // This is a get with timeout, or infinite wait
                coreMsg = coreConsumerSession.receiveWithWait(st, timeout);

                // d248044 Provide a warning if receive(wait) returns null on a stopped connection
                if (coreMsg == null && session.getState() != STARTED) {
                    // Find the stack entry of the caller of the receive method.
                    // d386440 - in some cases it seems that the first line of the stack can
                    //   be for the Throwable constructor, which throws off the fixed-offset
                    //   approach, and means we quote a line reference the JmsMsgConsumerImpl
                    //   class. This approach checks when we leave the JMS package.
                    String caller = JmsErrorUtils.getFirstApplicationStackString();
                    SibTr.warning(tc, "MC_CONN_STOPPED_CWSIA0087", caller);
                }
            }
            else {
                // This is a get with no wait.
                coreMsg = coreConsumerSession.receiveNoWait(st);

            }

            // Convert the core message to a JMS version - pass the session's 'pass thru props' so certain
            // properties will be associated with the message (SIB0121)
            msg = JmsInternalsFactory.getSharedUtils().inboundMessagePath(coreMsg, session, session.getPassThruProps());

            if (msg != null) {
                if (((JmsMessageImpl) msg).getMsgReference().getJmsDestination() == null) {
                    // The received message did not come from JMS (or had the JmsDestination field
                    // deliberately excluded).
                    JmsDestinationImpl dest = (JmsDestinationImpl) props.getJmsDestination();
                    if (!dest._getInhibitJMSDestination()) {
                        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                            SibTr.debug(this, tc, "This message was not sent by a JMS client, and so has no JmsDestination field set. Setting it to: "
                                                  + props.getJmsDestination().getDestName());
                        msg.setJMSDestination(dest);
                    }
                }
            }

            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                SibTr.debug(this, tc, "sessionAckMode : " + sessionAckMode);

            // This handles the commit of transaction for dups ok, and keeping a
            // tally of the number uncommitted messages received.
            // Optimise to call only if transaction is non-null, because we know
            // that it does nothing if it is null.
            if ((msg != null) && (st != null)) {
                session.notifyMessageConsumed(st);
            }
        } catch (SISessionUnavailableException oce) {
            // No FFDC code needed
            // This is normal if blocking receive is interrupted by close().
            // Trace and discard, will return null from this method.
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                SibTr.debug(this, tc, "caught SISessionUnavailableException: " + oce);
            // We do need to ensure this consumer is marked as closed, as we
            // may also enter this block if the ME becomes unavailable (but the
            // server stays active). PK53368
            close();

            // There is one known case where an SISessionUnavailableException
            // exception is thrown for a reason that we do need to report
            // to the user. This is when the receiver is created against a
            // destination that is stricly ordered, and there is an indoubt
            // transaction on that destination that prevents the consumer
            // from consuming messages.
            // The only way we have to test for this special case is using
            // the NLS message identifier
            String exceptionMsg = oce.getMessage();
            if (exceptionMsg != null &&
                (exceptionMsg.contains("CWSIP0180E") ||
                exceptionMsg.contains("CWSIP0194E"))) {
                throw (JMSException) JmsErrorUtils.newThrowable(JMSException.class,
                                                                "INBOUND_MSG_ERROR_CWSIA0103",
                                                                new Object[] { oce },
                                                                oce,
                                                                null, // null probeId = no FFDC
                                                                this,
                                                                tc);
            }
        } catch (SIException sice) {
            // No FFDC code needed

            // d238447 FFDC Review. Need to group the following into those requiring FFDC and those that don't:
            // Not much doc' available, I suspect that all of these are either external/app errors and/or
            // will already have been FFDCd. Don't generate FFDC here.
            //        SISessionUnavailableException, SISessionDroppedException,
            //        SIConnectionUnavailableException, SIConnectionDroppedException,
            //        SIResourceException, SIConnectionLostException, SILimitExceededException,
            //        SINotAuthorizedException,
            //        SIIncorrectCallException - thrown when in use for async delivery
            throw (JMSException) JmsErrorUtils.newThrowable(JMSException.class,
                                                            "INBOUND_MSG_ERROR_CWSIA0103",
                                                            new Object[] { sice },
                                                            sice,
                                                            null, // null probeId = no FFDC
                                                            this,
                                                            tc);
        }
        // 304501.api XD pacing
        if (mpc != null && mpc.isActive()) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                SibTr.debug(this, tc, "about to call postSynchReceive");
            Object context = coreConsumerSession;
            boolean msgReceived = msg != null;
            mpc.postSynchReceive(bus, destName, context, msgReceived);
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                SibTr.debug(this, tc, "postSynchReceive complete");
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(this, tc, "receiveInboundMessage", msg);
        return msg;
    }
500245
private void receiveMessage() {
		MessagingSystemInfo messagingSystemInfo = oneAgentSdk.createMessagingSystemInfo("DynatraceSample", "theQueue", MessageDestinationType.QUEUE, ChannelType.IN_PROCESS, null);
		IncomingMessageReceiveTracer incomingMessageReceiveTracer = oneAgentSdk.traceIncomingMessageReceive(messagingSystemInfo);
		incomingMessageReceiveTracer.start();
		try {
			Message msg = queueManager.receive("theQeue");
			if (msg == null) {
				return; // no message received
			}
			IncomingMessageProcessTracer incomingMessageProcessTracer = oneAgentSdk.traceIncomingMessageProcess(messagingSystemInfo);
			// store incoming tag to tracer:
			incomingMessageProcessTracer.setDynatraceStringTag(msg.getProperty(OneAgentSDK.DYNATRACE_MESSAGE_PROPERTYNAME));
			incomingMessageProcessTracer.setVendorMessageId(msg.getVendorMessageId());
						incomingMessageProcessTracer.start();
			try {
				// do something with the message ...
				System.out.println("Message received: " + msg.toString());
			} catch (Exception e) {
				incomingMessageProcessTracer.error(e);
			} finally {
				incomingMessageProcessTracer.end();
			}
			
			
		} catch (Exception e) {
			incomingMessageReceiveTracer.error(e);
		} finally {
			incomingMessageReceiveTracer.end();
		}
	}
348505
public SoapClientResponseActionBuilder receive() {
        SoapClientResponseActionBuilder soapClientResponseActionBuilder;
        if (soapClient != null) {
            soapClientResponseActionBuilder = new SoapClientResponseActionBuilder(action, soapClient);
        } else {
            soapClientResponseActionBuilder = new SoapClientResponseActionBuilder(action, soapClientUri);
        }

        soapClientResponseActionBuilder.withApplicationContext(applicationContext);

        return soapClientResponseActionBuilder;
    }
1257106
public void received(byte packetID, byte[] packet) {
		executor.execute(() -> {

			// Parse message
			Tree data;
			try {
				data = serializer.read(packet);
			} catch (Exception cause) {
				logger.warn("Unable to parse incoming message!", cause);
				return;
			}

			// Send message to proper component
			try {

				switch (packetID) {
				case PACKET_EVENT_ID:

					// Incoming event
					if (debug) {
						logger.info("Event message received:\r\n" + data);
					}
					eventbus.receiveEvent(data);
					return;

				case PACKET_REQUEST_ID:

					// Incoming request
					if (debug) {
						logger.info("Request message received:\r\n" + data);
					}
					registry.receiveRequest(data);
					return;

				case PACKET_RESPONSE_ID:

					// Incoming response
					if (debug) {
						logger.info("Response message received:\r\n" + data);
					}
					registry.receiveResponse(data);
					return;

				case PACKET_PING_ID:

					// Send pong
					if (debug) {
						logger.info("Ping message received:\r\n" + data);
					}
					String sender = data.get("sender", "");
					if (sender == null || sender.isEmpty()) {
						logger.warn("Missing \"sender\" property:\r\n" + data);
						return;
					}
					data.put("sender", this.nodeID);
					data.put("arrived", System.currentTimeMillis());
					writer.send(sender, serialize(PACKET_PONG_ID, data));
					return;

				case PACKET_PONG_ID:

					// Pong received
					if (debug) {
						logger.info("Pong message received:\r\n" + data);
					}
					registry.receivePong(data);
					return;

				case PACKET_GOSSIP_REQ_ID:

					// Incoming gossip request
					processGossipRequest(data);
					return;

				case PACKET_GOSSIP_RSP_ID:

					// Incoming gossip request
					processGossipResponse(data);
					return;

				case PACKET_GOSSIP_HELLO_ID:

					// Incoming "hello" message
					processGossipHello(data);
					return;

				default:
					logger.warn("Unsupported message ID (" + packetID + ")!");
				}

			} catch (Exception cause) {
				logger.warn("Unable to process incoming message!", cause);
			}
		});
	}
1348839
@Override
	public void send(Queue queue, Message message) throws JMSException
    {
        send((Destination)queue,message,defaultDeliveryMode,defaultPriority,defaultTimeToLive);
    }
1013309
@Override
    public <T> T receiveBody(Class<T> paramClass) throws MessageFormatRuntimeException, JMSRuntimeException {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "receiveBody", new Object[] { paramClass });

        try {
            // pass timeOut as 0
            return receiveBody(paramClass, 0);
        } finally {
            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                SibTr.exit(this, tc, "receiveBody");
        }

    }
659461
int receive(byte[] b, int offset, int length) throws IOException, InterruptedException {

    synchronized (readLock) {
      if (remaining > 0) {
        int bytesToRead = Math.min(remaining, length);
        int result = stdin.read(b, offset, bytesToRead);
        remaining -= result;
        return result;
      }
      if (eof) {
        return -1;
      }
    }

    // make client know we want more data!
    sendSendInput();

    synchronized (readLock) {
      if (remaining == 0 && !eof) {
        readLock.wait();
      }

      // at this point we should have data so call itself recursively to utilize
      // reentrant lock
      return receive(b, offset, length);
    }
  }
286172
@Override
    public java.util.concurrent.Future<ReceiveMessageResult> receiveMessageAsync(String queueUrl) {

        return receiveMessageAsync(new ReceiveMessageRequest().withQueueUrl(queueUrl));
    }
87720
def receive(bytes)
      response = ""
      loop do
        if bytes <= @receive_buffer.bytesize
          array = @receive_buffer.bytes.to_a
          response = array[0..(bytes - 1)].pack('c*')
          @receive_buffer = array[(bytes)..-1].pack('c*')
          break
        end

        chunk = @connection.read_data
        if chunk.bytesize > 0
          @receive_buffer += chunk
        else
          sleep(0.1)
        end
      end
      @logger.debug("RX: #{unpack(response).inspect}")

      response
    end
569128
def receive(self, msg):
        '''
        
        '''
        handler = getattr(self, 'receive_' + msg.__class__.__name__.lower(), None)
        if handler is None:
            raise InvalidMessageError('Receiving class does not support messages of type: ' + msg.__class__.__name__)
        return handler(msg)
600414
@Override
	public final void setMessageListener(MessageListener messageListener) throws JMSException
    {
        super.setMessageListener(messageListener);
        
        // If the connection was already started, wake up the new listener in case there were messages
        // waiting in the destination
        if (messageListener != null && session.getConnection().isStarted())
        	wakeUpMessageListener();
    }
1170551
public void send(Destination dest, Message msg) throws MessagingException {
        try {
            Session s =
                    connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            MessageProducer p = s.createProducer(dest);
            p.send(msg);
            s.close();
        } catch (JMSException e) {
            throw new MessagingException(e.getMessage(), e);
        }

        if(logger.isDebugEnabled()) {
            logger.debug("send() - message sent to destination " + dest);
        }
    }
666534
@Override
	public final void send(Message message) throws JMSException
    {
    	if (this.destination == null)
    		throw new UnsupportedOperationException("Destination was not set at creation time");
    	
    	// Setup message fields
    	setupMessage(destination,message,defaultDeliveryMode,defaultPriority,defaultTimeToLive);
    	
    	// Handle foreign message implementations
        message = MessageTools.normalize(message);

        sendToDestination(destination,false,message,defaultDeliveryMode,defaultPriority,defaultTimeToLive);
    }
643446
def receive(self):
        '''
        
        '''
        try:
            msg = self.sub.recv()
        except zmq.Again as error:
            log.error('Unable to receive messages: %s', error, exc_info=True)
            raise ListenerException(error)
        log.debug('[%s] Received %s', time.time(), msg)
        return msg, ''
403698
private javax.jms.Message receive(Destination destination, String selector) {
        javax.jms.Message receivedJmsMessage;

        if (log.isDebugEnabled()) {
            log.debug("Receiving JMS message on destination: '" + endpointConfiguration.getDestinationName(destination) + (StringUtils.hasText(selector) ? "(" + selector + ")" : "") + "'");
        }

        if (StringUtils.hasText(selector)) {
            receivedJmsMessage = endpointConfiguration.getJmsTemplate().receiveSelected(destination, selector);
        } else {
            receivedJmsMessage = endpointConfiguration.getJmsTemplate().receive(destination);
        }

        if (receivedJmsMessage == null) {
            throw new ActionTimeoutException("Action timed out while receiving JMS message on '" + endpointConfiguration.getDestinationName(destination) + (StringUtils.hasText(selector) ? "(" + selector + ")" : "") + "'");
        }

        log.info("Received JMS message on destination: '" + endpointConfiguration.getDestinationName(destination) + (StringUtils.hasText(selector) ? "(" + selector + ")" : "") + "'");

        return receivedJmsMessage;
    }
159175
public byte[] receiveMessages()
    {
        try
        {
            final byte[] data;
            final int size = in.available();
            if (size <= 0)
            {
                data = null;
            }
            else
            {
                data = new byte[size];
                in.readFully(data);
            }
            return data;
        }
        catch (final IOException exception)
        {
            Verbose.exception(exception);
            return new byte[0];
        }
    }