/*
(non-Javadoc)
@see net.roboconf.dm.rest.services.internal.resources.IDebugResource
#checkMessagingConnectionWithAgent(java.lang.String, java.lang.String, java.lang.String)
978358
@Override
	public Response checkMessagingConnectionWithAgent(
			String applicationName,
			String scopedInstancePath,
			String message ) {

		this.logger.fine( "Request: check the connection with agent " + applicationName + " :: " + scopedInstancePath + ". message=" + message );
		final ManagedApplication ma = this.manager.applicationMngr().findManagedApplicationByName( applicationName );
		String lang = lang( this.manager );

		Response response;
		int pingResult;
		final Instance instance;

		if( ma == null )
			response = handleError( Status.NOT_FOUND, new RestError( REST_INEXISTING, application( applicationName )), lang ).build();
		else if(( instance = InstanceHelpers.findInstanceByPath( ma.getApplication(), scopedInstancePath )) == null )
			response = handleError( Status.NOT_FOUND, new RestError( REST_INEXISTING, instance( scopedInstancePath ), application( applicationName )), lang ).build();
		else if(( pingResult = this.manager.debugMngr().pingAgent( ma, instance, message )) == 1 )
			response = handleError( Status.BAD_REQUEST, new RestError( REST_DEBUG_AGENT_KO ), lang ).build();
		else if( pingResult == 2 )
			response = handleError( Status.INTERNAL_SERVER_ERROR, new RestError( REST_MESSAGING_ERROR ), lang ).build();
		else
			response = handleError( Status.OK, new RestError( REST_DEBUG_AGENT_KO, name( "PING" ), value( message )), lang ).build();

		return response;
	}
1203240
@Override
	public String getMessageToClient(String mfc) {
		HttpSession httpSession = iRSEndpoint.getHttpSession();
		String httpid = httpSession.getId();
		boolean monitored = monitorSessionManager.isMonitored(httpid);
		long t0 = 0;
		if(monitored) {
			t0 = System.currentTimeMillis();
		}
		String mtc = iRSEndpoint.getMessageToClient(mfc);
		if(monitored) {
			long t1 = System.currentTimeMillis();
			publish("request-event-"+httpid, mfc, mtc, t1 - t0);
		}
		return mtc;
	}
1137150
@Override
    public void setMessageListener(MessageListener listener) throws JMSRuntimeException {

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "setMessageListener", new Object[] { listener });

        try {
            messageConsumer.setMessageListener(listener);
        } catch (JMSException jmse) {
            throw (JMSRuntimeException) JmsErrorUtils.getJMS2Exception(jmse, JMSRuntimeException.class);
        } finally {
            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                SibTr.exit(this, tc, "setMessageListener");
        }

    }
91078
public synchronized SIBusMessage getMessage(CommsConnection commsConnection)
      throws SIResourceException
   {
      if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(tc, "getMessage");

      checkReleased();

      SIBusMessage mess = null;
      // Now build a JsMessage from the returned data. Note that a message length of -1 indicates
      // that no message has been returned and a null value should be returned to the caller.

      // Get length of JsMessage
      int messageLen = (int) getLong();
      if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) SibTr.debug(this, tc, "Message length", messageLen);
      if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) SibTr.debug(this, tc, "Remaining in buffer", receivedBuffer.remaining());

      if (messageLen > -1)
      {
         // Build Message from byte array. If the buffer is backed by an array we should simply
         // pass that into MFP rather than copying into a new byte[]
         try
         {
            if (receivedBuffer.hasArray())
            {
               if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) SibTr.debug(this, tc, "Received buffer has a backing array");

               mess = JsMessageFactory.getInstance().createInboundJsMessage(receivedBuffer.array(),
                                                                            receivedBuffer.position() + receivedBuffer.arrayOffset(),
                                                                            messageLen,
                                                                            commsConnection);

               // Move the position to the end of the message so that any data after the message
               // can be got
               receivedBuffer.position(receivedBuffer.position() + messageLen);
            }
            else
            {
               if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) SibTr.debug(this, tc, "Received buffer does NOT have a backing array");

               byte[] messageArray = get(messageLen);
               mess = JsMessageFactory.getInstance().createInboundJsMessage(messageArray,
                                                                            0,
                                                                            messageLen,
                                                                            commsConnection);
            }
         }
         catch (Exception e)
         {
            FFDCFilter.processException(e, CLASS_NAME + ".getMessage", CommsConstants.COMMSBYTEBUFFER_GETMESSAGE_01, this,
              new Object[] {"messageLen="+messageLen+", position="+receivedBuffer.position()+", limit="+receivedBuffer.limit() + " " +
                (receivedBuffer.hasArray()?"arrayOffset="+receivedBuffer.arrayOffset()+" array.length="+receivedBuffer.array().length:"no backing array")});

            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
            {
               SibTr.debug(this, tc, "Unable to create message", e);
               dump(this, tc, 100);
            }

            throw new SIResourceException(e);
         }
      }

      if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(tc, "getMessage", mess);
      return mess;
   }
957821
private void failWithMessage(String errorMessage) {
      AssertionError assertionError = Failures.instance().failureIfErrorMessageIsOverridden(info);
      if (assertionError == null) {
        // error message was not overridden, build it.
        String description = MessageFormatter.instance().format(info.description(), info.representation(), "");
        assertionError = new AssertionError(description + errorMessage);
      }
      Failures.instance().removeAssertJRelatedElementsFromStackTraceIfNeeded(assertionError);
      throw assertionError;
    }
1350587
@Override
	public boolean sendMessageToClient(MessageFromClient message, Session client) {
		MessageToClient mtc = messageToClientService.createMessageToClient(message, client);
		if (mtc != null) {
			client.getAsyncRemote().sendObject(mtc);
			return true;
		}
		return false;
	}
210741
void handleAgentConnectEvent(AgentConnectEvent event)
    {
        AsteriskAgentImpl agent = getAgentByAgentId(event.getChannel());
        if (agent == null)
        {
            logger.error("Ignored AgentConnectEvent for unknown agent " + event.getChannel());
            return;
        }
        agent.updateState(AgentState.AGENT_ONCALL);
    }
63703
protected void connectToJMS(String clientId) throws MessagingException {
        // Check to see if already connected
        //
        if (connected == true) return;

        try {
            // Get a JMS Connection
            //
            connection = getConnection();
            if(clientId != null) {
                connection.setClientID(clientId);
            }
            connection.start();
            connected = true;
            logger.debug("connectToJMS - connected");
        } catch (JMSException e) {
            connected = false;
            logger.error("JMSManager.connectToJMS - Exception occurred:");
            throw new MessagingException(e.getMessage(), e);
        }
    }
478368
@Override
    public void notifyMessageReceived(SQSMessage message) throws JMSException {
        SQSMessageIdentifier messageIdentifier = SQSMessageIdentifier.fromSQSMessage(message);
        if (!unAckMessages.contains(messageIdentifier)) {
            unAckMessages.add(messageIdentifier);
        }
    }
1063544
@Override
	protected void openConnection( IMessagingClient newMessagingClient ) throws IOException {
		newMessagingClient.setOwnerProperties( RecipientKind.DM, this.domain, null, null );
		newMessagingClient.openConnection();
	}
377704
@Override
    public void doMessageReceivedListeners(final long sessionId, final long sessionReadBytes, final Object message) {
        runManagementTask(new Runnable() {
            @Override
            public void run() {
                try {
                    // The particular management listeners change on strategy, so get them here.
                    for (final GatewayManagementListener listener : getManagementListeners()) {
                        listener.doMessageReceived(GatewayManagementBeanImpl.this, sessionId);
                    }

                    markChanged();  // mark ourselves as changed, possibly tell listeners
                } catch (Exception ex) {
                    logger.warn("Error during messageReceived gateway listener notifications:", ex);
                }
            }
        });
    }
524566
@Override
	public void check() throws JMSException
	{
		if (jdniInitialContextFactoryName == null)
			throw new InvalidDescriptorException("Missing peer property : 'jdniInitialContextFactoryName'");
		if (jndiConnectionFactoryName == null)
			throw new InvalidDescriptorException("Missing peer property : 'jndiConnectionFactoryName'");
		if (providerURL == null)
			throw new InvalidDescriptorException("Missing peer property : 'providerURL'");
	}
1368887
@Override
	public void setMessageListener(MessageListener messageListener) throws JMSException
    {
    	externalAccessLock.readLock().lock();
    	try
		{
    		checkNotClosed();
    		this.messageListener = messageListener;
		}
    	finally
    	{
    		externalAccessLock.readLock().unlock();
    	}
    }
74104
@Override
    public UndeliverableReturnCode handleUndeliverableMessage(
                                                              SIMPMessage msg,
                                                              int exceptionReason,
                                                              String[] exceptionInserts,
                                                              TransactionCommon tran)
                    throws
                    SIResourceException
    {
        // F001333-14610
        // Delegate down onto the new method passing a null
        // subscription ID.
        return handleUndeliverableMessage(msg, exceptionReason, exceptionInserts, tran, null);
    }
1096451
public String getMessageWithoutCheckName() {
    return linkUrl != null
        ? String.format("%s\n%s", rawMessage, linkTextForDiagnostic(linkUrl))
        : String.format("%s", rawMessage);
  }
335664
@Override
    public synchronized boolean checkConnection(final boolean forceReconnect) {
        if (checkConnection(conn)) {
            return true;
        } else if (forceReconnect) {
            try {
                connect();
                recover();

                return true;
            } catch (final Exception ex) {
                logger.debug(dev, "reconnection failure", ex);
                return false;
            }
        }

        return false;
    }
1303753
@Override
    public JsMessage getMessage()
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "getMessage");

        JsMessage localMsg = getJSMessage(true);

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(this, tc, "getMessage", localMsg);

        return localMsg;
    }