Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Friends | List of all members
KM3NETDAQ::JClient Class Reference

Client data structure. More...

#include <JClient.hh>

Public Types

enum  JMode {
  UNKNOWN = -1, SLEEP = 0, ACTIVE, IGNORE = -2,
  ILLEGAL = -3
}
 Client modi. More...
 

Public Member Functions

 JClient ()
 Default constructor. More...
 
 JClient (const std::string &__name, const std::string &__hostname, const std::string &__start_command="")
 Constructor. More...
 
void start ()
 Start process. More...
 
void stop (const int signal=-9)
 Stop process. More...
 
const std::string & getName () const
 Get name of run control client. More...
 
const std::string & getHostname () const
 Get host name of run control client. More...
 
const std::string & getFullName () const
 Get full name of run control client. More...
 
const std::string & getStartCommand () const
 Get start command of run control client. More...
 
bool isSleep () const
 Check sleep mode. More...
 
bool isActive () const
 Check active mode. More...
 
bool isIgnore () const
 Check ignore mode. More...
 
bool isIllegal () const
 Check illegal mode. More...
 
bool update (const JNET::JTag &tag, const std::string &buffer)
 Update client. More...
 
const std::string & getStatename () const
 Get name of current state. More...
 
const std::string & getEventname () const
 Get name of last event. More...
 
int getEventnumber () const
 Get number of last event. More...
 
bool getAlive () const
 Get alive status. More...
 
void setAlive (const bool alive)
 Set alive status. More...
 
JMode getMode () const
 Get mode. More...
 
void setMode (const JMode mode)
 Set mode. More...
 
int getBorn () const
 Get born count. More...
 
int getDied () const
 Get died count. More...
 

Static Public Attributes

static std::string SERVER
 host name of message server More...
 
static std::string LOGGER
 host name of message logger More...
 

Protected Member Functions

void configure ()
 Configure client parameters. More...
 

Protected Attributes

std::string name
 
std::string hostname
 
JLANG::JString start_command
 
std::string full_name
 
JMode mode
 
int born
 
int died
 
bool is_alive
 
std::string state_name
 
std::string event_name
 
int event_number
 

Friends

std::istream & operator>> (std::istream &in, JClient &client)
 Read client from input. More...
 
std::ostream & operator<< (std::ostream &out, const JClient &client)
 Write client to output. More...
 

Detailed Description

Client data structure.

Definition at line 27 of file JClient.hh.

Member Enumeration Documentation

Client modi.

Enumerator
UNKNOWN 
SLEEP 
ACTIVE 
IGNORE 
ILLEGAL 

Definition at line 38 of file JClient.hh.

Constructor & Destructor Documentation

KM3NETDAQ::JClient::JClient ( )
inline

Default constructor.

Definition at line 44 of file JClient.hh.

44  :
45  name (),
46  hostname (),
47  start_command(),
48  mode(UNKNOWN),
49  born(0),
50  died(0),
51  is_alive(false),
52  state_name("?"),
53  event_name("?"),
54  event_number(-1)
55  {}
std::string name
Definition: JClient.hh:485
std::string event_name
Definition: JClient.hh:494
JLANG::JString start_command
Definition: JClient.hh:487
std::string state_name
Definition: JClient.hh:493
std::string hostname
Definition: JClient.hh:486
KM3NETDAQ::JClient::JClient ( const std::string &  __name,
const std::string &  __hostname,
const std::string &  __start_command = "" 
)
inline

Constructor.

Parameters
__namename of client
__hostnamehost name
__start_commandstart command

Definition at line 65 of file JClient.hh.

67  :
68  name (__name),
69  hostname (__hostname),
70  start_command(__start_command),
71  mode(UNKNOWN),
72  born(0),
73  died(0),
74  is_alive(false),
75  state_name("?"),
76  event_name("?"),
77  event_number(-1)
78  {
79  configure();
80  }
std::string name
Definition: JClient.hh:485
std::string event_name
Definition: JClient.hh:494
JLANG::JString start_command
Definition: JClient.hh:487
std::string state_name
Definition: JClient.hh:493
void configure(const T &value, const JAbstractCollection< JAbscissa_t > &bounds, JBool< false > option)
Configuration of value.
std::string hostname
Definition: JClient.hh:486

