Changeset 9dcf48ea


Ignore:
Timestamp:
Mar 9, 2018 11:52:59 AM (2 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
a845d4f
Parents:
33b2d834
Message:

Router: EnumSet? for state checking

File:
1 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/router/Router.java

    r33b2d834 r9dcf48ea  
    1414import java.util.Collection;
    1515import java.util.Collections;
     16import java.util.EnumSet;
    1617import java.util.LinkedList;
    1718import java.util.List;
     
    759760        STOPPED
    760761    }
     762
     763    /**
     764     *  For efficiency. EnumSets are bitmasks.
     765     *  @since 0.9.34
     766     */
     767    private static final Set<State> STATES_ALIVE =
     768        EnumSet.of(State.RUNNING, State.GRACEFUL_SHUTDOWN, State.STARTING_1, State.STARTING_2,
     769                   State.STARTING_3, State.NETDB_READY, State.EXPL_TUNNELS_READY);
     770
     771    private static final Set<State> STATES_GRACEFUL =
     772        EnumSet.of(State.GRACEFUL_SHUTDOWN, State.FINAL_SHUTDOWN_1, State.FINAL_SHUTDOWN_2,
     773                   State.FINAL_SHUTDOWN_3, State.STOPPED);
     774
     775    private static final Set<State> STATES_FINAL =
     776        EnumSet.of(State.FINAL_SHUTDOWN_1, State.FINAL_SHUTDOWN_2, State.FINAL_SHUTDOWN_3, State.STOPPED);
    761777   
    762778    /**
     
    781797    public boolean isAlive() {
    782798        synchronized(_stateLock) {
    783             return _state == State.RUNNING ||
    784                    _state == State.GRACEFUL_SHUTDOWN ||
    785                    _state == State.STARTING_1 ||
    786                    _state == State.STARTING_2 ||
    787                    _state == State.STARTING_3 ||
    788                    _state == State.NETDB_READY ||
    789                    _state == State.EXPL_TUNNELS_READY;
     799            return STATES_ALIVE.contains(_state);
    790800        }
    791801    }
     
    834844    public boolean gracefulShutdownInProgress() {
    835845        synchronized(_stateLock) {
    836             return _state == State.GRACEFUL_SHUTDOWN ||
    837                    _state == State.FINAL_SHUTDOWN_1 ||
    838                    _state == State.FINAL_SHUTDOWN_2 ||
    839                    _state == State.FINAL_SHUTDOWN_3 ||
    840                    _state == State.STOPPED;
     846            return STATES_GRACEFUL.contains(_state);
    841847        }
    842848    }
     
    848854    public boolean isFinalShutdownInProgress() {
    849855        synchronized(_stateLock) {
    850             return _state == State.FINAL_SHUTDOWN_1 ||
    851                    _state == State.FINAL_SHUTDOWN_2 ||
    852                    _state == State.FINAL_SHUTDOWN_3 ||
    853                    _state == State.STOPPED;
     856            return STATES_FINAL.contains(_state);
    854857        }
    855858    }
Note: See TracChangeset for help on using the changeset viewer.