Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
Controller
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pr1n19
Controller
Commits
27d7de0a
Commit
27d7de0a
authored
3 years ago
by
pr1n19
Browse files
Options
Downloads
Patches
Plain Diff
Join commad completed, and infrastructure for Remove command begun
parent
158eaef1
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Controller.java
+83
-1
83 additions, 1 deletion
src/Controller.java
with
83 additions
and
1 deletion
src/Controller.java
+
83
−
1
View file @
27d7de0a
import
java.io.BufferedReader
;
import
java.io.InputStreamReader
;
import
java.net.ServerSocket
;
import
java.net.Socket
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
public
class
Controller
{
public
class
Controller
{
//Ports of each dStore, and associated socket
private
static
final
HashMap
<
Integer
,
Socket
>
dStores
=
new
HashMap
<>();
//Ports of each dStore, and associated number of files
private
static
final
HashMap
<
Integer
,
Integer
>
storeNumbers
=
new
HashMap
<>();
//Store filename & ports
private
static
final
HashMap
<
String
,
int
[]>
index
=
new
HashMap
<>();
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
int
cPort
=
Integer
.
parseInt
(
args
[
0
]);
int
cPort
=
Integer
.
parseInt
(
args
[
0
]);
int
r
=
Integer
.
parseInt
(
args
[
1
]);
int
r
eplicationFactor
=
Integer
.
parseInt
(
args
[
1
]);
int
timeOut
=
Integer
.
parseInt
(
args
[
2
]);
int
timeOut
=
Integer
.
parseInt
(
args
[
2
]);
int
rebalancePeriod
=
Integer
.
parseInt
(
args
[
3
]);
int
rebalancePeriod
=
Integer
.
parseInt
(
args
[
3
]);
try
{
//Create socket for listening
ServerSocket
listeningSocket
=
new
ServerSocket
(
cPort
);
new
Thread
(()
->
{
//Continually listen for new commands
while
(
true
)
{
try
{
//Accept new TCP connection & get command
Socket
client
=
listeningSocket
.
accept
();
BufferedReader
in
=
new
BufferedReader
(
new
InputStreamReader
(
client
.
getInputStream
()));
String
received
=
in
.
readLine
();
String
command
=
received
.
split
(
" "
)[
0
];
//Process depending on command received
switch
(
command
)
{
case
"STORE"
->
System
.
out
.
println
(
"STORE"
);
case
"LOAD"
->
System
.
out
.
println
(
"LOAD"
);
case
"REMOVE"
->
removeFile
(
received
.
split
(
" "
)[
1
],
client
);
case
"LIST"
->
System
.
out
.
println
(
"LIST"
);
case
"JOIN"
->
{
int
portNo
=
Integer
.
parseInt
(
received
.
split
(
" "
)[
1
]);
dStores
.
put
(
portNo
,
client
);
storeNumbers
.
put
(
portNo
,
0
);
}
}
}
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"error "
+
e
);
}
}
}).
start
();
}
catch
(
Exception
e
){
System
.
out
.
println
(
"error "
+
e
);
}
}
//TODO Get r least populated DStores
private
static
ArrayList
<
Integer
>
emptyDStores
()
{
return
new
ArrayList
<>();
}
//Check for all working dStores
private
static
ArrayList
<
Integer
>
workingDStores
()
{
ArrayList
<
Integer
>
workingPorts
=
new
ArrayList
<>();
//If dstore is still working add it to the list
for
(
Integer
i:
dStores
.
keySet
())
{
if
(
checkDStore
(
dStores
.
get
(
i
))){
workingPorts
.
add
(
i
);
}
}
return
workingPorts
;
}
//TODO Test if given DStore is still active
private
static
boolean
checkDStore
(
Socket
dStore
)
{
return
false
;
}
//TODO Remove file from given DStores
private
static
void
removeFile
(
String
fileName
,
Socket
client
)
{
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment