Search in sources :

Example 1 with DeviceResponseMessageSender

use of com.alliander.osgp.adapter.protocol.oslp.elster.infra.messaging.DeviceResponseMessageSender in project Protocol-Adapter-OSLP by OSGP.

the class OslpChannelHandlerClient method send.

public void send(final InetSocketAddress address, final OslpEnvelope request, final OslpResponseHandler responseHandler, final String deviceIdentification) throws IOException {
    LOGGER.info("Sending OSLP request: {}", request.getPayloadMessage());
    // Open connection and send message.
    final ChannelFuture channelFuture = this.bootstrap.connect(address);
    this.callbackHandlers.put(channelFuture.getChannel().getId(), new OslpCallbackHandler(responseHandler));
    channelFuture.addListener(new ChannelFutureListener() {

        @Autowired
        protected DeviceResponseMessageSender responseMessageSender;

        @Override
        public void operationComplete(final ChannelFuture future) throws Exception {
            if (future.isSuccess()) {
                OslpChannelHandlerClient.this.write(future, address, request);
                // What is this call below good for?
                future.getChannel().getId();
            } else {
                LOGGER.info("The connection to the device {} is not successful", deviceIdentification);
                throw new IOException("ChannelFuture - Unable to connect");
            }
        }
    });
}
Also used : ChannelFuture(org.jboss.netty.channel.ChannelFuture) Autowired(org.springframework.beans.factory.annotation.Autowired) DeviceResponseMessageSender(com.alliander.osgp.adapter.protocol.oslp.elster.infra.messaging.DeviceResponseMessageSender) IOException(java.io.IOException) ChannelFutureListener(org.jboss.netty.channel.ChannelFutureListener) IOException(java.io.IOException) NoDeviceResponseException(com.alliander.osgp.shared.exceptionhandling.NoDeviceResponseException)

Aggregations

DeviceResponseMessageSender (com.alliander.osgp.adapter.protocol.oslp.elster.infra.messaging.DeviceResponseMessageSender)1 NoDeviceResponseException (com.alliander.osgp.shared.exceptionhandling.NoDeviceResponseException)1 IOException (java.io.IOException)1 ChannelFuture (org.jboss.netty.channel.ChannelFuture)1 ChannelFutureListener (org.jboss.netty.channel.ChannelFutureListener)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1