Member Function Documentation

void KM3NETDAQ::JClient::start ( )
inline

Start process.

The start command is issued on the (remote) host.

Definition at line 87 of file JClient.hh.

88  {
89  using JSYSTEM::JShell;
90 
91  if (start_command != "") {
92 
93  JShell& shell = JShell::getInstance();
94 
95  shell << start_command << std::endl;
96  shell.flush();
97  }
98  }
The JShell clas can be used to interact with the shell via I/O streams.
Definition: JShell.hh:32
JLANG::JString start_command
Definition: JClient.hh:487
static JShell & getInstance()
Get reference to unique instance of this class object.
Definition: JShell.hh:76
void KM3NETDAQ::JClient::stop ( const int  signal = -9)
inline

Stop process.

A kill command is issued on the (remote) host. To determine the PID for the kill command, the start command is compared to the output of a ps command on the (remote) host.

Parameters
signalsignal

Definition at line 109 of file JClient.hh.

110  {
111  using namespace std;
112  using JSYSTEM::JShell;
113 
114  if (start_command != "") {
115 
116  const string header = "__header___";
117  const string trailer = "__trailer__";
118 
119  ostringstream os;
120 
121  os << "ssh " << hostname << ' '
122  << "\""
123  << "echo" << ' ' << header << ";"
124  << "ps hax -o '%p %a'" << ";"
125  << "echo" << ' ' << trailer
126  << "\"";
127 
128  JShell& shell = JShell::getInstance();
129 
130  shell << os.str() << endl;
131 
132  os.str("");
133 
134  string buffer;
135 
136  while (getline(shell, buffer) && buffer.find(header) == string::npos) {}
137 
138  istringstream is;
139 
140  while (getline(shell, buffer) && buffer.find(trailer) == string::npos) {
141 
142  is.clear();
143  is.str(buffer);
144 
145  int pid;
146 
147  if (is >> pid && getline(is >> ws, buffer)) {
148  if (start_command.find(buffer) != string::npos) {
149  os << "ssh " << hostname << ' '
150  << "\""
151  << "kill " << signal << " " << pid << " </dev/null >&/dev/null"
152  << "\"";
153  }
154  }
155  }
156 
157  shell.flush();
158 
159  if (os.str() != "") {
160  shell << os.str() << endl;
161  shell.flush();
162  }
163  }
164  }
The JShell clas can be used to interact with the shell via I/O streams.
Definition: JShell.hh:32
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition: JString.hh:468
static JShell & getInstance()
Get reference to unique instance of this class object.
Definition: JShell.hh:76
const std::string& KM3NETDAQ::JClient::getName ( ) const
inline

Get name of run control client.

Returns
name

Definition at line 172 of file JClient.hh.

173  {
174  return name;
175  }
std::string name
Definition: JClient.hh:485
const std::string& KM3NETDAQ::JClient::getHostname ( ) const
inline

Get host name of run control client.

Returns
host name

Definition at line 183 of file JClient.hh.

184  {
185  return hostname;
186  }
std::string hostname
Definition: JClient.hh:486
const std::string& KM3NETDAQ::JClient::getFullName ( ) const
inline

Get full name of run control client.

Returns
full name

Definition at line 194 of file JClient.hh.

195  {
196  return full_name;
197  }
std::string full_name
Definition: JClient.hh:488
const std::string& KM3NETDAQ::JClient::getStartCommand ( ) const
inline

Get start command of run control client.

Returns
name

Definition at line 205 of file JClient.hh.

206  {
207  return start_command;
208  }
JLANG::JString start_command
Definition: JClient.hh:487
bool KM3NETDAQ::JClient::isSleep ( ) const
inline

Check sleep mode.

Returns
true if sleep; else false

Definition at line 216 of file JClient.hh.

217  {
218  return mode == SLEEP;
219  }
bool KM3NETDAQ::JClient::isActive ( ) const
inline

Check active mode.

Returns
true if active; else false

Definition at line 227 of file JClient.hh.

228  {
229  return mode == ACTIVE;
230  }
bool KM3NETDAQ::JClient::isIgnore ( ) const
inline

