39 XrdProofWorker::XrdProofWorker(
const char *str)
40 : fExport(256), fType(
'W'), fPort(-1), fPerfIdx(100), fNwrks(1), fActive(1)
42 fMutex =
new XrdSysRecMutex;
45 if (!str || strlen(str) <= 0)
54 XrdProofWorker::~XrdProofWorker()
62 XrdProofWorker::XrdProofWorker(
const XrdProofWorker &w)
64 fMutex =
new XrdSysRecMutex;
69 fPerfIdx = w.fPerfIdx;
71 fWorkDir = w.fWorkDir;
82 void XrdProofWorker::Reset(
const char *str)
84 XPDLOC(NMGR,
"Worker::Reset")
101 if (!str || strlen(str) <= 0)
109 XrdOucString typestr = "master|submaster|worker|slave";
110 int from = s.tokenize(tok, 0, ' ');
111 if (from == STR_NPOS || typestr.find(tok) == STR_NPOS)
113 if (tok == "submaster")
115 else if (tok == "master")
119 if ((from = s.tokenize(tok, from, ' ')) == STR_NPOS)
121 XrdClientUrlInfo ui(tok.c_str());
125 char *fullHostName = XrdSysDNS::getHostName((
char *)ui.Host.c_str(), &err);
126 if (!fullHostName || (fullHostName && !strcmp(fullHostName, "0.0.0.0"))) {
127 TRACE(XERR,
"DNS could not resolve '" << ui.Host <<
"'");
128 SafeFree(fullHostName);
131 fHost = fullHostName;
132 SafeFree(fullHostName);
134 fPort = (ui.Port > 0) ? ui.Port : fPort;
137 while ((from = s.tokenize(tok, from,
' ')) != STR_NPOS) {
138 if (tok.beginswith(
"workdir=")) {
140 tok.replace(
"workdir=",
"");
142 }
else if (tok.beginswith(
"image=")) {
144 tok.replace(
"image=",
"");
146 }
else if (tok.beginswith(
"msd=")) {
148 tok.replace(
"msd=",
"");
150 }
else if (tok.beginswith(
"port=")) {
152 tok.replace(
"port=",
"");
153 fPort = strtol(tok.c_str(), (
char **)0, 10);
154 }
else if (tok.beginswith(
"perf=")) {
156 tok.replace(
"perf=",
"");
157 fPerfIdx = strtol(tok.c_str(), (
char **)0, 10);
158 }
else if (!tok.beginswith(
"repeat=")) {
160 TRACE(XERR,
"ignoring unknown option '" << tok <<
"'");
169 bool XrdProofWorker::Matches(
const char *host)
171 return ((fHost.matches(host)) ? 1 : 0);
177 bool XrdProofWorker::Matches(XrdProofWorker *wrk)
185 if (wrk->fHost == fHost) {
187 int pa = (fPort > 0) ? fPort : XPD_DEF_PORT;
188 int pb = (wrk->fPort > 0) ? wrk->fPort : XPD_DEF_PORT;
203 const char *XrdProofWorker::Export(
const char *ord)
205 XPDLOC(NMGR,
"Worker::Export")
211 if (fUser.length() > 0) {
225 if (ord && strlen(ord) > 0) {
229 }
else if (fOrd.length() > 0) {
245 if (fImage.length() > 0) {
252 if (fWorkDir.length() > 0) {
259 if (fMsd.length() > 0) {
270 TRACE(DBG,
"sending: " << fExport);
271 return fExport.c_str();
280 int XrdProofWorker::GetNActiveSessions()
283 std::list<XrdProofdProofServ *>::iterator iter;
284 XrdSysMutexHelper mhp(fMutex);
285 for (iter = fProofServs.begin(); iter != fProofServs.end(); ++iter) {
287 if ((*iter)->Status() == kXPD_running)
298 void XrdProofWorker::MergeProofServs(
const XrdProofWorker &other)
300 std::list<XrdProofdProofServ *>::const_iterator iter;
301 XrdSysMutexHelper mhp(fMutex);
302 for (iter = other.fProofServs.begin(); iter != other.fProofServs.end(); ++iter) {
303 this->fProofServs.push_back(*iter);
313 void XrdProofWorker::Sort(std::list<XrdProofWorker *> *lst,
314 bool (*f)(XrdProofWorker *&lhs, XrdProofWorker *&rhs))
325 XrdProofWorker **ta =
new XrdProofWorker *[lst->size() - 1];
326 std::list<XrdProofWorker *>::iterator i = lst->begin();
329 for (; i != lst->end(); ++i)
333 XrdProofWorker *tmp = 0;
339 if (f(ta[j], ta[j+1]))
347 XPDSWAP(ta[j], ta[j+1], tmp);
350 if (!f(ta[k], ta[k-1])) {
351 XPDSWAP(ta[k], ta[k-1], tmp);
361 XrdProofWorker *mst = lst->front();
367 lst->push_back(ta[n]);