use of org.eclipse.kapua.service.device.call.message.app.request.DeviceRequestMessage in project kapua by eclipse.
the class DeviceCallExecutor method send.
@SuppressWarnings({ "unchecked" })
public RS send() throws KapuaException {
//
// Get the correct device call
KapuaLocator locator = KapuaLocator.getInstance();
DeviceCallFactory kapuaDeviceCallFactory = locator.getFactory(DeviceCallFactory.class);
DeviceCall<DeviceRequestMessage, DeviceResponseMessage> deviceCall = kapuaDeviceCallFactory.newDeviceCall();
Translator tKapuaToClient = Translator.getTranslatorFor(requestMessage.getRequestClass(), deviceCall.getBaseMessageClass());
DeviceResponseMessage responseMessage;
timeout = timeout == null ? DeviceManagementSetting.getInstance().getLong(DeviceManagementSettingKey.REQUEST_TIMEOUT) : timeout;
DeviceRequestMessage deviceRequestMessage = (DeviceRequestMessage) tKapuaToClient.translate(requestMessage);
switch(requestMessage.getChannel().getMethod()) {
case CREATE:
{
responseMessage = deviceCall.create(deviceRequestMessage, timeout);
}
break;
case READ:
{
responseMessage = deviceCall.read(deviceRequestMessage, timeout);
}
break;
case OPTIONS:
{
responseMessage = deviceCall.options(deviceRequestMessage, timeout);
}
break;
case DELETE:
{
responseMessage = deviceCall.delete(deviceRequestMessage, timeout);
}
break;
case EXECUTE:
{
responseMessage = deviceCall.execute(deviceRequestMessage, timeout);
}
break;
case WRITE:
{
responseMessage = deviceCall.write(deviceRequestMessage, timeout);
}
break;
default:
throw new DeviceManagementException(DeviceManagementErrorCodes.REQUEST_BAD_METHOD, null, requestMessage.getChannel().getMethod());
}
Translator tClientToKapua = Translator.getTranslatorFor(deviceCall.getBaseMessageClass(), requestMessage.getResponseClass());
return (RS) tClientToKapua.translate(responseMessage);
}
Aggregations