Check ignore mode.

Returns
true if ignore; else false

Definition at line 238 of file JClient.hh.

239  {
240  return mode == IGNORE;
241  }
bool KM3NETDAQ::JClient::isIllegal ( ) const
inline

Check illegal mode.

Returns
true if illegal; else false

Definition at line 249 of file JClient.hh.

250  {
251  return mode == ILLEGAL;
252  }
bool KM3NETDAQ::JClient::update ( const JNET::JTag tag,
const std::string &  buffer 
)
inline

Update client.

The client parameters are updated according to the ControlHost tag and message.

Parameters
tagtag
buffermessage
Returns
true if OK; else false

Definition at line 263 of file JClient.hh.

264  {
265  using namespace std;
267 
268  if (tag == JNET::DISPTAG_Born) {
269 
270  this->is_alive = true;
271  this->born += 1;
272 
273  return true;
274 
275  } else if (tag == JNET::DISPTAG_Died) {
276 
277  this->is_alive = false;
278  this->died += 1;
279 
280  return true;
281 
282  } else if (tag == RC_REPLY) {
283 
284  string key;
285  string ip;
286  string name;
287  JEvent_t event;
288  string state;
289 
290  istringstream is(buffer);
291 
292  const locale loc(is.getloc(), new JWhiteSpacesFacet(is.getloc(), TOKEN_DELIMETER));
293 
294  is.imbue(loc);
295 
296  if (is >> key >> ip >> name >> event >> state && key == RUN_CONTROL_CLIENT) {
297 
298  this->event_name = event.getName();
299  this->event_number = event.getNumber();
300  this->state_name = state;
301 
302  return true;
303  }
304  }
305 
306  return false;
307  }
static const JTag DISPTAG_Died("Died")
Structure to store the ToT mean and standard deviation of the hits produced by a nanobeacon in a sour...
static const std::string TOKEN_DELIMETER
Definition: JDAQTags.hh:36
static const std::string RUN_CONTROL_CLIENT
Definition: JDAQTags.hh:22
static const JNET::JTag RC_REPLY
Definition: JDAQTags.hh:45
static const JTag DISPTAG_Born("Born")
Auxiliary class to specify white space character(s) in currect locale.
const std::string& KM3NETDAQ::JClient::getStatename ( ) const
inline

Get name of current state.

Returns
state name

Definition at line 315 of file JClient.hh.

316  {
317  return state_name;
318  }
std::string state_name
Definition: JClient.hh:493
const std::string& KM3NETDAQ::JClient::getEventname ( ) const
inline

Get name of last event.

Returns
event name

Definition at line 326 of file JClient.hh.

327  {
328  return event_name;
329  }
std::string event_name
Definition: JClient.hh:494
int KM3NETDAQ::JClient::getEventnumber ( ) const
inline

Get number of last event.

Returns
event number

Definition at line 337 of file JClient.hh.

338  {
339  return event_number;
340  }
bool KM3NETDAQ::JClient::getAlive ( ) const
inline

Get alive status.

Returns
true if alive; else false

Definition at line 348 of file JClient.hh.

349  {
350  return is_alive;
351  }
void KM3NETDAQ::JClient::setAlive ( const bool  alive)
inline

Set alive status.

Parameters
alivealive

Definition at line 359 of file JClient.hh.

360  {
361  is_alive = alive;
362  }
JMode KM3NETDAQ::JClient::getMode ( ) const
inline

Get mode.

Returns
mode

Definition at line 370 of file JClient.hh.

371  {
372  return mode;
373  }
void KM3NETDAQ::JClient::setMode ( const JMode  mode)
inline

Set mode.

Parameters
modemode

Definition at line 381 of file JClient.hh.

382  {
383  this->mode = mode;
384  }
int KM3NETDAQ::JClient::getBorn ( ) const
inline

Get born count.

Returns
number of times born

Definition at line 392 of file JClient.hh.

393  {
394  return born;
395  }
int KM3NETDAQ::JClient::getDied ( ) const
inline

Get died count.

Returns
number of times died

Definition at line 403 of file JClient.hh.

404  {
405  return died;
406  }
void KM3NETDAQ::JClient::configure ( )
inlineprotected

