108
def runEventTransaction(store, func, *args, **kwargs):
110
This takes responsibility for setting up the transactional event
111
broadcasting junk, handling action errors, and broadcasting commit or
114
broadcaster = TransactionalEventBroadcaster()
116
# Set up event context for the duration of the action
117
# run. Additionally, handle raised ActionFailures by
118
# adding their events to the revert event list and
119
# re-raising them so they will revert the transaction.
122
{iimaginary.ITransactionalEventBroadcaster: broadcaster},
123
func, *args, **kwargs)
124
except eimaginary.ActionFailure, e:
125
broadcaster.addRevertEvent(e.event.reify())
128
result = store.transact(runHelper)
129
except eimaginary.ActionFailure, e:
130
broadcaster.broadcastRevertEvents()
133
broadcaster.broadcastEvents()
108
138
class Command(object):
109
139
__metaclass__ = CommandType
110
140
infrastructure = True
119
149
Take a player, line, and dictionary of parse results and execute the
120
150
actual Action implementation.
122
This takes responsibility for setting up the transactional event
123
broadcasting junk, handling action errors, and broadcasting commit or
126
152
@param player: A provider of C{self.actorInterface}
127
153
@param line: A unicode string containing the original input
128
154
@param match: A dictionary containing some parse results to pass
129
155
through to the C{run} method.
131
broadcaster = TransactionalEventBroadcaster()
133
# Set up event context for the duration of the action
134
# run. Additionally, handle raised ActionFailures by
135
# adding their events to the revert event list and
136
# re-raising them so they will revert the transaction.
139
{iimaginary.ITransactionalEventBroadcaster: broadcaster},
140
self.run, player, line, **match)
141
except eimaginary.ActionFailure, e:
142
broadcaster.addRevertEvent(e.event.reify())
145
result = player.store.transact(runHelper)
146
except eimaginary.ActionFailure, e:
147
broadcaster.broadcastRevertEvents()
150
broadcaster.broadcastEvents()
158
runEventTransaction(player.store, self.run, player, line, **match)