String name = (String) message.getMessageHeader().getHeader(NAME_ATTRIBUTE);
String id = (String) message.getMessageHeader().getHeader(IDENTITY_ATTRIBUTE);
String type = (String) message.getMessageHeader().getHeader(TYPE_ATTRIBUTE);
String operation = (String) message.getMessageHeader().getHeader(OPERATION_HEADER);
InternalMessage response;
if(SELF_NODE_NAME.equals(name) && type.equals(MANAGEMENT_TYPE))
{
response = performManagementOperation(message);
}
else if(CREATE_OPERATION.equals(operation))
{
response = performCreateOperation(message, type);
}
else
{
ConfiguredObject entity = findSubject(name, id, type);
if(entity != null)
{
response = performOperation(message, entity);
}
else
{
if(id != null)
{
response = createFailureResponse(message,
NOT_FOUND_STATUS_CODE,
"No entity with id {0} of type {1} found", id, type);
}
else
{
response = createFailureResponse(message,
NOT_FOUND_STATUS_CODE,
"No entity with name {0} of type {1} found", name, type);
}
}
}
ManagementNodeConsumer consumer = _consumers.get(message.getMessageHeader().getReplyTo());
response.setInitialRoutingAddress(message.getMessageHeader().getReplyTo());
if(consumer != null)
{
// TODO - check same owner
consumer.send(response);
}