Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Cameo
cameo
Commits
a3e78fa4
Commit
a3e78fa4
authored
Dec 10, 2021
by
legoc
Browse files
Context and Server refactored
parent
fbb3ebbb
Changes
5
Hide whitespace changes
Inline
Side-by-side
cameo-api/src/main/java/fr/ill/ics/cameo/base/Context.java
View file @
a3e78fa4
...
...
@@ -2,4 +2,5 @@ package fr.ill.ics.cameo.base;
public
interface
Context
{
void
terminate
();
}
cameo-api/src/main/java/fr/ill/ics/cameo/base/Server.java
View file @
a3e78fa4
...
...
@@ -28,11 +28,8 @@ import org.json.simple.JSONArray;
import
org.json.simple.JSONObject
;
import
org.json.simple.parser.ParseException
;
import
fr.ill.ics.cameo.Zmq
;
import
fr.ill.ics.cameo.Zmq.Socket
;
import
fr.ill.ics.cameo.base.Application.State
;
import
fr.ill.ics.cameo.base.Application.This
;
import
fr.ill.ics.cameo.base.impl.CancelIdGenerator
;
import
fr.ill.ics.cameo.base.impl.Response
;
import
fr.ill.ics.cameo.base.impl.zmq.ContextZmq
;
import
fr.ill.ics.cameo.messages.JSON
;
...
...
@@ -50,8 +47,7 @@ public class Server {
private
Endpoint
serverEndpoint
;
private
int
[]
serverVersion
=
new
int
[
3
];
private
int
statusPort
;
private
Zmq
.
Context
context
;
private
ContextZmq
contextImpl
;
private
Context
contextImpl
;
private
int
timeout
=
0
;
// default value because of ZeroMQ design
private
RequestSocket
requestSocket
;
private
JSON
.
Parser
parser
=
new
JSON
.
Parser
();
...
...
@@ -116,13 +112,11 @@ public class Server {
* Initializes the context and the request socket. The serverEndpoint must have been set.
*/
final
private
void
init
()
{
context
=
new
Zmq
.
Context
();
contextImpl
=
new
ContextZmq
(
context
);
//TODO Replace with factory.
contextImpl
=
new
ContextZmq
();
requestSocket
=
this
.
createRequestSocket
(
serverEndpoint
.
toString
());
}
private
int
getAvailableTimeout
()
{
int
timeout
=
getTimeout
();
if
(
timeout
>
0
)
{
...
...
@@ -155,11 +149,7 @@ public class Server {
public
Context
getContext
()
{
return
contextImpl
;
}
public
void
destroySocket
(
Socket
socket
)
{
context
.
destroySocket
(
socket
);
}
public
JSONObject
parse
(
byte
[]
data
)
throws
ParseException
{
return
parser
.
parse
(
Messages
.
parseString
(
data
));
}
...
...
@@ -260,7 +250,7 @@ public class Server {
terminateStatusThread
();
requestSocket
.
terminate
();
context
.
destroy
();
context
Impl
.
terminate
();
}
public
void
registerEventListener
(
EventListener
listener
)
{
...
...
cameo-api/src/main/java/fr/ill/ics/cameo/base/impl/zmq/ContextZmq.java
View file @
a3e78fa4
...
...
@@ -7,11 +7,15 @@ public class ContextZmq implements Context {
private
Zmq
.
Context
context
;
public
ContextZmq
(
Zmq
.
Context
context
)
{
this
.
context
=
c
ontext
;
public
ContextZmq
()
{
context
=
new
Zmq
.
C
ontext
()
;
}
public
Zmq
.
Context
getContext
()
{
return
context
;
}
public
void
terminate
()
{
context
.
destroy
();
}
}
cameo-api/src/main/java/fr/ill/ics/cameo/base/impl/zmq/EventStreamSocketZmq.java
View file @
a3e78fa4
...
...
@@ -217,6 +217,6 @@ public class EventStreamSocketZmq implements EventStreamSocketImpl {
}
public
void
destroy
()
{
server
.
destroySocket
(
subscriberSocket
);
context
.
destroySocket
(
subscriberSocket
);
}
}
\ No newline at end of file
cameo-api/src/main/java/fr/ill/ics/cameo/base/impl/zmq/OutputStreamSocketZmq.java
View file @
a3e78fa4
...
...
@@ -162,6 +162,6 @@ public class OutputStreamSocketZmq implements OutputStreamSocketImpl {
}
public
void
destroy
()
{
server
.
destroySocket
(
subscriberSocket
);
context
.
destroySocket
(
subscriberSocket
);
}
}
\ No newline at end of file
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