Skip to content

Commit

Permalink
Synchronize all public methods
Browse files Browse the repository at this point in the history
  • Loading branch information
zilm13 committed Oct 6, 2016
1 parent 11fa0b0 commit c44a9dc
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions ethereumj-core/src/main/java/org/ethereum/db/IndexedBlockStore.java
Expand Up @@ -78,7 +78,7 @@ public synchronized byte[] getBlockHashByNumber(long blockNumber){


@Override
public void flush(){
public synchronized void flush(){
blocks.flush();
index.flush();
if (blocksDS instanceof Flushable) {
Expand Down Expand Up @@ -112,7 +112,7 @@ private void addInternalBlock(Block block, BigInteger cummDifficulty, boolean ma
}


public List<Block> getBlocksByNumber(long number){
public synchronized List<Block> getBlocksByNumber(long number){

List<Block> result = new ArrayList<>();

Expand Down Expand Up @@ -153,18 +153,18 @@ public synchronized Block getChainBlockByNumber(long number){
}

@Override
public Block getBlockByHash(byte[] hash) {
public synchronized Block getBlockByHash(byte[] hash) {
return blocks.get(hash);
}

@Override
public boolean isBlockExist(byte[] hash) {
public synchronized boolean isBlockExist(byte[] hash) {
return blocks.get(hash) != null;
}


@Override
public BigInteger getTotalDifficultyForHash(byte[] hash){
public synchronized BigInteger getTotalDifficultyForHash(byte[] hash){
Block block = this.getBlockByHash(hash);
if (block == null) return ZERO;

Expand Down Expand Up @@ -215,7 +215,7 @@ public synchronized long getMaxNumber(){
}

@Override
public List<byte[]> getListHashesEndWith(byte[] hash, long number){
public synchronized List<byte[]> getListHashesEndWith(byte[] hash, long number){

List<Block> blocks = getListBlocksEndWith(hash, number);
List<byte[]> hashes = new ArrayList<>(blocks.size());
Expand All @@ -228,7 +228,7 @@ public List<byte[]> getListHashesEndWith(byte[] hash, long number){
}

@Override
public List<BlockHeader> getListHeadersEndWith(byte[] hash, long qty) {
public synchronized List<BlockHeader> getListHeadersEndWith(byte[] hash, long qty) {

List<Block> blocks = getListBlocksEndWith(hash, qty);
List<BlockHeader> headers = new ArrayList<>(blocks.size());
Expand All @@ -241,7 +241,7 @@ public List<BlockHeader> getListHeadersEndWith(byte[] hash, long qty) {
}

@Override
public List<Block> getListBlocksEndWith(byte[] hash, long qty) {
public synchronized List<Block> getListBlocksEndWith(byte[] hash, long qty) {
return getListBlocksEndWithInner(hash, qty);
}

Expand Down Expand Up @@ -330,7 +330,7 @@ public synchronized void reBranch(Block forkBlock){
}


public List<byte[]> getListHashesStartWith(long number, long maxBlocks){
public synchronized List<byte[]> getListHashesStartWith(long number, long maxBlocks){

List<byte[]> result = new ArrayList<>();

Expand Down Expand Up @@ -412,7 +412,7 @@ public List<BlockInfo> deserialize(byte[] bytes) {
};


public void printChain(){
public synchronized void printChain(){

Long number = getMaxNumber();

Expand All @@ -434,11 +434,11 @@ public void printChain(){

}

private List<BlockInfo> getBlockInfoForLevel(long level){
private synchronized List<BlockInfo> getBlockInfoForLevel(long level){
return index.get((int) level);
}

private void setBlockInfoForLevel(long level, List<BlockInfo> infos){
private synchronized void setBlockInfoForLevel(long level, List<BlockInfo> infos){
index.set((int) level, infos);
}

Expand All @@ -451,11 +451,11 @@ private static BlockInfo getBlockInfoForHash(List<BlockInfo> blocks, byte[] hash
}

@Override
public void load() {
public synchronized void load() {
}

@Override
public void close() {
public synchronized void close() {
logger.info("Closing IndexedBlockStore...");
try {
indexDS.close();
Expand Down

0 comments on commit c44a9dc

Please sign in to comment.