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
6bafb578
Commit
6bafb578
authored
Aug 14, 2024
by
amir.yosef
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Configure listening port ( Replication step 1 )
parent
03b93694
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
41 additions
and
12 deletions
+41
-12
misc.xml
.idea/misc.xml
+1
-1
Main.java
src/Main.java
+8
-2
Director.java
src/director/Director.java
+2
-2
Server.java
src/server/Server.java
+1
-3
ServerBuilder.java
src/server/ServerBuilder.java
+3
-3
StorageManager.java
src/storage/StorageManager.java
+1
-1
Settings.java
src/util/Settings.java
+25
-0
No files found.
.idea/misc.xml
View file @
6bafb578
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<project
version=
"4"
>
<component
name=
"JsBuildToolPackageJson"
sorting=
"DEFINITION_ORDER"
/>
<component
name=
"JsBuildToolPackageJson"
sorting=
"DEFINITION_ORDER"
/>
<component
name=
"ProjectRootManager"
version=
"2"
languageLevel=
"JDK_22"
default=
"true"
project-jdk-name=
"22"
project-jdk-type=
"JavaSDK"
>
<component
name=
"ProjectRootManager"
version=
"2"
languageLevel=
"JDK_22"
default=
"true"
project-jdk-name=
"
ibm-
22"
project-jdk-type=
"JavaSDK"
>
<output
url=
"file://$PROJECT_DIR$/out"
/>
<output
url=
"file://$PROJECT_DIR$/out"
/>
</component>
</component>
</project>
</project>
\ No newline at end of file
src/Main.java
View file @
6bafb578
import
director.Director
;
import
director.Director
;
import
server.ServerBuilder
;
import
server.Server
;
import
server.Server
;
import
server.ServerBuilder
;
import
util.Settings
;
import
java.util.Map
;
public
class
Main
{
public
class
Main
{
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
Map
<
String
,
String
>
parameters
=
Settings
.
extractArgs
(
args
);
int
port
=
6379
;
port
=
Settings
.
extractPort
(
parameters
,
port
);
Director
director
=
new
Director
();
Director
director
=
new
Director
();
ServerBuilder
builder
=
new
ServerBuilder
();
ServerBuilder
builder
=
new
ServerBuilder
();
director
.
buildMaster
(
builder
);
director
.
buildMaster
(
builder
);
builder
.
port
(
16379
);
builder
.
setPort
(
port
);
try
(
Server
server
=
builder
.
build
())
{
try
(
Server
server
=
builder
.
build
())
{
server
.
start
();
server
.
start
();
}
}
...
...
src/director/Director.java
View file @
6bafb578
...
@@ -4,10 +4,10 @@ import server.ServerBuilder;
...
@@ -4,10 +4,10 @@ import server.ServerBuilder;
public
class
Director
{
public
class
Director
{
public
void
buildMaster
(
ServerBuilder
builder
)
{
public
void
buildMaster
(
ServerBuilder
builder
)
{
builder
.
r
ole
(
"Master"
);
builder
.
setR
ole
(
"Master"
);
}
}
public
void
buildReplica
(
ServerBuilder
builder
)
{
public
void
buildReplica
(
ServerBuilder
builder
)
{
builder
.
r
ole
(
"Replica"
);
builder
.
setR
ole
(
"Replica"
);
}
}
}
}
src/server/Server.java
View file @
6bafb578
...
@@ -13,19 +13,17 @@ import java.util.concurrent.Executors;
...
@@ -13,19 +13,17 @@ import java.util.concurrent.Executors;
public
class
Server
implements
AutoCloseable
{
public
class
Server
implements
AutoCloseable
{
private
final
int
PORT
;
private
final
int
PORT
;
private
final
ExecutorService
executor
;
private
final
ExecutorService
executor
;
private
final
String
role
;
StorageManager
manager
=
new
StorageManager
();
StorageManager
manager
=
new
StorageManager
();
Server
(
int
port
,
String
role
)
{
Server
(
int
port
,
String
role
)
{
PORT
=
port
;
PORT
=
port
;
this
.
role
=
role
;
this
.
executor
=
Executors
.
newVirtualThreadPerTaskExecutor
();
this
.
executor
=
Executors
.
newVirtualThreadPerTaskExecutor
();
}
}
public
void
start
()
{
public
void
start
()
{
try
(
ServerSocket
serverSocket
=
new
ServerSocket
(
PORT
))
{
try
(
ServerSocket
serverSocket
=
new
ServerSocket
(
PORT
))
{
System
.
out
.
println
(
"Server started on
p
ort "
+
PORT
);
System
.
out
.
println
(
"Server started on
setP
ort "
+
PORT
);
while
(
true
)
{
while
(
true
)
{
serverSocket
.
setReuseAddress
(
true
);
serverSocket
.
setReuseAddress
(
true
);
...
...
src/server/ServerBuilder.java
View file @
6bafb578
package
server
;
package
server
;
public
class
ServerBuilder
{
public
class
ServerBuilder
{
private
int
port
;
private
int
port
=
6379
;
private
String
role
;
private
String
role
;
public
void
p
ort
(
int
port
)
{
public
void
setP
ort
(
int
port
)
{
this
.
port
=
port
;
this
.
port
=
port
;
}
}
public
void
r
ole
(
String
role
)
{
public
void
setR
ole
(
String
role
)
{
this
.
role
=
role
;
this
.
role
=
role
;
}
}
...
...
src/storage/StorageManager.java
View file @
6bafb578
...
@@ -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
,
30
,
30
,
TimeUnit
.
SECOND
S
);
scheduler
.
scheduleAtFixedRate
(
this
::
performMaintenance
,
2
,
2
,
TimeUnit
.
MINUTE
S
);
}
}
private
void
performMaintenance
()
{
private
void
performMaintenance
()
{
...
...
src/util/Settings.java
0 → 100644
View file @
6bafb578
package
util
;
import
java.util.HashMap
;
import
java.util.Map
;
public
class
Settings
{
public
static
int
extractPort
(
Map
<
String
,
String
>
args
,
int
port
)
{
if
(
args
.
containsKey
(
"--setPort"
))
{
port
=
Integer
.
parseInt
(
args
.
get
(
"--setPort"
));
}
return
port
;
}
public
static
Map
<
String
,
String
>
extractArgs
(
String
[]
args
)
{
Map
<
String
,
String
>
parameters
=
new
HashMap
<>();
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
if
(
i
+
1
>=
args
.
length
)
break
;
parameters
.
put
(
args
[
i
],
args
[
i
+
1
]);
}
System
.
out
.
println
(
parameters
);
return
parameters
;
}
}
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