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
fccf3c0a
Commit
fccf3c0a
authored
6 years ago
by
bontric
Browse files
Options
Downloads
Patches
Plain Diff
Add function to enable request handling (ensure that all handlers are
registered before reading requests) and cleanup
parent
659cacb8
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
bramble-core/src/main/java/org/briarproject/bramble/mailbox/protocol/MailboxProtocol.java
+28
-8
28 additions, 8 deletions
...riarproject/bramble/mailbox/protocol/MailboxProtocol.java
with
28 additions
and
8 deletions
bramble-core/src/main/java/org/briarproject/bramble/mailbox/protocol/MailboxProtocol.java
+
28
−
8
View file @
fccf3c0a
...
@@ -56,10 +56,6 @@ public class MailboxProtocol implements Runnable {
...
@@ -56,10 +56,6 @@ public class MailboxProtocol implements Runnable {
}
}
public
void
registerRequestHandler
(
MailboxRequestHandler
handler
)
{
requestHandlers
.
put
(
handler
.
getType
(),
handler
);
}
public
void
sendKeepAlive
()
throws
IOException
{
public
void
sendKeepAlive
()
throws
IOException
{
// flush the writer without pending data to send a keepalive
// flush the writer without pending data to send a keepalive
if
(
stopped
.
get
())
if
(
stopped
.
get
())
...
@@ -109,12 +105,33 @@ public class MailboxProtocol implements Runnable {
...
@@ -109,12 +105,33 @@ public class MailboxProtocol implements Runnable {
*/
*/
@Override
@Override
public
void
run
()
{
public
void
run
()
{
ioExecutor
.
execute
(()
->
writeOutgoingMessages
());
writeOutgoingMessages
();
readIncomingMessages
();
}
/**
* Register a Handler for a specific request type.
* <p>
* NOTE: {@link this#enableRequestHandling()} MUST be called after all handlers
* have been registered!
*
* @param handler
*/
public
void
registerRequestHandler
(
MailboxRequestHandler
handler
)
{
if
(
requestHandlers
.
containsKey
(
handler
.
getType
()))
throw
new
RuntimeException
(
"Handler for "
+
handler
.
getType
().
toString
()
+
" has been registered twice!"
);
requestHandlers
.
put
(
handler
.
getType
(),
handler
);
}
/**
* Request handling once all request handlers are registered
*/
public
void
enableRequestHandling
()
{
ioExecutor
.
execute
(()
->
readIncomingMessages
());
}
}
private
void
readIncomingMessages
()
{
private
void
readIncomingMessages
()
{
readingThread
=
Thread
.
currentThread
();
BdfList
bdfMsg
;
BdfList
bdfMsg
;
while
(!
stopped
.
get
())
{
while
(!
stopped
.
get
())
{
...
@@ -124,7 +141,6 @@ public class MailboxProtocol implements Runnable {
...
@@ -124,7 +141,6 @@ public class MailboxProtocol implements Runnable {
throw
new
EOFException
();
throw
new
EOFException
();
bdfMsg
=
mailboxBdfReader
.
readList
();
bdfMsg
=
mailboxBdfReader
.
readList
();
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
readingThread
.
interrupt
();
handleIOException
(
true
,
e
);
handleIOException
(
true
,
e
);
return
;
return
;
}
}
...
@@ -153,6 +169,10 @@ public class MailboxProtocol implements Runnable {
...
@@ -153,6 +169,10 @@ public class MailboxProtocol implements Runnable {
try
{
try
{
handler
.
handleRequest
(
req
);
handler
.
handleRequest
(
req
);
}
catch
(
ProtocolException
e
)
{
}
catch
(
ProtocolException
e
)
{
if
(!
req
.
hasResponse
())
throw
new
RuntimeException
(
"Protocol exception was thrown for request without response"
);
error
=
e
.
toString
();
error
=
e
.
toString
();
}
}
}
else
{
}
else
{
...
...
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