Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
K
key_value-server
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
amir.yosef
key_value-server
Commits
03b93694
Commit
03b93694
authored
Aug 13, 2024
by
amir.yosef
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update for runMaintenance functionality
parent
921ae604
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
9 additions
and
9 deletions
+9
-9
CommandHandler.java
src/command/CommandHandler.java
+1
-1
LRUCachePolicy.java
src/storage/LRUCachePolicy.java
+4
-4
Storage.java
src/storage/Storage.java
+3
-3
StorageManager.java
src/storage/StorageManager.java
+1
-1
No files found.
src/command/CommandHandler.java
View file @
03b93694
...
@@ -3,5 +3,5 @@ package command;
...
@@ -3,5 +3,5 @@ package command;
import
java.io.IOException
;
import
java.io.IOException
;
public
interface
CommandHandler
{
public
interface
CommandHandler
{
byte
[]
execute
(
)
throws
IOException
;
byte
[]
execute
(
)
throws
IOException
;
}
}
src/storage/LRUCachePolicy.java
View file @
03b93694
...
@@ -6,13 +6,13 @@ import java.util.concurrent.ConcurrentHashMap;
...
@@ -6,13 +6,13 @@ import java.util.concurrent.ConcurrentHashMap;
import
java.util.concurrent.ConcurrentLinkedQueue
;
import
java.util.concurrent.ConcurrentLinkedQueue
;
public
class
LRUCachePolicy
<
K
,
V
>
implements
CachePolicy
<
K
,
V
>
{
public
class
LRUCachePolicy
<
K
,
V
>
implements
CachePolicy
<
K
,
V
>
{
private
final
int
maxCapacity
;
private
final
int
threshold
;
private
final
Map
<
K
,
V
>
cacheMap
;
private
final
Map
<
K
,
V
>
cacheMap
;
private
final
Queue
<
K
>
accessOrder
;
private
final
Queue
<
K
>
accessOrder
;
public
LRUCachePolicy
(
int
maxCapacity
)
{
public
LRUCachePolicy
(
int
maxCapacity
,
int
threshold
)
{
this
.
maxCapacity
=
maxCapacity
;
this
.
cacheMap
=
new
ConcurrentHashMap
<>(
maxCapacity
);
this
.
cacheMap
=
new
ConcurrentHashMap
<>(
maxCapacity
);
this
.
threshold
=
threshold
;
this
.
accessOrder
=
new
ConcurrentLinkedQueue
<>();
this
.
accessOrder
=
new
ConcurrentLinkedQueue
<>();
}
}
...
@@ -39,7 +39,7 @@ public class LRUCachePolicy<K, V> implements CachePolicy<K, V> {
...
@@ -39,7 +39,7 @@ public class LRUCachePolicy<K, V> implements CachePolicy<K, V> {
@Override
@Override
public
void
runMaintenance
()
{
public
void
runMaintenance
()
{
while
(
cacheMap
.
size
()
>
maxCapacity
)
{
while
(
cacheMap
.
entrySet
().
size
()
>
threshold
)
{
evictLeastRecentlyUsed
();
evictLeastRecentlyUsed
();
}
}
}
}
...
...
src/storage/Storage.java
View file @
03b93694
...
@@ -9,12 +9,12 @@ public class Storage {
...
@@ -9,12 +9,12 @@ public class Storage {
private
final
Map
<
String
,
Long
>
timeToExpiration
=
new
ConcurrentHashMap
<>(
capacity
);
private
final
Map
<
String
,
Long
>
timeToExpiration
=
new
ConcurrentHashMap
<>(
capacity
);
private
final
Map
<
String
,
Long
>
currentTimeForKey
=
new
ConcurrentHashMap
<>(
capacity
);
private
final
Map
<
String
,
Long
>
currentTimeForKey
=
new
ConcurrentHashMap
<>(
capacity
);
private
Storage
()
{
private
Storage
(
int
threshold
)
{
this
.
storage
=
new
LRUCachePolicy
<>(
capacity
);
this
.
storage
=
new
LRUCachePolicy
<>(
capacity
,
threshold
);
}
}
private
static
final
class
StorageHolder
{
private
static
final
class
StorageHolder
{
private
static
final
Storage
instance
=
new
Storage
();
private
static
final
Storage
instance
=
new
Storage
(
8000
);
}
}
public
static
Storage
getInstance
()
{
public
static
Storage
getInstance
()
{
...
...
src/storage/StorageManager.java
View file @
03b93694
...
@@ -12,7 +12,7 @@ public class StorageManager {
...
@@ -12,7 +12,7 @@ public class StorageManager {
public
StorageManager
()
{
public
StorageManager
()
{
this
.
storage
=
Storage
.
getInstance
();
this
.
storage
=
Storage
.
getInstance
();
this
.
scheduler
=
Executors
.
newSingleThreadScheduledExecutor
();
this
.
scheduler
=
Executors
.
newSingleThreadScheduledExecutor
();
scheduler
.
scheduleAtFixedRate
(
this
::
performMaintenance
,
2
,
2
,
TimeUnit
.
MINUTE
S
);
scheduler
.
scheduleAtFixedRate
(
this
::
performMaintenance
,
30
,
30
,
TimeUnit
.
SECOND
S
);
}
}
private
void
performMaintenance
()
{
private
void
performMaintenance
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment