Search in sources :

Example 6 with MessageType

use of org.opensmartgridplatform.shared.infra.jms.MessageType in project open-smart-grid-platform by OSGP.

the class MockOslpChannelHandler method sendNotifications.

private void sendNotifications(final InetSocketAddress inetAddress, final OslpEnvelope message, final String deviceUid, final DeviceState deviceState) throws DeviceSimulatorException, IOException {
    final MessageType messageType = this.getMessageType(message.getPayloadMessage());
    if (MessageType.SET_LIGHT == messageType) {
        final List<Oslp.LightValue> lightValueList = message.getPayloadMessage().getSetLightRequest().getValuesList();
        for (final Oslp.LightValue lightValue : lightValueList) {
            final Oslp.Event event = lightValue.getOn() ? Oslp.Event.LIGHT_EVENTS_LIGHT_ON : Oslp.Event.LIGHT_EVENTS_LIGHT_OFF;
            final OslpEnvelope notification = this.buildNotification(message, deviceUid, deviceState, event, lightValue.getIndex());
            this.send(inetAddress, notification, deviceUid);
        }
    }
}
Also used : Oslp(org.opensmartgridplatform.oslp.Oslp) MessageType(org.opensmartgridplatform.shared.infra.jms.MessageType) OslpEnvelope(org.opensmartgridplatform.oslp.OslpEnvelope)

Example 7 with MessageType

use of org.opensmartgridplatform.shared.infra.jms.MessageType in project open-smart-grid-platform by OSGP.

the class MockOslpChannelHandler method handleRequest.

public Oslp.Message handleRequest(final OslpEnvelope requestMessage) throws DeviceSimulatorException {
    final Oslp.Message request = requestMessage.getPayloadMessage();
    final String deviceUid = MockOslpChannelHandler.getDeviceUid(requestMessage);
    final MessageType messageType = this.getMessageType(requestMessage.getPayloadMessage());
    final DeviceState deviceState = this.devicesContext.getDeviceState(deviceUid);
    LOGGER.info("Device {} received [{}], sequence number [{}]", deviceUid, request, requestMessage.getSequenceNumber());
    // Calculate expected sequence number
    deviceState.incrementSequenceNumber();
    // sleep for a little while
    if (this.responseDelayTime != null && this.reponseDelayRandomRange == null) {
        this.sleep(this.responseDelayTime);
    } else if (this.responseDelayTime != null) {
        final Long randomDelay = (long) (this.reponseDelayRandomRange * this.random.nextDouble());
        this.sleep(this.responseDelayTime + randomDelay);
    }
    deviceState.addReceivedRequest(messageType, request);
    final Oslp.Message response = deviceState.pollMockedResponse(messageType);
    LOGGER.info("Device {} mocked response: [{}]", deviceState.getDeviceUid(), response);
    return response;
}
Also used : Message(org.opensmartgridplatform.oslp.Oslp.Message) ByteString(com.google.protobuf.ByteString) Oslp(org.opensmartgridplatform.oslp.Oslp) MessageType(org.opensmartgridplatform.shared.infra.jms.MessageType)

Aggregations

MessageType (org.opensmartgridplatform.shared.infra.jms.MessageType)7 Oslp (org.opensmartgridplatform.oslp.Oslp)3 OslpEnvelope (org.opensmartgridplatform.oslp.OslpEnvelope)3 ByteString (com.google.protobuf.ByteString)2 JMSException (javax.jms.JMSException)2 Message (org.opensmartgridplatform.oslp.Oslp.Message)2 ResponseMessage (org.opensmartgridplatform.shared.infra.jms.ResponseMessage)2 Bootstrap (io.netty.bootstrap.Bootstrap)1 ChannelFuture (io.netty.channel.ChannelFuture)1 ChannelFutureListener (io.netty.channel.ChannelFutureListener)1 Sharable (io.netty.channel.ChannelHandler.Sharable)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 SimpleChannelInboundHandler (io.netty.channel.SimpleChannelInboundHandler)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 PrivateKey (java.security.PrivateKey)1 ParseException (java.text.ParseException)1 LocalDateTime (java.time.LocalDateTime)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 ArrayList (java.util.ArrayList)1