Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
huangzhicong
/
SmartCanteen
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
6d25c5c9
authored
Jun 02, 2020
by
pye52
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化Monitor的代码结构
parent
75095b78
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
8 deletions
+16
-8
app/src/main/java/com/bgycc/smartcanteen/activity/MainActivity.java
+2
-4
app/src/main/java/com/bgycc/smartcanteen/utils/MonitorUtils.java
+14
-4
No files found.
app/src/main/java/com/bgycc/smartcanteen/activity/MainActivity.java
View file @
6d25c5c9
...
...
@@ -325,8 +325,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
commandViewModel
.
initialize
();
handler
.
post
(
updateTimeRunnable
);
MonitorUtils
.
startLogFilesMonitor
(
this
);
MonitorUtils
.
startDatabaseMonitor
(
this
);
MonitorUtils
.
startMonitors
(
this
);
SCWebSocketClient
.
getInstance
().
tryConnect
();
}
...
...
@@ -400,8 +399,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
TTSHelper
.
release
();
SCWebSocketClient
.
getInstance
().
realClose
();
SCTaskExecutor
.
getInstance
().
quit
();
MonitorUtils
.
stopDatabaseMonitor
(
this
);
MonitorUtils
.
stopLogFilesMonitor
(
this
);
MonitorUtils
.
stopMonitors
(
this
);
}
private
void
initViews
()
{
...
...
app/src/main/java/com/bgycc/smartcanteen/utils/MonitorUtils.java
View file @
6d25c5c9
...
...
@@ -17,8 +17,18 @@ public class MonitorUtils {
private
static
final
int
LOG_REPEAT_INTERVAL
=
4
;
private
static
final
int
DATABASE_REPEAT_INTERVAL
=
12
;
public
static
void
startMonitors
(
Context
context
)
{
startLogFilesMonitor
(
context
);
startDatabaseMonitor
(
context
);
}
public
static
void
stopMonitors
(
Context
context
)
{
stopLogFilesMonitor
(
context
);
stopDatabaseMonitor
(
context
);
}
// 每隔一定时间检查日志文件夹并进行清理
p
ublic
static
void
startLogFilesMonitor
(
Context
context
)
{
p
rivate
static
void
startLogFilesMonitor
(
Context
context
)
{
stopLogFilesMonitor
(
context
);
PeriodicWorkRequest
request
=
new
PeriodicWorkRequest
.
Builder
(
LogFileMonitor
.
class
,
LOG_REPEAT_INTERVAL
,
TimeUnit
.
HOURS
)
.
addTag
(
LOG_MONITOR_WORKER
)
...
...
@@ -27,13 +37,13 @@ public class MonitorUtils {
.
enqueue
(
request
);
}
p
ublic
static
void
stopLogFilesMonitor
(
Context
context
)
{
p
rivate
static
void
stopLogFilesMonitor
(
Context
context
)
{
WorkManager
.
getInstance
(
context
)
.
cancelAllWorkByTag
(
LOG_MONITOR_WORKER
);
}
// 每隔一定时间检查数据库并进行清理
p
ublic
static
void
startDatabaseMonitor
(
Context
context
)
{
p
rivate
static
void
startDatabaseMonitor
(
Context
context
)
{
stopDatabaseMonitor
(
context
);
PeriodicWorkRequest
request
=
new
PeriodicWorkRequest
.
Builder
(
DatabaseMonitor
.
class
,
DATABASE_REPEAT_INTERVAL
,
TimeUnit
.
HOURS
)
.
addTag
(
DATABASE_MONITOR_WORKER
)
...
...
@@ -42,7 +52,7 @@ public class MonitorUtils {
.
enqueue
(
request
);
}
p
ublic
static
void
stopDatabaseMonitor
(
Context
context
)
{
p
rivate
static
void
stopDatabaseMonitor
(
Context
context
)
{
WorkManager
.
getInstance
(
context
)
.
cancelAllWorkByTag
(
DATABASE_MONITOR_WORKER
);
}
...
...
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