Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
the_dungeon_project
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
12
Issues
12
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
genie_logiciel_2015
the_dungeon_project
Commits
1c54937a
Commit
1c54937a
authored
Jan 06, 2016
by
bogdanbear
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Detect broken connections when they occur with a thread that wakes up every 2 seconds
parent
88d6bf09
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
7 deletions
+44
-7
src/gameloop/LocalGameLoop.java
src/gameloop/LocalGameLoop.java
+27
-5
src/network/inner_shell/ClientConnection.java
src/network/inner_shell/ClientConnection.java
+2
-1
src/network/inner_shell/NetworkConnection.java
src/network/inner_shell/NetworkConnection.java
+15
-1
No files found.
src/gameloop/LocalGameLoop.java
View file @
1c54937a
...
...
@@ -105,6 +105,29 @@ public class LocalGameLoop extends Thread{
LOGGER
.
info
(
"Released relayer"
);
}
/**
* a separate thread which will verify periodically whether the network connection is still alive
* wakes up every 2 seconds, thus it is not a performance issue
*/
private
Runnable
BrokenConnectionVerifier
=
new
Runnable
()
{
@Override
public
void
run
()
{
while
(
true
)
{
if
(
LocalGameLoop
.
getInstance
().
isPlaying
)
{
//System.out.println("Broken Connection verifier!");
if
(
getNetworkConnection
().
isBroken
())
GameStarter
.
initiateBrokenConnectionMeasures
();
}
try
{
sleep
(
2000
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
}
}
};
public
synchronized
boolean
getIsPlaying
()
{
return
isPlaying
;
...
...
@@ -132,6 +155,8 @@ public class LocalGameLoop extends Thread{
@Override
public
void
run
()
{
//start the thread which verifies if the connection is still alive
(
new
Thread
(
BrokenConnectionVerifier
)).
start
();
LOGGER
.
info
(
"LocalGameLoop Thread started+"
+
currentThread
().
getId
());
while
(
true
)
{
//System.out.println("DummyLocalGameLoopThread, game is "+isPlaying);
...
...
@@ -183,14 +208,11 @@ public class LocalGameLoop extends Thread{
/**
* Entities, relayers and objects related to the GameContent should not have a direct reference to the network connection
* this is why I insert here a sendEvent method
* it is inefficient to test whether the connection is alive here
*/
public
void
sendEvent
(
NetworkObject
event
)
{
if
(
getNetworkConnection
().
isBroken
())
GameStarter
.
initiateBrokenConnectionMeasures
();
else
{
getNetworkConnection
().
sendEvent
(
event
);
}
getNetworkConnection
().
sendEvent
(
event
);
}
/**
...
...
src/network/inner_shell/ClientConnection.java
View file @
1c54937a
...
...
@@ -44,7 +44,8 @@ public class ClientConnection extends NetworkConnection{
/**
* Send an event to the server.
* The event is written on the socket.
* Still to be implemented - throwing exceptions when the connection is not open
* Exceptions are not implemented per se, they are included into isBroken(), which can be tested before trying to read
* or write(but that is not efficient)
* @param e the event to send; e has to be serializable and not empty
*/
@Override
...
...
src/network/inner_shell/NetworkConnection.java
View file @
1c54937a
...
...
@@ -94,7 +94,11 @@ public abstract class NetworkConnection {
}
}
//public visibility
/**
* tests whether a thread encountered a problem and updated the flag of the connection as broken
* actively tests if the connection is not broken now
* @return a boolean representing whether the connection is broken or not
*/
public
boolean
isBroken
()
{
//attempt to send a test event first
//must not be sunchronized because broken might need to be updated when we attempt to send a test event
...
...
@@ -104,6 +108,16 @@ public abstract class NetworkConnection {
return
broken
;
}
/**
* like isBroken(), but does not do an active test and just looks at whether a thread encountered a problem
* this could be an alternative to using isBroken and the timer
* by calling this every time before sending or receiving an event
* @return a boolean with the value of broken
*/
public
boolean
isSoftBroken
(){
return
broken
;
}
//package visibility
synchronized
void
setBroken
(
boolean
broken
)
{
this
.
broken
=
broken
;
...
...
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