Configure client parameters.

In this, the following tokens in the start command are substituted: $HOST$ by <host name>; $NAME$ by <process name>; $SERVER$ by JClient::SERVER; $LOGGER$ by JClient::LOGGER; $ARGS$ by part following last '/' in <process name>;

Definition at line 463 of file JClient.hh.

464  {
465  using std::string;
466 
467  full_name = KM3NETDAQ::getFullName(hostname, name);
468 
470  start_command = start_command.replace(" ", " ");
471 
472  start_command.replace("$HOST$", hostname);
473  start_command.replace("$NAME$", name);
474  start_command.replace("$SERVER$", SERVER);
475  start_command.replace("$LOGGER$", LOGGER);
476 
477  string::size_type pos = name.find_last_of(CLIENTNAME_DELIMETER);
478 
479  if (pos != string::npos) {
480  start_command.replace("$ARGS$", name.substr(pos + 1));
481  }
482  }
std::string name
Definition: JClient.hh:485
std::string full_name
Definition: JClient.hh:488
JLANG::JString start_command
Definition: JClient.hh:487
JString & trim()
Trim string.
Definition: JString.hh:248
static const std::string CLIENTNAME_DELIMETER
Definition: JDAQTags.hh:37
JString & replace(const char target, const char replacement, const std::size_t max=std::numeric_limits< std::size_t >::max())
Replace characters.
Definition: JString.hh:189
std::string getFullName(const std::string &hostname, const std::string &name)
Get full name of run control client.

Friends And Related Function Documentation

std::istream& operator>> ( std::istream &  in,
JClient client 
)
friend

Read client from input.

Parameters
inistream
clientclient
Returns
istream

Definition at line 416 of file JClient.hh.

417  {
418  in >> client.name;
419  in >> client.hostname;
420 
421  if (in) {
422 
423  getline(in >> std::ws, client.start_command);
424 
425  in.clear(); // clear error state of input stream if no start command is available.
426 
427  client.configure();
428  }
429 
430  return in;
431  }
JSocketInputChannel_t in
reader for incoming messages
Definition: JLigier.cc:437
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition: JString.hh:468
virtual void clear()
Clear status of reader.
std::ostream& operator<< ( std::ostream &  out,
const JClient client 
)
friend

Write client to output.

Parameters
outostream
clientclient
Returns
ostream

Definition at line 441 of file JClient.hh.

442  {
443  out << client.name;
444  out << ' ';
445  out << client.hostname;
446  out << ' ';
447  out << client.start_command;
448 
449  return out;
450  }
JSocketNonblockingWriter out
writer for outgoing messages
Definition: JLigier.cc:438

Member Data Documentation

std::string KM3NETDAQ::JClient::SERVER
static

host name of message server

Author
mdejonghost name of message server

Definition at line 31 of file JClient.hh.

std::string KM3NETDAQ::JClient::LOGGER
static

host name of message logger

Definition at line 32 of file JClient.hh.

std::string KM3NETDAQ::JClient::name
protected

Definition at line 485 of file JClient.hh.

std::string KM3NETDAQ::JClient::hostname
protected

Definition at line 486 of file JClient.hh.

JLANG::JString KM3NETDAQ::JClient::start_command
protected

Definition at line 487 of file JClient.hh.

std::string KM3NETDAQ::JClient::full_name
protected

Definition at line 488 of file JClient.hh.

JMode KM3NETDAQ::JClient::mode
protected

Definition at line 489 of file JClient.hh.

int KM3NETDAQ::JClient::born
protected

Definition at line 490 of file JClient.hh.

int KM3NETDAQ::JClient::died
protected

Definition at line 491 of file JClient.hh.

bool KM3NETDAQ::JClient::is_alive
protected

Definition at line 492 of file JClient.hh.

std::string KM3NETDAQ::JClient::state_name
protected

Definition at line 493 of file JClient.hh.

std::string KM3NETDAQ::JClient::event_name
protected

Definition at line 494 of file JClient.hh.

int KM3NETDAQ::JClient::event_number
protected

Definition at line 495 of file JClient.hh.


The documentation for this class was generated from the following files: