private void persistActionRecord() { if (LOGGING_ENABLED) { ActionRecord record = new ActionRecord(); record.setInitiator(mAction.getInitiator()); record.setName(mAction.getName()); record.getReceivers().addAll(mAction.getReceiver()); record.setResult(mResult); record.setDatestamp(new Date(mContext.getContextTime())); localPersist(record); } }
private void postActionHook() { if (LOG.isTraceEnabled()) { LOG.trace("postActionHook()... Task: " + mAction.getName() + "has completed"); } persistActionRecord(); // Check if the initiator of this action supports scoring... Object initiator = mContext.getMapObjectCollection().getObjectByGuid(mAction.getInitiator()); if (initiator instanceof IScoringAbility) { ((IScoringAbility) initiator).score(mAction); } }
/** * The actual wrapped call. Note that all of the action's execution method is wrapped in a * try/catch block, so that we can contain any explosive exceptions that occur during operation. */ public String call() throws Exception { /* * Perform pre-action checks to verify that the initiators and * receivers support the action's required IAbilities */ if (!preActionHook()) { persistActionRecord(); return mResult; } try { mAction.preActionHook(); mResult = mAction.executeCallableAction(); mAction.postActionHook(); } catch (Exception e) { LOG.error( "Exception occured while attempting to perform PreActionHook for action:" + e.getLocalizedMessage()); mResult = "FAILED: EXCEPTION " + e.getLocalizedMessage(); } /* * If this is a repeating task, schedule the future task at the * appropriate period. Note that we are carrying forward the same * mAction, so that internal changes to the action object will have * continuity over their entire lifetime. * * Calling get() or any other waiting block will only work for the * first iteration of the task, because the caller would have a * reference to the first of many possible ScheduledFuture's... this * is alright, because the IAction's behavior is still the same as * if it were submitted normally, the Future that the caller got * still behaves as if the task were running periodically. No loss * for them... */ if (mAction.getPeriod() > 0) { mAction.schedule(mAction.getPeriod(), mAction.getTimeUnit()); } postActionHook(); persistActionRecord(); return mResult; }
private boolean preActionHook() { if (LOG.isTraceEnabled()) { LOG.trace("preActionHook()... Task: " + mAction.getName() + "starting"); } /* * If this action was started by the SYSTEM_GUID, we don't do any * ability checking on the operation. We may want to expand this out * later to include different processes with different abilities, * but for now, let's just let the system do anything it wants. */ if (!GuidManager.SYSTEM_GUID.equals(mAction.getInitiator())) { Object initiator = mContext.getMapObjectCollection().getObjectByGuid(mAction.getInitiator()); if (initiator == null) { initiator = mContext.getRegionCollection().getRegion(mAction.getInitiator()); if (null == initiator) { LOG.warn("Command action using the system guid...was this expected?"); } } // TODO: This check may not be appropriate here.... How about AI objects? Moving Zones? if (!(initiator instanceof IMapObject) && !(initiator instanceof IMapRegion)) { mResult = "FAIL: Initiator is not an IMapObject or IMapRegion"; return false; } // Now verify that the initiator supports all of the IAction's // required abilities if (!supportsRequiredAbilities( mAction.getRequiredInitiatorAbilities(), ((IAbility) initiator).getObjectAbilities())) { mResult = "FAIL: Initiator doesn't support one of the required IAbilities"; return false; } } /* * Now walk each of the receivers, verifying that they support all * of the required methods necessary to support the action. But, * recievers might not be in the trackableByGuidList. atm I am * trying to use a record that does implement the IAction And if it * is the system, just return. */ Iterator<Long> itor = mAction.getReceiver().iterator(); while (itor.hasNext()) { // Verify first that this receiver supports IAbility long next = itor.next(); // if system, then continue to next itoration if (next == GuidManager.SYSTEM_GUID) { continue; } Object receiver = mContext.getMapObjectCollection().getObjectByGuid(next); // The recever might be found int the // m_context.getPlayerSignUpActionCollection.get(next); // if (receiver == null) // receiver = m_context.getPlayerSignUpActionHashtable().get(next); if (!(receiver instanceof IAbility)) { mResult = "FAIL: Receiver doesn't support IAbility"; return false; } // Now verify that the receiver supports all of the IAction's // required abilities if (!supportsRequiredAbilities( mAction.getRequiredReceiverAbilities(), ((IAbility) receiver).getObjectAbilities())) { mResult = "FAIL: Receiver doesn't support one of the required IAbilities"; return false; } } return true; }