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);
}
}
}
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;
}
Aggregations