Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
Briar Mailbox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
Julian Dehm
Briar Mailbox
Commits
85e91c2e
There was a problem fetching the pipeline summary.
Commit
85e91c2e
authored
6 years ago
by
bontric
Browse files
Options
Downloads
Patches
Plain Diff
Use getPrivateMailbox function in mailbox service
parent
33b5d754
No related branches found
No related tags found
No related merge requests found
Pipeline
#
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bramble-core/src/main/java/org/briarproject/bramble/mailbox/MailboxServiceImpl.java
+26
-38
26 additions, 38 deletions
.../org/briarproject/bramble/mailbox/MailboxServiceImpl.java
with
26 additions
and
38 deletions
bramble-core/src/main/java/org/briarproject/bramble/mailbox/MailboxServiceImpl.java
+
26
−
38
View file @
85e91c2e
...
...
@@ -2,6 +2,7 @@ package org.briarproject.bramble.mailbox;
import
org.briarproject.bramble.api.contact.Contact
;
import
org.briarproject.bramble.api.contact.ContactId
;
import
org.briarproject.bramble.api.contact.ContactManager
;
import
org.briarproject.bramble.api.contact.ContactType
;
import
org.briarproject.bramble.api.contact.event.ContactAddedEvent
;
import
org.briarproject.bramble.api.db.DatabaseComponent
;
...
...
@@ -56,12 +57,12 @@ public class MailboxServiceImpl implements MailboxService, EventListener {
private
final
Executor
ioExecutor
;
private
final
ScheduledExecutorService
scheduler
;
private
EventBus
eventBus
;
private
ContactManager
contactManager
;
private
final
DatabaseComponent
db
;
private
final
ConnectionRegistry
connectionRegistry
;
private
final
PluginManager
pluginManager
;
private
final
MailboxManager
mailboxManager
;
private
final
TransportPropertyManager
transportPropertyManager
;
private
final
SecureRandom
random
;
private
volatile
Future
mailboxLanFuture
;
...
...
@@ -71,29 +72,37 @@ public class MailboxServiceImpl implements MailboxService, EventListener {
@Inject
MailboxServiceImpl
(
@IoExecutor
Executor
ioExecutor
,
@Scheduler
ScheduledExecutorService
scheduler
,
EventBus
eventBus
,
ContactManager
contactManager
,
DatabaseComponent
db
,
ConnectionRegistry
connectionRegistry
,
PluginManager
pluginManager
,
MailboxManager
mailboxManager
,
TransportPropertyManager
transportPropertyManager
,
SecureRandom
random
)
{
TransportPropertyManager
transportPropertyManager
)
{
this
.
ioExecutor
=
ioExecutor
;
this
.
scheduler
=
scheduler
;
this
.
eventBus
=
eventBus
;
this
.
contactManager
=
contactManager
;
this
.
db
=
db
;
this
.
connectionRegistry
=
connectionRegistry
;
this
.
pluginManager
=
pluginManager
;
this
.
mailboxManager
=
mailboxManager
;
this
.
transportPropertyManager
=
transportPropertyManager
;
this
.
random
=
random
;
}
@Override
public
void
startService
()
throws
ServiceException
{
public
void
startService
()
{
if
(
LOG
.
isLoggable
(
INFO
))
LOG
.
info
(
"Starting Mailbox Service"
);
checkForPrivateMailbox
();
try
{
privateMailboxId
=
contactManager
.
getPrivateMailbox
().
getId
();
}
catch
(
DbException
e1
)
{
if
(
LOG
.
isLoggable
(
WARNING
))
LOG
.
info
(
e1
.
toString
());
}
if
(
privateMailboxId
!=
null
)
hasPrivateMailbox
.
set
(
true
);
tryToRunLanMailboxFuture
();
this
.
eventBus
.
addListener
(
this
);
}
...
...
@@ -116,9 +125,17 @@ public class MailboxServiceImpl implements MailboxService, EventListener {
}
}
if
(
e
instanceof
ContactAddedEvent
)
{
if
(!
hasPrivateMailbox
.
get
())
ioExecutor
.
execute
(()
->
checkForPrivateMailbox
());
if
(
e
instanceof
ContactAddedEvent
){
if
(
hasPrivateMailbox
.
get
())
return
;
try
{
privateMailboxId
=
contactManager
.
getPrivateMailbox
().
getId
();
}
catch
(
DbException
e1
)
{
if
(
LOG
.
isLoggable
(
WARNING
))
LOG
.
info
(
e1
.
toString
());
}
if
(
privateMailboxId
!=
null
)
hasPrivateMailbox
.
set
(
true
);
}
}
...
...
@@ -134,35 +151,6 @@ public class MailboxServiceImpl implements MailboxService, EventListener {
POLLING_INTERVALL
,
plugin
),
POLLING_INTERVALL
);
}
private
void
checkForPrivateMailbox
()
{
synchronized
(
hasPrivateMailbox
)
{
if
(
hasPrivateMailbox
.
get
())
return
;
Transaction
txn
=
null
;
Collection
<
Contact
>
privateMb
;
try
{
txn
=
db
.
startTransaction
(
true
);
privateMb
=
db
.
getContactsByType
(
txn
,
PRIVATE_MAILBOX
);
db
.
commitTransaction
(
txn
);
if
(
privateMb
.
size
()
>
1
)
throw
new
RuntimeException
(
"Multiple Private Mailboxes exist!"
);
if
(!
privateMb
.
isEmpty
())
{
privateMailboxId
=
privateMb
.
iterator
().
next
().
getId
();
hasPrivateMailbox
.
set
(
true
);
}
}
catch
(
DbException
dbe
)
{
logException
(
LOG
,
WARNING
,
dbe
);
}
finally
{
if
(
txn
!=
null
)
db
.
endTransaction
(
txn
);
}
}
}
private
Future
schedule
(
Runnable
task
,
int
delay
)
{
return
scheduler
.
schedule
(()
->
ioExecutor
.
execute
(
task
),
delay
,
MILLISECONDS
);
...
...
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