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
03aa0c1a
Commit
03aa0c1a
authored
Aug 15, 2024
by
amir.yosef
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clean up
parent
a1b617f9
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
27 additions
and
18 deletions
+27
-18
Main.java
src/Main.java
+3
-7
MasterClient.java
src/client/master/MasterClient.java
+1
-2
InfoCommand.java
src/command/InfoCommand.java
+1
-1
SetCommand.java
src/command/SetCommand.java
+4
-3
Server.java
src/server/Server.java
+1
-1
ServerBuilder.java
src/server/ServerBuilder.java
+14
-1
ServerInfo.java
src/server/ServerInfo.java
+1
-1
Settings.java
src/util/Settings.java
+2
-2
No files found.
src/Main.java
View file @
03aa0c1a
import
director.Director
;
import
server.Server
;
import
server.ServerBuilder
;
import
util.Settings
;
import
java.util.
Map
;
import
java.util.
Arrays
;
public
class
Main
{
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
();
ServerBuilder
builder
=
new
ServerBuilder
();
// System.out.println(Arrays.toString(args));
ServerBuilder
builder
=
new
ServerBuilder
(
args
);
director
.
buildMaster
(
builder
);
builder
.
setPort
(
port
);
try
(
Server
server
=
builder
.
build
())
{
server
.
start
();
}
...
...
src/client/
primary
/MasterClient.java
→
src/client/
master
/MasterClient.java
View file @
03aa0c1a
package
client
.
primary
;
package
client
.
master
;
import
client.Client
;
...
...
@@ -12,7 +12,6 @@ import java.util.List;
public
class
MasterClient
extends
Client
{
public
MasterClient
(
Socket
socket
)
{
super
(
socket
);
...
...
src/command/InfoCommand.java
View file @
03aa0c1a
...
...
@@ -2,7 +2,7 @@ package command;
import
model.Command
;
import
util.Response
;
import
util
.ServerInfo
;
import
server
.ServerInfo
;
import
java.util.List
;
import
java.util.Map
;
...
...
src/command/SetCommand.java
View file @
03aa0c1a
...
...
@@ -18,6 +18,10 @@ public class SetCommand implements CommandHandler {
@Override
public
byte
[]
execute
()
{
return
getBytes
(
args
,
storage
);
}
private
byte
[]
getBytes
(
List
<
String
>
args
,
Storage
storage
)
{
Map
<
String
,
String
>
commandsMap
=
new
HashMap
<>();
for
(
int
i
=
2
;
i
<
args
.
size
();
i
+=
2
)
{
...
...
@@ -25,7 +29,6 @@ public class SetCommand implements CommandHandler {
}
String
value
=
args
.
get
(
1
);
String
expiration
=
commandsMap
.
get
(
Command
.
PX
.
getValue
().
toLowerCase
());
if
(
expiration
!=
null
)
{
try
{
...
...
@@ -37,8 +40,6 @@ public class SetCommand implements CommandHandler {
}
else
{
storage
.
save
(
args
.
getFirst
().
toLowerCase
(),
value
);
}
return
(
"+OK\r\n"
.
getBytes
());
}
}
src/server/Server.java
View file @
03aa0c1a
package
server
;
import
client.Client
;
import
client.
primary
.MasterClient
;
import
client.
master
.MasterClient
;
import
storage.StorageManager
;
import
java.io.IOException
;
...
...
src/server/ServerBuilder.java
View file @
03aa0c1a
package
server
;
import
util.Settings
;
import
java.util.Map
;
public
class
ServerBuilder
{
private
int
port
=
6379
;
private
String
role
;
String
[]
masterPortAndHost
;
private
final
static
ServerInfo
info
=
ServerInfo
.
getInstance
();
Map
<
String
,
String
>
parameters
;
public
void
setPort
(
int
port
)
{
this
.
port
=
port
;
this
.
port
=
Settings
.
extractPort
(
parameters
,
port
);
}
public
ServerBuilder
(
String
[]
args
)
{
this
.
parameters
=
Settings
.
extractArgs
(
args
);
this
.
port
=
Settings
.
extractPort
(
parameters
,
port
);
this
.
masterPortAndHost
=
info
.
findRole
(
parameters
);
}
public
void
setRole
(
String
role
)
{
...
...
src/
util
/ServerInfo.java
→
src/
server
/ServerInfo.java
View file @
03aa0c1a
package
util
;
package
server
;
import
java.util.Map
;
...
...
src/util/Settings.java
View file @
03aa0c1a
...
...
@@ -6,8 +6,8 @@ import java.util.Map;
public
class
Settings
{
public
static
int
extractPort
(
Map
<
String
,
String
>
args
,
int
port
)
{
if
(
args
.
containsKey
(
"--
set
Port"
))
{
port
=
Integer
.
parseInt
(
args
.
get
(
"--
set
Port"
));
if
(
args
.
containsKey
(
"--Port"
))
{
port
=
Integer
.
parseInt
(
args
.
get
(
"--Port"
));
}
return
port
;
}
...
...
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