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
director.Director
;
import
server.Server
;
import
server.Server
;
import
server.ServerBuilder
;
import
server.ServerBuilder
;
import
util.Settings
;
import
java.util.
Map
;
import
java.util.
Arrays
;
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
();
// System.out.println(Arrays.toString(args));
ServerBuilder
builder
=
new
ServerBuilder
(
args
);
director
.
buildMaster
(
builder
);
director
.
buildMaster
(
builder
);
builder
.
setPort
(
port
);
try
(
Server
server
=
builder
.
build
())
{
try
(
Server
server
=
builder
.
build
())
{
server
.
start
();
server
.
start
();
}
}
...
...
src/client/
primary
/MasterClient.java
→
src/client/
master
/MasterClient.java
View file @
03aa0c1a
package
client
.
primary
;
package
client
.
master
;
import
client.Client
;
import
client.Client
;
...
@@ -12,7 +12,6 @@ import java.util.List;
...
@@ -12,7 +12,6 @@ import java.util.List;
public
class
MasterClient
extends
Client
{
public
class
MasterClient
extends
Client
{
public
MasterClient
(
Socket
socket
)
{
public
MasterClient
(
Socket
socket
)
{
super
(
socket
);
super
(
socket
);
...
...
src/command/InfoCommand.java
View file @
03aa0c1a
...
@@ -2,7 +2,7 @@ package command;
...
@@ -2,7 +2,7 @@ package command;
import
model.Command
;
import
model.Command
;
import
util.Response
;
import
util.Response
;
import
util
.ServerInfo
;
import
server
.ServerInfo
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
...
...
src/command/SetCommand.java
View file @
03aa0c1a
...
@@ -18,6 +18,10 @@ public class SetCommand implements CommandHandler {
...
@@ -18,6 +18,10 @@ public class SetCommand implements CommandHandler {
@Override
@Override
public
byte
[]
execute
()
{
public
byte
[]
execute
()
{
return
getBytes
(
args
,
storage
);
}
private
byte
[]
getBytes
(
List
<
String
>
args
,
Storage
storage
)
{
Map
<
String
,
String
>
commandsMap
=
new
HashMap
<>();
Map
<
String
,
String
>
commandsMap
=
new
HashMap
<>();
for
(
int
i
=
2
;
i
<
args
.
size
();
i
+=
2
)
{
for
(
int
i
=
2
;
i
<
args
.
size
();
i
+=
2
)
{
...
@@ -25,7 +29,6 @@ public class SetCommand implements CommandHandler {
...
@@ -25,7 +29,6 @@ public class SetCommand implements CommandHandler {
}
}
String
value
=
args
.
get
(
1
);
String
value
=
args
.
get
(
1
);
String
expiration
=
commandsMap
.
get
(
Command
.
PX
.
getValue
().
toLowerCase
());
String
expiration
=
commandsMap
.
get
(
Command
.
PX
.
getValue
().
toLowerCase
());
if
(
expiration
!=
null
)
{
if
(
expiration
!=
null
)
{
try
{
try
{
...
@@ -37,8 +40,6 @@ public class SetCommand implements CommandHandler {
...
@@ -37,8 +40,6 @@ public class SetCommand implements CommandHandler {
}
else
{
}
else
{
storage
.
save
(
args
.
getFirst
().
toLowerCase
(),
value
);
storage
.
save
(
args
.
getFirst
().
toLowerCase
(),
value
);
}
}
return
(
"+OK\r\n"
.
getBytes
());
return
(
"+OK\r\n"
.
getBytes
());
}
}
}
}
src/server/Server.java
View file @
03aa0c1a
package
server
;
package
server
;
import
client.Client
;
import
client.Client
;
import
client.
primary
.MasterClient
;
import
client.
master
.MasterClient
;
import
storage.StorageManager
;
import
storage.StorageManager
;
import
java.io.IOException
;
import
java.io.IOException
;
...
...
src/server/ServerBuilder.java
View file @
03aa0c1a
package
server
;
package
server
;
import
util.Settings
;
import
java.util.Map
;
public
class
ServerBuilder
{
public
class
ServerBuilder
{
private
int
port
=
6379
;
private
int
port
=
6379
;
private
String
role
;
private
String
role
;
String
[]
masterPortAndHost
;
private
final
static
ServerInfo
info
=
ServerInfo
.
getInstance
();
Map
<
String
,
String
>
parameters
;
public
void
setPort
(
int
port
)
{
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
)
{
public
void
setRole
(
String
role
)
{
...
...
src/
util
/ServerInfo.java
→
src/
server
/ServerInfo.java
View file @
03aa0c1a
package
util
;
package
server
;
import
java.util.Map
;
import
java.util.Map
;
...
...
src/util/Settings.java
View file @
03aa0c1a
...
@@ -6,8 +6,8 @@ import java.util.Map;
...
@@ -6,8 +6,8 @@ import java.util.Map;
public
class
Settings
{
public
class
Settings
{
public
static
int
extractPort
(
Map
<
String
,
String
>
args
,
int
port
)
{
public
static
int
extractPort
(
Map
<
String
,
String
>
args
,
int
port
)
{
if
(
args
.
containsKey
(
"--
set
Port"
))
{
if
(
args
.
containsKey
(
"--Port"
))
{
port
=
Integer
.
parseInt
(
args
.
get
(
"--
set
Port"
));
port
=
Integer
.
parseInt
(
args
.
get
(
"--Port"
));
}
}
return
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