public static void messageReceived(ChannelHandlerContext ctx, User user, StringMessage message) { String[] split = split2(message.body); if (split.length < 2) { throw new IllegalCommandException("Wrong income message format."); } int dashId = Integer.parseInt(split[0]); String deviceString = split[1]; if (deviceString == null || deviceString.isEmpty()) { throw new IllegalCommandException("Income device message is empty."); } DashBoard dash = user.profile.getDashByIdOrThrow(dashId); Device newDevice = JsonParser.parseDevice(deviceString, message.id); log.debug("Updating new device {}.", deviceString); if (newDevice.isNotValid()) { throw new IllegalCommandException("Income device message is not valid."); } Device existingDevice = user.profile.getDeviceById(dash, newDevice.id); if (existingDevice == null) { log.debug("Attempt to update device with non existing id."); ctx.writeAndFlush(illegalCommandBody(message.id), ctx.voidPromise()); return; } existingDevice.update(newDevice); dash.updatedAt = System.currentTimeMillis(); user.lastModifiedTs = dash.updatedAt; ctx.writeAndFlush(ok(message.id), ctx.voidPromise()); }