/** * Builds a new counter with a given identifier. * * @param id the counter identifier. */ public Counter(final String id) { _id = id; try { sync(); if (_data == -1L) { _data = 0; _dao.set(_id, 0L); LOGGER.info(MessageCatalog._00080_INIT_COUNTER, id, _data); } } catch (final DataAccessLayerException exception) { LOGGER.error(MessageCatalog._00093_DATA_ACCESS_LAYER_FAILURE, exception); throw new IllegalStateException(exception); } }
/** * Builds a new counter with a given identifier. * * @param id the counter identifier. */ public Counter(final String id) { _id = id; try { sync(); if (_data == -1L) { _data = 0; _dao.set(_id, 0L); LOGGER.info(MessageCatalog._00080_INIT_COUNTER, id, _data); } } catch (final DataAccessLayerException exception) { LOGGER.error(MessageCatalog._00093_DATA_ACCESS_LAYER_FAILURE, exception); throw new IllegalStateException(exception); } }
/** * Increases the counter value. * * @param increment the increment. * @return the new value of the counter. * @throws DataAccessLayerException if the counter can not be incremented. */ public synchronized long increment(final long increment) throws DataAccessLayerException { _dao.increment(_id, increment); sync(); if (_data < 0) { LOGGER.error(MessageCatalog._00081_COUNTER_OVERFLOW, _id, _data); } return _data; }
/** * Increases the counter value. * * @param increment the increment. * @return the new value of the counter. * @throws DataAccessLayerException if the counter can not be incremented. */ public synchronized long increment(final long increment) throws DataAccessLayerException { _dao.increment(_id, increment); sync(); if (_data < 0) { LOGGER.error(MessageCatalog._00081_COUNTER_OVERFLOW, _id, _data); } return _data; }
/** * Increments the counter. * * @return the new value of the counter * @throws DataAccessLayerException if the counter can not be incremented. */ public synchronized long next() throws DataAccessLayerException { _dao.increment(_id, 1L); sync(); return _data; }
/** * Returns the current value of the counter. * @return the current value of the counter. * * @throws DataAccessLayerException if the counter value can not be read. */ public long current() throws DataAccessLayerException { sync(); return _data; }
/** * Decreases the counter value. * * @param decrement the decrement. * @return the new value of the counter. * @throws DataAccessLayerException if the counter can not be decremented. */ public synchronized long decrement(final long decrement) throws DataAccessLayerException { _dao.decrement(_id, decrement); sync(); return _data; }
/** * Sets the counter to the given value. * * @param val the target counter value. * @throws DataAccessLayerException if the counter cannot be set. */ public synchronized void set(final long val) throws DataAccessLayerException { _dao.set(_id, val); sync(); }
/** * Decreases the counter value. * * @param decrement the decrement. * @return the new value of the counter. * @throws DataAccessLayerException if the counter can not be decremented. */ public synchronized long decrement(final long decrement) throws DataAccessLayerException { _dao.decrement(_id, decrement); sync(); return _data; }
/** * Sets the counter to the given value. * * @param val the target counter value. * @throws DataAccessLayerException if the counter cannot be set. */ public synchronized void set(final long val) throws DataAccessLayerException { _dao.set(_id, val); sync(); }
/** * Returns the current value of the counter. * @return the current value of the counter. * * @throws DataAccessLayerException if the counter value can not be read. */ public long current() throws DataAccessLayerException { sync(); return _data; }
/** * Increments the counter. * * @return the new value of the counter * @throws DataAccessLayerException if the counter can not be incremented. */ public synchronized long next() throws DataAccessLayerException { _dao.increment(_id, 1L); sync(); return _data; }