Skip to content

Commit a14947e

Browse files
committed
XrdApps::JCache make dir listing an asynchronous function with a handler
1 parent 444320a commit a14947e

File tree

5 files changed

+125
-20
lines changed

5 files changed

+125
-20
lines changed

src/XrdApps.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ add_library(
230230
XrdApps/XrdClJCachePlugin/system/XrdClJCacheSystem.cc
231231
XrdApps/XrdClJCachePlugin/vector/XrdClVectorCache.cc
232232
XrdApps/XrdClJCachePlugin/vector/XrdClVectorCache.hh
233+
XrdApps/XrdClJCachePlugin/handler/XrdClJCacheDirListHandler.cc
233234
XrdApps/XrdClJCachePlugin/handler/XrdClJCacheOpenHandler.cc
234235
XrdApps/XrdClJCachePlugin/handler/XrdClJCacheOpenHandler.hh
235236
XrdApps/XrdClJCachePlugin/handler/XrdClJCacheReadHandler.hh
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//------------------------------------------------------------------------------
2+
// Copyright (c) 2024 by European Organization for Nuclear Research (CERN)
3+
// Author: Andreas-Joachim Peters <[email protected]>
4+
//------------------------------------------------------------------------------
5+
// This file is part of the XRootD software suite.
6+
//
7+
// XRootD is free software: you can redistribute it and/or modify
8+
// it under the terms of the GNU Lesser General Public License as published by
9+
// the Free Software Foundation, either version 3 of the License, or
10+
// (at your option) any later version.
11+
//
12+
// XRootD is distributed in the hope that it will be useful,
13+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
// GNU General Public License for more details.
16+
//
17+
// You should have received a copy of the GNU Lesser General Public License
18+
// along with XRootD. If not, see <http://www.gnu.org/licenses/>.
19+
//
20+
// In applying this licence, CERN does not waive the privileges and immunities
21+
// granted to it by virtue of its status as an Intergovernmental Organization
22+
// or submit itself to any jurisdiction.
23+
24+
/*----------------------------------------------------------------------------*/
25+
26+
/*----------------------------------------------------------------------------*/
27+
#include "handler/XrdClJCacheDirListHandler.hh"
28+
#include "file/XrdClJCacheFile.hh"
29+
#include "system/XrdClJCacheSystem.hh"
30+
#include <iostream>
31+
/*----------------------------------------------------------------------------*/
32+
33+
namespace XrdCl {
34+
// ---------------------------------------------------------------------- //
35+
void JCacheDirListHandler::HandleResponse(XrdCl::XRootDStatus *pStatus, XrdCl::AnyObject *pResponse) {
36+
std::cerr << "Handling DirList Response ..." << mPath << std::endl;
37+
if (pStatus->IsOK()) {
38+
if (pResponse) {
39+
// save the listing
40+
std::cerr << "Saving DirList: " << mPath << std::endl;
41+
XrdCl::DirectoryList* lList;
42+
pResponse->Get(lList);
43+
pSystem->SaveDirList(mPath, lList);
44+
} else {
45+
std::cerr << "Failed Listing: " << mPath << std::endl;
46+
}
47+
} else {
48+
std::cerr << "Failed Listing: " << mPath << std::endl;
49+
}
50+
mHandler->HandleResponse(pStatus, pResponse);
51+
}
52+
53+
} // namespace XrdCl
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//------------------------------------------------------------------------------
2+
// Copyright (c) 2024 by European Organization for Nuclear Research (CERN)
3+
// Author: Andreas-Joachim Peters <[email protected]>
4+
//------------------------------------------------------------------------------
5+
// This file is part of the XRootD software suite.
6+
//
7+
// XRootD is free software: you can redistribute it and/or modify
8+
// it under the terms of the GNU Lesser General Public License as published by
9+
// the Free Software Foundation, either version 3 of the License, or
10+
// (at your option) any later version.
11+
//
12+
// XRootD is distributed in the hope that it will be useful,
13+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
// GNU General Public License for more details.
16+
//
17+
// You should have received a copy of the GNU Lesser General Public License
18+
// along with XRootD. If not, see <http://www.gnu.org/licenses/>.
19+
//
20+
// In applying this licence, CERN does not waive the privileges and immunities
21+
// granted to it by virtue of its status as an Intergovernmental Organization
22+
// or submit itself to any jurisdiction.
23+
24+
#pragma once
25+
/*----------------------------------------------------------------------------*/
26+
#include "XrdCl/XrdClFile.hh"
27+
#include "XrdCl/XrdClXRootDResponses.hh"
28+
/*----------------------------------------------------------------------------*/
29+
30+
/*----------------------------------------------------------------------------*/
31+
32+
namespace XrdCl {
33+
34+
class JCacheSystem;
35+
36+
class JCacheDirListHandler : public XrdCl::ResponseHandler
37+
// ---------------------------------------------------------------------- //
38+
{
39+
public:
40+
JCacheDirListHandler() {}
41+
JCacheDirListHandler(XrdCl::ResponseHandler *handler, JCacheSystem *system,
42+
const std::string &path)
43+
: mHandler(handler), pSystem(system), mPath(path) {}
44+
45+
virtual ~JCacheDirListHandler() {}
46+
47+
void HandleResponse(XrdCl::XRootDStatus *pStatus,
48+
XrdCl::AnyObject *pResponse);
49+
50+
private:
51+
XrdCl::ResponseHandler *mHandler;
52+
JCacheSystem *pSystem;
53+
std::string mPath;
54+
};
55+
56+
} // namespace XrdCl

src/XrdApps/XrdClJCachePlugin/system/XrdClJCacheSystem.cc

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "system/XrdClJCacheSystem.hh"
2525
#include "file/Hierarchy.hh"
2626
#include "file/XrdClJCacheFile.hh"
27+
#include "handler/XrdClJCacheDirListHandler.hh"
2728

2829
#include <sys/stat.h>
2930
#include <sys/types.h>
@@ -80,26 +81,15 @@ XRootDStatus JCacheSystem::DirList(const std::string &path,
8081
}
8182
// get the listing
8283

83-
XrdCl::DirectoryList *response = nullptr;
84-
AnyObject *obj = new AnyObject();
84+
auto lhandler = new JCacheDirListHandler(handler, this, ListingPath);
8585

86-
SyncResponseHandler lhandler;
87-
XRootDStatus st = pSystem->DirList(path, flags, &lhandler, timeout);
86+
std::cerr << "Creating handler for path: " << path << std::endl;
87+
XRootDStatus st = pSystem->DirList(path, flags, lhandler, timeout);
88+
std::cerr << "Command sumbitted" << std::endl;
8889
if (!st.IsOK()) {
8990
std::cerr << "error: unable to get listing: " << path << std::endl;
90-
return st;
9191
}
9292

93-
st = MessageUtils::WaitForResponse(&lhandler, response);
94-
if (!st.IsOK())
95-
return st;
96-
97-
// save the listing
98-
SaveDirList(ListingPath, response);
99-
100-
obj->Set(response);
101-
XRootDStatus *ret_st = new XRootDStatus(XRootDStatus(stOK, 0));
102-
handler->HandleResponse(ret_st, obj);
10393
return st;
10494
}
10595

src/XrdApps/XrdClJCachePlugin/system/XrdClJCacheSystem.hh

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,15 +223,20 @@ public:
223223
return pSystem->GetProperty(name, value);
224224
}
225225

226+
XrdCl::FileSystem *System() { return pSystem; }
227+
228+
bool SaveDirList(const std::string &path, DirectoryList *dirList);
229+
226230
private:
227231
XrdCl::FileSystem *pSystem;
228232
std::string mUrl;
229233

230-
DirectoryList* LoadDirList(const std::string& path);
231-
bool SaveDirList(const std::string& path, DirectoryList* dirList);
234+
DirectoryList *LoadDirList(const std::string &path);
232235

233-
std::string Serialize(const std::string& hostaddress, const std::string& name, XrdCl::StatInfo* stat);
234-
std::tuple<std::string, std::string, XrdCl::StatInfo*> Deserialize(const std::string& data);
236+
std::string Serialize(const std::string &hostaddress, const std::string &name,
237+
XrdCl::StatInfo *stat);
238+
std::tuple<std::string, std::string, XrdCl::StatInfo *>
239+
Deserialize(const std::string &data);
235240
};
236241

237-
}
242+
} // namespace XrdCl

0 commit comments

Comments
 (0)