001package arez; 002 003/** 004 * Flags that can be passed to configure actions. 005 */ 006public final class ActionFlags 007{ 008 /** 009 * The action can only read arez state. 010 */ 011 public static final int READ_ONLY = 1 << 24; 012 /** 013 * The action can read or write arez state. 014 */ 015 public static final int READ_WRITE = 1 << 23; 016 /** 017 * Do not report result to spy infrastructure. 018 */ 019 public static final int NO_REPORT_RESULT = 1 << 12; 020 /** 021 * The action must create a new transaction and will not use containing transaction. 022 */ 023 public static final int REQUIRE_NEW_TRANSACTION = 1 << 11; 024 /** 025 * If passed to an action, the the action must verify that an action performed an activity 026 * that required a transaction. These activities include: 027 * <ul> 028 * <li>read or write an observable property.</li> 029 * <li>read a computable property.</li> 030 * <li>schedule an observer.</li> 031 * <li>mark an observer as stale.</li> 032 * <li>report possible change in computable property.</li> 033 * </ul> 034 * <p>This flag must not be present if {@link #NO_VERIFY_ACTION_REQUIRED} is present. If neither 035 * VERIFY_ACTION_REQUIRED nor {@link #NO_VERIFY_ACTION_REQUIRED} is specified then VERIFY_ACTION_REQUIRED 036 * is assumed.</p> 037 */ 038 public static final int VERIFY_ACTION_REQUIRED = 1 << 27; 039 /** 040 * This flag can be passed to skip verification that action was required. 041 * This flag must not be present if {@link #VERIFY_ACTION_REQUIRED} is present. 042 */ 043 public static final int NO_VERIFY_ACTION_REQUIRED = 1 << 26; 044 /** 045 * Mask used to extract verify action bits. 046 */ 047 private static final int VERIFY_ACTION_MASK = VERIFY_ACTION_REQUIRED | NO_VERIFY_ACTION_REQUIRED; 048 /** 049 * Mask containing flags that can be applied to an action. 050 */ 051 static final int CONFIG_FLAGS_MASK = 052 READ_ONLY | READ_WRITE | REQUIRE_NEW_TRANSACTION | VERIFY_ACTION_MASK | NO_REPORT_RESULT; 053 054 private ActionFlags() 055 { 056 } 057 058 static int verifyActionRule( final int flags ) 059 { 060 return Arez.shouldCheckApiInvariants() ? 061 0 != ( flags & VERIFY_ACTION_MASK ) ? 0 : VERIFY_ACTION_REQUIRED : 062 0; 063 } 064 065 /** 066 * Return true if flags contains a valid verify action rule. 067 * 068 * @param flags the flags. 069 * @return true if flags contains verify action rule. 070 */ 071 static boolean isVerifyActionRuleValid( final int flags ) 072 { 073 return VERIFY_ACTION_REQUIRED == ( flags & VERIFY_ACTION_MASK ) || 074 NO_VERIFY_ACTION_REQUIRED == ( flags & VERIFY_ACTION_MASK ); 075 } 076}