Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Instrument Control
NomadCommandSystem
Commits
331ef8e4
Commit
331ef8e4
authored
Jun 05, 2020
by
helene ortiz
Browse files
Merge branch 'V4.0' of
https://code.ill.fr/instrument-control/nomad-command-system.git
into V4.0
parents
daef3a65
6eb9880d
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/main/java/fr/ill/ics/nscclient/notification/commandline/ServerCommandLineEventManager.java
0 → 100644
View file @
331ef8e4
/*
* Nomad Instrument Control Software
*
* Copyright 2011 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
package
fr.ill.ics.nscclient.notification.commandline
;
import
java.io.ByteArrayInputStream
;
import
java.io.IOException
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.logging.Logger
;
import
fr.ill.ics.cameo.Application
;
import
fr.ill.ics.nomadserver.notification.NotificationMessage
;
import
fr.ill.ics.nscclient.notification.commandline.sync.CommandLineSyncEventNotifier
;
import
fr.ill.ics.nscclient.notification.commandline.sync.ICommandLineSyncEvent
;
import
fr.ill.ics.nscclient.notification.commandzone.sync.CommandZoneSyncEventClient
;
import
fr.ill.ics.nscclient.serverconnection.ServerInstance
;
public
class
ServerCommandLineEventManager
{
private
static
final
Logger
LOGGER
=
Logger
.
getLogger
(
ServerCommandLineEventManager
.
class
.
getName
());
private
Application
.
Subscriber
subscriber
;
private
Thread
subscriberThread
;
private
String
serverId
;
private
static
Map
<
String
,
ServerCommandLineEventManager
>
instances
=
new
HashMap
<
String
,
ServerCommandLineEventManager
>();
private
CommandLineSyncEventNotifier
syncEventNotifier
;
private
ServerCommandLineEventManager
(
String
serverId
)
{
this
.
serverId
=
serverId
;
syncEventNotifier
=
new
CommandLineSyncEventNotifier
(
serverId
);
}
public
static
ServerCommandLineEventManager
getInstance
(
String
serverId
)
{
if
(!
instances
.
containsKey
(
serverId
))
{
ServerCommandLineEventManager
instance
=
new
ServerCommandLineEventManager
(
serverId
);
instances
.
put
(
serverId
,
instance
);
}
return
instances
.
get
(
serverId
);
}
public
void
init
()
{
// Connect nomad server.
Application
.
Instance
nomad
=
ServerInstance
.
getInstance
().
getApplicationInstance
(
serverId
);
if
(
nomad
==
null
)
{
System
.
err
.
println
(
"Problem to connect to the nomad server "
+
serverId
);
return
;
}
// Define the command line publisher.
String
commandLinePublisherName
=
"command_line_publisher"
;
System
.
out
.
println
(
"Trying to connect command line subscriber to "
+
commandLinePublisherName
);
// Create the subscriber.
subscriber
=
Application
.
Subscriber
.
create
(
nomad
,
commandLinePublisherName
);
System
.
out
.
println
(
"Connected command line subscriber "
+
subscriber
);
// Start the thread.
subscriberThread
=
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
// Receive data
while
(
true
)
{
// Blocking call.
byte
[][]
data
=
subscriber
.
receiveTwoParts
();
if
(
data
!=
null
)
{
try
{
if
(
NotificationMessage
.
Message
.
parseFrom
(
data
[
0
]).
getType
()
==
fr
.
ill
.
ics
.
nomadserver
.
notification
.
NotificationMessage
.
Message
.
Type
.
CommandLineSync
)
{
notifyCommandLineSync
(
syncEventNotifier
.
processMessage
(
NotificationMessage
.
CommandLineSync
.
parseFrom
(
new
ByteArrayInputStream
(
data
[
1
]))));
}
else
{
System
.
out
.
println
(
"Unable to process "
+
NotificationMessage
.
Message
.
parseFrom
(
data
[
0
]).
getType
());
}
}
catch
(
IOException
e
)
{
System
.
err
.
println
(
"Cannot parse notification server command zone message"
);
}
}
else
{
break
;
}
}
}
});
subscriberThread
.
start
();
}
public
void
reset
()
{
if
(
subscriber
!=
null
)
{
System
.
out
.
println
(
"Unsubscribing command line..."
);
// Stop the subscriber.
subscriber
.
cancel
();
// Join the thread.
try
{
subscriberThread
.
join
();
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
// Terminate the subscriber.
subscriber
.
terminate
();
System
.
out
.
println
(
"Unsubscribed from the command line"
);
}
}
private
void
notifyCommandLineSync
(
ICommandLineSyncEvent
event
)
{
// The event can be null if the incoming message if from client itself.
if
(
event
!=
null
)
{
//CommandZoneSyncEventClient.getInstance().eventOccurred(event);
}
}
}
\ No newline at end of file
src/main/java/fr/ill/ics/nscclient/notification/commandline/sync/CommandLineSyncEventNotifier.java
0 → 100644
View file @
331ef8e4
package
fr.ill.ics.nscclient.notification.commandline.sync
;
import
java.io.IOException
;
import
fr.ill.ics.nomadserver.commandline.CommandLineRequest
;
import
fr.ill.ics.nomadserver.notification.NotificationMessage
;
import
fr.ill.ics.nscclient.notification.commandzone.sync.ICommandZoneSyncEvent
;
import
fr.ill.ics.nscclient.sessionmanagement.SessionManager
;
public
class
CommandLineSyncEventNotifier
{
private
String
serverId
;
private
Integer
clientId
;
public
CommandLineSyncEventNotifier
(
String
serverId
)
{
this
.
serverId
=
serverId
;
}
private
int
getClientID
()
{
if
(
clientId
==
null
)
{
// Get the client id from the session manager.
clientId
=
SessionManager
.
getInstance
(
serverId
).
getClientId
();
}
return
clientId
;
}
public
ICommandLineSyncEvent
processMessage
(
NotificationMessage
.
CommandLineSync
message
)
{
try
{
CommandLineRequest
.
Message
.
Type
type
=
CommandLineRequest
.
Message
.
parseFrom
(
message
.
getSerializedType
()).
getType
();
if
(
type
==
CommandLineRequest
.
Message
.
Type
.
SetCommandLineState
)
{
// CommandLineRequest.CommandBoxRequest request = CommandZoneRequests.CommandBoxRequest.parseFrom(message.getSerializedContent());
//
// // Notify if it is not the same client that sent the request.
// if (request.getClientID() != getClientID()) {
// return new CommandBoxToggleBackground(request.getCommandBoxID());
// }
System
.
out
.
println
(
"Process command line sync message of type "
+
type
);
}
else
{
System
.
out
.
println
(
"Unable to process command line sync message of type "
+
type
);
}
}
catch
(
IOException
e
)
{
System
.
err
.
println
(
"Cannot parse notification server command line sync message"
);
}
return
null
;
}
}
src/main/java/fr/ill/ics/nscclient/notification/commandline/sync/ICommandLineSyncEvent.java
0 → 100644
View file @
331ef8e4
/*
* Nomad Instrument Control Software
*
* Copyright 2011 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
package
fr.ill.ics.nscclient.notification.commandline.sync
;
public
interface
ICommandLineSyncEvent
{
}
\ No newline at end of file
src/main/java/fr/ill/ics/nscclient/notification/commandzone/sync/CommandZoneSyncEventNotifier.java
View file @
331ef8e4
...
...
@@ -378,6 +378,22 @@ public class CommandZoneSyncEventNotifier {
return
new
DeleteFile
(
request
.
getFileName
());
}
}
else
if
(
type
==
CommandZoneRequests
.
Message
.
Type
.
SetModifiable
||
type
==
CommandZoneRequests
.
Message
.
Type
.
StopCommandBox
||
type
==
CommandZoneRequests
.
Message
.
Type
.
SetInt32Value
||
type
==
CommandZoneRequests
.
Message
.
Type
.
SetFloat64Value
||
type
==
CommandZoneRequests
.
Message
.
Type
.
SetStringValue
||
type
==
CommandZoneRequests
.
Message
.
Type
.
SetBooleanValue
||
type
==
CommandZoneRequests
.
Message
.
Type
.
Create
||
type
==
CommandZoneRequests
.
Message
.
Type
.
Reset
||
type
==
CommandZoneRequests
.
Message
.
Type
.
Execute
||
type
==
CommandZoneRequests
.
Message
.
Type
.
Stop
||
type
==
CommandZoneRequests
.
Message
.
Type
.
StopAtEnd
||
type
==
CommandZoneRequests
.
Message
.
Type
.
Pause
||
type
==
CommandZoneRequests
.
Message
.
Type
.
Restart
||
type
==
CommandZoneRequests
.
Message
.
Type
.
SetPropertyExpression
)
{
// Do nothing for those notifications.
}
else
{
System
.
out
.
println
(
"Unable to process command zone sync message of type "
+
type
);
}
...
...
src/main/java/fr/ill/ics/nscclient/sessionmanagement/ServerSessionManager.java
View file @
331ef8e4
...
...
@@ -32,6 +32,7 @@ import fr.ill.ics.nscclient.dataprovider.DataAccessor;
import
fr.ill.ics.nscclient.dataprovider.ServantManagerAccessor
;
import
fr.ill.ics.nscclient.log.LogSubscriber
;
import
fr.ill.ics.nscclient.notification.DataChangeSubscriber
;
import
fr.ill.ics.nscclient.notification.commandline.ServerCommandLineEventManager
;
import
fr.ill.ics.nscclient.notification.commandzone.ServerCommandZoneEventManager
;
import
fr.ill.ics.nscclient.ploty.PlotyInstance
;
import
fr.ill.ics.nscclient.servant.ConfigurationManager
;
...
...
@@ -69,6 +70,7 @@ public class ServerSessionManager {
CommandZoneAccessor
.
getInstance
(
serverId
).
init
();
ServerCommandZoneEventManager
.
getInstance
(
serverId
).
init
();
ServerCommandLineEventManager
.
getInstance
(
serverId
).
init
();
VariableManagerAccessor
.
getInstance
(
serverId
).
init
();
ConditionManagerAccessor
.
getInstance
(
serverId
).
init
();
...
...
@@ -147,6 +149,7 @@ public class ServerSessionManager {
public
void
logout
()
{
ServerCommandZoneEventManager
.
getInstance
(
serverId
).
reset
();
ServerCommandLineEventManager
.
getInstance
(
serverId
).
reset
();
LogSubscriber
.
getInstance
(
serverId
).
unsubscribe
();
SurveySubscriberImpl
.
getInstance
(
serverId
).
unsubscribe
();
...
...
@@ -171,6 +174,7 @@ public class ServerSessionManager {
public
void
logoutAll
(
boolean
stop
)
{
ServerCommandZoneEventManager
.
getInstance
(
serverId
).
reset
();
ServerCommandLineEventManager
.
getInstance
(
serverId
).
reset
();
try
{
LogSubscriber
.
getInstance
(
serverId
).
unsubscribe
();
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment