Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LatinIME
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
Container 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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
keyboard
LatinIME
Commits
7423005b
Commit
7423005b
authored
12 years ago
by
Jean Chalard
Committed by
Kurt Partridge
12 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[Lazy1] Switch to blocking log closures
Change-Id: I4daec20b7b47b0d71c5aab6e17cd660015e19e71
parent
bba39b9b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
java/src/com/android/inputmethod/research/ResearchLog.java
+32
-15
32 additions, 15 deletions
java/src/com/android/inputmethod/research/ResearchLog.java
java/src/com/android/inputmethod/research/ResearchLogger.java
+13
-27
13 additions, 27 deletions
.../src/com/android/inputmethod/research/ResearchLogger.java
with
45 additions
and
42 deletions
java/src/com/android/inputmethod/research/ResearchLog.java
+
32
−
15
View file @
7423005b
...
@@ -20,11 +20,11 @@ import android.content.Context;
...
@@ -20,11 +20,11 @@ import android.content.Context;
import
android.util.JsonWriter
;
import
android.util.JsonWriter
;
import
android.util.Log
;
import
android.util.Log
;
import
com.android.inputmethod.annotations.UsedForTesting
;
import
com.android.inputmethod.latin.define.ProductionFlag
;
import
com.android.inputmethod.latin.define.ProductionFlag
;
import
java.io.BufferedWriter
;
import
java.io.BufferedWriter
;
import
java.io.File
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.io.OutputStream
;
import
java.io.OutputStreamWriter
;
import
java.io.OutputStreamWriter
;
...
@@ -54,7 +54,6 @@ public class ResearchLog {
...
@@ -54,7 +54,6 @@ public class ResearchLog {
private
static
final
String
TAG
=
ResearchLog
.
class
.
getSimpleName
();
private
static
final
String
TAG
=
ResearchLog
.
class
.
getSimpleName
();
private
static
final
boolean
DEBUG
=
false
&&
ProductionFlag
.
IS_EXPERIMENTAL_DEBUG
;
private
static
final
boolean
DEBUG
=
false
&&
ProductionFlag
.
IS_EXPERIMENTAL_DEBUG
;
private
static
final
long
FLUSH_DELAY_IN_MS
=
1000
*
5
;
private
static
final
long
FLUSH_DELAY_IN_MS
=
1000
*
5
;
private
static
final
int
ABORT_TIMEOUT_IN_MS
=
1000
*
4
;
/* package */
final
ScheduledExecutorService
mExecutor
;
/* package */
final
ScheduledExecutorService
mExecutor
;
/* package */
final
File
mFile
;
/* package */
final
File
mFile
;
...
@@ -100,7 +99,7 @@ public class ResearchLog {
...
@@ -100,7 +99,7 @@ public class ResearchLog {
*
*
* See class comment for details about {@code JsonWriter} construction.
* See class comment for details about {@code JsonWriter} construction.
*/
*/
p
ublic
synchronized
void
close
(
final
Runnable
onClosed
)
{
p
rivate
synchronized
void
close
(
final
Runnable
onClosed
)
{
mExecutor
.
submit
(
new
Callable
<
Object
>()
{
mExecutor
.
submit
(
new
Callable
<
Object
>()
{
@Override
@Override
public
Object
call
()
throws
Exception
{
public
Object
call
()
throws
Exception
{
...
@@ -131,15 +130,22 @@ public class ResearchLog {
...
@@ -131,15 +130,22 @@ public class ResearchLog {
mExecutor
.
shutdown
();
mExecutor
.
shutdown
();
}
}
private
boolean
mIsAbortSuccessful
;
/**
/**
*
Waits for publication requests to finish, closes the {@link JsonWriter}, but then deletes the
*
Block until the research log has shut down and spooled out all output or {@code timeout}
*
backing file used for output
.
*
occurs
.
*
*
* See class comment for details about {@code JsonWriter} construction.
* @param timeout time to wait for close in milliseconds
*/
public
void
blockingClose
(
final
long
timeout
)
{
close
(
null
);
awaitTermination
(
timeout
,
TimeUnit
.
MILLISECONDS
);
}
/**
* Waits for publication requests to finish, closes the JsonWriter, but then deletes the backing
* output file.
*/
*/
p
ublic
synchronized
void
abort
()
{
p
rivate
synchronized
void
abort
()
{
mExecutor
.
submit
(
new
Callable
<
Object
>()
{
mExecutor
.
submit
(
new
Callable
<
Object
>()
{
@Override
@Override
public
Object
call
()
throws
Exception
{
public
Object
call
()
throws
Exception
{
...
@@ -151,7 +157,7 @@ public class ResearchLog {
...
@@ -151,7 +157,7 @@ public class ResearchLog {
}
}
}
finally
{
}
finally
{
if
(
mFile
!=
null
)
{
if
(
mFile
!=
null
)
{
mIsAbortSuccessful
=
mFile
.
delete
();
mFile
.
delete
();
}
}
}
}
return
null
;
return
null
;
...
@@ -161,14 +167,25 @@ public class ResearchLog {
...
@@ -161,14 +167,25 @@ public class ResearchLog {
mExecutor
.
shutdown
();
mExecutor
.
shutdown
();
}
}
public
boolean
blockingAbort
()
throws
InterruptedException
{
/**
* Block until the research log has aborted or {@code timeout} occurs.
*
* @param timeout time to wait for close in milliseconds
*/
public
void
blockingAbort
(
final
long
timeout
)
{
abort
();
abort
();
mExecutor
.
awaitTermination
(
ABORT_TIMEOUT_IN_MS
,
TimeUnit
.
MILLISECONDS
);
awaitTermination
(
timeout
,
TimeUnit
.
MILLISECONDS
);
return
mIsAbortSuccessful
;
}
}
public
void
awaitTermination
(
int
delay
,
TimeUnit
timeUnit
)
throws
InterruptedException
{
@UsedForTesting
mExecutor
.
awaitTermination
(
delay
,
timeUnit
);
public
void
awaitTermination
(
final
long
delay
,
final
TimeUnit
timeUnit
)
{
try
{
if
(!
mExecutor
.
awaitTermination
(
delay
,
timeUnit
))
{
Log
.
e
(
TAG
,
"ResearchLog executor timed out while awaiting terminaion"
);
}
}
catch
(
final
InterruptedException
e
)
{
Log
.
e
(
TAG
,
"ResearchLog executor interrupted while awaiting terminaion"
,
e
);
}
}
}
/* package */
synchronized
void
flush
()
{
/* package */
synchronized
void
flush
()
{
...
...
This diff is collapsed.
Click to expand it.
java/src/com/android/inputmethod/research/ResearchLogger.java
+
13
−
27
View file @
7423005b
...
@@ -154,6 +154,9 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
...
@@ -154,6 +154,9 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
private
static
final
int
MAX_INPUTVIEW_LENGTH_TO_CAPTURE
=
8192
;
// must be >=1
private
static
final
int
MAX_INPUTVIEW_LENGTH_TO_CAPTURE
=
8192
;
// must be >=1
private
static
final
String
PREF_RESEARCH_SAVED_CHANNEL
=
"pref_research_saved_channel"
;
private
static
final
String
PREF_RESEARCH_SAVED_CHANNEL
=
"pref_research_saved_channel"
;
private
static
final
long
RESEARCHLOG_CLOSE_TIMEOUT_IN_MS
=
5
*
1000
;
private
static
final
long
RESEARCHLOG_ABORT_TIMEOUT_IN_MS
=
5
*
1000
;
private
static
final
ResearchLogger
sInstance
=
new
ResearchLogger
();
private
static
final
ResearchLogger
sInstance
=
new
ResearchLogger
();
private
static
String
sAccountType
=
null
;
private
static
String
sAccountType
=
null
;
private
static
String
sAllowedAccountDomain
=
null
;
private
static
String
sAllowedAccountDomain
=
null
;
...
@@ -502,42 +505,29 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
...
@@ -502,42 +505,29 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
commitCurrentLogUnit
();
commitCurrentLogUnit
();
mMainLogBuffer
.
setIsStopping
();
mMainLogBuffer
.
setIsStopping
();
mMainLogBuffer
.
shiftAndPublishAll
();
mMainLogBuffer
.
shiftAndPublishAll
();
mMainResearchLog
.
close
(
null
/* callback */
);
mMainResearchLog
.
blockingClose
(
RESEARCHLOG_CLOSE_TIMEOUT_IN_MS
);
mMainLogBuffer
=
null
;
mMainLogBuffer
=
null
;
}
}
if
(
mFeedbackLogBuffer
!=
null
)
{
if
(
mFeedbackLogBuffer
!=
null
)
{
mFeedbackLog
.
close
(
null
/* callback */
);
mFeedbackLog
.
blockingClose
(
RESEARCHLOG_CLOSE_TIMEOUT_IN_MS
);
mFeedbackLogBuffer
=
null
;
mFeedbackLogBuffer
=
null
;
}
}
}
}
public
boolean
abort
()
{
public
void
abort
()
{
if
(
DEBUG
)
{
if
(
DEBUG
)
{
Log
.
d
(
TAG
,
"abort called"
);
Log
.
d
(
TAG
,
"abort called"
);
}
}
boolean
didAbortMainLog
=
false
;
if
(
mMainLogBuffer
!=
null
)
{
if
(
mMainLogBuffer
!=
null
)
{
mMainLogBuffer
.
clear
();
mMainLogBuffer
.
clear
();
try
{
mMainResearchLog
.
blockingAbort
(
RESEARCHLOG_ABORT_TIMEOUT_IN_MS
);
didAbortMainLog
=
mMainResearchLog
.
blockingAbort
();
}
catch
(
InterruptedException
e
)
{
// Don't know whether this succeeded or not. We assume not; this is reported
// to the caller.
}
mMainLogBuffer
=
null
;
mMainLogBuffer
=
null
;
}
}
boolean
didAbortFeedbackLog
=
false
;
if
(
mFeedbackLogBuffer
!=
null
)
{
if
(
mFeedbackLogBuffer
!=
null
)
{
mFeedbackLogBuffer
.
clear
();
mFeedbackLogBuffer
.
clear
();
try
{
mFeedbackLog
.
blockingAbort
(
RESEARCHLOG_ABORT_TIMEOUT_IN_MS
);
didAbortFeedbackLog
=
mFeedbackLog
.
blockingAbort
();
}
catch
(
InterruptedException
e
)
{
// Don't know whether this succeeded or not. We assume not; this is reported
// to the caller.
}
mFeedbackLogBuffer
=
null
;
mFeedbackLogBuffer
=
null
;
}
}
return
didAbortMainLog
&&
didAbortFeedbackLog
;
}
}
private
void
restart
()
{
private
void
restart
()
{
...
@@ -620,7 +610,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
...
@@ -620,7 +610,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
private
void
startRecordingInternal
()
{
private
void
startRecordingInternal
()
{
if
(
mUserRecordingLog
!=
null
)
{
if
(
mUserRecordingLog
!=
null
)
{
mUserRecordingLog
.
abort
(
);
mUserRecordingLog
.
blockingAbort
(
RESEARCHLOG_ABORT_TIMEOUT_IN_MS
);
}
}
mUserRecordingFile
=
createUserRecordingFile
(
mFilesDir
);
mUserRecordingFile
=
createUserRecordingFile
(
mFilesDir
);
mUserRecordingLog
=
new
ResearchLog
(
mUserRecordingFile
,
mLatinIME
);
mUserRecordingLog
=
new
ResearchLog
(
mUserRecordingFile
,
mLatinIME
);
...
@@ -658,7 +648,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
...
@@ -658,7 +648,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
private
void
cancelRecording
()
{
private
void
cancelRecording
()
{
if
(
mUserRecordingLog
!=
null
)
{
if
(
mUserRecordingLog
!=
null
)
{
mUserRecordingLog
.
abort
(
);
mUserRecordingLog
.
blockingAbort
(
RESEARCHLOG_ABORT_TIMEOUT_IN_MS
);
}
}
mUserRecordingLog
=
null
;
mUserRecordingLog
=
null
;
mUserRecordingLogBuffer
=
null
;
mUserRecordingLogBuffer
=
null
;
...
@@ -670,7 +660,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
...
@@ -670,7 +660,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
private
void
saveRecording
()
{
private
void
saveRecording
()
{
commitCurrentLogUnit
();
commitCurrentLogUnit
();
publishLogBuffer
(
mUserRecordingLogBuffer
,
mUserRecordingLog
,
true
);
publishLogBuffer
(
mUserRecordingLogBuffer
,
mUserRecordingLog
,
true
);
mUserRecordingLog
.
close
(
null
);
mUserRecordingLog
.
blockingClose
(
RESEARCHLOG_CLOSE_TIMEOUT_IN_MS
);
mUserRecordingLog
=
null
;
mUserRecordingLog
=
null
;
mUserRecordingLogBuffer
=
null
;
mUserRecordingLogBuffer
=
null
;
...
@@ -782,12 +772,8 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
...
@@ -782,12 +772,8 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
feedbackContents
,
accountName
,
recording
);
feedbackContents
,
accountName
,
recording
);
mFeedbackLogBuffer
.
shiftIn
(
feedbackLogUnit
);
mFeedbackLogBuffer
.
shiftIn
(
feedbackLogUnit
);
publishLogBuffer
(
mFeedbackLogBuffer
,
mSavedFeedbackLog
,
true
/* isIncludingPrivateData */
);
publishLogBuffer
(
mFeedbackLogBuffer
,
mSavedFeedbackLog
,
true
/* isIncludingPrivateData */
);
mSavedFeedbackLog
.
close
(
new
Runnable
()
{
mSavedFeedbackLog
.
blockingClose
(
RESEARCHLOG_CLOSE_TIMEOUT_IN_MS
);
@Override
uploadNow
();
public
void
run
()
{
uploadNow
();
}
});
if
(
isIncludingRecording
&&
DEBUG_REPLAY_AFTER_FEEDBACK
)
{
if
(
isIncludingRecording
&&
DEBUG_REPLAY_AFTER_FEEDBACK
)
{
final
Handler
handler
=
new
Handler
();
final
Handler
handler
=
new
Handler
();
...
...
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