Updates will be applied - 3:30pm EDT (UTC -400). No downtime expected.

Commit 821e143a authored by Utkarsh Ayachit's avatar Utkarsh Ayachit

Fixed issues with getting return value from Invoke.

* There was no logic to fetch the reply from server-side. Fixed that.
* Also removed automatic response fetching. That can have performance
  implications especially since most of the times no one cares about the return
  value. Fixed by adding an explicit GetLastResult() call.
parent b81541eb
......@@ -89,5 +89,7 @@ void vtkPMObject::Pull(vtkSMMessage* msg)
//----------------------------------------------------------------------------
void vtkPMObject::Invoke(vtkSMMessage* msg)
{
// Nothing
msg->Clear();
// build an empty response message.
*msg << pvstream::InvokeResponse();
}
......@@ -57,6 +57,8 @@ public:
// Description:
// Invoke a given method on the underneath objects
// The provided implementation is Empty and do nothing
// Invoke changes the contents of \c msg to be the result of the invocation if
// any.
virtual void Invoke(vtkSMMessage* msg);
//ETX
......
......@@ -651,9 +651,11 @@ bool vtkSMReaderFactory::CanReadFile(const char* filename, vtkSMProxy* proxy)
msg << pvstream::InvokeRequestNoWarning() << "CanReadFile" << filename;
session->Invoke(&msg);
if(!msg.GetExtension(InvokeResponse::error))
const vtkSMMessage* reply = session->GetLastResult(proxy->GetLocation());
if (!reply->GetExtension(InvokeResponse::error))
{
canRead = msg.GetExtension(InvokeResponse::arguments).variant(0).integer(0);
canRead = reply->GetExtension(InvokeResponse::arguments).variant(0).integer(0);
}
return (canRead != 0);
......
......@@ -219,6 +219,15 @@ void vtkSMSession::Invoke(vtkSMMessage* msg)
this->DeActivate();
}
//----------------------------------------------------------------------------
const vtkSMMessage* vtkSMSession::GetLastResult(
vtkTypeUInt32 vtkNotUsed(location))
{
// This class does not handle remote sessions, so all messages are directly
// processes locally.
return this->Core->GetLastResult();
}
//----------------------------------------------------------------------------
void vtkSMSession::DeletePMObject(vtkSMMessage* msg)
{
......@@ -227,6 +236,7 @@ void vtkSMSession::DeletePMObject(vtkSMMessage* msg)
// Manage Undo/Redo if possible
if(this->StateManagement)
{
// FIXME_COLLABORATION
// FIXME Store state in cache
// vtkSMMessage previousState = this->Internals->ReplaceState(msg->global_id(),NULL);
}
......
......@@ -86,9 +86,16 @@ public:
virtual void PullState(vtkSMMessage* msg);
// Description:
// Invoke a method remotely
// Invoke a method. Use GetLastResult() to obtain the response of an
// invocation.
virtual void Invoke(vtkSMMessage* msg);
// Description:
// Returns the response of the Invoke() call from the location. Note if
// location refers to multiple processes, then the reply is only fetched from
// the "closest" process.
virtual const vtkSMMessage* GetLastResult(vtkTypeUInt32 location);
// Description:
// Delete server side object. (PMObject)
virtual void DeletePMObject(vtkSMMessage* msg);
......
......@@ -53,6 +53,7 @@ vtkSMSessionClient::vtkSMSessionClient()
this->DataServerInformation = vtkPVServerInformation::New();
this->RenderServerInformation = vtkPVServerInformation::New();
this->ServerInformation = vtkPVServerInformation::New();
this->ServerLastInvokeResult = new vtkSMMessage();
}
//----------------------------------------------------------------------------
......@@ -68,6 +69,9 @@ vtkSMSessionClient::~vtkSMSessionClient()
this->RenderServerInformation->Delete();
this->ServerInformation->Delete();
this->SetURI(0);
delete this->ServerLastInvokeResult;
this->ServerLastInvokeResult = NULL;
}
//----------------------------------------------------------------------------
......@@ -542,6 +546,64 @@ void vtkSMSessionClient::Invoke(vtkSMMessage* message)
}
}
//----------------------------------------------------------------------------
const vtkSMMessage* vtkSMSessionClient::GetLastResult(vtkTypeUInt32 location)
{
if (this->RenderServerController == NULL)
{
// re-route all render-server messages to data-server.
if (location & vtkProcessModule::RENDER_SERVER)
{
location |= vtkProcessModule::DATA_SERVER_ROOT;
location &= ~vtkProcessModule::RENDER_SERVER;
}
if (location & vtkProcessModule::RENDER_SERVER_ROOT)
{
location |= vtkProcessModule::DATA_SERVER_ROOT;
location &= ~vtkProcessModule::RENDER_SERVER_ROOT;
}
}
if (location & vtkPVSession::CLIENT)
{
return this->Superclass::GetLastResult(location);
}
vtkMultiProcessController* controller = NULL;
if ( (location & vtkPVSession::DATA_SERVER_ROOT) ||
(location & vtkPVSession::DATA_SERVER) )
{
controller = this->DataServerController;
}
else if ( (location & vtkPVSession::RENDER_SERVER_ROOT) ||
(location & vtkPVSession::RENDER_SERVER) )
{
controller = this->RenderServerController;
}
if (controller)
{
this->ServerLastInvokeResult->Clear();
vtkMultiProcessStream stream;
stream << static_cast<int>(LAST_RESULT);
vtkstd::vector<unsigned char> raw_message;
stream.GetRawData(raw_message);
controller->TriggerRMIOnAllChildren(
&raw_message[0], static_cast<int>(raw_message.size()),
CLIENT_SERVER_MESSAGE_RMI);
// Get the reply
vtkMultiProcessStream replyStream;
controller->Receive(replyStream, 1, REPLY_LAST_RESULT);
vtkstd::string string;
replyStream >> string;
this->ServerLastInvokeResult->ParseFromString(string);
return this->ServerLastInvokeResult;
}
return this->Superclass::GetLastResult(location);
}
//----------------------------------------------------------------------------
bool vtkSMSessionClient::GatherInformation(
vtkTypeUInt32 location, vtkPVInformation* information, vtkTypeUInt32 globalid)
......
......@@ -89,7 +89,7 @@ public:
virtual void PushState(vtkSMMessage* msg);
virtual void PullState(vtkSMMessage* message);
virtual void Invoke(vtkSMMessage* msg);
virtual const vtkSMMessage* GetLastResult(vtkTypeUInt32 location);
//ETX
// Description:
......@@ -125,10 +125,12 @@ public:
PULL=3,
GATHER_INFORMATION=4,
REGISTER_MTON_SOCKET_CONNECTION=5,
LAST_RESULT=6,
CLIENT_SERVER_MESSAGE_RMI=55625,
CLOSE_SESSION=55626,
REPLY_GATHER_INFORMATION_TAG=55627,
REPLY_PULL=55628
REPLY_PULL=55628,
REPLY_LAST_RESULT=55629,
};
protected:
......@@ -147,6 +149,7 @@ protected:
vtkPVServerInformation* DataServerInformation;
vtkPVServerInformation* RenderServerInformation;
vtkPVServerInformation* ServerInformation;
vtkSMMessage* ServerLastInvokeResult;
vtkSetStringMacro(URI);
......
......@@ -222,6 +222,8 @@ vtkSMSessionCore::vtkSMSessionCore()
LOG("Log for " << options->GetArgv0() << " ("
<< this->ParallelController->GetLocalProcessId() << ")");
}
this->LastInvokeResult = new vtkSMMessage();
}
//----------------------------------------------------------------------------
......@@ -238,6 +240,8 @@ vtkSMSessionCore::~vtkSMSessionCore()
delete this->Internals;
this->ProxyDefinitionManager->Delete();
this->ProxyDefinitionManager = NULL;
delete this->LastInvokeResult;
this->LastInvokeResult = NULL;
}
//----------------------------------------------------------------------------
......@@ -518,10 +522,21 @@ void vtkSMSessionCore::InvokeInternal(vtkSMMessage* message)
<< "----------------------------------------------------------------\n"
<< message->DebugString().c_str());
this->LastInvokeResult->Clear();
vtkPMObject* obj = this->Internals->GetPMObject(message->global_id());
if (obj)
{
obj->Invoke(message);
if (message->HasExtension(paraview_protobuf::InvokeResponse::arguments) ||
message->HasExtension(paraview_protobuf::InvokeResponse::error))
{
// preserve the response.
this->LastInvokeResult->CopyFrom(*message);
message->Clear(); // this is unnecessary, but to avoid not detecting bugs
// when someone simply uses the invoke stream's value as the response in
// builtin mode, we clear it.
}
}
else
{
......
......@@ -59,6 +59,12 @@ public:
// Invoke a method remotely
virtual void Invoke(vtkSMMessage* message);
// Description:
// Returns the return value for the most recent Invoke() call.
// When running in parallel, this only returns the result from the root node.
virtual const vtkSMMessage* GetLastResult()
{ return this->LastInvokeResult; }
// Description:
// Invoke a method remotely
virtual void DeletePMObject(vtkSMMessage* message);
......@@ -134,6 +140,11 @@ protected:
vtkSMProxyDefinitionManager* ProxyDefinitionManager;
vtkMultiProcessController* ParallelController;
vtkClientServerInterpreter* Interpreter;
// Used to preserve the response from the most recent "Invoke" call until
// requested.
vtkSMMessage* LastInvokeResult;
private:
vtkSMSessionCore(const vtkSMSessionCore&); // Not implemented
void operator=(const vtkSMSessionCore&); // Not implemented
......
......@@ -352,6 +352,12 @@ void vtkSMSessionServer::OnClientServerMessageRMI(void* message, int message_len
}
break;
case vtkSMSessionClient::LAST_RESULT:
{
this->SendLastResultToClient();
}
break;
case vtkSMSessionClient::GATHER_INFORMATION:
{
vtkstd::string classname;
......@@ -376,6 +382,16 @@ void vtkSMSessionServer::OnClientServerMessageRMI(void* message, int message_len
}
}
//----------------------------------------------------------------------------
void vtkSMSessionServer::SendLastResultToClient()
{
const vtkSMMessage* result =
this->GetLastResult(vtkPVSession::CLIENT_AND_SERVERS);
vtkMultiProcessStream reply;
reply << result->SerializeAsString();
this->ClientController->Send(reply, 1, vtkSMSessionClient::REPLY_LAST_RESULT);
}
//----------------------------------------------------------------------------
void vtkSMSessionServer::GatherInformationInternal(
vtkTypeUInt32 location, const char* classname, vtkTypeUInt32 globalid,
......
......@@ -101,6 +101,7 @@ public:
void OnClientServerMessageRMI(void* message, int message_length);
void OnCloseSessionRMI();
void SendLastResultToClient();
protected:
vtkSMSessionServer();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment