/** * Tries to claim the given token {@code entry}. If the claim fails an {@link UnableToClaimTokenException} should be * thrown. Otherwise the given {@code resultSet} should be updated to reflect the claim. * * @param resultSet the updatable query result of an executed {@link PreparedStatement} * @param entry the entry extracted from the given result set * @return the claimed tracking token * * @throws UnableToClaimTokenException if the token cannot be claimed because another node currently owns the token * @throws SQLException when an exception occurs while claiming the token entry */ protected TrackingToken claimToken(ResultSet resultSet, AbstractTokenEntry<?> entry) throws SQLException { if (!entry.claim(nodeId, claimTimeout)) { throw new UnableToClaimTokenException( format("Unable to claim token '%s[%s]'. It is owned by '%s'", entry.getProcessorName(), entry.getSegment(), entry.getOwner())); } resultSet.updateString(schema.ownerColum(), entry.getOwner()); resultSet.updateString(schema.timestampColumn(), entry.timestampAsString()); resultSet.updateRow(); return entry.getToken(serializer); }
/** * {@inheritDoc} */ @Override public TrackingToken fetchToken(String processorName, int segment) throws UnableToClaimTokenException { AbstractTokenEntry<?> tokenEntry = loadOrInsertTokenEntry(processorName, segment); return tokenEntry.getToken(serializer); }
/** * {@inheritDoc} */ @Override public TrackingToken fetchToken(String processorName, int segment) throws UnableToClaimTokenException { AbstractTokenEntry<?> tokenEntry = loadOrInsertTokenEntry(processorName, segment); return tokenEntry.getToken(serializer); }
/** * Tries to claim the given token {@code entry}. If the claim fails an {@link UnableToClaimTokenException} should be * thrown. Otherwise the given {@code resultSet} should be updated to reflect the claim. * * @param resultSet the updatable query result of an executed {@link PreparedStatement} * @param entry the entry extracted from the given result set * @return the claimed tracking token * * @throws UnableToClaimTokenException if the token cannot be claimed because another node currently owns the token * @throws SQLException when an exception occurs while claiming the token entry */ protected TrackingToken claimToken(ResultSet resultSet, AbstractTokenEntry<?> entry) throws SQLException { if (!entry.claim(nodeId, claimTimeout)) { throw new UnableToClaimTokenException( format("Unable to claim token '%s[%s]'. It is owned by '%s'", entry.getProcessorName(), entry.getSegment(), entry.getOwner())); } resultSet.updateString(schema.ownerColum(), entry.getOwner()); resultSet.updateString(schema.timestampColumn(), entry.timestampAsString()); resultSet.updateRow(); return entry.getToken(serializer); }
/** * Tries to claim the given token {@code entry}. If the claim fails an {@link UnableToClaimTokenException} should be * thrown. Otherwise the given {@code resultSet} should be updated to reflect the claim. * * @param resultSet the updatable query result of an executed {@link PreparedStatement} * @param entry the entry extracted from the given result set * @return the claimed tracking token * @throws UnableToClaimTokenException if the token cannot be claimed because another node currently owns the token * @throws SQLException when an exception occurs while claiming the token entry */ protected TrackingToken claimToken(ResultSet resultSet, AbstractTokenEntry<?> entry) throws SQLException { if (!entry.claim(nodeId, claimTimeout)) { throw new UnableToClaimTokenException( format("Unable to claim token '%s[%s]'. It is owned by '%s'", entry.getProcessorName(), entry.getSegment(), entry.getOwner())); } resultSet.updateString(schema.ownerColum(), entry.getOwner()); resultSet.updateString(schema.timestampColumn(), entry.timestampAsString()); resultSet.updateRow(); return entry.getToken(serializer); }