Search in sources :

Example 1 with ServiceDetectionFailedException

use of org.opennms.netmgt.provision.support.DetectFutureNettyImpl.ServiceDetectionFailedException in project opennms by OpenNMS.

the class DetectorHandlerNettyImpl method messageReceived.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent message) {
    try {
        final AsyncClientConversation<Request, Response> conversation = getConversation();
        LOG.debug("Client Receiving: {}", message.getMessage().toString().trim());
        LOG.debug("Conversation: {}", conversation);
        if (conversation.hasExchanges() && conversation.validate((Response) message.getMessage())) {
            Object request = conversation.getRequest();
            if (request != null) {
                LOG.debug("Writing request: {}", request);
                ctx.getChannel().write(request);
            } else if (request == null && conversation.isComplete()) {
                LOG.debug("Closing channel: {}", conversation);
                // getFuture().setServiceDetected(true);
                ctx.getChannel().close();
            } else {
                // getFuture().setServiceDetected(false);
                LOG.debug("Closing channel, detection failed: {}", conversation);
                ctx.getChannel().close();
                Channels.fireExceptionCaught(ctx, new ServiceDetectionFailedException());
            }
        } else {
            LOG.debug("Invalid response: {}", message.getMessage().toString().trim());
            // getFuture().setServiceDetected(false);
            ctx.getChannel().close();
            Channels.fireExceptionCaught(ctx, new ServiceDetectionFailedException());
        }
    } catch (Throwable e) {
        LOG.debug("Exception caught!", e);
        ctx.getChannel().close();
        Channels.fireExceptionCaught(ctx, e);
    }
}
Also used : ServiceDetectionFailedException(org.opennms.netmgt.provision.support.DetectFutureNettyImpl.ServiceDetectionFailedException)

Aggregations

ServiceDetectionFailedException (org.opennms.netmgt.provision.support.DetectFutureNettyImpl.ServiceDetectionFailedException)1