-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#218 Implementing lock based proxy manager for managed hazelcast
- Loading branch information
1 parent
642510d
commit abe78de
Showing
12 changed files
with
351 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 0 additions & 27 deletions
27
.../main/java/io/github/bucket4j/distributed/proxy/generic/select_for_update/LockResult.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...ast-3/src/main/java/io/github/bucket4j/grid/hazelcast/HazelcastLockBasedProxyManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package io.github.bucket4j.grid.hazelcast; | ||
|
||
import com.hazelcast.core.IMap; | ||
import io.github.bucket4j.distributed.proxy.ClientSideConfig; | ||
import io.github.bucket4j.distributed.proxy.generic.select_for_update.AbstractLockBasedProxyManager; | ||
import io.github.bucket4j.distributed.proxy.generic.select_for_update.LockBasedTransaction; | ||
|
||
import java.util.Objects; | ||
|
||
public class HazelcastLockBasedProxyManager<K> extends AbstractLockBasedProxyManager<K> { | ||
|
||
private final IMap<K, byte[]> map; | ||
|
||
public HazelcastLockBasedProxyManager(IMap<K, byte[]> map) { | ||
this(map, ClientSideConfig.getDefault()); | ||
} | ||
|
||
public HazelcastLockBasedProxyManager(IMap<K, byte[]> map, ClientSideConfig clientSideConfig) { | ||
super(clientSideConfig); | ||
this.map = Objects.requireNonNull(map); | ||
} | ||
|
||
@Override | ||
public void removeProxy(K key) { | ||
map.remove(key); | ||
} | ||
|
||
@Override | ||
public boolean isAsyncModeSupported() { | ||
// Because Hazelcast IMap does not provide "lockAsync" API. | ||
return false; | ||
} | ||
|
||
@Override | ||
protected LockBasedTransaction allocateTransaction(K key) { | ||
return new LockBasedTransaction() { | ||
|
||
@Override | ||
public void begin() { | ||
// do nothing | ||
} | ||
|
||
@Override | ||
public void rollback() { | ||
// do nothing | ||
} | ||
|
||
@Override | ||
public void commit() { | ||
// do nothing | ||
} | ||
|
||
@Override | ||
public byte[] lockAndGet() { | ||
map.lock(key); | ||
return map.get(key); | ||
} | ||
|
||
@Override | ||
public void unlock() { | ||
map.unlock(key); | ||
} | ||
|
||
@Override | ||
public void create(byte[] data) { | ||
map.put(key, data); | ||
} | ||
|
||
@Override | ||
public void update(byte[] data) { | ||
map.put(key, data); | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
protected void releaseTransaction(LockBasedTransaction transaction) { | ||
// do nothing | ||
} | ||
|
||
} |
Oops, something went wrong.