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
Instrument Control
NomadCommandSystem
Commits
e5571088
Commit
e5571088
authored
Feb 07, 2017
by
yannick legoc
Browse files
Moved access to nomad server instance in a dedicated class.
parent
4300cea4
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/main/java/fr/ill/ics/bridge/ChangeManager.java
View file @
e5571088
...
...
@@ -22,7 +22,7 @@ import java.util.Iterator;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
fr.ill.ics.nscclient.log.LogSubcriber
Impl
;
import
fr.ill.ics.nscclient.log.LogSub
s
criber
;
import
fr.ill.ics.nscclient.notification.DataNotificationClient
;
import
fr.ill.ics.nscclient.notification.commandzone.CommandZoneEventClient
;
import
fr.ill.ics.nscclient.survey.SurveySubcriberImpl
;
...
...
@@ -48,10 +48,10 @@ public class ChangeManager {
CommandZoneEventClient
.
getInstance
().
readAndDispatch
();
// Iterating the map of log subscribers
Map
<
String
,
LogSubcriber
Impl
>
logSubscriberMap
=
LogSubcriber
Impl
.
getInstances
();
Iterator
<
Entry
<
String
,
LogSubcriber
Impl
>>
it
=
logSubscriberMap
.
entrySet
().
iterator
();
Map
<
String
,
LogSub
s
criber
>
logSubscriberMap
=
LogSub
s
criber
.
getInstances
();
Iterator
<
Entry
<
String
,
LogSub
s
criber
>>
it
=
logSubscriberMap
.
entrySet
().
iterator
();
while
(
it
.
hasNext
())
{
LogSubcriber
Impl
logSubscriber
=
it
.
next
().
getValue
();
LogSub
s
criber
logSubscriber
=
it
.
next
().
getValue
();
logSubscriber
.
readAndDispatch
();
}
...
...
src/main/java/fr/ill/ics/bridge/LogEventSender.java
View file @
e5571088
...
...
@@ -23,7 +23,7 @@ import java.util.Map;
import
fr.ill.ics.bridge.listeners.ServerLogEventListener
;
import
fr.ill.ics.bridge.listeners.ServerLogXMLListener
;
import
fr.ill.ics.nscclient.log.LogSubcriber
Impl
;
import
fr.ill.ics.nscclient.log.LogSub
s
criber
;
public
class
LogEventSender
{
...
...
@@ -48,18 +48,18 @@ public class LogEventSender {
* @param listener
*/
public
void
addLogEventListener
(
ServerLogEventListener
listener
)
{
LogSubcriber
Impl
.
getInstance
(
serverId
).
addLogEventListener
(
listener
);
LogSub
s
criber
.
getInstance
(
serverId
).
addLogEventListener
(
listener
);
}
public
void
removeLogEventListener
(
ServerLogEventListener
listener
)
{
LogSubcriber
Impl
.
getInstance
(
serverId
).
removeLogEventListener
(
listener
);
LogSub
s
criber
.
getInstance
(
serverId
).
removeLogEventListener
(
listener
);
}
public
void
addLogXMLListener
(
ServerLogXMLListener
listener
)
{
LogSubcriber
Impl
.
getInstance
(
serverId
).
addLogXMLListener
(
listener
);
LogSub
s
criber
.
getInstance
(
serverId
).
addLogXMLListener
(
listener
);
}
public
void
removeLogXMLListener
(
ServerLogXMLListener
listener
)
{
LogSubcriber
Impl
.
getInstance
(
serverId
).
removeLogXMLListener
(
listener
);
LogSub
s
criber
.
getInstance
(
serverId
).
removeLogXMLListener
(
listener
);
}
}
\ No newline at end of file
src/main/java/fr/ill/ics/nscclient/log/LogSubcriber
Impl
.java
→
src/main/java/fr/ill/ics/nscclient/log/LogSub
s
criber.java
View file @
e5571088
...
...
@@ -38,9 +38,10 @@ import fr.ill.ics.cameo.Application;
import
fr.ill.ics.cameo.ConnectionTimeout
;
import
fr.ill.ics.cameo.Server
;
import
fr.ill.ics.nomadserver.notification.NotificationMessage
;
import
fr.ill.ics.nscclient.serverconnection.ServerInstance
;
import
fr.ill.ics.util.ConfigManager
;
public
class
LogSubcriber
Impl
{
public
class
LogSub
s
criber
{
private
Set
<
ServerLogEventListener
>
logEventListeners
=
new
LinkedHashSet
<
ServerLogEventListener
>();
private
Set
<
ServerLogEvent
>
pendingChanges
=
new
LinkedHashSet
<
ServerLogEvent
>();
...
...
@@ -54,24 +55,24 @@ public class LogSubcriberImpl {
private
Application
.
Subscriber
subscriber
;
private
Thread
subscriberThread
;
private
static
Map
<
String
,
LogSubcriber
Impl
>
instances
=
new
HashMap
<
String
,
LogSubcriber
Impl
>();
private
static
Map
<
String
,
LogSub
s
criber
>
instances
=
new
HashMap
<
String
,
LogSub
s
criber
>();
private
String
serverId
;
private
LogSubcriber
Impl
(
String
serverId
)
{
private
LogSub
s
criber
(
String
serverId
)
{
this
.
serverId
=
serverId
;
}
public
static
LogSubcriber
Impl
getInstance
(
String
serverId
)
{
public
static
LogSub
s
criber
getInstance
(
String
serverId
)
{
if
(!
instances
.
containsKey
(
serverId
))
{
LogSubcriber
Impl
instance
=
new
LogSubcriber
Impl
(
serverId
);
LogSub
s
criber
instance
=
new
LogSub
s
criber
(
serverId
);
instances
.
put
(
serverId
,
instance
);
}
return
instances
.
get
(
serverId
);
}
public
static
Map
<
String
,
LogSubcriber
Impl
>
getInstances
()
{
public
static
Map
<
String
,
LogSub
s
criber
>
getInstances
()
{
return
instances
;
}
...
...
@@ -137,57 +138,23 @@ public class LogSubcriberImpl {
}
public
void
init
()
{
// Connect nomad server.
Application
.
Instance
nomad
=
ServerInstance
.
getInstance
().
getApplicationInstance
(
serverId
);
// Get the server endpoint.
String
nomadServerEndpoint
=
ConfigManager
.
getInstance
().
getNomadServerEndpoint
();
if
(
nomad
==
null
)
{
System
.
err
.
println
(
"Problem to connect to the nomad server "
+
serverId
);
return
;
}
// Connect to the server.
Server
server
=
new
Server
(
nomadServerEndpoint
);
// Define the log publisher.
String
logPublisherName
=
"log_publisher"
;
// Connect nomad server.
Application
.
Instance
nomad
=
null
;
// Do not connect to the same application if it is simulated.
if
(!
serverId
.
equals
(
CommandZoneWrapper
.
SERVER_ID
))
{
// Add the server id to the publisher name.
logPublisherName
+=
serverId
;
try
{
// Find the simulated instance.
List
<
Application
.
Instance
>
nomadApps
=
server
.
connectAll
(
"nssim"
);
for
(
Application
.
Instance
app
:
nomadApps
)
{
if
(
app
.
exists
()
&&
app
.
getId
()
==
Integer
.
parseInt
(
serverId
))
{
nomad
=
app
;
break
;
}
}
}
catch
(
ConnectionTimeout
e
)
{
System
.
err
.
println
(
"Timeout while connecting nomad server"
);
}
}
else
{
// Find the real instance.
String
[]
nomadAppNames
=
{
"ns"
,
"nsd"
,
"nsv"
};
try
{
for
(
String
appName
:
nomadAppNames
)
{
nomad
=
server
.
connect
(
appName
);
if
(
nomad
.
exists
())
{
break
;
}
}
}
catch
(
ConnectionTimeout
e
)
{
System
.
err
.
println
(
"Timeout while connecting nomad server"
);
}
}
if
(
nomad
==
null
)
{
System
.
err
.
println
(
"Problem to connect to the nomad server "
+
serverId
);
}
System
.
out
.
println
(
"Trying to connect log subscriber to "
+
logPublisherName
);
...
...
src/main/java/fr/ill/ics/nscclient/serverconnection/ServerInstance.java
0 → 100644
View file @
e5571088
package
fr.ill.ics.nscclient.serverconnection
;
import
java.util.List
;
import
fr.ill.ics.bridge.command.CommandZoneWrapper
;
import
fr.ill.ics.cameo.Application
;
import
fr.ill.ics.cameo.ConnectionTimeout
;
import
fr.ill.ics.cameo.Server
;
import
fr.ill.ics.util.ConfigManager
;
/**
* Class providing access to the running Nomad server instances using Cameo.
*/
public
class
ServerInstance
{
private
static
ServerInstance
instance
;
private
Server
server
;
public
static
ServerInstance
getInstance
()
{
if
(
instance
==
null
)
{
instance
=
new
ServerInstance
();
}
return
instance
;
}
public
void
init
()
{
// Get the server endpoint.
String
nomadServerEndpoint
=
ConfigManager
.
getInstance
().
getNomadServerEndpoint
();
// Connect to the server.
server
=
new
Server
(
nomadServerEndpoint
);
}
public
Application
.
Instance
getApplicationInstance
(
String
serverId
)
{
// Connect nomad server.
Application
.
Instance
nomad
=
null
;
// Do not connect to the same application if it is simulated.
if
(!
serverId
.
equals
(
CommandZoneWrapper
.
SERVER_ID
))
{
try
{
// Find the simulated instance.
List
<
Application
.
Instance
>
nomadApps
=
server
.
connectAll
(
"nssim"
);
for
(
Application
.
Instance
app
:
nomadApps
)
{
if
(
app
.
exists
()
&&
app
.
getId
()
==
Integer
.
parseInt
(
serverId
))
{
nomad
=
app
;
break
;
}
}
}
catch
(
ConnectionTimeout
e
)
{
System
.
err
.
println
(
"Timeout while connecting nomad server"
);
}
}
else
{
// Find the real instance.
String
[]
nomadAppNames
=
{
"ns"
,
"nsd"
,
"nsv"
};
try
{
for
(
String
appName
:
nomadAppNames
)
{
nomad
=
server
.
connect
(
appName
);
if
(
nomad
.
exists
())
{
break
;
}
}
}
catch
(
ConnectionTimeout
e
)
{
System
.
err
.
println
(
"Timeout while connecting nomad server"
);
}
}
return
nomad
;
}
}
src/main/java/fr/ill/ics/nscclient/sessionmanagement/ServerSessionManager.java
View file @
e5571088
...
...
@@ -35,11 +35,12 @@ import fr.ill.ics.nscclient.command.ScanCommandBoxAccessorProxy;
import
fr.ill.ics.nscclient.commandline.CommandLineProxyImpl
;
import
fr.ill.ics.nscclient.condition.ConditionManagerProxy
;
import
fr.ill.ics.nscclient.dataprovider.DataAccessor
;
import
fr.ill.ics.nscclient.log.LogSubcriber
Impl
;
import
fr.ill.ics.nscclient.log.LogSub
s
criber
;
import
fr.ill.ics.nscclient.notification.commandzone.ServerCommandZoneEventManager
;
import
fr.ill.ics.nscclient.servant.ConfigurationManager
;
import
fr.ill.ics.nscclient.servant.ConfigurationManager.LoadFailure
;
import
fr.ill.ics.nscclient.servant.CorbaServantManager
;
import
fr.ill.ics.nscclient.serverconnection.ServerInstance
;
import
fr.ill.ics.nscclient.survey.SurveySubcriberImpl
;
public
class
ServerSessionManager
{
...
...
@@ -57,6 +58,8 @@ public class ServerSessionManager {
private
void
init
()
throws
ConnectionFailure
{
ServerInstance
.
getInstance
().
init
();
CorbaSessionManager
.
getInstance
(
serverId
).
init
();
// See if the Server is up and running
...
...
@@ -80,7 +83,7 @@ public class ServerSessionManager {
ConditionManagerProxy
.
getInstance
(
serverId
).
init
();
CommandLineProxyImpl
.
getInstance
(
serverId
).
init
();
LogSubcriber
Impl
.
getInstance
(
serverId
).
init
();
LogSub
s
criber
.
getInstance
(
serverId
).
init
();
SurveySubcriberImpl
.
getInstance
(
serverId
).
init
();
}
...
...
@@ -148,7 +151,7 @@ public class ServerSessionManager {
public
void
logout
()
{
ServerCommandZoneEventManager
.
getInstance
(
serverId
).
reset
();
LogSubcriber
Impl
.
getInstance
(
serverId
).
unsubscribe
();
LogSub
s
criber
.
getInstance
(
serverId
).
unsubscribe
();
SurveySubcriberImpl
.
getInstance
(
serverId
).
unsubscribe
();
currentSession
.
logout
();
...
...
@@ -159,7 +162,7 @@ public class ServerSessionManager {
ServerCommandZoneEventManager
.
getInstance
(
serverId
).
reset
();
try
{
LogSubcriber
Impl
.
getInstance
(
serverId
).
unsubscribe
();
LogSub
s
criber
.
getInstance
(
serverId
).
unsubscribe
();
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"Cannot unsubscribe Log"
);
}
...
...
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