Avatar

Please consider registering
guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed Topic RSS sp_TopicIcon
Handle ServerState on Shutdown
May 24, 2013
9:49, EEST
Avatar
fred
Member
Members
Forum Posts: 37
Member Since:
January 27, 2012
sp_UserOfflineSmall Offline

Hi,

My Server is running as a Windows Service and I am wondering how to set ServerState to e.g. “SHUTDOWN” when the service is stopped?

Actually, the state according to client is changed to: ServerState changed from Running to CommunicationFault

Is there a listener for shutdown on server?

Thanks
BR

May 24, 2013
12:22, EEST
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 846
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

UaClient is polling the ServerState (1000 ms by default), so it should notice the change, if you call UaServer.shutdown() with a 5 second delay, for example, when the service is requested to close. How do you run it as service – that’s the next question of course.

If the client fails to read Shutdown state, it will notice the change when the read fails – and it results to CommunicationFault.

May 27, 2013
6:40, EEST
Avatar
fred
Member
Members
Forum Posts: 37
Member Since:
January 27, 2012
sp_UserOfflineSmall Offline

Solved this topic by adding a simple ShutdownHook in main method. Btw, I use Tanuki Service Wrapper for starting the server as a service.

Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
server.shutdown(5, new LocalizedText("OPC-UA Server was shutdown", Locale.ENGLISH));
}
});
May 27, 2013
7:45, EEST
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 846
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

Very good! Thanks for sharing the solution – and the note about Tanuki.

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 267

Currently Online:
10 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

hbrackel: 100

pramanj: 86

ibrahim: 70

kapsl: 57

gjevremovic: 49

TimK: 41

Fransua33: 39

fred: 37

Rainer Versteeg: 32

Thomas Reuther: 26

Member Stats:

Guest Posters: 0

Members: 1058

Moderators: 14

Admins: 1

Forum Stats:

Groups: 3

Forums: 14

Topics: 981

Posts: 4145

Newest Members:

mats989, Sebastien Petitrenaud, sting2005, Ron Hoppe, Seb, p.devito, g.ilengo, MohamedLazrek, brittr83165991, martintinsley9

Moderators: Jouni Aro: 846, Otso Palonen: 32, Tuomas Hiltunen: 5, janimakela: 0, Pyry: 1, Terho: 0, Petri: 0, Bjarne Boström: 523, Heikki Tahvanainen: 402, Jukka Asikainen: 1, Teppo Uimonen: 20, Markus Johansson: 18, Matti Siponen: 31, Lusetti: 0

Administrators: admin: 0