public final void onMessage(final Message message) throws Exception {
        InterconnectContext.reset();

        final long begin = System.currentTimeMillis();
        if (message instanceof TextMessage) {
            final TextMessage textMessage = (TextMessage) message;
            this.getLogger().debug("TextMessage received: {}", textMessage.getText());
            final boolean secure = MessageConnector.isMessageSecure(textMessage);
            if (secure) {
                MessageConnector.decryptMessage(textMessage);
            }
            final InterconnectObject ivoIn = InterconnectMapper.fromJson(textMessage.getText(), InterconnectObject.class);
            final Class<? extends InterconnectObject> icoClass = ivoIn.getClass();
            final DaemonRequest request = new DaemonRequest(textMessage.getJMSCorrelationID(), textMessage.getJMSReplyTo(), ivoIn);
            if (icoClass.equals(PingIVO.class)) {
                this.reply(new DaemonResponse(request, new PongIVO.PongIVOBuilder().build()), secure);
                return;
            }
            final DaemonScanner.DaemonMethod method = this.registry.get(icoClass);
            if (method == null) {
                throw new Exception("No registered method found for " + icoClass.getSimpleName() + " from " + message.getJMSReplyTo());
            }
            if (method.isSecure() != secure) {
                throw new Exception("Insecure call (is " + secure + " should be " + method.isSecure() + ") for " + icoClass.getSimpleName() + " from " + message.getJMSReplyTo());
            }
            final String requestUUID = message.getStringProperty(InterconnectConnector.HEADER_REQUEST_UUID);
            if (requestUUID == null) {
                throw new Exception("No request UUID found in message with " + icoClass.getSimpleName() + " from " + message.getJMSReplyTo());

            }
            try {
                InterconnectContext.setUuid(UUID.fromString(requestUUID));
            } catch (final IllegalArgumentException e) {
                throw new Exception("No valid request UUID " + requestUUID + " message with " + icoClass.getSimpleName() + " from " + message.getJMSReplyTo());
            }
            int deliveryCount;
            try {
                deliveryCount = message.getIntProperty("JMSXDeliveryCount");
            } catch (final Exception e) {
                if (message.getJMSRedelivered()) {
                    deliveryCount = 2;
                } else {
                    deliveryCount = 1;
                }
                this.getLogger().warn("Can not get JMSXDeliveryCount");
            }
            InterconnectContext.setDeliveryCount(deliveryCount);
            InterconnectContext.setRedelivered(message.getJMSRedelivered());

            Class<? extends IVO> ivoClass = null;
            if (ivoIn instanceof IVO) {
                ivoClass = (Class<? extends IVO>) ivoIn.getClass();
                InterconnectContext.setRequestClass(ivoClass);
            }
            final IDaemonHandler handler = this.createRequestHandler();
            final StringBuilder sbInvokeLog = new StringBuilder();
            sbInvokeLog.append("Invoke ").append(method.getMethod().getName()).append("(").append(icoClass.getSimpleName()).append(")");
            if (ivoIn instanceof IPageable) {
                sbInvokeLog.append(" at Page ").append(((IPageable) ivoIn).getOffset()).append(";").append(((IPageable) ivoIn).getLimit());
            }
            sbInvokeLog.append(" with ").append(InterconnectContext.getContext());
            this.getLogger().info(sbInvokeLog.toString());
            if (method.getType() == DaemonScanner.Type.voit) {
                this.handleReceiver(handler, method, ivoIn);
            } else {

                final DaemonResponse response;
                try {
                    final InterconnectObject out = this.handleRequest(handler, method, ivoIn);
                    response = new DaemonResponse(request, out);
                    final long end = System.currentTimeMillis();
                    final long runtime = end - begin;
                    if (runtime > method.getTimeoutInMs()) {
                        if (this.throwExceptionOnTimeout) {
                            throw new Exception("Response skipped because runtime " + runtime + " ms was greater than timeout " + method.getTimeoutInMs() + " ms for " + method.getMethod().getName() + "(" + icoClass.getSimpleName() + ")" + " with " + InterconnectContext.getContext());
                        }
                        this.getLogger().warn("Response skipped because runtime " + runtime + " ms was greater than timeout " + method.getTimeoutInMs() + " ms for " + method.getMethod().getName() + "(" + icoClass.getSimpleName() + ")" + " with " + InterconnectContext.getContext());
                        return;
                    } else if (runtime > (method.getTimeoutInMs() / 2L)) {
                        this.getLogger().info("Slow response because runtime " + runtime + " ms for " + method.getMethod().getName() + "(" + icoClass.getSimpleName() + ")" + " with " + InterconnectContext.getContext());
                    }
                } catch (final DaemonError e) {
                    this.getLogger().debug("DaemonError for " + method.getMethod().getName() + "(" + icoClass.getSimpleName() + ")" + " with " + InterconnectContext.getContext(), e);
                    final DaemonErrorIVO.DaemonErrorIVOBuilder error = new DaemonErrorIVO.DaemonErrorIVOBuilder();
                    error.number(e.getNumber().get());
                    error.daemon(e.getNumber().daemon());
                    error.message(e.getMessage());
                    this.reply(new DaemonResponse(request, error.build()), secure);
                    return;
                }
                this.reply(response, secure);
            }
        } else {
            throw new Exception("Invalid message type received: " + message.getClass().getSimpleName());
        }
    }
