正文
;
}
catch
(SequenceOutOfRangeException ex){
LOGGER.error(
"gen error SequenceOutOfRangeException index {} total available {}"
,
currentPartitionIndex,
availablePartitionIndices.size());
hasError=
true
;
LOGGER.error(
"set {} to SKIP"
,currentPartitionIndex);
this
.innerSequences.set(currentPartitionIndex,SkipSequence.INSTANCE);
onError(ownerKey,currentPartitionIndex,innerGen,ex);
LOGGER.error(
"after onError total available {}/{}"
,currentPartitionIndex,
availablePartitionIndices.size());
}
catch
(Exception ex){
LOGGER.error(
"gen error index {} total available {}"
,currentPartitionIndex,
availablePartitionIndices.size());
LOGGER.error(
"gen error "
,ex);
hasError=
true
;
onError(ownerKey,currentPartitionIndex,innerGen,ex);
LOGGER.error(
"after onError total available {}/{}"
,currentPartitionIndex,
availablePartitionIndices.size());
}
finally
{
long
usedTime=System.
currentTimeMillis
()-startTime;
boolean
isTimeout=usedTime>timeoutThresholdInMilliseconds;
if
(!hasError&&isTimeout){
onTimeout(currentPartitionIndex,innerGen,usedTime);
}
LOGGER.trace(
"gen usedTime {}"
,usedTime);
}
}
while
(
true
);
return
sequence;
}
使用时配置bean使用即可, 如下spring bean xml配置:
<bean id="highAvailableSequenceGen" class="com.jd.coo.sa.sequence.ha.BitwiseLoadBalanceSequenceGen">
<constructor-arg index="0" value="2"/>
<constructor-arg index="1">
<map>
<entry key="0">
<bean class="com.jd.coo.sa.sequence.AutoIncrementTablesSequenceGen">
<property name="dataSource" ref="dataSourceA"/>
<property name="sequenceTableFormat" value="%s_code_%d"/>
bean>
entry>
<entry key="1">
<bean class="com.jd.coo.sa.sequence.AutoIncrementTablesSequenceGen">
<property name="dataSource" ref="dataSourceB"/>
<property name="sequenceTableFormat" value="%s_code_%d"/>
bean>
entry>
<entry key="2">
<bean class