/** @param name to use in log and error messages * @note does error handling, but delegates the actual * execution to the protected (subclass) member */ ExecResult HandlingPattern::invoke (CommandImpl& command, Symbol name) const { TRACE (proc_dbg, "invoking %s...", name.c()); static format err_pre ("Error state detected, %s *NOT* invoked."); static format err_post ("Error state after %s invocation."); static format err_fatal ("Execution of %s raised unknown error."); try { Symbol errID_pre = lumiera_error(); if (errID_pre) return ExecResult (error::Logic (str (err_pre % command), errID_pre)); // execute or undo it... perform (command); Symbol errID = lumiera_error(); if (errID) return ExecResult (error::State (str (err_post % command),errID)); else return ExecResult(); } catch (lumiera::Error& problem) { Symbol errID = lumiera_error(); WARN (command, "Invocation of %s failed: %s", name.c(), problem.what()); TRACE (proc_dbg, "Error flag was: %s", errID.c()); return ExecResult (problem); } catch (std::exception& library_problem) { Symbol errID = lumiera_error(); WARN (command, "Invocation of %s failed: %s", name.c(), library_problem.what()); TRACE (proc_dbg, "Error flag was: %s", errID.c()); return ExecResult (error::External (library_problem)); } catch (...) { Symbol errID = lumiera_error(); ERROR (command, "Invocation of %s failed with unknown exception; error flag is: %s", name.c(), errID.c()); throw error::Fatal (str (err_fatal % command), errID); } }
void Transfer::Dispatch(Message* m) { switch(m->type()) { case TRANSFER_INNER_COMMAND: { MsgCommand msg; memcpy(&msg, m->data(), sizeof(msg)); ExecCommand(msg.tranId, msg.step, msg.message); if(msg.message) { delete msg.message; } } break; case TRANSFER_INNER_RESULT: { // 提取事务信息 MsgResult msg; memcpy(&msg, m->data(), sizeof(msg)); // 执行事务步骤 ExecResult(msg.tranId, msg.step, msg.compId, msg.message); // 释放内部消息 if(msg.message) { delete msg.message; } } break; case TRANSFER_INNER_REQUEST: { MsgRequest msg; memcpy(&msg, m->data(), sizeof(msg)); ExecRequest(msg.tranId, msg.step, msg.compId, msg.message); if(msg.message) { delete msg.message; } } break; default: { LOG(LEVEL_WARNING, "Don't Support This Command, Type = %d", m->type()); } break; } // 释放消息 delete m; }