Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
NetworkedGraphicsMV3500
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Savage
NetworkedGraphicsMV3500
Commits
8a708230
Commit
8a708230
authored
5 years ago
by
J. M. Bailey
Browse files
Options
Downloads
Patches
Plain Diff
Use threaded net access class, DisThreadedNetIF
parent
1b330074
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/edu/nps/moves/dis7/util/playerrecorder/Recorder.java
+22
-40
22 additions, 40 deletions
src/edu/nps/moves/dis7/util/playerrecorder/Recorder.java
with
22 additions
and
40 deletions
src/edu/nps/moves/dis7/util/playerrecorder/Recorder.java
+
22
−
40
View file @
8a708230
...
@@ -4,7 +4,7 @@ import com.google.common.primitives.Longs;
...
@@ -4,7 +4,7 @@ import com.google.common.primitives.Longs;
import
edu.nps.moves.dis7.Pdu
;
import
edu.nps.moves.dis7.Pdu
;
import
edu.nps.moves.dis7.enumerations.DISPDUType
;
import
edu.nps.moves.dis7.enumerations.DISPDUType
;
import
edu.nps.moves.dis7.util.DisNetworking
;
import
edu.nps.moves.dis7.util.DisNetworking
;
import
edu.nps.moves.dis7.util.Dis
Networking.BuffAndLength
;
import
edu.nps.moves.dis7.util.Dis
ThreadedNetIF
;
import
edu.nps.moves.dis7.util.PduFactory
;
import
edu.nps.moves.dis7.util.PduFactory
;
import
org.apache.commons.io.FilenameUtils
;
import
org.apache.commons.io.FilenameUtils
;
...
@@ -31,8 +31,8 @@ public class Recorder implements PduReceiver
...
@@ -31,8 +31,8 @@ public class Recorder implements PduReceiver
private
BufferedWriter
bwr
;
private
BufferedWriter
bwr
;
private
File
logFile
;
private
File
logFile
;
private
DisNetworking
disnet
;
private
Thread
receiverThrd
;
private
Dis
Thread
edNetIF
disnetworking
;
public
Recorder
()
throws
IOException
public
Recorder
()
throws
IOException
{
{
...
@@ -44,25 +44,8 @@ public class Recorder implements PduReceiver
...
@@ -44,25 +44,8 @@ public class Recorder implements PduReceiver
logFile
=
makeFile
(
new
File
(
outputDir
).
toPath
(),
DEFAULT_FILEPREFIX
+
DISLOG_FILE_TAIL
);
logFile
=
makeFile
(
new
File
(
outputDir
).
toPath
(),
DEFAULT_FILEPREFIX
+
DISLOG_FILE_TAIL
);
bwr
=
new
BufferedWriter
(
new
FileWriter
(
logFile
));
bwr
=
new
BufferedWriter
(
new
FileWriter
(
logFile
));
disnet
=
new
DisNetworking
(
port
,
mcastaddr
);
disnetworking
=
new
DisThreadedNetIF
(
port
,
mcastaddr
);
// Start a thread to receive and record pdus
disnetworking
.
addRawListener
(
bAndL
->
receivePdu
(
bAndL
.
buff
,
bAndL
.
length
));
receiverThrd
=
new
Thread
(()->{
int
count
=
1
;
while
(!
Thread
.
interrupted
()){
try
{
BuffAndLength
blen
=
disnet
.
receiveRawPdu
();
//System.out.println(""+ count++ +" Got pdu from DisNetworking");
receivePdu
(
blen
.
buff
,
blen
.
length
);
}
catch
(
IOException
ex
)
{
// this is the normal exception if you do disnet.stop() System.err.println("Exception receiving Pdu: "+ex.getLocalizedMessage());
}
}
});
receiverThrd
.
setPriority
(
Thread
.
NORM_PRIORITY
);
receiverThrd
.
setDaemon
(
true
);
receiverThrd
.
start
();
}
}
public
void
startResume
()
public
void
startResume
()
...
@@ -82,23 +65,18 @@ public class Recorder implements PduReceiver
...
@@ -82,23 +65,18 @@ public class Recorder implements PduReceiver
return
null
;
return
null
;
}
}
public
void
end
()
public
File
end
()
throws
IOException
{
{
disnet
.
stop
();
disnetworking
.
kill
();
receiverThrd
.
interrupt
();
writeFooter
();
try
{
bwr
.
flush
();
writeFooter
();
bwr
.
close
();
bwr
.
flush
();
System
.
out
.
println
();
bwr
.
close
();
System
.
out
.
println
(
"Recorder log file closed"
);
System
.
out
.
println
();
return
logFile
;
System
.
out
.
println
(
"Recorder log file closed"
);
}
catch
(
IOException
ex
)
{
System
.
out
.
println
(
"IOException closing file: "
+
ex
.
getMessage
());
}
}
}
Long
startNanoTime
=
null
;
Long
startNanoTime
=
null
;
StringBuilder
sb
=
new
StringBuilder
();
StringBuilder
sb
=
new
StringBuilder
();
Base64
.
Encoder
encdr
=
Base64
.
getEncoder
();
Base64
.
Encoder
encdr
=
Base64
.
getEncoder
();
...
@@ -136,9 +114,8 @@ public class Recorder implements PduReceiver
...
@@ -136,9 +114,8 @@ public class Recorder implements PduReceiver
System
.
err
.
println
(
"Fatal exception writing DIS log file in Recorder.start()"
);
System
.
err
.
println
(
"Fatal exception writing DIS log file in Recorder.start()"
);
throw
new
RuntimeException
(
ex
);
throw
new
RuntimeException
(
ex
);
}
}
System
.
out
.
print
(
++
pduCount
+
"\r"
);
//
System.out.print
ln("Recorder: "+
++pduCount);
//bwr.flush();
sb
.
setLength
(
0
);
sb
.
setLength
(
0
);
}
}
...
@@ -218,7 +195,12 @@ public class Recorder implements PduReceiver
...
@@ -218,7 +195,12 @@ public class Recorder implements PduReceiver
});
});
sleep
(
2000
);
sleep
(
2000
);
recorder
.
end
();
try
{
recorder
.
end
();
}
catch
(
Exception
ex
)
{
System
.
err
.
println
(
"Exception closing recorder: "
+
ex
.
getClass
().
getSimpleName
()+
": "
+
ex
.
getLocalizedMessage
());
}
}
}
private
static
void
sleep
(
long
ms
)
private
static
void
sleep
(
long
ms
)
...
...
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