public final void onMessage ( final Message message ) throws Exception { InterconnectContext . reset ( ) ; final long begin = System . currentTimeMillis ( ) ; if ( message instanceof TextMessage ) { final TextMessage textMessage = ( TextMessage ) message ; this . getLogger ( ) . debug ( "TextMessage received: {}" , textMessage . getText ( ) ) ; final boolean secure = MessageConnector . isMessageSecure ( textMessage ) ; if ( secure ) { MessageConnector . decryptMessage ( textMessage ) ; } final InterconnectObject ivoIn = InterconnectMapper . fromJson ( textMessage . getText ( ) , InterconnectObject . class ) ; final Class < ? extends InterconnectObject > icoClass = ivoIn . getClass ( ) ; final DaemonRequest request = new DaemonRequest ( textMessage . getJMSCorrelationID ( ) , textMessage . getJMSReplyTo ( ) , ivoIn ) ; if ( icoClass . equals ( PingIVO . class ) ) { this . reply ( new DaemonResponse ( request , new PongIVO . PongIVOBuilder ( ) . build ( ) ) , secure ) ; return ; } final DaemonScanner . DaemonMethod method = this . registry . get ( icoClass ) ; if ( method == null ) { throw new Exception ( "No registered method found for " + icoClass . getSimpleName ( ) + " from " + message . getJMSReplyTo ( ) ) ; } if ( method . isSecure ( ) != secure ) { throw new Exception ( "Insecure call (is " + secure + " should be " + method . isSecure ( ) + ") for " + icoClass . getSimpleName ( ) + " from " + message . getJMSReplyTo ( ) ) ; } final String requestUUID = message . getStringProperty ( InterconnectConnector . HEADER_REQUEST_UUID ) ; if ( requestUUID == null ) { throw new Exception ( "No request UUID found in message with " + icoClass . getSimpleName ( ) + " from " + message . getJMSReplyTo ( ) ) ; } try { InterconnectContext . setUuid ( UUID . fromString ( requestUUID ) ) ; } catch ( final IllegalArgumentException e ) { throw new Exception ( "No valid request UUID " + requestUUID + " message with " + icoClass . getSimpleName ( ) + " from " + message . getJMSReplyTo ( ) ) ; } int deliveryCount ; try { deliveryCount = message . getIntProperty ( "JMSXDeliveryCount" ) ; } catch ( final Exception e ) { if ( message . getJMSRedelivered ( ) ) { deliveryCount = 2 ; } else { deliveryCount = 1 ; } this . getLogger ( ) . warn ( "Can not get JMSXDeliveryCount" ) ; } InterconnectContext . setDeliveryCount ( deliveryCount ) ; InterconnectContext . setRedelivered ( message . getJMSRedelivered ( ) ) ; Class < ? extends IVO > ivoClass = null ; if ( ivoIn instanceof IVO ) { ivoClass = ( Class < ? extends IVO > ) ivoIn . getClass ( ) ; InterconnectContext . setRequestClass ( ivoClass ) ; } final IDaemonHandler handler = this . createRequestHandler ( ) ; final StringBuilder sbInvokeLog = new StringBuilder ( ) ; sbInvokeLog . append ( "Invoke " ) . append ( method . getMethod ( ) . getName ( ) ) . append ( "(" ) . append ( icoClass . getSimpleName ( ) ) . append ( ")" ) ; if ( ivoIn instanceof IPageable ) { sbInvokeLog . append ( " at Page " ) . append ( ( ( IPageable ) ivoIn ) . getOffset ( ) ) . append ( ";" ) . append ( ( ( IPageable ) ivoIn ) . getLimit ( ) ) ; } sbInvokeLog . append ( " with " ) . append ( InterconnectContext . getContext ( ) ) ; this . getLogger ( ) . info ( sbInvokeLog . toString ( ) ) ; if ( method . getType ( ) == DaemonScanner . Type . voit ) { this . handleReceiver ( handler , method , ivoIn ) ; } else { final DaemonResponse response ; try { final InterconnectObject out = this . handleRequest ( handler , method , ivoIn ) ; response = new DaemonResponse ( request , out ) ; final long end = System . currentTimeMillis ( ) ; final long runtime = end - begin ; if ( runtime > method . getTimeoutInMs ( ) ) { if ( this . throwExceptionOnTimeout ) { throw new Exception ( "Response skipped because runtime " + runtime + " ms was greater than timeout " + method . getTimeoutInMs ( ) + " ms for " + method . getMethod ( ) . getName ( ) + "(" + icoClass . getSimpleName ( ) + ")" + " with " + InterconnectContext . getContext ( ) ) ; } this . getLogger ( ) . warn ( "Response skipped because runtime " + runtime + " ms was greater than timeout " + method . getTimeoutInMs ( ) + " ms for " + method . getMethod ( ) . getName ( ) + "(" + icoClass . getSimpleName ( ) + ")" + " with " + InterconnectContext . getContext ( ) ) ; return ; } else if ( runtime > ( method . getTimeoutInMs ( ) / 2L ) ) { this . getLogger ( ) . info ( "Slow response because runtime " + runtime + " ms for " + method . getMethod ( ) . getName ( ) + "(" + icoClass . getSimpleName ( ) + ")" + " with " + InterconnectContext . getContext ( ) ) ; } } catch ( final DaemonError e ) { this . getLogger ( ) . debug ( "DaemonError for " + method . getMethod ( ) . getName ( ) + "(" + icoClass . getSimpleName ( ) + ")" + " with " + InterconnectContext . getContext ( ) , e ) ; final DaemonErrorIVO . DaemonErrorIVOBuilder error = new DaemonErrorIVO . DaemonErrorIVOBuilder ( ) ; error . number ( e . getNumber ( ) . get ( ) ) ; error . daemon ( e . getNumber ( ) . daemon ( ) ) ; error . message ( e . getMessage ( ) ) ; this . reply ( new DaemonResponse ( request , error . build ( ) ) , secure ) ; return ; } this . reply ( response , secure ) ; } } else { throw new Exception ( "Invalid message type received: " + message . getClass ( ) . getSimpleName ( ) ) ; } }
@param message Message
@throws Exception If no registered method was found for the incomming InterconnectObject or Insecure call or no (valid) Request UUID
or no