Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
NomadCommandSystem
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Instrument Control
NomadCommandSystem
Commits
7973b345
"...Framework/git@code.ill.fr:scientific-software/mdanse.git" did not exist on "1cb9aeb0a0600dbcaaa412bac339682fe9d83b4c"
Commit
7973b345
authored
4 months ago
by
yannick legoc
Browse files
Options
Downloads
Patches
Plain Diff
Implemented SurveyAccessor
parent
5fe0bf92
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.classpath
+7
-0
7 additions, 0 deletions
.classpath
pom.xml
+2
-2
2 additions, 2 deletions
pom.xml
src/main/java/fr/ill/ics/nscclient/survey/SurveyAccessor.java
+274
-0
274 additions, 0 deletions
...main/java/fr/ill/ics/nscclient/survey/SurveyAccessor.java
with
283 additions
and
2 deletions
.classpath
+
7
−
0
View file @
7973b345
...
...
@@ -10,6 +10,7 @@
<attributes>
<attribute
name=
"maven.pomderived"
value=
"true"
/>
<attribute
name=
"test"
value=
"true"
/>
<attribute
name=
"optional"
value=
"true"
/>
</attributes>
</classpathentry>
<classpathentry
kind=
"con"
path=
"org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"
>
...
...
@@ -29,5 +30,11 @@
<attribute
name=
"test"
value=
"true"
/>
</attributes>
</classpathentry>
<classpathentry
excluding=
"**"
kind=
"src"
output=
"target/classes"
path=
"src/main/resources"
>
<attributes>
<attribute
name=
"maven.pomderived"
value=
"true"
/>
<attribute
name=
"optional"
value=
"true"
/>
</attributes>
</classpathentry>
<classpathentry
kind=
"output"
path=
"target/classes"
/>
</classpath>
This diff is collapsed.
Click to expand it.
pom.xml
+
2
−
2
View file @
7973b345
...
...
@@ -2,7 +2,7 @@
<modelVersion>
4.0.0
</modelVersion>
<groupId>
fr.ill.ics
</groupId>
<artifactId>
nomadcommandsystem
</artifactId>
<version>
5.
2.1
</version>
<version>
5.
3.0-SNAPSHOT
</version>
<name>
NomadCommandSystem
</name>
<description>
Java bridge for the communication with the Nomad server
</description>
<scm>
...
...
@@ -66,7 +66,7 @@
<dependency>
<groupId>
fr.ill.ics
</groupId>
<artifactId>
nomadcommandsystem-messages
</artifactId>
<version>
0.0.5
6
</version>
<version>
0.0.5
7
</version>
</dependency>
<dependency>
<groupId>
fr.ill.ics
</groupId>
...
...
This diff is collapsed.
Click to expand it.
src/main/java/fr/ill/ics/nscclient/survey/SurveyAccessor.java
0 → 100644
+
274
−
0
View file @
7973b345
/*
* 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.survey
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
com.google.protobuf.InvalidProtocolBufferException
;
import
fr.ill.ics.cameo.base.App
;
import
fr.ill.ics.cameo.base.InitException
;
import
fr.ill.ics.cameo.coms.Requester
;
import
fr.ill.ics.nomadserver.common.Common
;
import
fr.ill.ics.nomadserver.survey.SurveyRequest
;
import
fr.ill.ics.nscclient.serverconnection.ServerInstance
;
import
fr.ill.ics.nscclient.sessionmanagement.SessionManager
;
/**
*/
public
class
SurveyAccessor
{
private
static
final
Logger
LOGGER
=
Logger
.
getLogger
(
SurveyAccessor
.
class
.
getName
());
private
String
serverId
;
private
Integer
clientId
;
private
Requester
surveyRequester
;
private
static
Map
<
String
,
SurveyAccessor
>
instances
=
new
HashMap
<
String
,
SurveyAccessor
>();
public
static
class
PropertyResponse
{
private
String
controllerName
;
private
String
propertyName
;
private
int
index
;
private
int
activeWriteTime
;
PropertyResponse
(
String
controllerName
,
String
propertyName
,
int
index
,
int
activeWriteTime
)
{
this
.
controllerName
=
controllerName
;
this
.
propertyName
=
propertyName
;
this
.
index
=
index
;
this
.
activeWriteTime
=
activeWriteTime
;
}
public
String
getControllerName
()
{
return
controllerName
;
}
public
String
getPropertyName
()
{
return
propertyName
;
}
public
int
getIndex
()
{
return
index
;
}
public
int
getActiveWriteTime
()
{
return
activeWriteTime
;
}
}
public
SurveyAccessor
(
String
serverId
)
{
this
.
serverId
=
serverId
;
}
public
static
SurveyAccessor
getInstance
(
String
serverId
)
{
if
(!
instances
.
containsKey
(
serverId
))
{
SurveyAccessor
instance
=
new
SurveyAccessor
(
serverId
);
instances
.
put
(
serverId
,
instance
);
}
return
instances
.
get
(
serverId
);
}
public
synchronized
void
init
()
{
// Connect nomad server.
App
nomad
=
ServerInstance
.
getInstance
().
getApplicationInstance
(
serverId
);
if
(
nomad
==
null
)
{
System
.
err
.
println
(
"Problem to connect to the nomad server "
+
serverId
);
return
;
}
System
.
out
.
println
(
"Trying to create survey requester"
);
// Create the requester.
try
{
surveyRequester
=
Requester
.
create
(
nomad
,
"survey"
);
surveyRequester
.
init
();
}
catch
(
InitException
e
)
{
System
.
err
.
println
(
"Problem to connect to the survey responder: "
+
e
.
getMessage
());
return
;
}
System
.
out
.
println
(
"Created requester "
+
surveyRequester
);
}
public
synchronized
void
reset
()
{
// Terminate the requester.
if
(
surveyRequester
!=
null
)
{
surveyRequester
.
terminate
();
}
}
private
int
getClientID
()
{
if
(
clientId
==
null
)
{
// Get the client id from the session manager.
clientId
=
SessionManager
.
getInstance
(
serverId
).
getClientId
();
}
return
clientId
;
}
public
synchronized
List
<
PropertyResponse
>
getProperties
()
{
// Create the message type.
SurveyRequest
.
Message
type
=
SurveyRequest
.
Message
.
newBuilder
()
.
setType
(
SurveyRequest
.
Message
.
Type
.
GetProperties
)
.
build
();
// Create the request.
SurveyRequest
.
EmptyRequest
request
=
SurveyRequest
.
EmptyRequest
.
newBuilder
()
.
setClientID
(
getClientID
())
.
build
();
surveyRequester
.
sendTwoParts
(
type
.
toByteArray
(),
request
.
toByteArray
());
try
{
SurveyRequest
.
GetPropertiesResponse
response
=
SurveyRequest
.
GetPropertiesResponse
.
parseFrom
(
surveyRequester
.
receive
());
List
<
PropertyResponse
>
result
=
new
ArrayList
<
PropertyResponse
>();
for
(
int
i
=
0
;
i
<
response
.
getPropertiesCount
();
i
++)
{
SurveyRequest
.
PropertyResponse
property
=
response
.
getProperties
(
i
);
result
.
add
(
new
PropertyResponse
(
property
.
getControllerName
(),
property
.
getPropertyName
(),
property
.
getIndex
(),
property
.
getSeconds
()));
}
return
result
;
}
catch
(
InvalidProtocolBufferException
e
)
{
LOGGER
.
logp
(
Level
.
WARNING
,
this
.
getClass
().
getName
(),
"getProperties"
,
"error in parsing response"
);
}
return
null
;
}
public
synchronized
boolean
addProperty
(
String
controllerName
,
String
propertyName
,
int
index
)
{
// Create the message type.
SurveyRequest
.
Message
type
=
SurveyRequest
.
Message
.
newBuilder
()
.
setType
(
SurveyRequest
.
Message
.
Type
.
AddProperty
)
.
build
();
// Create the request.
SurveyRequest
.
PropertyRequest
request
=
SurveyRequest
.
PropertyRequest
.
newBuilder
()
.
setClientID
(
getClientID
())
.
setControllerName
(
controllerName
)
.
setPropertyName
(
propertyName
)
.
setIndex
(
index
)
.
build
();
surveyRequester
.
sendTwoParts
(
type
.
toByteArray
(),
request
.
toByteArray
());
try
{
Common
.
BooleanResponse
response
=
Common
.
BooleanResponse
.
parseFrom
(
surveyRequester
.
receive
());
// Test the error.
if
(
response
.
hasError
())
{
return
false
;
}
else
{
return
true
;
}
}
catch
(
InvalidProtocolBufferException
e
)
{
LOGGER
.
logp
(
Level
.
WARNING
,
this
.
getClass
().
getName
(),
"addProperty"
,
"error in parsing response"
);
}
return
false
;
}
public
synchronized
boolean
removeProperty
(
String
controllerName
,
String
propertyName
,
int
index
)
{
// Create the message type.
SurveyRequest
.
Message
type
=
SurveyRequest
.
Message
.
newBuilder
()
.
setType
(
SurveyRequest
.
Message
.
Type
.
RemoveProperty
)
.
build
();
// Create the request.
SurveyRequest
.
PropertyRequest
request
=
SurveyRequest
.
PropertyRequest
.
newBuilder
()
.
setClientID
(
getClientID
())
.
setControllerName
(
controllerName
)
.
setPropertyName
(
propertyName
)
.
setIndex
(
index
)
.
build
();
surveyRequester
.
sendTwoParts
(
type
.
toByteArray
(),
request
.
toByteArray
());
try
{
Common
.
BooleanResponse
response
=
Common
.
BooleanResponse
.
parseFrom
(
surveyRequester
.
receive
());
// Test the error.
if
(
response
.
hasError
())
{
return
false
;
}
else
{
return
true
;
}
}
catch
(
InvalidProtocolBufferException
e
)
{
LOGGER
.
logp
(
Level
.
WARNING
,
this
.
getClass
().
getName
(),
"removeProperty"
,
"error in parsing response"
);
}
return
false
;
}
public
synchronized
boolean
setActiveWriteTime
(
String
controllerName
,
String
propertyName
,
int
index
,
int
seconds
)
{
// Create the message type.
SurveyRequest
.
Message
type
=
SurveyRequest
.
Message
.
newBuilder
()
.
setType
(
SurveyRequest
.
Message
.
Type
.
SetActiveWriteTime
)
.
build
();
// Create the request.
SurveyRequest
.
SetActiveWriteTimeRequest
request
=
SurveyRequest
.
SetActiveWriteTimeRequest
.
newBuilder
()
.
setClientID
(
getClientID
())
.
setControllerName
(
controllerName
)
.
setPropertyName
(
propertyName
)
.
setIndex
(
index
)
.
setSeconds
(
seconds
)
.
build
();
surveyRequester
.
sendTwoParts
(
type
.
toByteArray
(),
request
.
toByteArray
());
try
{
Common
.
BooleanResponse
response
=
Common
.
BooleanResponse
.
parseFrom
(
surveyRequester
.
receive
());
// Test the error.
if
(
response
.
hasError
())
{
return
false
;
}
else
{
return
true
;
}
}
catch
(
InvalidProtocolBufferException
e
)
{
LOGGER
.
logp
(
Level
.
WARNING
,
this
.
getClass
().
getName
(),
"setActiveWriteTime"
,
"error in parsing response"
);
}
return
false
;
}
}
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