@Override public boolean init(long id) { // Add 1 hour worth of IDs as a reserve: due to long batch validity some clients might be still getting // older IDs. 1 hour is just a safe enough value, not a real guarantee: some clients might have longer // validity. // The init method should normally be called before any client generated IDs: in this case no reserve is // needed, so we don't want to increase the reserve excessively. long reserve = HOURS.toMillis(1) << (FlakeIdGeneratorProxy.BITS_NODE_ID + FlakeIdGeneratorProxy.BITS_SEQUENCE); return newId() >= id + reserve; }
private IdBatch newIdBatch(int batchSize) { ClientMessage requestMsg = FlakeIdGeneratorNewIdBatchCodec.encodeRequest(name, batchSize); ClientMessage responseMsg = new ClientInvocation(getClient(), requestMsg, getName()) .invoke().join(); ResponseParameters response = FlakeIdGeneratorNewIdBatchCodec.decodeResponse(responseMsg); return new IdBatch(response.base, response.increment, response.batchSize); }
public ClientFlakeIdGeneratorProxy(String serviceName, String objectName, ClientContext context) { super(serviceName, objectName, context); ClientFlakeIdGeneratorConfig config = getContext().getClientConfig().findFlakeIdGeneratorConfig(getName()); batcher = new AutoBatcher(config.getPrefetchCount(), config.getPrefetchValidityMillis(), new AutoBatcher.IdBatchSupplier() { @Override public IdBatch newIdBatch(int batchSize) { return ClientFlakeIdGeneratorProxy.this.newIdBatch(batchSize); } }); }
private IdBatch newIdBatch(int batchSize) { ClientMessage requestMsg = FlakeIdGeneratorNewIdBatchCodec.encodeRequest(name, batchSize); ClientMessage responseMsg = new ClientInvocation(getClient(), requestMsg, getName()) .invoke().join(); ResponseParameters response = FlakeIdGeneratorNewIdBatchCodec.decodeResponse(responseMsg); return new IdBatch(response.base, response.increment, response.batchSize); }
public ClientFlakeIdGeneratorProxy(String serviceName, String objectName, ClientContext context) { super(serviceName, objectName, context); ClientFlakeIdGeneratorConfig config = getContext().getClientConfig().findFlakeIdGeneratorConfig(getName()); batcher = new AutoBatcher(config.getPrefetchCount(), config.getPrefetchValidityMillis(), new AutoBatcher.IdBatchSupplier() { @Override public IdBatch newIdBatch(int batchSize) { return ClientFlakeIdGeneratorProxy.this.newIdBatch(batchSize); } }); }
@Override public boolean init(long id) { // Add 1 hour worth of IDs as a reserve: due to long batch validity some clients might be still getting // older IDs. 1 hour is just a safe enough value, not a real guarantee: some clients might have longer // validity. // The init method should normally be called before any client generated IDs: in this case no reserve is // needed, so we don't want to increase the reserve excessively. long reserve = HOURS.toMillis(1) << (FlakeIdGeneratorProxy.BITS_NODE_ID + FlakeIdGeneratorProxy.BITS_SEQUENCE); return newId() >= id + reserve; }