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
a1b617f9
Commit
a1b617f9
authored
Aug 14, 2024
by
amir.yosef
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Info Command ( Replication step 2 )
parent
6bafb578
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
78 additions
and
2 deletions
+78
-2
InfoCommand.java
src/command/InfoCommand.java
+32
-0
CommandFactory.java
src/factory/CommandFactory.java
+1
-0
Server.java
src/server/Server.java
+1
-1
ServerInfo.java
src/util/ServerInfo.java
+44
-0
Settings.java
src/util/Settings.java
+0
-1
No files found.
src/command/InfoCommand.java
0 → 100644
View file @
a1b617f9
package
command
;
import
model.Command
;
import
util.Response
;
import
util.ServerInfo
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
public
class
InfoCommand
implements
CommandHandler
{
private
final
ServerInfo
configuration
=
ServerInfo
.
getInstance
();
List
<
String
>
args
;
public
InfoCommand
(
List
<
String
>
args
)
{
this
.
args
=
args
;
}
@Override
public
byte
[]
execute
()
{
String
command
=
args
.
getFirst
();
if
(
command
.
equalsIgnoreCase
(
Command
.
REPLICATION
.
getValue
()))
{
Map
<
String
,
String
>
info
=
configuration
.
getInfo
();
String
response
=
info
.
entrySet
()
.
stream
()
.
map
(
data
->
data
.
getKey
()
+
":"
+
data
.
getValue
())
.
collect
(
Collectors
.
joining
());
return
Response
.
getResponse
(
response
);
}
return
null
;
}
}
\ No newline at end of file
src/factory/CommandFactory.java
View file @
a1b617f9
...
@@ -25,6 +25,7 @@ public class CommandFactory implements Factory {
...
@@ -25,6 +25,7 @@ public class CommandFactory implements Factory {
case
ECHO
->
new
EchoCommand
(
args
);
case
ECHO
->
new
EchoCommand
(
args
);
case
SET
->
new
SetCommand
(
args
);
case
SET
->
new
SetCommand
(
args
);
case
GET
->
new
GetCommand
(
args
);
case
GET
->
new
GetCommand
(
args
);
case
INFO
->
new
InfoCommand
(
args
);
// case REPLCONF -> new ReplConfCommand(replicaReceiver);
// case REPLCONF -> new ReplConfCommand(replicaReceiver);
// case PSYNC -> new FullResyncCommandProcessor(replicaSender);
// case PSYNC -> new FullResyncCommandProcessor(replicaSender);
// case WAIT -> new WaitCommandProcessor(replicaSender, replicaReceiver);
// case WAIT -> new WaitCommandProcessor(replicaSender, replicaReceiver);
...
...
src/server/Server.java
View file @
a1b617f9
...
@@ -23,7 +23,7 @@ public class Server implements AutoCloseable {
...
@@ -23,7 +23,7 @@ public class Server implements AutoCloseable {
public
void
start
()
{
public
void
start
()
{
try
(
ServerSocket
serverSocket
=
new
ServerSocket
(
PORT
))
{
try
(
ServerSocket
serverSocket
=
new
ServerSocket
(
PORT
))
{
System
.
out
.
println
(
"Server started on
set
Port "
+
PORT
);
System
.
out
.
println
(
"Server started on Port "
+
PORT
);
while
(
true
)
{
while
(
true
)
{
serverSocket
.
setReuseAddress
(
true
);
serverSocket
.
setReuseAddress
(
true
);
...
...
src/util/ServerInfo.java
0 → 100644
View file @
a1b617f9
package
util
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
public
class
ServerInfo
{
private
static
ServerInfo
serverInfo
;
private
final
Map
<
String
,
String
>
info
=
new
ConcurrentHashMap
<>();
private
ServerInfo
()
{
info
.
put
(
"role"
,
"master"
);
}
public
static
ServerInfo
getInstance
()
{
if
(
serverInfo
==
null
)
{
serverInfo
=
new
ServerInfo
();
}
return
serverInfo
;
}
public
String
getRole
()
{
return
serverInfo
.
info
.
get
(
"role"
);
}
public
String
[]
findRole
(
Map
<
String
,
String
>
parameters
)
{
String
[]
masterPortAndHost
=
new
String
[]{};
String
role
=
"master"
;
if
(
parameters
.
containsKey
(
"--replicaof"
))
{
masterPortAndHost
=
parameters
.
get
(
"--replicaof"
).
split
(
" "
);
role
=
"slave"
;
}
else
{
info
.
put
(
"master_repl_offset"
,
"0"
);
info
.
put
(
"master_replid"
,
"8371b4fb1155b71f4a04d3e1bc3e18c4a990aeeb"
);
}
info
.
put
(
"role"
,
role
);
return
masterPortAndHost
;
}
public
Map
<
String
,
String
>
getInfo
()
{
return
this
.
info
;
}
}
src/util/Settings.java
View file @
a1b617f9
...
@@ -19,7 +19,6 @@ public class Settings {
...
@@ -19,7 +19,6 @@ public class Settings {
parameters
.
put
(
args
[
i
],
args
[
i
+
1
]);
parameters
.
put
(
args
[
i
],
args
[
i
+
1
]);
}
}
System
.
out
.
println
(
parameters
);
return
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